diff --git a/src/g.rs b/src/g.rs index 86086a62a..a530a61db 100644 --- a/src/g.rs +++ b/src/g.rs @@ -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); @@ -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(), diff --git a/stdlib/helpers.lm b/stdlib/helpers.lm index 560b5b4e0..1a31fb024 100644 --- a/stdlib/helpers.lm +++ b/stdlib/helpers.lm @@ -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 := ( diff --git a/stdlib/prelude.lm b/stdlib/prelude.lm index 351fb4192..baa22a3b4 100644 --- a/stdlib/prelude.lm +++ b/stdlib/prelude.lm @@ -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 );