refactor: change register format

replace/7746dba3cc6b3860afe1faf69e86ed84ee46988d
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