diff --git a/src/g.rs b/src/g.rs index 6e229feb2..c4a43734b 100644 --- a/src/g.rs +++ b/src/g.rs @@ -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) + } } } diff --git a/stdlib/helpers.lm b/stdlib/helpers.lm index fe72f2bcb..8f3e339c4 100644 --- a/stdlib/helpers.lm +++ b/stdlib/helpers.lm @@ -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 := (