diff --git a/CMakeLists.txt b/.old/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to .old/CMakeLists.txt diff --git a/src/assembler/as_exceptions.hh b/.old/src/assembler/as_exceptions.hh similarity index 100% rename from src/assembler/as_exceptions.hh rename to .old/src/assembler/as_exceptions.hh diff --git a/src/assembler/assembler.cc b/.old/src/assembler/assembler.cc similarity index 100% rename from src/assembler/assembler.cc rename to .old/src/assembler/assembler.cc diff --git a/src/assembler/assembler.hh b/.old/src/assembler/assembler.hh similarity index 100% rename from src/assembler/assembler.hh rename to .old/src/assembler/assembler.hh diff --git a/src/assembler/lexer.cc b/.old/src/assembler/lexer.cc similarity index 100% rename from src/assembler/lexer.cc rename to .old/src/assembler/lexer.cc diff --git a/src/assembler/lexer.hh b/.old/src/assembler/lexer.hh similarity index 100% rename from src/assembler/lexer.hh rename to .old/src/assembler/lexer.hh diff --git a/src/assembler/tests.cc b/.old/src/assembler/tests.cc similarity index 100% rename from src/assembler/tests.cc rename to .old/src/assembler/tests.cc diff --git a/src/bytecode/bc_exceptions.hh b/.old/src/bytecode/bc_exceptions.hh similarity index 100% rename from src/bytecode/bc_exceptions.hh rename to .old/src/bytecode/bc_exceptions.hh diff --git a/src/bytecode/bytecode.cc b/.old/src/bytecode/bytecode.cc similarity index 100% rename from src/bytecode/bytecode.cc rename to .old/src/bytecode/bytecode.cc diff --git a/src/bytecode/bytecode.hh b/.old/src/bytecode/bytecode.hh similarity index 100% rename from src/bytecode/bytecode.hh rename to .old/src/bytecode/bytecode.hh diff --git a/src/bytecode/bytecodeprototype.hh b/.old/src/bytecode/bytecodeprototype.hh similarity index 100% rename from src/bytecode/bytecodeprototype.hh rename to .old/src/bytecode/bytecodeprototype.hh diff --git a/src/bytecode/constant.hh b/.old/src/bytecode/constant.hh similarity index 100% rename from src/bytecode/constant.hh rename to .old/src/bytecode/constant.hh diff --git a/src/bytecode/tests.cc b/.old/src/bytecode/tests.cc similarity index 100% rename from src/bytecode/tests.cc rename to .old/src/bytecode/tests.cc diff --git a/src/common/bytearray.cc b/.old/src/common/bytearray.cc similarity index 100% rename from src/common/bytearray.cc rename to .old/src/common/bytearray.cc diff --git a/src/common/bytearray.hh b/.old/src/common/bytearray.hh similarity index 100% rename from src/common/bytearray.hh rename to .old/src/common/bytearray.hh diff --git a/src/common/overloaded.hh b/.old/src/common/overloaded.hh similarity index 100% rename from src/common/overloaded.hh rename to .old/src/common/overloaded.hh diff --git a/src/vm/code.cc b/.old/src/vm/code.cc similarity index 100% rename from src/vm/code.cc rename to .old/src/vm/code.cc diff --git a/src/vm/code.hh b/.old/src/vm/code.hh similarity index 100% rename from src/vm/code.hh rename to .old/src/vm/code.hh diff --git a/src/vm/expr.cc b/.old/src/vm/expr.cc similarity index 100% rename from src/vm/expr.cc rename to .old/src/vm/expr.cc diff --git a/src/vm/expr.hh b/.old/src/vm/expr.hh similarity index 100% rename from src/vm/expr.hh rename to .old/src/vm/expr.hh diff --git a/src/vm/instruction.cc b/.old/src/vm/instruction.cc similarity index 100% rename from src/vm/instruction.cc rename to .old/src/vm/instruction.cc diff --git a/src/vm/instruction.hh b/.old/src/vm/instruction.hh similarity index 100% rename from src/vm/instruction.hh rename to .old/src/vm/instruction.hh diff --git a/src/vm/location.hh b/.old/src/vm/location.hh similarity index 100% rename from src/vm/location.hh rename to .old/src/vm/location.hh diff --git a/src/vm/stack.cc b/.old/src/vm/stack.cc similarity index 100% rename from src/vm/stack.cc rename to .old/src/vm/stack.cc diff --git a/src/vm/stack.hh b/.old/src/vm/stack.hh similarity index 100% rename from src/vm/stack.hh rename to .old/src/vm/stack.hh diff --git a/src/vm/tests.cc b/.old/src/vm/tests.cc similarity index 100% rename from src/vm/tests.cc rename to .old/src/vm/tests.cc diff --git a/src/vm/value.cc b/.old/src/vm/value.cc similarity index 100% rename from src/vm/value.cc rename to .old/src/vm/value.cc diff --git a/src/vm/value.hh b/.old/src/vm/value.hh similarity index 100% rename from src/vm/value.hh rename to .old/src/vm/value.hh diff --git a/src/vm/vm.cc b/.old/src/vm/vm.cc similarity index 100% rename from src/vm/vm.cc rename to .old/src/vm/vm.cc diff --git a/src/vm/vm.hh b/.old/src/vm/vm.hh similarity index 100% rename from src/vm/vm.hh rename to .old/src/vm/vm.hh diff --git a/src/vm/vm_exceptions.hh b/.old/src/vm/vm_exceptions.hh similarity index 100% rename from src/vm/vm_exceptions.hh rename to .old/src/vm/vm_exceptions.hh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/TODO.md b/TODO.md index e695e00..f7d3955 100644 --- a/TODO.md +++ b/TODO.md @@ -1,65 +1,52 @@ -## Bytecode +## C -- [x] Byte array - - Auto-expand - - Add/retrive byte/int/float/string - - Should not be larger than the byte array itself -- [x] Bytecode - - Add/retrive all types of data - - Keeps no memory except for caching - - [x] Refactor bytecode code +Decisions: + - How to handle errors + - How values and heap values will be represented + - Transparency and log levels -Improvements: -- [x] Fixed int type (based on opcode) -- [x] Constant type (only floats and strings for now) - -After some additional development: -- [ ] Bytecode debugging info - - -## VM - -- [x] VM - - [x] Code - - [x] Simple bytecode loader - - [x] Output bytecode format - - [x] Value object - - [x] Stack object - - [x] External interface - - [x] Code execution (except functions) - - [x] Functions - - [x] Print stack -- [x] Assembler -- [ ] VM execution - - [x] Stack operations (nil, integer, float, string, function) - - [x] Integer - - [x] Float - - [x] String - - [x] Expressions - - [x] Integer - - [x] Float - - [x] String - - [ ] Local/global variables +- [ ] Makefile +- [ ] Value and stack value +- [ ] Stack + - [ ] Test application (C++?) +- [ ] Heap +- [ ] VM + - [ ] (Lua interface) call assembler + - [ ] (Lua) generate bytecode + - [ ] Labels + - [ ] Code + - [ ] Interpret bytecode (fast) + - [ ] Execution loop (fast) +- [ ] VM operations + - [ ] Expressions + - [ ] Local variables - [ ] Functions - - [ ] Constants - - [ ] Other operations - - [ ] Arrays - - [ ] Iteration - - [ ] Expressions - - [ ] Tables - - [ ] Iteration - - [ ] Metatables - - [ ] Expressions + - [ ] With parameters - [ ] Control flow - - [ ] Compilation + - [ ] Recursion + - [ ] Strings + - [ ] From constants + - [ ] Garbage collection + - [ ] Arrays + - [ ] Garbage collection + - [ ] Tables + - [ ] Garbage collection + - [ ] Metatables + - [ ] Iteration + - [ ] Floats (real) + - [ ] Globals (?) - [ ] Error handling -- [ ] C++ API - - [ ] Run native code on VM - - [ ] Run tyche code from C++ - - [ ] C API + - [ ] Stack trace in case of errors + - [ ] Closure/upvalues + - [ ] Rest of opcodes +- [ ] Prepare for release + - [ ] Documentation and webpage -After some additional development: -- [ ] Bytecode loader - - Combine multiple chunks - - Resolve function ids, constant ids, etc -- [ ] Upvalues \ No newline at end of file +## Future versions + +- [ ] Debugging information +- [ ] Debugger +- [ ] Dynamic language +- [ ] Support tools + - [ ] Editor syntax file, etc +- [ ] Static language diff --git a/doc/OPCODES b/doc/OPCODES index 764758b..41828c9 100644 --- a/doc/OPCODES +++ b/doc/OPCODES @@ -22,12 +22,13 @@ Stack operations: a0 c0 e0 pushi [int] Push int a1 c1 e1 pushc [index] Push constant a2 c2 e2 pushf [function] Push function id -00 pushz Push zero (or false) -01 pusht Push true -02 newa Push (create) empty array -03 newt Push (create) empty table -04 pop -05 dup +00 pushn Push nil +01 pushz Push zero (or false) +02 pusht Push true +03 newa Push (create) empty array +04 newt Push (create) empty table +05 pop +06 dup Local variables: a3 c3 e3 pushv [int] Push n nil values into the stack (used to init local vars) @@ -44,12 +45,12 @@ Function operations: Table and array operations: 16 getkv Get table's value based on key (pull 1 value, push 1 value) 17 setkv Set table's key and value (pull 2 values from stack) -18 geta Get array's position value -19 seta Set array's position value (pull 2 values from stack) -1a appnd Add value to the end of array -1b next Push the next pair into the stack (for loops) -1c smt Set value metatable -1d mt Get value metatable + a8 c8 e8 geti Get array's position value + a9 c9 e9 seti Set array's position value +18 appnd Add value to the end of array +19 next Push the next pair into the stack (for loops) +1a smt Set value metatable +1b mt Get value metatable Logical/arithmetic: 20 sum Sum top 2 values in stack @@ -57,24 +58,24 @@ Logical/arithmetic: 22 mul Multiply top 2 values in stack 23 div Float division 24 idiv Integer division -25 eq Equality -26 neq Inequality -27 lt Less than -28 lte Less than or equals -29 gt Greater than -2a gte Greater than or equals -2b and Bitwise AND -2c or Bitwise OR -2d xor Bitwise XOR -2e pow Power -2f shl Shift left -30 shr Shift right -31 mod Modulo +25 mod Modulo +26 eq Equality +27 neq Inequality +28 lt Less than +29 lte Less than or equals +2a gt Greater than +2b gte Greater than or equals +2c and Bitwise AND +2d or Bitwise OR +2e xor Bitwise XOR +2f pow Power +30 shl Shift left +31 shr Shift right Other value operations: 40 len Get table, array or string size 41 type Get type from value at the top of the stack - b0 cast [type] Cast type to another type + aa cast [type] Cast type to another type 42 ver Return VM version External code: @@ -82,12 +83,14 @@ External code: 49 asmbl Assemble code to bytecode format 4a load Load bytecode as function (will place function on stack) -Control flow: - a8 c8 e8 bz [pc] Branch if zero - a9 c9 e9 bnz [pc] Branch if not zero - aa ca ea jmp [pc] Unconditional jump +Control flow (the destination is always a 16-bit field): + ca bz [pc] Branch if zero + cb bnz [pc] Branch if not zero + cc jmp [pc] Unconditional jump * Jumps can only happen within the same function. +Memory management: +4b gc Call garbage collector Error handling: (0xa0~0xaf) ???