mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
refactor: cleanup unused, def
=> let
This commit is contained in:
parent
a08f3ee5f0
commit
6d2cbd42ea
|
@ -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`
|
||||
|
|
|
@ -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])),
|
||||
|
|
|
@ -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!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"))))
|
Loading…
Reference in a new issue