add jump fn for 16 bit jump
This commit is contained in:
parent
316e8a6a58
commit
979afdbcb9
|
@ -261,13 +261,20 @@ impl Chunk {
|
|||
*i += 1;
|
||||
}
|
||||
PushBinding | MatchTuple | MatchList | MatchDict | LoadDictValue | PushTuple
|
||||
| PushBox | Jump | JumpIfFalse | JumpIfTrue | JumpIfNoMatch | JumpIfMatch
|
||||
| JumpBack | JumpIfZero | MatchDepth | PopN | StoreAt | Call | SetUpvalue
|
||||
| GetUpvalue | Partial | MatchString | PushStringMatches => {
|
||||
| PushBox | MatchDepth | PopN | StoreAt | Call | SetUpvalue | GetUpvalue | Partial
|
||||
| MatchString | PushStringMatches => {
|
||||
let next = self.bytecode[*i + 1];
|
||||
println!("{i:04}: {:16} {next:03}", op.to_string());
|
||||
*i += 1;
|
||||
}
|
||||
Jump | JumpIfFalse | JumpIfTrue | JumpIfNoMatch | JumpIfMatch | JumpBack
|
||||
| JumpIfZero => {
|
||||
let high = self.bytecode[*i + 1];
|
||||
let low = self.bytecode[*i + 2];
|
||||
let rand = ((high as u16) << 8) + low as u16;
|
||||
println!("{i:04}: {:16} {rand:05}", op.to_string());
|
||||
*i += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,6 +402,14 @@ impl<'a> Compiler<'a> {
|
|||
self.span = root_span;
|
||||
}
|
||||
|
||||
fn jump(&mut self, op: Op, len: usize) {
|
||||
let low = len as u8;
|
||||
let high = (len >> 8) as u8;
|
||||
self.emit_op(op);
|
||||
self.chunk.bytecode.push(high);
|
||||
self.chunk.bytecode.push(low);
|
||||
}
|
||||
|
||||
fn emit_constant(&mut self, val: Value) {
|
||||
let const_idx = if let Some(idx) = self.chunk.constants.iter().position(|v| *v == val) {
|
||||
idx
|
||||
|
|
Loading…
Reference in New Issue
Block a user