summaryrefslogtreecommitdiff
path: root/chapter18/src/main/java/com/seaofnodes
diff options
context:
space:
mode:
Diffstat (limited to 'chapter18/src/main/java/com/seaofnodes')
-rw-r--r--chapter18/src/main/java/com/seaofnodes/simple/Parser.java12
-rw-r--r--chapter18/src/main/java/com/seaofnodes/simple/node/FunNode.java5
2 files changed, 12 insertions, 5 deletions
diff --git a/chapter18/src/main/java/com/seaofnodes/simple/Parser.java b/chapter18/src/main/java/com/seaofnodes/simple/Parser.java
index 8f0cf493..4f19dda2 100644
--- a/chapter18/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter18/src/main/java/com/seaofnodes/simple/Parser.java
@@ -1123,10 +1123,14 @@ public class Parser {
_scope.define(id, FRefNode.FREF_TYPE, true, XCTRL, loc());
n = _scope.lookup(id);
} else {
- // Lookup worked on an out-of-function value. No closures, so this
- // has to be a final constant.
- if( _scope.outOfFunction(n) && !(n._final && _scope.in(n._idx)._type.isConstant()) )
- throw error("Variable '"+n._name+"' is out of function scope and must be a final constant");
+ // Lookup worked on an out-of-function value.
+ if( _scope.outOfFunction(n) ) {
+ // No closures, so this has to be a final constant (which
+ // includes forward refs)
+ Node def = _scope.in(n._idx);
+ if( !(def instanceof FRefNode) && !(n._final && def._type.isConstant()) )
+ throw error("Variable '"+n._name+"' is out of function scope and must be a final constant");
+ }
}
return n;
}
diff --git a/chapter18/src/main/java/com/seaofnodes/simple/node/FunNode.java b/chapter18/src/main/java/com/seaofnodes/simple/node/FunNode.java
index 8300d80f..1f0c76eb 100644
--- a/chapter18/src/main/java/com/seaofnodes/simple/node/FunNode.java
+++ b/chapter18/src/main/java/com/seaofnodes/simple/node/FunNode.java
@@ -71,7 +71,10 @@ public class FunNode extends RegionNode {
// to collapse
if( unknownCallers() ) return null;
Node progress = super.idealize();
- if( progress!=null ) IterPeeps.add( CodeGen.CODE._stop);
+ if( progress!=null ) {
+ IterPeeps.add( CodeGen.CODE._stop);
+ IterPeeps.add( _ret );
+ }
return progress;
}