From 81bf01319657f477bf21b05e6862d1c151f1e5ca Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Wed, 8 Jan 2025 23:45:16 -0800 Subject: [PATCH] Simplify FuncDeclStmtNode to not need funcBodySource --- .../part_15/nodes/stmts/variables/FuncDeclStmtNode.java | 5 +---- .../truffle/part_15/parsing/EasyScriptTruffleParser.java | 9 +++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/part-16/src/main/java/com/endoflineblog/truffle/part_15/nodes/stmts/variables/FuncDeclStmtNode.java b/part-16/src/main/java/com/endoflineblog/truffle/part_15/nodes/stmts/variables/FuncDeclStmtNode.java index 29f75ff8..1c27c8b4 100644 --- a/part-16/src/main/java/com/endoflineblog/truffle/part_15/nodes/stmts/variables/FuncDeclStmtNode.java +++ b/part-16/src/main/java/com/endoflineblog/truffle/part_15/nodes/stmts/variables/FuncDeclStmtNode.java @@ -16,7 +16,6 @@ import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.DynamicObjectLibrary; -import com.oracle.truffle.api.source.SourceSection; /** * A Node that represents the declaration of a function in EasyScript. @@ -29,13 +28,11 @@ @NodeField(name = "frameDescriptor", type = FrameDescriptor.class) @NodeField(name = "funcBody", type = UserFuncBodyStmtNode.class) @NodeField(name = "argumentCount", type = int.class) -@NodeField(name = "funcBodySource", type = SourceSection.class) public abstract class FuncDeclStmtNode extends SkippedStmtNode { protected abstract String getFuncName(); protected abstract FrameDescriptor getFrameDescriptor(); protected abstract UserFuncBodyStmtNode getFuncBody(); protected abstract int getArgumentCount(); - protected abstract SourceSection getFuncBodySource(); @CompilationFinal private FunctionObject cachedFunction; @@ -48,7 +45,7 @@ protected Object declareFunction(DynamicObject containerObject, var truffleLanguage = this.currentTruffleLanguage(); var funcRootNode = new StmtBlockRootNode(truffleLanguage, - this.getFrameDescriptor(), this.getFuncBody(), this.getFuncName(), this.getFuncBodySource()); + this.getFrameDescriptor(), this.getFuncBody(), this.getFuncName(), this.getFuncBody().getSourceSection()); var callTarget = funcRootNode.getCallTarget(); ShapesAndPrototypes shapesAndPrototypes = this.currentLanguageContext().shapesAndPrototypes; diff --git a/part-16/src/main/java/com/endoflineblog/truffle/part_15/parsing/EasyScriptTruffleParser.java b/part-16/src/main/java/com/endoflineblog/truffle/part_15/parsing/EasyScriptTruffleParser.java index cb87ad46..c4b91693 100644 --- a/part-16/src/main/java/com/endoflineblog/truffle/part_15/parsing/EasyScriptTruffleParser.java +++ b/part-16/src/main/java/com/endoflineblog/truffle/part_15/parsing/EasyScriptTruffleParser.java @@ -492,13 +492,10 @@ private FuncDeclStmtNode parseSubroutineDecl(EasyScriptParser.Subroutine_declCon this.state = previousParserState; this.localScopes = previousLocalScopes; - return FuncDeclStmtNodeGen.create( - containerObjectExpr, + return FuncDeclStmtNodeGen.create(containerObjectExpr, subroutineDecl.name.getText(), - frameDescriptor, - new UserFuncBodyStmtNode(funcStmts, this.createSourceSection(subroutineDecl)), - argumentCount, - this.createSourceSection(subroutineDecl)); + frameDescriptor, new UserFuncBodyStmtNode(funcStmts, this.createSourceSection(subroutineDecl)), + argumentCount); } private EasyScriptExprNode parseExpr1(EasyScriptParser.Expr1Context expr1) {