mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-09-28 07:27:35 +00:00
feat: some comment in compiled file
This commit is contained in:
parent
4ce5e43c78
commit
8be3cb5a55
|
@ -26,7 +26,6 @@ impl Compiler {
|
||||||
|
|
||||||
pub fn compile(&mut self, src: Sexpr) -> Result<Vec<Instr>, String> {
|
pub fn compile(&mut self, src: Sexpr) -> Result<Vec<Instr>, String> {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let comp = src.clone(); // Used for commenting
|
|
||||||
|
|
||||||
'tco: loop {
|
'tco: loop {
|
||||||
match src {
|
match src {
|
||||||
|
@ -40,7 +39,6 @@ impl Compiler {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fun" => {
|
"fun" => {
|
||||||
result.push(Instr::Comment { text: format!("function {}", comp) });
|
|
||||||
let function_name = match &cdr[0] {
|
let function_name = match &cdr[0] {
|
||||||
Symbol(ref name) => format!("function_{}", name.clone()),
|
Symbol(ref name) => format!("function_{}", name.clone()),
|
||||||
_ => return Err(format!("Expected function name, got {}", cdr[0])),
|
_ => return Err(format!("Expected function name, got {}", cdr[0])),
|
||||||
|
@ -180,7 +178,7 @@ impl Compiler {
|
||||||
result.push(Instr::Not);
|
result.push(Instr::Not);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
result.push(Instr::Comment { text: format!("{} function", intrinsic) });
|
result.push(Instr::Comment { text: format!("`{}` function", intrinsic) });
|
||||||
result.push(Instr::JumpLabel { to: format!("function_{}", intrinsic), });
|
result.push(Instr::JumpLabel { to: format!("function_{}", intrinsic), });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,6 +207,7 @@ impl Compiler {
|
||||||
Some((_, pointer)) => *pointer,
|
Some((_, pointer)) => *pointer,
|
||||||
None => return Err(format!("Undefined variable {}", s)),
|
None => return Err(format!("Undefined variable {}", s)),
|
||||||
};
|
};
|
||||||
|
result.push(Instr::Comment { text: format!("`{}` variable", s) });
|
||||||
result.push(Instr::Load { address: var_pointer });
|
result.push(Instr::Load { address: var_pointer });
|
||||||
},
|
},
|
||||||
_ => { result.append(&mut self.compile(atom.clone())?); }
|
_ => { result.append(&mut self.compile(atom.clone())?); }
|
||||||
|
|
Loading…
Reference in a new issue