Skip to content

Commit

Permalink
make sure to fully evaluated everything
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-johnson-4 committed Jan 2, 2024
1 parent 0d2d6d6 commit 93c4e61
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
21 changes: 11 additions & 10 deletions src/g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,21 @@ fn yield_atom(helpers_ctx: &S, s: &str) -> S {
}

fn compile_expr(helpers_ctx: &S, program_ctx: &S, e: &S) -> S {
if head(e).to_string() == "lambda" {
let e = ctx_eval_soft(helpers_ctx, e);
if head(&e).to_string() == "lambda" {
unimplemented!("compile_expr: {}", e);
} else if head(e).to_string() == "app" {
let fx = tail(e);
} else if head(&e).to_string() == "app" {
let fx = tail(&e);
let f = head(&fx);
let x = tail(&fx);
let xpd = compile_expr(helpers_ctx, program_ctx, &x);
if head(&f).to_string() == "variable" {
let f_name = label_case( &tail(&f).to_string() );
let call = variable( &format!("\tcall {}\n", f_name) );
let prog = app(
let prog = ctx_eval_soft(helpers_ctx, &app(
head(&xpd),
call
);
));
s_cons(prog, tail(&xpd))
} else {
let fpd = compile_expr(helpers_ctx, program_ctx, &f);
Expand All @@ -125,11 +126,11 @@ fn compile_expr(helpers_ctx: &S, program_ctx: &S, e: &S) -> S {
);
s_cons(prog, data)
}
} 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) {
} 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")),
nil(),
Expand Down
38 changes: 33 additions & 5 deletions stdlib/helpers.lm
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,48 @@
tail # this is tail
::close-this # %r12 is tail

\t mov $0, %r8 \n # this.atom is NULL
\t mov %r13, %r9 \n # this.head is head
\t mov %r12, %r10 \n # this.tail is tail
\t mov $0, %r11 \n # this.flags is 0
\t mov $0, %r8 \n # this.atom is NULL
\t mov %r13, %r9 \n # this.head is head
\t mov %r12, %r10 \n # this.tail is tail
\t mov $0, %r11 \n # this.flags is 0

#debug log
::show-cons
);

::show-cons := (
::push-this
\t mov %r8, %rdi \n
\t call __put64 \n
::pop-this

::push-this
\t mov %r9, %rdi \n
\t call __put64 \n
::pop-this

::push-this
\t mov %r10, %rdi \n
\t call __put64 \n
::pop-this

::push-this
\t mov %r11, %rdi \n
\t call __put64 \n
::pop-this
);

::push-this := (
\t push %r8 \n
\t push %r9 \n
\t push %r10 \n
\t push %r11 \n
);

::pop-this := (
\t pop %r11 \n
\t pop %r10 \n
\t pop %r9 \n
\t pop %r8 \n
);

::close-this := (
Expand Down
32 changes: 16 additions & 16 deletions stdlib/prelude.lm
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,25 @@
\t mov $1, %rax \n
\t mov $1, %rdi \n
\t mov $__put64_buffer, %rsi \n
\t mov $18, %rdx \n
\t mov $19, %rdx \n
\t syscall \n
\t ret \n
);

.data := (
\n
__cons_counter: \n
\t .zero 8 \n
__cons_section: \n
\t .zero 65536 \n
__nil_literal: \n
\t .ascii "()" \n
\t .zero 1 \n
__hex_buffer: \n
\t .ascii "0123456789abcdef" \n
__put64_buffer: \n
\t .ascii "0x" \n
__put64_write_buffer: \n
\t .ascii "0000000000000000" \n
\t .zero 1 \n
\n
__cons_counter: \n
\t .zero 8 \n
__cons_section: \n
\t .zero 65536 \n
__nil_literal: \n
\t .ascii "()" \n
\t .zero 1 \n
__hex_buffer: \n
\t .ascii "0123456789abcdef" \n
__put64_buffer: \n
\t .ascii "0x" \n
__put64_write_buffer: \n
\t .ascii "0000000000000000 " \n
\t .zero 1 \n
);

0 comments on commit 93c4e61

Please sign in to comment.