1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 00:10:27 +00:00
This commit is contained in:
Calvin Rose 2017-02-12 15:53:52 -05:00
parent 47d9aceb0a
commit 4a15052d38
5 changed files with 36 additions and 4 deletions

View File

@ -203,7 +203,9 @@ enum OpCode {
VM_OP_SBM, /* 0x001d */ VM_OP_SBM, /* 0x001d */
VM_OP_MUM, /* 0x001e */ VM_OP_MUM, /* 0x001e */
VM_OP_DVM, /* 0x001f */ VM_OP_DVM, /* 0x001f */
VM_OP_RTN /* 0x0020 */ VM_OP_RTN, /* 0x0020 */
VM_OP_SET, /* 0x0021 */
VM_OP_GET, /* 0x0022 */
}; };
#endif /* end of include guard: DATATYPES_H_PJJ035NT */ #endif /* end of include guard: DATATYPES_H_PJJ035NT */

3
main.c
View File

@ -8,6 +8,7 @@
#include "value.h" #include "value.h"
#include "disasm.h" #include "disasm.h"
/* Test c function */
Value print(VM * vm) { Value print(VM * vm) {
uint32_t i, j, count; uint32_t i, j, count;
Value nil; Value nil;
@ -85,7 +86,7 @@ void debugRepl() {
} }
/* Print the function that will be executed */ /* Print the function that will be executed */
dasmFunc(stdout, func); //dasmFunc(stdout, func);
/* Execute function */ /* Execute function */
VMLoad(&vm, func); VMLoad(&vm, func);

21
value.c
View File

@ -351,3 +351,24 @@ int ValueCompare(Value x, Value y) {
} }
return 1; return 1;
} }
/* Get a value out af an associated data structure. Can throw VM error. */
Value ValueGet(VM * vm, Value ds, Value key) {
switch (ds.type) {
case TYPE_ARRAY:
case TYPE_FORM:
case TYPE_BYTEBUFFER:
case TYPE_SYMBOL:
case TYPE_STRING:
case TYPE_DICTIONARY:
case TYPE_FUNCENV:
default:
VMError(vm, "Cannot get.");
break;
}
}
/* Set a value in an associative data structure. Can throw VM error. */
int ValueSet(VM * vm, Value ds, Value key, Value value) {
}

View File

@ -9,6 +9,10 @@ int ValueCompare(Value x, Value y);
int ValueEqual(Value x, Value y); int ValueEqual(Value x, Value y);
Value ValueGet(VM * vm, Value ds, Value key);
int ValueSet(VM * vm, Value ds, Value key, Value value);
Value ValueLoadCString(VM * vm, const char * string); Value ValueLoadCString(VM * vm, const char * string);
uint8_t * ValueToString(VM * vm, Value x); uint8_t * ValueToString(VM * vm, Value x);

8
vm.c
View File

@ -716,6 +716,10 @@ int VMStart(VM * vm) {
VMReturn(vm, temp); VMReturn(vm, temp);
break; break;
case VM_OP_GET:
break;
default: default:
VMError(vm, "Unknown opcode"); VMError(vm, "Unknown opcode");
break; break;
@ -755,7 +759,7 @@ void VMInit(VM * vm) {
vm->black = 0; vm->black = 0;
vm->lock = 0; vm->lock = 0;
/* Create new thread */ /* Create new thread */
vm->thread = ArrayNew(vm, 20); vm->thread = ArrayNew(vm, 32);
} }
/* Load a function into the VM. The function will be called with /* Load a function into the VM. The function will be called with
@ -764,7 +768,7 @@ void VMLoad(VM * vm, Func * func) {
Value callee; Value callee;
callee.type = TYPE_FUNCTION; callee.type = TYPE_FUNCTION;
callee.data.func = func; callee.data.func = func;
vm->thread = ArrayNew(vm, 100); vm->thread = ArrayNew(vm, 32);
VMThreadPush(vm, vm->thread, callee, func->def->locals); VMThreadPush(vm, vm->thread, callee, func->def->locals);
vm->pc = func->def->byteCode; vm->pc = func->def->byteCode;
} }