Skip to content

Commit d6ce011

Browse files
committed
Merge remote-tracking branch 'origin/val-fix' into codegen-meri
2 parents 052bb6c + f698189 commit d6ce011

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

lib/src/codegen/ir.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,10 @@ fn generate_code_stmt(
740740
is_last_instr,
741741
);
742742
let body_len = get_instructions_length(&body) as i16;
743-
result.push(Instruction::ifeq(3 + body_len, body.len() as i16 + 1));
743+
result.push(Instruction::ifeq(
744+
2 + 1 + 3 + body_len,
745+
body.len() as i16 + 2,
746+
));
744747
result.append(&mut body);
745748
result.push(Instruction::goto(
746749
-3 - body_len - cond_len,

lib/src/codegen/stack.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ impl StackMapFrame {
438438
v
439439
}
440440
StackMapFrame::CHOP(chopped_amount, offset_delta) => {
441-
todo!()
441+
let mut v = Vec::with_capacity(8);
442+
v.push(*chopped_amount);
443+
v.extend_from_slice(&offset_delta.to_be_bytes());
444+
v
442445
}
443446
StackMapFrame::APPEND(appended_amount, offset_delta, types) => {
444447
let mut v = Vec::with_capacity(16);

lib/src/tests/fib_class.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ fn fib_class() -> Class {
217217
))),
218218
Type::Int,
219219
),
220+
TypedStmt(
221+
Box::new(LocalVarDecl(Type::Int, "next".to_string())),
222+
Type::Int,
223+
),
224+
TypedStmt(
225+
Box::new(StmtExprStmt(TypedStmtExpr(
226+
Box::new(Assign(
227+
Expr::TypedExpr(
228+
Box::new(Expr::LocalVar("next".to_string())),
229+
Type::Int,
230+
),
231+
TypedExpr(Box::new(Expr::Integer(0)), Type::Int),
232+
)),
233+
Type::Int,
234+
))),
235+
Type::Int,
236+
),
220237
TypedStmt(
221238
Box::new(While(
222239
TypedExpr(
@@ -235,10 +252,6 @@ fn fib_class() -> Class {
235252
),
236253
Box::new(TypedStmt(
237254
Box::new(Block(vec![
238-
TypedStmt(
239-
Box::new(LocalVarDecl(Type::Int, "next".to_string())),
240-
Type::Int,
241-
),
242255
TypedStmt(
243256
Box::new(StmtExprStmt(TypedStmtExpr(
244257
Box::new(Assign(

lib/testcases/Fib.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ int iter(int n) {
1414
int x = 0;
1515
int y = 1;
1616
int i = 1;
17+
int next = 0;
1718
while (i < n) {
18-
int next = y + x;
19+
next = y + x;
1920
x = y;
2021
y = next;
2122
i = i + 1;

0 commit comments

Comments
 (0)