.
This commit is contained in:
4
TODO.md
4
TODO.md
@@ -12,8 +12,8 @@ Decisions:
|
|||||||
- [x] Heap
|
- [x] Heap
|
||||||
- [x] Heap value
|
- [x] Heap value
|
||||||
- [x] Strings
|
- [x] Strings
|
||||||
- [ ] Arrays
|
- [x] Arrays
|
||||||
- [ ] Tables
|
- [x] Tables
|
||||||
- [ ] VM
|
- [ ] VM
|
||||||
- [ ] (Lua interface) call assembler
|
- [ ] (Lua interface) call assembler
|
||||||
- [ ] (Lua) generate bytecode
|
- [ ] (Lua) generate bytecode
|
||||||
|
|||||||
47
doc/BYTECODE
47
doc/BYTECODE
@@ -3,33 +3,34 @@ Bytecode format
|
|||||||
|
|
||||||
The bytecode file is composed of the following sections:
|
The bytecode file is composed of the following sections:
|
||||||
|
|
||||||
* HEADER: 16-byte header
|
* HEADER: 8-byte header
|
||||||
[0:3]: Magic
|
[0:3]: Magic
|
||||||
[4]: VM format
|
[4:5]: Bytecode version
|
||||||
[rest]: Reserved for future use
|
[6:7]: Reserved for future use
|
||||||
* TABLE_OF_CONTENTS: list of 8 records pointing to each one of the sections
|
|
||||||
Each record (6 bytes):
|
* CONSTANTS
|
||||||
- Pointer to section: 4 bytes
|
[0:3]: Code start address
|
||||||
- Number of records in section: 2 bytes
|
[4:7]: Number of constants
|
||||||
* [0x0] Constants indexes: pointers to each of the constant locations
|
[...]: Constant index
|
||||||
* Table of 4-byte constant indexes with pointer to constant
|
Each constant:
|
||||||
(counter start at beginning of raw constants)
|
[0]: Type (0 = string, 1 = real)
|
||||||
* [0x1] Functions indexes: Pointer to functions within the code
|
if string:
|
||||||
[0:3]: function pointer (counter start at the beginning of executable code)
|
[1..4]: string size
|
||||||
[4:5]: number of parameters
|
[...]: string
|
||||||
[6:7]: number of local variables
|
if real
|
||||||
[8:b]: function size
|
[1..4]: real
|
||||||
* [0x2] Constants raw data
|
|
||||||
* [0x3] Code: executable code
|
* CODE
|
||||||
* [0x4] Debugging info
|
Each function:
|
||||||
???
|
[0:3] Address of next function
|
||||||
|
[4:5] Number of parameters
|
||||||
|
[6:7] Number of variables
|
||||||
|
[...] Code
|
||||||
|
[0] : Opcode
|
||||||
|
[between 1 and 4] : Operand
|
||||||
|
|
||||||
The max file size is 2 Gb.
|
The max file size is 2 Gb.
|
||||||
|
|
||||||
## Values can be encoded in the following ways:
|
## Values can be encoded in the following ways:
|
||||||
* The type is defined by the operator.
|
* The type is defined by the operator.
|
||||||
* Encoding varies according to the type:
|
|
||||||
int: use protobuf format
|
|
||||||
float: 4-bit floating point
|
|
||||||
string: int-defined length, followed by the string proper - no null terminator
|
|
||||||
* Constant indexes and function ids are encoded as ints
|
* Constant indexes and function ids are encoded as ints
|
||||||
|
|||||||
12
lib/priv.h
12
lib/priv.h
@@ -24,6 +24,7 @@ typedef struct Stack Stack;
|
|||||||
typedef struct Array Array;
|
typedef struct Array Array;
|
||||||
typedef struct Table Table;
|
typedef struct Table Table;
|
||||||
typedef struct Heap Heap;
|
typedef struct Heap Heap;
|
||||||
|
typedef struct Code Code;
|
||||||
|
|
||||||
typedef uint32_t HEAP_KEY;
|
typedef uint32_t HEAP_KEY;
|
||||||
typedef uint64_t TABLE_HASH;
|
typedef uint64_t TABLE_HASH;
|
||||||
@@ -115,4 +116,15 @@ size_t heap_size(Heap const* h);
|
|||||||
|
|
||||||
void heap_gc(Heap* h, VALUE const* roots, size_t n_roots);
|
void heap_gc(Heap* h, VALUE const* roots, size_t n_roots);
|
||||||
|
|
||||||
|
//
|
||||||
|
// CODE
|
||||||
|
//
|
||||||
|
|
||||||
|
TYC_RESULT code_assemble(const char* code, uint8_t** bytecode, size_t* bytecode_sz);
|
||||||
|
|
||||||
|
Code* code_load_bytecode(uint8_t* bytecode, size_t bytecode_sz);
|
||||||
|
Code* code_load_bytecode_cb(void(*read_bytes)(size_t, void*), void* data);
|
||||||
|
|
||||||
|
void code_destroy(Code* code);
|
||||||
|
|
||||||
#endif //TYCHE_PRIV_H
|
#endif //TYCHE_PRIV_H
|
||||||
|
|||||||
Reference in New Issue
Block a user