Skip to content

Commit

Permalink
yield atom should be working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-johnson-4 committed Jan 1, 2024
1 parent 1f3002b commit 9313428
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn flatten(output: &mut String, input: &S) {
else if l=="\\n" { output.push('\n'); }
else if l=="(" { output.push('('); }
else if l==")" { output.push(')'); }
else if l=="$" { output.push('$'); }
else if l=="\"" { output.push('"'); }
else {
output.push_str( &l );
Expand Down Expand Up @@ -72,6 +73,20 @@ fn label_case(s: &str) -> String {
format!("{}", s.replace("-","_"))
}

static mut UUID_COUNTER: usize = 0;
fn uuid() -> String {
let id = unsafe { UUID_COUNTER += 1; UUID_COUNTER };
format!("_uuid_{}", id)
}

fn yield_atom(helpers_ctx: &S, s: &str) -> S {
let id = uuid();
s_cons(
ctx_eval_soft(helpers_ctx, &app( variable("::yield-atom"), variable(&id) )),
variable(&format!("{}:\n\t.ascii \"{}\"\n\t.zero 1\n", id, s)),
)
}

fn compile_expr(helpers_ctx: &S, program_ctx: &S, e: &S) -> S {
if head(e).to_string() == "lambda" {
unimplemented!("compile_expr: {}", e);
Expand All @@ -81,13 +96,17 @@ fn compile_expr(helpers_ctx: &S, program_ctx: &S, e: &S) -> S {
let x = tail(&fx);
let xpg = compile_expr(helpers_ctx, program_ctx, &x);
assert_eq!( head(&f).to_string(), "variable" );
let f_name = variable(&label_case( &tail(&f).to_string() ));
let call = app( variable("jmp"), f_name );
let f_name = label_case( &tail(&f).to_string() );
let call = variable( &format!("\tjmp {}\n", f_name) );
let prog = app(
head(&xpg),
call
);
s_cons(prog, tail(&xpg))
} else if head(e).to_string() == "variable" {
yield_atom(helpers_ctx, &tail(e).to_string() )
} else if head(e).to_string() == "literal" {
yield_atom(helpers_ctx, &tail(e).to_string() )
} else if is_nil(e) {
s_cons(
ctx_eval_soft(helpers_ctx, &variable("::yield-nil")),
Expand Down
9 changes: 9 additions & 0 deletions stdlib/helpers.lm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
\t mov $0, %r11 \n # $_.$4 = 0, .flags
);

::yield-atom := λlabel. (
# $_.$0 ref_counter is unnecessary when open
# open structures must be completely "owned" by the current context
\t mov $ label , %r8 \n # $_.$1 = 0, .atom
\t mov $0, %r9 \n # $_.$2 = 0, .head
\t mov $0, %r10 \n # $_.$3 = 0, .tail
\t mov $0, %r11 \n # $_.$4 = 0, .flags
);

::program-header := (
.global _start \n
.text \n
Expand Down

0 comments on commit 9313428

Please sign in to comment.