From 0671df6c0b76f160ec8c29c219a4af5249569aea Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Thu, 21 Dec 2023 00:53:10 +0000 Subject: Chapter8 update to sync with latest changes (#53) * #52 Update chapter8 to align with chapter7 * #52 Update chapter8 to align with chapter7 * #52 Fix spacing --- chapter07/src/main/java/com/seaofnodes/simple/Parser.java | 4 ++-- .../src/main/java/com/seaofnodes/simple/node/ScopeNode.java | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'chapter07/src/main/java/com') diff --git a/chapter07/src/main/java/com/seaofnodes/simple/Parser.java b/chapter07/src/main/java/com/seaofnodes/simple/Parser.java index c3972be9..3bc532c2 100644 --- a/chapter07/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter07/src/main/java/com/seaofnodes/simple/Parser.java @@ -87,14 +87,14 @@ public class Parser { public StopNode parse() { return parse(false); } public StopNode parse(boolean show) { - _xScopes.push(_scope); + _xScopes.push(_scope); // Enter a new scope for the initial control and arguments _scope.push(); _scope.define(ScopeNode.CTRL, new ProjNode(START, 0, ScopeNode.CTRL).peephole()); _scope.define(ScopeNode.ARG0, new ProjNode(START, 1, ScopeNode.ARG0).peephole()); parseBlock(); _scope.pop(); - _xScopes.pop(); + _xScopes.pop(); if (!_lexer.isEOF()) throw error("Syntax error, unexpected " + _lexer.getAnyNextToken()); STOP.peephole(); if( show ) showGraph(); diff --git a/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java index b5ce997b..a83ae1a7 100644 --- a/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java +++ b/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java @@ -142,11 +142,12 @@ public class ScopeNode extends Node { // 3) Ensure that the order of defs is the same to allow easy merging for( HashMap syms : _scopes ) dup._scopes.push(new HashMap<>(syms)); - String[] names = reverseNames(); // Get the variable names + dup.addDef(ctrl()); // Control input is just copied for( int i=1; i