pub enum IR {
Label(String),
Call(String),
+ WordPointer(String),
+ CallPtr,
Ret,
StackPush(u64),
StackPushString(String), // refers to string label, not the string itself
"endif" => IR::EndIf,
"loop" => IR::Loop,
"endloop" => IR::EndLoop,
+ "call" => IR::CallPtr,
"=" => IR::Equals,
">" => IR::GreaterThan,
"<" => IR::LessThan,
"sys5" => IR::Sys5,
"sys6" => IR::Sys6,
// TODO num type specfic math like `+:i32`, etc.
- _ => IR::Call(String::from(*word))
+ _ => {
+ if word.starts_with("'") {
+ let actual_word = &word[1..];
+ IR::WordPointer(String::from(actual_word))
+ } else {
+ IR::Call(String::from(*word))
+ }
+ }
}
},
Token::String(text) => {
IR::Call(name) => {
IR::Call(module.get_label_for_call(name))
},
+ IR::WordPointer(name) => {
+ IR::WordPointer(module.get_label_for_call(name))
+ },
_ => instruction.clone()
};
self.text.push(new_instruction);
self.label(format!("# call {}", mangled));
self.line(format!("call {}", mangled));
},
+ IR::WordPointer(name) => {
+ let mangled = mangle(name);
+ self.label(format!("# '{} (word pointer)", mangled));
+ self.line(format!("la t0, {}", mangled));
+ self.push_from("t0");
+ },
+ IR::CallPtr => {
+ self.label("# callptr");
+ self.pop_to("t0");
+ self.line("jalr t0");
+ },
IR::Ret => {
if last_label == "main" {
self.label("# exit 0 syscall");
free \ ( )
42 43 44 "soup" putstack
+
+: hello_world_again
+ "Hello World, Again!\n" puts drop
+;
+
+'hello_world_again call