From 4a15052d38d4bbb9b9bf449d53bd36207b0aeb16 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 12 Feb 2017 15:53:52 -0500 Subject: [PATCH] . --- datatypes.h | 4 +++- main.c | 3 ++- value.c | 21 +++++++++++++++++++++ value.h | 4 ++++ vm.c | 8 ++++++-- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/datatypes.h b/datatypes.h index 3a0b6cef..713772ed 100644 --- a/datatypes.h +++ b/datatypes.h @@ -203,7 +203,9 @@ enum OpCode { VM_OP_SBM, /* 0x001d */ VM_OP_MUM, /* 0x001e */ 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 */ diff --git a/main.c b/main.c index 947d1eab..080ea137 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,7 @@ #include "value.h" #include "disasm.h" +/* Test c function */ Value print(VM * vm) { uint32_t i, j, count; Value nil; @@ -85,7 +86,7 @@ void debugRepl() { } /* Print the function that will be executed */ - dasmFunc(stdout, func); + //dasmFunc(stdout, func); /* Execute function */ VMLoad(&vm, func); diff --git a/value.c b/value.c index 01a67bfb..3901546b 100644 --- a/value.c +++ b/value.c @@ -351,3 +351,24 @@ int ValueCompare(Value x, Value y) { } 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) { + +} diff --git a/value.h b/value.h index 6a587b9d..22f0bf27 100644 --- a/value.h +++ b/value.h @@ -9,6 +9,10 @@ int ValueCompare(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); uint8_t * ValueToString(VM * vm, Value x); diff --git a/vm.c b/vm.c index 73fe0446..06afeefb 100644 --- a/vm.c +++ b/vm.c @@ -716,6 +716,10 @@ int VMStart(VM * vm) { VMReturn(vm, temp); break; + case VM_OP_GET: + + break; + default: VMError(vm, "Unknown opcode"); break; @@ -755,7 +759,7 @@ void VMInit(VM * vm) { vm->black = 0; vm->lock = 0; /* 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 @@ -764,7 +768,7 @@ void VMLoad(VM * vm, Func * func) { Value callee; callee.type = TYPE_FUNCTION; callee.data.func = func; - vm->thread = ArrayNew(vm, 100); + vm->thread = ArrayNew(vm, 32); VMThreadPush(vm, vm->thread, callee, func->def->locals); vm->pc = func->def->byteCode; }