Separate the IR evaluator, add an interesting stack-breaking case.

This commit is contained in:
2024-04-18 12:33:34 -07:00
parent 7d4f182a67
commit 6800064bdf
16 changed files with 283 additions and 122 deletions

View File

@@ -15,7 +15,7 @@ impl ConstantType {
match self {
ConstantType::Void => &[],
ConstantType::I8 | ConstantType::I16 | ConstantType::I32 | ConstantType::I64 => {
&[("+", 2), ("-", 1), ("-", 2), ("*", 2), ("/", 2)]
&[("+", 2), ("negate", 1), ("-", 2), ("*", 2), ("/", 2)]
}
ConstantType::U8 | ConstantType::U16 | ConstantType::U32 | ConstantType::U64 => {
&[("+", 2), ("-", 2), ("*", 2), ("/", 2)]

View File

@@ -146,7 +146,8 @@ impl Expression {
Value::Primitive(name) if name == "print" => {
if let [Expression::Reference(_, name)] = &args[..] {
let value = Expression::Reference(loc.clone(), name.clone()).eval(stdout, env)?;
let value = Expression::Reference(loc.clone(), name.clone())
.eval(stdout, env)?;
let value = match value {
Value::Number(x) => Value::U64(x),
x => x,
@@ -156,7 +157,10 @@ impl Expression {
stdout.push_str(&addendum);
Ok(Value::Void)
} else {
panic!("Non-reference/non-singleton argument to 'print': {:?}", args);
panic!(
"Non-reference/non-singleton argument to 'print': {:?}",
args
);
}
}