change function depending on the operation
This commit is contained in:
@@ -66,7 +66,7 @@ ArgonObject *ARGON_TYPE_TYPE___call__(size_t argc, ArgonObject **argv,
|
||||
if (argc < 1) {
|
||||
*err =
|
||||
create_err(0, 0, 0, "", "Runtime Error",
|
||||
"__call__ expects at least 1 argument, got %" PRIu64, argc);
|
||||
"__call__ expects at least 1 argument, got %" PRIu64, argc);
|
||||
return ARGON_NULL;
|
||||
}
|
||||
ArgonObject *cls = argv[0];
|
||||
|
||||
@@ -8,20 +8,26 @@
|
||||
size_t translate_parsed_call(Translated *translated, ParsedCall *call,
|
||||
ArErr *err) {
|
||||
set_registers(translated, 1);
|
||||
translate_parsed(translated, call->to_call, err);
|
||||
size_t first = push_instruction_byte(translated, OP_INIT_CALL);
|
||||
size_t first = translate_parsed(translated, call->to_call, err);
|
||||
if (err->exists) {
|
||||
return first;
|
||||
}
|
||||
push_instruction_byte(translated, OP_INIT_CALL);
|
||||
push_instruction_code(translated, call->args.size);
|
||||
|
||||
push_instruction_byte(translated, OP_NEW_SCOPE);
|
||||
DArray *old_return_jumps = translated->return_jumps;
|
||||
translated->return_jumps = NULL;
|
||||
for (size_t i = 0; i < call->args.size; i++) {
|
||||
translate_parsed(translated, darray_get(&call->args, i), err);
|
||||
if (err->exists)
|
||||
if (err->exists) {
|
||||
translated->return_jumps = old_return_jumps;
|
||||
return first;
|
||||
}
|
||||
push_instruction_byte(translated, OP_INSERT_ARG);
|
||||
push_instruction_code(translated, i);
|
||||
}
|
||||
if (err->exists)
|
||||
return first;
|
||||
|
||||
translated->return_jumps = old_return_jumps;
|
||||
|
||||
push_instruction_byte(translated, OP_SOURCE_LOCATION);
|
||||
push_instruction_code(translated, call->line);
|
||||
@@ -29,6 +35,5 @@ size_t translate_parsed_call(Translated *translated, ParsedCall *call,
|
||||
push_instruction_code(translated, 1);
|
||||
|
||||
push_instruction_byte(translated, OP_CALL);
|
||||
push_instruction_byte(translated, OP_POP_SCOPE);
|
||||
return first;
|
||||
}
|
||||
@@ -10,7 +10,17 @@
|
||||
size_t translate_operation(Translated *translated, ParsedOperation *operation,
|
||||
ArErr *err) {
|
||||
set_registers(translated, 1);
|
||||
uint64_t first = push_instruction_byte(translated, OP_LOAD_ADDITION_FUNCTION);
|
||||
uint64_t first;
|
||||
switch (operation->operation) {
|
||||
case TOKEN_PLUS:;
|
||||
first = push_instruction_byte(translated, OP_LOAD_ADDITION_FUNCTION);
|
||||
break;
|
||||
default:
|
||||
*err = create_err(operation->line, operation->column,
|
||||
operation->length, translated->path, "Syntax Error",
|
||||
"unknown operation");
|
||||
return 0;
|
||||
}
|
||||
push_instruction_byte(translated, OP_INIT_CALL);
|
||||
push_instruction_code(translated, operation->to_operate_on.size);
|
||||
|
||||
|
||||
@@ -1,6 +1 @@
|
||||
let f(x) = do
|
||||
return x
|
||||
|
||||
let x = 10
|
||||
|
||||
term.log(x)
|
||||
term.log(1984+1)
|
||||
Reference in New Issue
Block a user