A project to implement a console using the Mbed using VGA for video output and a PS/2 keyboard for the input. The eventual goal is to also include tools for managing SD cards, and a semi-self-hosting programming environment.
Dependencies: PS2_MbedConsole fastlib SDFileSystem vga640x480g_mbedconsole lightvm mbed
plEarlz.h
00001 /* 00002 <Copyright Header> 00003 Copyright (c) 2012 Jordan "Earlz" Earls <http://lastyearswishes.com> 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions 00008 are met: 00009 00010 1. Redistributions of source code must retain the above copyright 00011 notice, this list of conditions and the following disclaimer. 00012 2. Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 3. The name of the author may not be used to endorse or promote products 00016 derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 00019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00021 THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00022 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00023 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00024 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00025 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00026 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00027 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 00029 This file is part of the MbedConsole project 00030 */ 00031 00032 #ifndef PLEARLZ_H 00033 #define PLEARLZ_H 00034 00035 #define MAXSTACK 64 00036 #define MAXTEMPSTACK 64 00037 #define MAXLINELENGTH 128 00038 #define DICTIONARYSTEP 4 //how much memory to reserve when doing a reallocation for resizing 00039 #define CODEBLOCKSTEP 16 00040 00041 enum ErrorType 00042 { 00043 None, 00044 StackOverflow, 00045 StackUnderflow 00046 }; 00047 00048 //arguments are in the bytecode, not the stack! But, things like Add has no arguments and uses the stack 00049 //pointers are assumed 32-bit? 00050 enum Opcode 00051 { 00052 BranchTrue, //argument is 16 bit vaddress 00053 BranchFalse, //argument is 16bit vaddress 00054 Branch, 00055 PushTemp, //pops from stack and pushes onto the temporary stack 00056 PopTemp, //pushes onto stack from temporary stack 00057 Push, //argument is 32bit number 00058 Drop, //trashes top value on stack 00059 Call, //call. argument is WORD entry pointer in dictionary 00060 CallInt, //call internal argument is function pointer 00061 Add, 00062 Sub, 00063 Mul, 00064 Div, 00065 Mod, 00066 Cgt, //takes two integers and compares for greater than pushes 1 if so, 0 if not 00067 Clt, //less than 00068 Cgte, //greater than or equal 00069 Clte, 00070 Ceq, 00071 Cneq, 00072 LoadStr, //argument is variable length string ending with 0. Pushes address onto stack 00073 LoadConst, //pushes the value pointed to by the argument 00074 StoreConst, //pops a value and stores it in the memory pointed to by the argument 00075 Load, //same as above, except the address is popped first. 00076 Store, 00077 Swap, 00078 New, //pushes a pointer to free memory for an integer 00079 NewVar, //pushes a pointer to memory. Size is specified by argument 00080 Delete, //pops a pointer and frees it. 00081 Pick, //takes an integer position from the stack. Goes that many slots back in the stack and peeks at the value, and then pushes it on the top of the stack 00082 Ret //exit 00083 }; 00084 00085 typedef void (*BuiltinFunction)(void); 00086 typedef struct 00087 { 00088 char name[12]; 00089 enum Type{ 00090 Constant, 00091 ConstantString, 00092 Builtin, 00093 Function 00094 } type; 00095 union valueunion{ 00096 int intvalue; 00097 BuiltinFunction builtin; 00098 char *string; 00099 } value; 00100 } WordKey; 00101 00102 /** 00103 BranchTarget tracks branches/labels. 00104 When a beginning conditional/looping structure is found, it adds a branch target to the list with `target` set to point to the relevant branch target in codeblock 00105 When an ending structure is found, it replaces the branch target(which starts at -1) with the actual branch address, 00106 **/ 00107 typedef struct TargetNode 00108 { 00109 int target; //position inside of codeblock. Can't use pointers because life is cruel and the block could be reallocated at anytime. 00110 TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse 00111 } BranchTarget; 00112 00113 extern ErrorType pl_error; 00114 00115 int pl_shell(); 00116 00117 static inline int is_whitespace(char c){ 00118 return (c==' ') || (c=='\t') || (c=='\n') || (c=='\r'); 00119 } 00120 00121 static inline int is_numeric(char c){ 00122 return (c>='0') && (c<='9'); 00123 } 00124 00125 static inline int is_alpha(char c){ 00126 return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')); 00127 } 00128 00129 static inline int is_identifier(char c){ 00130 return is_alpha(c) || is_numeric(c) || (c=='_'); 00131 } 00132 00133 static inline int is_quote(char c){ 00134 return (c=='\"') || (c=='\''); 00135 } 00136 int forth_execute(uint8_t* block, int length); 00137 WordKey *pl_lookup(char* name); 00138 int pl_pop(); 00139 void pl_push(int val); 00140 00141 00142 00143 //builtin functions 00144 void bi_print(); 00145 00146 00147 #endif
Generated on Sun Jul 17 2022 09:10:09 by 1.7.2