From 4831b1265fe7cb0a4477cf4ea99691aace982e52 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Fri, 28 Jan 2022 07:33:58 +0700 Subject: [PATCH] refactor: change register format --- README.md | 1 + blspc/src/compiler/compile.rs | 1 - blspc/src/vm/instr.rs | 8 +++++--- example/math.blsp | 3 ++- example/s.blsp | 0 test.sh | 27 ++++++++++++++++++--------- 6 files changed, 26 insertions(+), 14 deletions(-) delete mode 100644 example/s.blsp diff --git a/README.md b/README.md index 9c10642..a3a5bae 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ DONE: - Math: TODO: +- Prove turing complete - Do the intrinsic left - Quote, Quasiquote, etc. - Optimizing diff --git a/blspc/src/compiler/compile.rs b/blspc/src/compiler/compile.rs index 4647a18..14b2e34 100644 --- a/blspc/src/compiler/compile.rs +++ b/blspc/src/compiler/compile.rs @@ -52,7 +52,6 @@ impl Compiler { _ => { result.append(&mut self.compile_intrinsic(call, &cdr)?); } - _ => { dbg!(call); unimplemented!() }, } // End `match call` }, // End `Symbol(call)` _ => { dbg!(car); unimplemented!() }, diff --git a/blspc/src/vm/instr.rs b/blspc/src/vm/instr.rs index d291277..f13cae2 100644 --- a/blspc/src/vm/instr.rs +++ b/blspc/src/vm/instr.rs @@ -161,15 +161,17 @@ impl Register { impl Display for Register { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "r{}", self.value) + write!(f, "%{}", self.value) } } impl FromStr for Register { - type Err = (); + type Err = String; fn from_str(s: &str) -> Result { - let value = s[1..].parse::().map_err(|_| ())?; + if !s.starts_with("%") { return Err(format!("Invalid register: {}", s)); } + + let value = s[1..].parse::().map_err(|_| (format!("Invalid register: {}", s)))?; Ok(Register { value }) } } diff --git a/example/math.blsp b/example/math.blsp index 1f2ec3e..8fdf481 100644 --- a/example/math.blsp +++ b/example/math.blsp @@ -1,2 +1,3 @@ +(fun cool_number (/ (+ 345 345) 10)) (fun main - (print (/ (+ 345 345) 10))) \ No newline at end of file + (print cool_number)) \ No newline at end of file diff --git a/example/s.blsp b/example/s.blsp deleted file mode 100644 index e69de29..0000000 diff --git a/test.sh b/test.sh index 51e622e..30a4b38 100755 --- a/test.sh +++ b/test.sh @@ -2,12 +2,21 @@ in=$1 # Get first's file name noext=${in%.*} # Remove extension name=${noext##*/} # Remove path -make debug -blspc compile $noext.blsp -echo -e "------------------------------------------- SOURCE" -cat $noext.blsp -echo -e "\n----------------------------------------- COMPILED" -cat $name.bsm -echo -e "------------------------------------------- OUTPUT" -blspc run $name.bsm -echo -e "--------------------------------------------------" +echo $2 +# if $2 equal to "noecho" +if [ $2 = "noecho" ]; +then + make debug; echo ""; blspc compile $noext.blsp; echo "" + cat $noext.blsp; echo -e "\n"; cat $name.bsm; echo "" + blspc run $name.bsm +else + make debug + blspc compile $noext.blsp + echo -e "------------------------------------------- SOURCE" + cat $noext.blsp + echo -e "\n----------------------------------------- COMPILED" + cat $name.bsm + echo -e "------------------------------------------- OUTPUT" + blspc run $name.bsm + echo -e "--------------------------------------------------" +fi