From 16e7a7973657e8f0d43123bd5accefc9fbcb9a86 Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sat, 22 Feb 2025 12:54:53 +0000 Subject: [PATCH] Small refactor to help with the incremental SSA diff --- .../ezlang/compiler/CompiledFunction.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java index 06c42b5..2eaf92b 100644 --- a/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java +++ b/optvm/src/main/java/com/compilerprogramming/ezlang/compiler/CompiledFunction.java @@ -393,23 +393,6 @@ private boolean compileSetFieldExpr(AST.SetFieldExpr setFieldExpr) { return false; } - private void codeNew(Type type) { - var temp = createTemp(type); - if (type instanceof Type.TypeArray typeArray) { - code(new Instruction.NewArray(typeArray, temp)); - } - else if (type instanceof Type.TypeStruct typeStruct) { - code(new Instruction.NewStruct(typeStruct, temp)); - } - else - throw new CompilerException("Unexpected type: " + type); - } - - private void codeStoreAppend() { - var operand = pop(); - code(new Instruction.AStoreAppend((Operand.RegisterOperand) top(), operand)); - } - private boolean compileNewExpr(AST.NewExpr newExpr) { codeNew(newExpr.type); if (newExpr.initExprList != null && !newExpr.initExprList.isEmpty()) { @@ -636,6 +619,23 @@ else if (indexed instanceof Operand.LoadFieldOperand loadFieldOperand) { code(new Instruction.Move(value, indexed)); } + private void codeNew(Type type) { + var temp = createTemp(type); + if (type instanceof Type.TypeArray typeArray) { + code(new Instruction.NewArray(typeArray, temp)); + } + else if (type instanceof Type.TypeStruct typeStruct) { + code(new Instruction.NewStruct(typeStruct, temp)); + } + else + throw new CompilerException("Unexpected type: " + type); + } + + private void codeStoreAppend() { + var operand = pop(); + code(new Instruction.AStoreAppend((Operand.RegisterOperand) top(), operand)); + } + private boolean vstackEmpty() { return virtualStack.isEmpty(); }