1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

refactor: change register format

This commit is contained in:
Natapat Samutpong 2022-01-28 07:33:58 +07:00
parent 8230151489
commit 4831b1265f
6 changed files with 26 additions and 14 deletions

View file

@ -28,6 +28,7 @@ DONE:
- Math:
TODO:
- Prove turing complete
- Do the intrinsic left
- Quote, Quasiquote, etc.
- Optimizing

View file

@ -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!() },

View file

@ -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<Self, Self::Err> {
let value = s[1..].parse::<usize>().map_err(|_| ())?;
if !s.starts_with("%") { return Err(format!("Invalid register: {}", s)); }
let value = s[1..].parse::<usize>().map_err(|_| (format!("Invalid register: {}", s)))?;
Ok(Register { value })
}
}

View file

@ -1,2 +1,3 @@
(fun cool_number (/ (+ 345 345) 10))
(fun main
(print (/ (+ 345 345) 10)))
(print cool_number))

View file

27
test.sh
View file

@ -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