Skip to content

Commit

Permalink
ImlValue::compile_load() & ImlValue::compile_call()
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward committed Apr 19, 2023
1 parent 6566246 commit 5946136
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/compiler/iml/imlop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl ImlOp {
ops.push(Op::Offset(Box::new(*offset)));
}

ops.push(target.compile_to_load(program));
target.compile_load(program, ops);
}
ImlOp::Call {
offset,
Expand All @@ -305,7 +305,7 @@ impl ImlOp {
ops.push(Op::Offset(Box::new(*offset)));
}

ops.extend(target.compile_to_call(program, *args));
target.compile_call(program, *args, ops);
}
ImlOp::Alt { alts } => {
let mut ret = Vec::new();
Expand Down
40 changes: 18 additions & 22 deletions src/compiler/iml/imlvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,56 +138,55 @@ impl ImlValue {
/** Generates code for a value load. For several, oftenly used values, there exists a direct operation pendant,
which makes storing the static value obsolete. Otherwise, *value* will be registered and a static load operation
is returned. */
pub fn compile_to_load(&self, program: &mut ImlProgram) -> Op {
pub fn compile_load(&self, program: &mut ImlProgram, ops: &mut Vec<Op>) {
match self {
ImlValue::Shared(value) => return value.borrow().compile_to_load(program),
ImlValue::Shared(value) => return value.borrow().compile_load(program, ops),
ImlValue::Value(value) => match &*value.borrow() {
Value::Void => return Op::PushVoid,
Value::Null => return Op::PushNull,
Value::True => return Op::PushTrue,
Value::False => return Op::PushFalse,
Value::Void => return ops.push(Op::PushVoid),
Value::Null => return ops.push(Op::PushNull),
Value::True => return ops.push(Op::PushTrue),
Value::False => return ops.push(Op::PushFalse),
Value::Int(i) => match i.to_i64() {
Some(0) => return Op::Push0,
Some(1) => return Op::Push1,
Some(0) => return ops.push(Op::Push0),
Some(1) => return ops.push(Op::Push1),
_ => {}
},
_ => {}
},
ImlValue::Parselet(_) => {}
ImlValue::Local(addr) => return Op::LoadFast(*addr),
ImlValue::Global(addr) => return Op::LoadGlobal(*addr),
ImlValue::Local(addr) => return ops.push(Op::LoadFast(*addr)),
ImlValue::Global(addr) => return ops.push(Op::LoadGlobal(*addr)),
ImlValue::Name { name, .. } => {
program.errors.push(Error::new(
None,
format!("Use of unresolved symbol '{}'", name),
));

return Op::Nop;
return;
}
_ => todo!(),
}

Op::LoadStatic(program.register(self))
ops.push(Op::LoadStatic(program.register(self)))
}

/** Generates code for a value call. */
pub fn compile_to_call(
pub fn compile_call(
&self,
program: &mut ImlProgram,
args: Option<(usize, bool)>,
) -> Vec<Op> {
let mut ops = Vec::new();

ops: &mut Vec<Op>,
) {
match self {
ImlValue::Shared(value) => return value.borrow().compile_to_call(program, args),
ImlValue::Shared(value) => return value.borrow().compile_call(program, args, ops),
ImlValue::Local(addr) => ops.push(Op::LoadFast(*addr)),
ImlValue::Global(addr) => ops.push(Op::LoadGlobal(*addr)),
ImlValue::Name { name, .. } => {
program.errors.push(Error::new(
None,
format!("Call to unresolved symbol '{}'", name),
));
return ops;
return;
}
value => {
// When value is a parselet, check for accepted constant configuration
Expand Down Expand Up @@ -221,7 +220,6 @@ impl ImlValue {
}
}
*/

let idx = program.register(value);

match args {
Expand All @@ -245,7 +243,7 @@ impl ImlValue {
}
}

return ops;
return;
}
_ => todo!(),
}
Expand All @@ -264,8 +262,6 @@ impl ImlValue {
// Call or load
None => ops.push(Op::CallOrCopy),
}

ops
}
}

Expand Down

0 comments on commit 5946136

Please sign in to comment.