From d32f97238c903765dec4e9a9f3cbfa5fd12cded6 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 10 Aug 2026 11:11:18 -0700 Subject: Chapter 25: Modules, Separate Compilation, and SSA Construction Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: Symious <14933944+symious@users.noreply.github.com> Co-authored-by: Jun Kawasaki Co-authored-by: Claude Opus 5 --- .../java/com/seaofnodes/simple/node/FRefNode.java | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/seaofnodes/simple/node/FRefNode.java') diff --git a/src/main/java/com/seaofnodes/simple/node/FRefNode.java b/src/main/java/com/seaofnodes/simple/node/FRefNode.java index e7333c23..644f1434 100644 --- a/src/main/java/com/seaofnodes/simple/node/FRefNode.java +++ b/src/main/java/com/seaofnodes/simple/node/FRefNode.java @@ -10,17 +10,32 @@ import com.seaofnodes.simple.type.Type; * A Forward Reference. Its any final constant, including functions. When * the Def finally appears its plugged into the forward reference, which then * peepholes to the Def. + + * FRefs can be external references, to other Simple defined values in ELF + * files, or external FFI/C libs. If external, a file system lookup needs to + * find it in another file, and the name (one time) change to match the found + * location. + * + * Example, a ambiguous name "foo" is looked up externally; it might resolve + * to "A.B.foo" or "libc.foo" or the like; the name is changed to match. */ public class FRefNode extends ConstantNode { public static final Type FREF_TYPE = Type.BOTTOM; - public final Var _n; - public FRefNode( Var n ) { super(FREF_TYPE); _n = n; } + public String _name; + public final Parser.Lexer _loc; // Source location + + public FRefNode( String name, Parser.Lexer loc ) { this(name,loc,FREF_TYPE); } + public FRefNode( String name, Parser.Lexer loc, Type type ) { + super(type); + _name = name; + _loc = loc; + } - @Override public String label() { return "FRef"+_n; } + @Override public String label() { return "FRef"+_name; } @Override protected ExprPrinter _print1(ExprPrinter p) { - return p.p("FRef_").p(_n); + return p.p("FRef_").p(_name); } @Override public Node idealize() { @@ -28,8 +43,8 @@ public class FRefNode extends ConstantNode { return nIns()==1 ? null : in(1); } - public Parser.ParseException err() { return Parser.error("Undefined name '"+_n._name+"'",_n._loc); } + public Parser.ParseException err() { return Parser.error("Undefined name '"+_name+"'",_loc); } @Override public boolean eq(Node n) { return this==n; } - @Override int hash() { return _n._idx; } + @Override int hash() { return _name.hashCode(); } } -- cgit v1.2.3