Skip to content

Commit

Permalink
-lc is correct, but having strange behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-johnson-4 committed Jan 2, 2024
1 parent ff466e7 commit d87765f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,32 @@ fn assemble(cfg: &str, program: &S) {
let mut file = File::create(&tmp_s).expect("Could not create file in Term::compile");
file.write_all(code.as_bytes()).expect("Could not write to file in Term::compile");

Command::new("as")
let output = Command::new("as")
.arg(&tmp_s)
.arg("-o")
.arg(&tmp_o)
.spawn()
.expect("Could not run assembler in g::assemble")
.wait()
.wait_with_output()
.expect("Could not wait for assembler in g::assemble");
if !output.status.success() {
let err = String::from_utf8_lossy(&output.stderr).to_string();
panic!("{}", err)
}

Command::new("ld")
.arg("-s")
let output = Command::new("ld")
.arg("-lc")
.arg("-o")
.arg(cfg)
.arg(&tmp_o)
.spawn()
.expect("Could not run linker in g::assemble")
.wait()
.wait_with_output()
.expect("Could not wait for linker in g::assemble");
if !output.status.success() {
let err = String::from_utf8_lossy(&output.stderr).to_string();
panic!("{}", err)
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions stdlib/helpers.lm
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
::close-this := (
# move this S onto the heap
# %r12 becomes pointer to new location
# push 4
# call malloc
# add esp, 4
# ; now eax points to an allocated buffer of the requested size
\t mov $32, %edi \n # allocate 8*4 bytes
\t call malloc \n # call malloc
# ; now rax points to an allocated buffer of the requested size
\t mov %rax, %r12 \n # set %r12 as result
);

::open-this := (
Expand Down

0 comments on commit d87765f

Please sign in to comment.