Skip to content

Commit

Permalink
print atom is working along with hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-johnson-4 committed Jan 2, 2024
1 parent 9313428 commit f7d49ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

[env]
RUST_TEST_THREADS = "1"
4 changes: 1 addition & 3 deletions src/g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn compile_expr(helpers_ctx: &S, program_ctx: &S, e: &S) -> S {
let xpg = compile_expr(helpers_ctx, program_ctx, &x);
assert_eq!( head(&f).to_string(), "variable" );
let f_name = label_case( &tail(&f).to_string() );
let call = variable( &format!("\tjmp {}\n", f_name) );
let call = variable( &format!("\tcall {}\n", f_name) );
let prog = app(
head(&xpg),
call
Expand Down Expand Up @@ -152,8 +152,6 @@ pub fn compile(cfg: &str, main_ctx: &S) {
for (k,v) in kv_iter(&main_ctx) {
let k = k.to_string();
let v = compile_expr(&helpers_ctx, &main_ctx, &v);
println!("compile user {} = {}", k, v);
println!("compile user {} = {}", k, head(&v));
raw_program = app(
raw_program,
app(
Expand Down
21 changes: 20 additions & 1 deletion stdlib/prelude.lm
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@

.text := (
# internal strlen (%rdi: *char)
_strlen: \n
\t xor %rcx, %rcx \n
_strlen_loop: \n
\t cmpb $0, 0(%rdi) \n
\t jz _strlen_exit \n
\t inc %rcx \n
\t inc %rdi \n
\t jmp _strlen_loop \n
_strlen_exit: \n
\t ret \n
# result is stored in %rcx

# entry points
print_s: \n
__print_this: \n
Expand All @@ -8,7 +21,13 @@
__print_this_atom: \n
\t cmp $0, %r8 \n
\t je __print_this_cons \n
# TODO print .atom
\t mov %r8, %rdi \n
\t call _strlen \n
\t mov %r8, %rsi \n # address of string to output
\t mov %rcx, %rdx \n # length is %rcx
\t mov $1, %rax \n # system call 1 is write
\t mov $1, %rdi \n # file handle 1 is stdout
\t syscall \n # invoke operating system to do the write
\t ret \n

__print_this_cons: \n
Expand Down

0 comments on commit f7d49ec

Please sign in to comment.