mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
.
This commit is contained in:
parent
47d9aceb0a
commit
4a15052d38
@ -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
3
main.c
@ -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
21
value.c
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
4
value.h
4
value.h
@ -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
8
vm.c
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user