From 6d2cbd42eab69cae1fc24b355799aee995f76928 Mon Sep 17 00:00:00 2001 From: azur <73991665+azur1s@users.noreply.github.com> Date: Fri, 4 Feb 2022 09:46:47 +0700 Subject: [PATCH] refactor: cleanup unused, `def` => `let` --- README.md | 6 +++++- blspc/src/compiler/compile.rs | 2 +- blspc/src/vm/instr.rs | 12 ------------ blspc/src/vm/vm.rs | 2 -- example/var.blsp | 10 +++++++--- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0ee3af7..d2c17e0 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/blspc/src/compiler/compile.rs b/blspc/src/compiler/compile.rs index e5576be..82031cb 100644 --- a/blspc/src/compiler/compile.rs +++ b/blspc/src/compiler/compile.rs @@ -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])), diff --git a/blspc/src/vm/instr.rs b/blspc/src/vm/instr.rs index 60b2be3..0c6b93e 100644 --- a/blspc/src/vm/instr.rs +++ b/blspc/src/vm/instr.rs @@ -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!(), } } diff --git a/blspc/src/vm/vm.rs b/blspc/src/vm/vm.rs index be02918..d5da987 100644 --- a/blspc/src/vm/vm.rs +++ b/blspc/src/vm/vm.rs @@ -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"), } } diff --git a/example/var.blsp b/example/var.blsp index fdf9e43..019468a 100644 --- a/example/var.blsp +++ b/example/var.blsp @@ -1,3 +1,7 @@ -(fun main - (do (def name "Bobby") - (print name))) \ No newline at end of file +(fun return_true true) + +(fun main (do + (let name "John") + (if (return_true) + (print name) + (print "no")))) \ No newline at end of file