1
0
Fork 0
forked from fun/fun

Some more internal optimizations. (0.41.15)

This commit is contained in:
Johannes Findeisen 2026-05-26 05:13:04 +02:00
commit a5de8b167a
13 changed files with 194 additions and 25 deletions

View file

@ -33,6 +33,7 @@
*/
case OP_ADD: {
vm_require_stack(vm, 2);
Value b = pop_value(vm);
Value a = pop_value(vm);
if ((a.type == VAL_INT || a.type == VAL_FLOAT) && (b.type == VAL_INT || b.type == VAL_FLOAT)) {

View file

@ -28,10 +28,7 @@
*/
case OP_DUP: {
if (vm->sp < 0) {
fprintf(stderr, "Runtime error: stack underflow for DUP\n");
exit(1);
}
vm_require_stack(vm, 1);
Value top = vm->stack[vm->sp];
push_value(vm, copy_value(&top));
break;

View file

@ -26,10 +26,7 @@
*/
case OP_POP: {
if (vm->sp < 0) {
fprintf(stderr, "Runtime error: stack underflow for POP\n");
exit(1);
}
vm_require_stack(vm, 1);
Value v = pop_value(vm);
free_value(v);
break;

View file

@ -23,10 +23,7 @@
*/
case OP_SWAP: {
if (vm->sp < 1) {
fprintf(stderr, "Runtime error: stack underflow for SWAP\n");
exit(1);
}
vm_require_stack(vm, 2);
Value a = vm->stack[vm->sp];
Value b = vm->stack[vm->sp - 1];
vm->stack[vm->sp] = b;