1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-08 03:23:01 +00:00

Consolidate files

* Move GC struct into VM for easier use.
* Put all data structures into one file
This commit is contained in:
Calvin Rose
2017-02-09 18:50:47 -05:00
parent 715c239fc1
commit 0557c8b2a6
22 changed files with 800 additions and 897 deletions

View File

@@ -39,7 +39,6 @@ typedef struct Array Array;
typedef struct Buffer Buffer;
typedef struct Dictionary Dictionary;
typedef struct DictionaryIterator DictionaryIterator;
typedef struct GC GC;
typedef struct Parser Parser;
typedef struct ParseState ParseState;
typedef struct Scope Scope;
@@ -134,21 +133,18 @@ struct DictBucket {
DictBucket * next;
};
struct GC {
struct VM {
/* Garbage collection */
void * blocks;
void * user;
void (*handleOutOfMemory)(GC * gc);
uint32_t memoryInterval;
uint32_t nextCollection;
uint32_t black : 1;
};
struct VM {
GC gc;
const char * error;
/* Thread */
uint16_t * pc;
Array * thread;
Value * base;
/* Return state */
const char * error;
jmp_buf jump;
Value tempRoot; /* Temporary GC root */
};
@@ -182,4 +178,48 @@ struct Compiler {
Buffer * buffer;
};
/* String utils */
#define VStringRaw(s) ((uint32_t *)(s) - 2)
#define VStringSize(v) (VStringRaw(v)[0])
#define VStringHash(v) (VStringRaw(v)[1])
/* Bytecode */
enum OpCode {
VM_OP_ADD = 0, /* 0x0000 */
VM_OP_SUB, /* 0x0001 */
VM_OP_MUL, /* 0x0002 */
VM_OP_DIV, /* 0x0003 */
VM_OP_NOT, /* 0x0004 */
VM_OP_LD0, /* 0x0005 */
VM_OP_LD1, /* 0x0006 */
VM_OP_FLS, /* 0x0007 */
VM_OP_TRU, /* 0x0008 */
VM_OP_NIL, /* 0x0009 */
VM_OP_I16, /* 0x000a */
VM_OP_UPV, /* 0x000b */
VM_OP_JIF, /* 0x000c */
VM_OP_JMP, /* 0x000d */
VM_OP_CAL, /* 0x000e */
VM_OP_RET, /* 0x000f */
VM_OP_SUV, /* 0x0010 */
VM_OP_CST, /* 0x0011 */
VM_OP_I32, /* 0x0012 */
VM_OP_F64, /* 0x0013 */
VM_OP_MOV, /* 0x0014 */
VM_OP_CLN, /* 0x0015 */
VM_OP_EQL, /* 0x0016 */
VM_OP_LTN, /* 0x0017 */
VM_OP_LTE, /* 0x0018 */
VM_OP_ARR, /* 0x0019 */
VM_OP_DIC, /* 0x001a */
VM_OP_TCL, /* 0x001b */
VM_OP_ADM, /* 0x001c */
VM_OP_SBM, /* 0x001d */
VM_OP_MUM, /* 0x001e */
VM_OP_DVM, /* 0x001f */
VM_OP_RTN /* 0x0020 */
};
#endif /* end of include guard: DATATYPES_H_PJJ035NT */