From 85be56d890f100b72dde8e011d7421e597888363 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 9 Jul 2023 11:59:27 +0100 Subject: Add explicit function return statement --- .../java/org/shedlang/compiler/stackir/StackCompiler.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main/java/org/shedlang/compiler/stackir') diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index 449360e1..d3b8801c 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -112,14 +112,19 @@ public class StackCompiler { return P.vector(defineFunctionInstruction, storeInstruction); } + + private static PVector compileFunctionReturn(TypedFunctionReturnNode node) { + return compileExpression(node.expression()) + .plus(new ReturnInstruction(node.source())); + } public static PVector compileFunctionStatement(TypedFunctionStatementNode node) { return switch (node) { case TypedExpressionStatementNode expressionStatement -> compileExpressionStatement(expressionStatement); - case TypedReturnNode return_ -> - compileReturn(return_); + case TypedFunctionReturnNode functionReturn -> + compileFunctionReturn(functionReturn); case TypedValNode val -> compileVal(val); @@ -169,11 +174,6 @@ public class StackCompiler { return P.vector(new LocalLoadInstruction(node.name(), node.source())); } - private static PVector compileReturn(TypedReturnNode node) { - return compileExpression(node.expression()) - .plus(new ReturnInstruction(node.source())); - } - private static PVector compileStringLiteral(TypedStringLiteralNode node) { return P.vector(new PushStringInstruction(node.value(), node.source())); } -- cgit v1.2.3