[fine] Static methods I guess
This commit is contained in:
parent
bc57978dda
commit
19e57db724
6 changed files with 111 additions and 51 deletions
|
|
@ -216,6 +216,13 @@ macro_rules! ice {
|
|||
}}
|
||||
}
|
||||
|
||||
macro_rules! inst_panic {
|
||||
($($t:tt)+) => {{
|
||||
// eprintln!($($t)*);
|
||||
Instruction::Panic
|
||||
}};
|
||||
}
|
||||
|
||||
// macro_rules! ice {
|
||||
// ($compiler:expr, $tr:expr, $($t:tt)*) => {{}};
|
||||
// }
|
||||
|
|
@ -295,7 +302,7 @@ fn compile_expression(c: &mut Compiler, t: TreeRef) {
|
|||
_ => ice!(c, t, "{tree:?} is not an expression, cannot compile"),
|
||||
};
|
||||
if matches!(cr, None) {
|
||||
c.push(Instruction::Panic);
|
||||
c.push(inst_panic!("panic compiling expression {:?}", tree));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +337,7 @@ fn compile_literal(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR {
|
|||
let index = c.add_string(result);
|
||||
c.push(Instruction::PushString(index))
|
||||
}
|
||||
Type::Error => c.push(Instruction::Panic),
|
||||
Type::Error => c.push(inst_panic!("compiling literal {:?}", tr)),
|
||||
_ => ice!(c, t, "unsupported literal type: {t:?}"),
|
||||
};
|
||||
OK
|
||||
|
|
@ -401,7 +408,7 @@ fn compile_binary_expression(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR {
|
|||
TokenKind::Plus => compile_simple_binary_expression(c, tr, |_, t| match t {
|
||||
Type::F64 => Instruction::FloatAdd,
|
||||
Type::String => Instruction::StringAdd,
|
||||
_ => Instruction::Panic,
|
||||
_ => inst_panic!("panic adding {}", t),
|
||||
}),
|
||||
TokenKind::Minus => {
|
||||
compile_simple_binary_expression(c, tr, |_, _| Instruction::FloatSubtract)
|
||||
|
|
@ -451,7 +458,7 @@ fn compile_binary_expression(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR {
|
|||
Type::F64 => Instruction::CompareFloat,
|
||||
Type::String => Instruction::CompareString,
|
||||
Type::Bool => Instruction::CompareBool, // ?
|
||||
_ => Instruction::Panic,
|
||||
_ => inst_panic!("panic comparing {}", arg_type),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -494,9 +501,9 @@ fn compile_binary_expression(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR {
|
|||
}
|
||||
}
|
||||
|
||||
Declaration::ExternFunction { .. } => Instruction::Panic,
|
||||
Declaration::Function { .. } => Instruction::Panic,
|
||||
Declaration::Class { .. } => Instruction::Panic,
|
||||
Declaration::ExternFunction { .. } => inst_panic!("store ext"),
|
||||
Declaration::Function { .. } => inst_panic!("store func"),
|
||||
Declaration::Class { .. } => inst_panic!("store class"),
|
||||
};
|
||||
c.push(instruction);
|
||||
}
|
||||
|
|
@ -573,8 +580,8 @@ fn compile_load_declaration(c: &mut Compiler, t: TreeRef, declaration: &Declarat
|
|||
}
|
||||
Declaration::ExternFunction { id, .. } => Instruction::LoadExternFunction(id.id()),
|
||||
|
||||
// There is no universe where it's possible to use a class as a variable.
|
||||
Declaration::Class { .. } => Instruction::Panic,
|
||||
// Must be a static don't worry about it.
|
||||
Declaration::Class { .. } => return OK,
|
||||
};
|
||||
|
||||
c.push(instruction);
|
||||
|
|
@ -628,8 +635,8 @@ fn compile_argument(c: &mut Compiler, tree: &Tree) -> CR {
|
|||
|
||||
fn compile_new_object_expression(c: &mut Compiler, t: TreeRef, tree: &Tree) -> CR {
|
||||
// We pass in the arguments.... by... field order?
|
||||
let Type::Class(ct, _) = c.semantics.type_of(t) else {
|
||||
c.push(Instruction::Panic);
|
||||
let Type::Object(ct, _) = c.semantics.type_of(t) else {
|
||||
c.push(inst_panic!("new obj not ob"));
|
||||
return OK;
|
||||
};
|
||||
let class = c.semantics.class_of(ct);
|
||||
|
|
@ -724,7 +731,7 @@ fn compile_statement(c: &mut Compiler, t: TreeRef, gen_value: bool) {
|
|||
_ => ice!(c, t, "unsupported tree kind {:?}", tree.kind),
|
||||
};
|
||||
if matches!(cr, None) {
|
||||
c.push(Instruction::Panic);
|
||||
c.push(inst_panic!("stat {:?}", tree));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue