This commit is contained in:
Charles Kralapp 2025-07-05 16:38:42 -04:00
parent f28dd417d9
commit 7bff3208a0
3 changed files with 8 additions and 9 deletions

View File

@ -20,11 +20,11 @@ uint32_t demo_add_compile(Value *memory) {
memory[i++].u = OP(OP_SUB_UINT, 1, 1, 2);
memory[i++].u = OP(OP_JGT_UINT, 5, 1, 0);
memory[i++].u = OP(OP_REAL_TO_STRING, 6, 4, 0);
memory[i++].u = OP(OP_PRINT_STRING, 0, 6, 0);
memory[i++].u = OP(OP_REAL_TO_UINT, 1, 4, 4);
memory[i++].u = OP(OP_UINT_TO_STRING, 7, 1, 0);
memory[i++].u = OP(OP_PRINT_STRING, 0, 7, 0);
memory[i++].u = OP(OP_READ_STRING, 8, 0, 0);
memory[i++].u = OP(OP_PRINT_STRING, 0, 6, 0);
memory[i++].u = OP(OP_PRINT_STRING, 0, 7, 0);
memory[i++].u = OP(OP_PRINT_STRING, 0, 8, 0);
memory[i++].u = OP(OP_HALT, 0, 0, 0); /* explicit halt */
return i;

View File

@ -54,8 +54,7 @@ int main(int argc, char **argv) {
vm.frame_stack_size = FRAME_STACK_SIZE;
vm.return_stack_size = RETURN_STACK_SIZE;
vm.memory_size = MEMORY_SIZE;
uint32_t i = demo_add_compile(vm.memory);
vm.frame_stack[vm.fp].allocated.end = i + 1;
vm.frame_stack[vm.fp].allocated.end = demo_add_compile(vm.memory);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(mainloop, 0, 1);

View File

@ -5,8 +5,8 @@
do { \
type value = vm->frame_stack[vm->fp].registers[src1].accessor; \
type value2 = vm->frame_stack[vm->fp].registers[src2].accessor; \
vm->pc = \
(value op value2) ? vm->frame_stack[vm->fp].registers[dest].u : vm->pc; \
vm->pc = (value op value2) ? vm->frame_stack[vm->fp].registers[dest].u \
: vm->pc; \
return true; \
} while (0)
@ -197,7 +197,7 @@ bool step_vm(VM *vm) {
int len = sprintf(buffer, "%d", a);
mem_strcpy(vm->memory, buffer, len, str_dest); /* copy buffer to dest */
vm->frame_stack[vm->fp].allocated.end +=
len + 1; /* increment to end of allocated */
((len / 4) + (len % 4) + 1); /* increment to end of allocated */
return true;
}
case OP_UINT_TO_STRING: {
@ -211,7 +211,7 @@ bool step_vm(VM *vm) {
int len = sprintf(buffer, "%d", a);
mem_strcpy(vm->memory, buffer, len, str_dest); /* copy buffer to dest */
vm->frame_stack[vm->fp].allocated.end +=
len + 1; /* increment to end of allocated */
((len / 4) + (len % 4) + 1); /* increment to end of allocated */
return true;
}
case OP_REAL_TO_STRING: {
@ -224,7 +224,7 @@ bool step_vm(VM *vm) {
int len = sprintf(buffer, "%f", a);
mem_strcpy(vm->memory, buffer, len, str_dest); /* copy buffer to dest */
vm->frame_stack[vm->fp].allocated.end +=
len + 1; /* increment to end of allocated */
((len / 4) + (len % 4) + 1); /* increment to end of allocated */
return true;
}
case OP_READ_STRING: {