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) {
|
if (argc < 1) {
|
||||||
*err =
|
*err =
|
||||||
create_err(0, 0, 0, "", "Runtime Error",
|
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;
|
return ARGON_NULL;
|
||||||
}
|
}
|
||||||
ArgonObject *cls = argv[0];
|
ArgonObject *cls = argv[0];
|
||||||
|
|||||||
@@ -8,20 +8,26 @@
|
|||||||
size_t translate_parsed_call(Translated *translated, ParsedCall *call,
|
size_t translate_parsed_call(Translated *translated, ParsedCall *call,
|
||||||
ArErr *err) {
|
ArErr *err) {
|
||||||
set_registers(translated, 1);
|
set_registers(translated, 1);
|
||||||
translate_parsed(translated, call->to_call, err);
|
size_t first = translate_parsed(translated, call->to_call, err);
|
||||||
size_t first = push_instruction_byte(translated, OP_INIT_CALL);
|
if (err->exists) {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
push_instruction_byte(translated, OP_INIT_CALL);
|
||||||
push_instruction_code(translated, call->args.size);
|
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++) {
|
for (size_t i = 0; i < call->args.size; i++) {
|
||||||
translate_parsed(translated, darray_get(&call->args, i), err);
|
translate_parsed(translated, darray_get(&call->args, i), err);
|
||||||
if (err->exists)
|
if (err->exists) {
|
||||||
|
translated->return_jumps = old_return_jumps;
|
||||||
return first;
|
return first;
|
||||||
|
}
|
||||||
push_instruction_byte(translated, OP_INSERT_ARG);
|
push_instruction_byte(translated, OP_INSERT_ARG);
|
||||||
push_instruction_code(translated, i);
|
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_byte(translated, OP_SOURCE_LOCATION);
|
||||||
push_instruction_code(translated, call->line);
|
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_code(translated, 1);
|
||||||
|
|
||||||
push_instruction_byte(translated, OP_CALL);
|
push_instruction_byte(translated, OP_CALL);
|
||||||
push_instruction_byte(translated, OP_POP_SCOPE);
|
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,17 @@
|
|||||||
size_t translate_operation(Translated *translated, ParsedOperation *operation,
|
size_t translate_operation(Translated *translated, ParsedOperation *operation,
|
||||||
ArErr *err) {
|
ArErr *err) {
|
||||||
set_registers(translated, 1);
|
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_byte(translated, OP_INIT_CALL);
|
||||||
push_instruction_code(translated, operation->to_operate_on.size);
|
push_instruction_code(translated, operation->to_operate_on.size);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1 @@
|
|||||||
let f(x) = do
|
term.log(1984+1)
|
||||||
return x
|
|
||||||
|
|
||||||
let x = 10
|
|
||||||
|
|
||||||
term.log(x)
|
|
||||||
Reference in New Issue
Block a user