lang: Switch to callee cleanup of non-return arguments
This simplifies calling things and will allow proper tail calls.
This commit is contained in:
parent
74c622a1ba
commit
6aef030766
4 changed files with 6 additions and 10 deletions
|
@ -20,10 +20,9 @@ enum opcodes {
|
|||
static const unsigned char bytecode[] = {
|
||||
0x05, 0x05, 0x05, 0x01, 0x6a, 0x02, 0x00, 0x00, 0x07, 0x01,
|
||||
0x05, 0x06, 0x01, 0x06, 0x01, 0x04, 0x02, 0x41, 0x64, 0x64,
|
||||
0x00, 0x08, 0x01, 0x07, 0x02, 0x05, 0x01, 0x02, 0x00, 0x00,
|
||||
0x00, 0x06, 0x02, 0x04, 0x02, 0x4d, 0x69, 0x6e, 0x75, 0x73,
|
||||
0x00, 0x08, 0x01, 0x07, 0x03, 0x06, 0x03, 0x07, 0x00, 0x08,
|
||||
0x03, 0x03,
|
||||
0x00, 0x07, 0x02, 0x05, 0x01, 0x02, 0x00, 0x00, 0x00, 0x06,
|
||||
0x02, 0x04, 0x02, 0x4d, 0x69, 0x6e, 0x75, 0x73, 0x00, 0x07,
|
||||
0x03, 0x06, 0x03, 0x07, 0x00, 0x08, 0x03, 0x03,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
|
@ -250,12 +250,10 @@ def generate_ir_call(ast):
|
|||
args_count = len(ast.args)
|
||||
alloc_ir = [IRAllocate(1)]
|
||||
call_ir = [IRCall(ast.verb, args_count)]
|
||||
drop_ir = [IRDrop(args_count)]
|
||||
final_ir = final_ir + alloc_ir
|
||||
final_ir = final_ir + args_ir
|
||||
final_ir = final_ir + subject_ir
|
||||
final_ir = final_ir + call_ir
|
||||
final_ir = final_ir + drop_ir
|
||||
return final_ir
|
||||
|
||||
def generate_ir_set(ast):
|
||||
|
|
|
@ -13,9 +13,8 @@ static void test_number(struct vm_state *state) {
|
|||
vm_stack_push(state, numB);
|
||||
numB = NULL;
|
||||
vm_call(numA, "Add", 2, state);
|
||||
struct object *numC = vm_stack_get(state, 0);
|
||||
struct object *numC = vm_stack_pop(state);
|
||||
printf("numC value is %i\n", number_value(numC));
|
||||
vm_stack_drop(state, 2);
|
||||
object_drop(&numA);
|
||||
object_drop(&numC);
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ static void number_add(
|
|||
struct number *numB = (struct number *)arg1;
|
||||
int added = numA->value + numB->value;
|
||||
vm_stack_set(state, 0, number_create(added));
|
||||
vm_stack_drop(state, 1);
|
||||
object_drop(&arg1);
|
||||
numB = NULL;
|
||||
}
|
||||
|
||||
static void number_minus(
|
||||
|
@ -61,8 +61,8 @@ static void number_minus(
|
|||
struct number *numB = (struct number *)arg1;
|
||||
int subbed = numA->value - numB->value;
|
||||
vm_stack_set(state, 0, number_create(subbed));
|
||||
vm_stack_drop(state, 1);
|
||||
object_drop(&arg1);
|
||||
numB = NULL;
|
||||
}
|
||||
|
||||
static struct object_call calls[] = {{.name = "Add", .handler = number_add},
|
||||
|
|
Loading…
Add table
Reference in a new issue