Skip to content

Commit

Permalink
feat: enable let_call transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
myuon committed Sep 17, 2023
1 parent 8c89f3c commit d1e633c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions quartz/compiler.qz
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import quartz::ir;
import quartz::value;
import quartz::location;
import quartz::preprocessor;
import quartz::ir_path::let_call;

struct LoadedModule {
path: Path,
Expand Down Expand Up @@ -176,6 +177,8 @@ module Compiler {
irgen.globals = typechecker.globals;
let term = irgen.run(module_).try;

term = transform_let_call(term);

let gen = Generator::new(validate_address);
gen.set_globals(typechecker.globals);
gen.set_strings(irgen.strings.strings);
Expand Down
10 changes: 5 additions & 5 deletions quartz/core.qz
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ let _bp: u32 = 1610612736 as u32;

@[no_allocation]
fun push_memstack(value: ptr[any]) {
if !_reflection_is_pointer(value) {
debug(error_not_an_pointer);
debug(value);
abort();
}
// if !_reflection_is_pointer(value) {
// debug(error_not_an_pointer);
// debug(value);
// abort();
// }

let sp_ptr = _sp as ptr[ptr[byte]];
sp_ptr.at(0) = value;
Expand Down
26 changes: 13 additions & 13 deletions quartz/generator.qz
Original file line number Diff line number Diff line change
Expand Up @@ -756,20 +756,20 @@ module Generator {
t_ident: expr.t_let!.name,
});

// FIXME: this is broken at 2.8.1
// push to stack
// if expr.t_let!.type_.t_address != nil && !self.globals.has(expr.t_let!.name) {
// self.new_statement();
// self.expression(IrTerm {
// t_ident: expr.t_let!.name,
// });

// self.new_statement();
// self.write("call $quartz_core_push_memstack");

// self.new_statement();
// self.write("drop");
// }
let is_core_function = self.current_function_name.starts_with("quartz_core");
if (expr.t_let!.type_.t_address != nil || expr.t_let!.type_.t_any != nil) && !self.globals.has(expr.t_let!.name) && !is_core_function {
self.new_statement();
self.expression(IrTerm {
t_ident: expr.t_let!.name,
});

self.new_statement();
self.write("call $quartz_core_push_memstack");

self.new_statement();
self.write("drop");
}
} else if expr.t_return != nil {
self.new_statement();
self.expression(expr.t_return!.value);
Expand Down

0 comments on commit d1e633c

Please sign in to comment.