Skip to content

Commit 3d14435

Browse files
committed
Load argument into a variable in the beginning of a function
1 parent 2159d75 commit 3d14435

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Diff for: compiler/compiler.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ unsigned short compileExpr(KaosIR* program, Expr* expr)
438438
load_dict(program, symbol);
439439
break;
440440
case V_REF:
441-
load_ref(program, symbol);
442441
break;
443442
default:
444443
load_any(program, symbol);
@@ -1054,6 +1053,20 @@ void compileDecl(KaosIR* program, Decl* decl)
10541053

10551054
compileSpec(program, decl->v.func_decl->type->v.func_type->params);
10561055

1056+
for (int i = 0; i < function->parameter_count; i++) {
1057+
Symbol* parameter = function->parameters[i];
1058+
push_inst_r_i(program, GETARG, R0, (i * 2));
1059+
push_inst_r_i(program, GETARG, R1, (i * 2) + 1);
1060+
1061+
parameter->addr = stack_counter++;
1062+
push_inst_i_i(program, ALLOCAI, parameter->addr, 2 * sizeof(long long));
1063+
push_inst_r_i(program, REF_ALLOCAI, R2, parameter->addr);
1064+
push_inst_r_r_i(program, STR, R2, R0, sizeof(long long));
1065+
push_inst_r_i(program, MOVI, R3, sizeof(long long));
1066+
push_inst_r_r_r_i(program, STXR, R2, R3, R1, sizeof(long long));
1067+
parameter->value_type = V_INT; // TODO: temp, set it according to parameter type
1068+
}
1069+
10571070
compileStmt(program, decl->v.func_decl->body);
10581071
if (decl->v.func_decl->decision != NULL)
10591072
compileSpec(program, decl->v.func_decl->decision);
@@ -1988,13 +2001,6 @@ void load_any(KaosIR* program, Symbol* symbol)
19882001
// i64 addr = symbol->addr;
19892002
}
19902003

1991-
void load_ref(KaosIR* program, Symbol* symbol)
1992-
{
1993-
i64 addr = symbol->addr;
1994-
push_inst_r_i(program, GETARG, R0, addr);
1995-
push_inst_r_i(program, GETARG, R1, addr + 1);
1996-
}
1997-
19982004
char* compile_module_selector(Expr* module_selector)
19992005
{
20002006
char* name = NULL;

Diff for: compiler/compiler.h

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ void load_string(KaosIR* program, Symbol* symbol);
7474
void load_list(KaosIR* program, Symbol* symbol);
7575
void load_dict(KaosIR* program, Symbol* symbol);
7676
void load_any(KaosIR* program, Symbol* symbol);
77-
void load_ref(KaosIR* program, Symbol* symbol);
7877

7978
char* compile_module_selector(Expr* module_selector);
8079
bool declare_function(Stmt* stmt, File* file, KaosIR* program);

0 commit comments

Comments
 (0)