From 1c2965adcdfa8d732998bf154dd341ad8fe3032d Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Fri, 27 Oct 2023 19:22:24 +0100 Subject: Applied fix for #12 to chapter 3 (#15) ScopeNode added to chapter 3 Revised the description for Chapter 3 and 4 to include ScopeNode. --- chapter04/README.md | 3 ++- chapter04/src/main/java/com/seaofnodes/simple/Parser.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'chapter04') diff --git a/chapter04/README.md b/chapter04/README.md index 7e8a8eea..45d054de 100644 --- a/chapter04/README.md +++ b/chapter04/README.md @@ -33,6 +33,7 @@ Below is our list of Nodes from [Chapter 3](../chapter03/README.md): | Mul | Data | Multiply two values | Two data nodes, values are multiplied, order not important | Result of the multiply | | Div | Data | Divide a value by another | Two data nodes, values are divided, order matters | Result of the division | | UnaryMinus | Data | Negate a value | One data node, value is negated | Result of the unary minus | +| Scope | ? | Represents scopes in the graph | All nodes that define variables | None | ## Projection Nodes @@ -228,7 +229,7 @@ The peephole method does following: private Node deadCodeElim(Node m) { // If self is going dead and not being returned here (Nodes returned // from peephole commonly have no uses (yet)), then kill self. - if( m != this && isDead() ) { + if( m != this && isUnused() ) { // Killing self - and since self recursively kills self's inputs we // might end up killing 'm', which we are returning as a live Node. // So we add a bogus extra null output edge to stop kill(). diff --git a/chapter04/src/main/java/com/seaofnodes/simple/Parser.java b/chapter04/src/main/java/com/seaofnodes/simple/Parser.java index a6872106..147515f6 100644 --- a/chapter04/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter04/src/main/java/com/seaofnodes/simple/Parser.java @@ -45,6 +45,8 @@ public class Parser { String src() { return new String( _lexer._input ); } + + public ReturnNode parse() { _scope.push(); try { -- cgit v1.2.3