Skip to content

Commit e126141

Browse files
committed
Minimal changes
1 parent 4ff0928 commit e126141

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

vm/vm.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ void vm_step(vm_thread_t **thread) {
170170
if (lib_idx.type != VM_VAL_UINT || lib_idx.number.uinteger > (*thread)->state->lib_qty)
171171
err = VM_ERR_BAD_VALUE;
172172

173-
vm_value_t ref = { .type = VM_VAL_LIB_OBJ };
174-
vm_heap_object_t obj = { .type = VM_VAL_LIB_OBJ, .lib_obj.identifier = 0, .lib_obj.addr = NULL, .lib_obj.lib_idx = lib_idx.number.uinteger,
175-
173+
vm_value_t ref = {
174+
.type = VM_VAL_LIB_OBJ
175+
};
176+
vm_heap_object_t obj = {
177+
.type = VM_VAL_LIB_OBJ,
178+
.lib_obj.identifier = 0,
179+
.lib_obj.addr = NULL,
180+
.lib_obj.lib_idx = lib_idx.number.uinteger,
176181
};
182+
177183
uint32_t heap_ref = vm_heap_save((*thread)->state->heap, obj, &((*thread)->frames[(*thread)->fc].gc_mark));
178184
ref.lib_obj.heap_ref = heap_ref;
179185
vm_do_push(thread, ref);
@@ -331,7 +337,7 @@ void vm_step(vm_thread_t **thread) {
331337
}
332338
break;
333339
default:
334-
err = VM_ERR_CONST_BADTYPE;
340+
err = VM_ERR_CONST_BADTYPE;
335341
}
336342

337343
(*thread)->sp += 1;
@@ -348,7 +354,7 @@ void vm_step(vm_thread_t **thread) {
348354

349355
vm_do_push(thread, heap_id);
350356
} else
351-
err = VM_ERR_BAD_VALUE;
357+
err = VM_ERR_BAD_VALUE;
352358
break;
353359
}
354360

@@ -365,7 +371,7 @@ void vm_step(vm_thread_t **thread) {
365371
(*thread)->sp -= n_fields;
366372

367373
if (heap_id == 0xffffffff)
368-
err = VM_ERR_OUTOFMEMORY;
374+
err = VM_ERR_OUTOFMEMORY;
369375
else {
370376
vm_value_t val;
371377
val.type = VM_VAL_ARRAY;
@@ -374,7 +380,7 @@ void vm_step(vm_thread_t **thread) {
374380
vm_do_push(thread, val);
375381
}
376382
} else
377-
err = VM_ERR_BAD_VALUE;
383+
err = VM_ERR_BAD_VALUE;
378384
}
379385
break;
380386

@@ -392,9 +398,9 @@ void vm_step(vm_thread_t **thread) {
392398
}
393399

394400
if (arr->type == VM_VAL_ARRAY && index >= 0 && index < arr->array.qty)
395-
vm_do_push(thread, arr->array.fields[index]);
401+
vm_do_push(thread, arr->array.fields[index]);
396402
else
397-
err = VM_ERR_BAD_VALUE;
403+
err = VM_ERR_BAD_VALUE;
398404
}
399405
break;
400406

@@ -414,9 +420,9 @@ void vm_step(vm_thread_t **thread) {
414420
vm_value_t val = vm_do_pop(thread);
415421

416422
if (arr->type == VM_VAL_ARRAY && index >= 0 && index < arr->array.qty)
417-
arr->array.fields[index] = val;
423+
arr->array.fields[index] = val;
418424
else
419-
err = VM_ERR_BAD_VALUE;
425+
err = VM_ERR_BAD_VALUE;
420426
}
421427
break;
422428

@@ -487,7 +493,7 @@ void vm_step(vm_thread_t **thread) {
487493
--(*thread)->sp;
488494
vm_value_t b = STK_NEW(thread);
489495
if (b.number.uinteger == 0)
490-
err = VM_ERR_DIVBYZERO;
496+
err = VM_ERR_DIVBYZERO;
491497
else {
492498
if (a->type == VM_VAL_INT && b.type == VM_VAL_INT) {
493499
a->number.integer = a->number.integer / b.number.integer;
@@ -588,11 +594,11 @@ void vm_step(vm_thread_t **thread) {
588594
};
589595

590596
if (var_idx > VM_MAX_GLOBAL_VARS)
591-
err = VM_ERR_OUTOFRANGE;
597+
err = VM_ERR_OUTOFRANGE;
592598
else {
593599
if (var_idx < (*thread)->global_vars_qty) {
594600
if (!vm_heap_set((*thread)->state->heap, value, (*thread)->global_vars[var_idx]))
595-
err = VM_ERR_OUTOFRANGE;
601+
err = VM_ERR_OUTOFRANGE;
596602
} else {
597603
uint32_t heap_id = vm_heap_save((*thread)->state->heap, value, &((*thread)->frames[0].gc_mark));
598604
(*thread)->global_vars[var_idx] = heap_id;
@@ -616,7 +622,7 @@ void vm_step(vm_thread_t **thread) {
616622
}
617623

618624
if (var_idx > (*thread)->global_vars_qty - 1)
619-
err = VM_ERR_OUTOFRANGE;
625+
err = VM_ERR_OUTOFRANGE;
620626
else {
621627
vm_heap_object_t *value = vm_heap_load((*thread)->state->heap, (*thread)->global_vars[var_idx]);
622628
vm_do_push(thread, value->value);
@@ -655,7 +661,7 @@ void vm_step(vm_thread_t **thread) {
655661
if (val.type != VM_VAL_BOOL && val.type != VM_VAL_UINT && val.type != VM_VAL_UINT && val.type != VM_VAL_FLOAT) {
656662
err = VM_ERR_BAD_VALUE;
657663
} else if (val.number.boolean == false || val.number.integer == 0 || val.number.uinteger == 0 || val.number.real == 0)
658-
(*thread)->pc = new_pc;
664+
(*thread)->pc = new_pc;
659665
}
660666
break;
661667

@@ -675,26 +681,26 @@ void vm_step(vm_thread_t **thread) {
675681
vm_do_push_frame(thread, nargs);
676682
(*thread)->pc = pc_idx;
677683
} else
678-
err = VM_ERR_TOOMANYTHREADS;
684+
err = VM_ERR_TOOMANYTHREADS;
679685
}
680686
break;
681687

682688
case RETURN: {
683689
vm_value_t vm_value_null = {VM_VAL_NULL};
684690
(*thread)->ret_val = vm_value_null;
685691
if ((*thread)->fc > 0)
686-
vm_do_pop_frame(thread);
692+
vm_do_pop_frame(thread);
687693
else
688-
err = VM_ERR_INVALIDRETURN;
694+
err = VM_ERR_INVALIDRETURN;
689695
}
690696
break;
691697

692698
case RETURN_VALUE: {
693699
(*thread)->ret_val = vm_do_pop(thread);
694700
if ((*thread)->fc > 0)
695-
vm_do_pop_frame(thread);
701+
vm_do_pop_frame(thread);
696702
else
697-
err = VM_ERR_INVALIDRETURN;
703+
err = VM_ERR_INVALIDRETURN;
698704
}
699705
break;
700706

@@ -713,7 +719,7 @@ void vm_step(vm_thread_t **thread) {
713719
if (f_idx <= (*thread)->state->foreign_functions_qty - 1) {
714720
(*thread)->ret_val = (*thread)->state->foreign_functions[f_idx](thread, fn);
715721
} else
716-
err = VM_ERR_FOREINGFNUNKN;
722+
err = VM_ERR_FOREINGFNUNKN;
717723
}
718724
break;
719725

@@ -723,7 +729,7 @@ void vm_step(vm_thread_t **thread) {
723729
uint32_t arg = vm_read_u32(thread, &(*thread)->pc);
724730
err = (*thread)->state->lib[STK_TOP(thread).lib_obj.lib_idx](thread, calltype, STK_TOP(thread).lib_obj.lib_idx, arg);
725731
} else
726-
err = VM_ERR_BAD_VALUE;
732+
err = VM_ERR_BAD_VALUE;
727733
}
728734
break;
729735

@@ -735,9 +741,9 @@ void vm_step(vm_thread_t **thread) {
735741
(*thread)->state->program[(*thread)->pc++];
736742

737743
if (local_idx < (*thread)->frames[(*thread)->fc - 1].locals)
738-
vm_do_push(thread, (*thread)->stack[(*thread)->fp - (local_idx + 1)]);
744+
vm_do_push(thread, (*thread)->stack[(*thread)->fp - (local_idx + 1)]);
739745
else
740-
err = VM_ERR_LOCALNOTEXIST;
746+
err = VM_ERR_LOCALNOTEXIST;
741747
}
742748
break;
743749

@@ -751,7 +757,7 @@ void vm_step(vm_thread_t **thread) {
751757
vm_value_t val = vm_do_pop(thread);
752758
(*thread)->stack[(*thread)->fp - (local_idx + 1)] = val;
753759
} else
754-
err = VM_ERR_LOCALNOTEXIST;
760+
err = VM_ERR_LOCALNOTEXIST;
755761
}
756762
break;
757763

@@ -768,7 +774,7 @@ void vm_step(vm_thread_t **thread) {
768774
#ifdef VM_ENABLE_TOTYPES
769775
uint8_t type = (*thread)->state->program[(*thread)->pc++];
770776
if (STK_TOP(thread).type == type)
771-
return;
777+
return;
772778

773779
vm_value_t tmp;
774780
switch (type) {
@@ -844,7 +850,7 @@ void vm_step(vm_thread_t **thread) {
844850
break;
845851

846852
default:
847-
err = VM_ERR_UNKNOWNOP;
853+
err = VM_ERR_UNKNOWNOP;
848854
}
849855

850856
(*thread)->indirect += ind_inc;

0 commit comments

Comments
 (0)