This commit is contained in:
2026-05-10 07:53:28 -05:00
parent 9561d5cacd
commit 1b53c813b4
34 changed files with 79 additions and 89 deletions

0
Makefile Normal file
View File

105
TODO.md
View File

@@ -1,65 +1,52 @@
## Bytecode ## C
- [x] Byte array Decisions:
- Auto-expand - How to handle errors
- Add/retrive byte/int/float/string - How values and heap values will be represented
- Should not be larger than the byte array itself - Transparency and log levels
- [x] Bytecode
- Add/retrive all types of data
- Keeps no memory except for caching
- [x] Refactor bytecode code
Improvements: - [ ] Makefile
- [x] Fixed int type (based on opcode) - [ ] Value and stack value
- [x] Constant type (only floats and strings for now) - [ ] Stack
- [ ] Test application (C++?)
After some additional development: - [ ] Heap
- [ ] Bytecode debugging info - [ ] VM
- [ ] (Lua interface) call assembler
- [ ] (Lua) generate bytecode
## VM - [ ] Labels
- [ ] Code
- [x] VM - [ ] Interpret bytecode (fast)
- [x] Code - [ ] Execution loop (fast)
- [x] Simple bytecode loader - [ ] VM operations
- [x] Output bytecode format - [ ] Expressions
- [x] Value object - [ ] Local variables
- [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
- [ ] Functions - [ ] Functions
- [ ] Constants - [ ] With parameters
- [ ] Other operations
- [ ] Arrays
- [ ] Iteration
- [ ] Expressions
- [ ] Tables
- [ ] Iteration
- [ ] Metatables
- [ ] Expressions
- [ ] Control flow - [ ] Control flow
- [ ] Compilation - [ ] Recursion
- [ ] Strings
- [ ] From constants
- [ ] Garbage collection
- [ ] Arrays
- [ ] Garbage collection
- [ ] Tables
- [ ] Garbage collection
- [ ] Metatables
- [ ] Iteration
- [ ] Floats (real)
- [ ] Globals (?)
- [ ] Error handling - [ ] Error handling
- [ ] C++ API - [ ] Stack trace in case of errors
- [ ] Run native code on VM - [ ] Closure/upvalues
- [ ] Run tyche code from C++ - [ ] Rest of opcodes
- [ ] C API - [ ] Prepare for release
- [ ] Documentation and webpage
After some additional development: ## Future versions
- [ ] Bytecode loader
- Combine multiple chunks - [ ] Debugging information
- Resolve function ids, constant ids, etc - [ ] Debugger
- [ ] Upvalues - [ ] Dynamic language
- [ ] Support tools
- [ ] Editor syntax file, etc
- [ ] Static language

View File

@@ -22,12 +22,13 @@ Stack operations:
a0 c0 e0 pushi [int] Push int a0 c0 e0 pushi [int] Push int
a1 c1 e1 pushc [index] Push constant a1 c1 e1 pushc [index] Push constant
a2 c2 e2 pushf [function] Push function id a2 c2 e2 pushf [function] Push function id
00 pushz Push zero (or false) 00 pushn Push nil
01 pusht Push true 01 pushz Push zero (or false)
02 newa Push (create) empty array 02 pusht Push true
03 newt Push (create) empty table 03 newa Push (create) empty array
04 pop 04 newt Push (create) empty table
05 dup 05 pop
06 dup
Local variables: Local variables:
a3 c3 e3 pushv [int] Push n nil values into the stack (used to init local vars) 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: Table and array operations:
16 getkv Get table's value based on key (pull 1 value, push 1 value) 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) 17 setkv Set table's key and value (pull 2 values from stack)
18 geta Get array's position value a8 c8 e8 geti Get array's position value
19 seta Set array's position value (pull 2 values from stack) a9 c9 e9 seti Set array's position value
1a appnd Add value to the end of array 18 appnd Add value to the end of array
1b next Push the next pair into the stack (for loops) 19 next Push the next pair into the stack (for loops)
1c smt Set value metatable 1a smt Set value metatable
1d mt Get value metatable 1b mt Get value metatable
Logical/arithmetic: Logical/arithmetic:
20 sum Sum top 2 values in stack 20 sum Sum top 2 values in stack
@@ -57,24 +58,24 @@ Logical/arithmetic:
22 mul Multiply top 2 values in stack 22 mul Multiply top 2 values in stack
23 div Float division 23 div Float division
24 idiv Integer division 24 idiv Integer division
25 eq Equality 25 mod Modulo
26 neq Inequality 26 eq Equality
27 lt Less than 27 neq Inequality
28 lte Less than or equals 28 lt Less than
29 gt Greater than 29 lte Less than or equals
2a gte Greater than or equals 2a gt Greater than
2b and Bitwise AND 2b gte Greater than or equals
2c or Bitwise OR 2c and Bitwise AND
2d xor Bitwise XOR 2d or Bitwise OR
2e pow Power 2e xor Bitwise XOR
2f shl Shift left 2f pow Power
30 shr Shift right 30 shl Shift left
31 mod Modulo 31 shr Shift right
Other value operations: Other value operations:
40 len Get table, array or string size 40 len Get table, array or string size
41 type Get type from value at the top of the stack 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 42 ver Return VM version
External code: External code:
@@ -82,12 +83,14 @@ External code:
49 asmbl Assemble code to bytecode format 49 asmbl Assemble code to bytecode format
4a load Load bytecode as function (will place function on stack) 4a load Load bytecode as function (will place function on stack)
Control flow: Control flow (the destination is always a 16-bit field):
a8 c8 e8 bz [pc] Branch if zero ca bz [pc] Branch if zero
a9 c9 e9 bnz [pc] Branch if not zero cb bnz [pc] Branch if not zero
aa ca ea jmp [pc] Unconditional jump cc jmp [pc] Unconditional jump
* Jumps can only happen within the same function. * Jumps can only happen within the same function.
Memory management:
4b gc Call garbage collector
Error handling: (0xa0~0xaf) Error handling: (0xa0~0xaf)
??? ???