From 979afdbcb93312e0a5d558f6e87be8116a43136d Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Wed, 18 Jun 2025 13:15:57 -0400 Subject: [PATCH] add jump fn for 16 bit jump --- src/compiler.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 69e9fa5..c0186cf 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -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