1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-09-28 05:27:35 +00:00

refactor: cleanup unused, def => let

This commit is contained in:
azur 2022-02-04 09:46:47 +07:00 committed by Natapat Samutpong
parent a08f3ee5f0
commit 6d2cbd42ea
5 changed files with 13 additions and 19 deletions

View file

@ -22,7 +22,11 @@ Hello, World!
DONE:
- Parsing, Compiling, Running(VM)
- Intrinsic:
- `fun`, `do`, `print`, `if`
- Function definition: `fun`
- Variable definition: `let`
- Do blocks: `do`
- Printing: `print`
- Condition: `if`
- Math:
- `+` , `add`
- `-` , `sub`

View file

@ -66,7 +66,7 @@ impl Compiler {
result.push(Instr::Jump { to: len(&else_) });
result.append(&mut else_);
},
"def" => {
"let" => {
let var_name = match &cdr[0] {
Symbol(ref name) => name.clone(),
_ => return Err(format!("Expected variable name, got {}", cdr[0])),

View file

@ -10,19 +10,9 @@ pub enum Type {
Float(f64),
Boolean(bool),
String(String),
Symbol(String),
}
impl Type {
pub fn as_bool(&self) -> bool {
match self {
Type::Boolean(b) => *b,
Type::Int(i) => *i != 0,
Type::Float(f) => *f != 0.0,
Type::String(s) => !s.is_empty(),
_ => unreachable!(),
}
}
pub fn is_null(&self) -> bool {
match self {
@ -48,7 +38,6 @@ impl Type {
false => "false".to_string(),
},
Type::String(s) => s.clone(),
_ => unreachable!(),
}
}
}
@ -117,7 +106,6 @@ impl Display for Type {
Type::Float(fl) => write!(f, ":{}", fl),
Type::Boolean(b) => write!(f, ":{}", b),
Type::String(s) => write!(f, "$\"{}\"", s),
Type::Symbol(s) => write!(f, "function_{}", s),
_ => unreachable!(),
}
}

View file

@ -7,7 +7,6 @@ pub enum Error {
StackOverflow,
UnknownFunction(String),
UnknownFunctionCall(isize, isize),
UnknownVariable(String),
InvalidAriphmeticOperation,
}
@ -18,7 +17,6 @@ impl Display for Error {
Error::StackOverflow => write!(f, "Stack overflow"),
Error::UnknownFunction(name) => write!(f, "Unknown function: {}", name),
Error::UnknownFunctionCall(l, e) => write!(f, "Unknown function call at {}: {}", l, e),
Error::UnknownVariable(name) => write!(f, "Unknown variable: {}", name),
Error::InvalidAriphmeticOperation => write!(f, "Invalid ariphmetic operation"),
}
}

View file

@ -1,3 +1,7 @@
(fun main
(do (def name "Bobby")
(print name)))
(fun return_true true)
(fun main (do
(let name "John")
(if (return_true)
(print name)
(print "no"))))