diff options
| author | Cliff Click <cliffc@acm.org> | 2025-01-13 16:55:25 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-01-15 15:07:30 -0800 |
| commit | ce0c74158bbd91c1ca6443816f51b603d557e376 (patch) | |
| tree | a05bd7ce5ce6c02c90461ae3d669966691ac6f8c /chapter18/src/main/java | |
| parent | a0bee26d769adf61ed0a292983992a70e4e261c3 (diff) | |
| download | Simple-ce0c74158bbd91c1ca6443816f51b603d557e376.tar.gz Simple-ce0c74158bbd91c1ca6443816f51b603d557e376.zip | |
MergeSort to its own file
Allow self-recursive forward refs.
Missing progress.
Diffstat (limited to 'chapter18/src/main/java')
| -rw-r--r-- | chapter18/src/main/java/com/seaofnodes/simple/Parser.java | 12 | ||||
| -rw-r--r-- | chapter18/src/main/java/com/seaofnodes/simple/node/FunNode.java | 5 |
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; } |
