commit 531c773d4894d90a8b36bc8d9c008e1a51aac9b9
parent 33a90a70e24e7c315805416802ce1b1f3beacb46
Author: citbl <citbl@citbl.org>
Date: Sun, 14 Jun 2026 16:57:35 +1000
scoping params, refac callstmt to callexpr
Diffstat:
11 files changed, 80 insertions(+), 21 deletions(-)
diff --git a/plan b/plan
@@ -0,0 +1,23 @@
+
+- attach the scope / entities (Symbols) to the AST
+- attach the types (resolving types)
+- lower to IR
+
+
+String literal:
+ Typ := Standard_String
+
+Identifier:
+ Typ := Type_Of(Entity)
+
+
+1. Program / package / function / block nodes -> Scope
+2. Identifier / selected-name / call callee nodes -> Entity
+3. Every expression node -> Typ after typing
+
+Reuse the AST.
+Decorate it with Entity, Scope, and Type fields.
+Use No_Entity / No_Scope / No_Type before the relevant phase.
+Use checked accessors once a phase guarantees the field exists.
+Lower to a separate IR later, not for every semantic step.
+
diff --git a/src/ir.adb b/src/ir.adb
@@ -1,5 +1,3 @@
package body IR is
-
-
end IR;
diff --git a/src/ir.ads b/src/ir.ads
@@ -1,7 +1,3 @@
-
package IR is
-
-
-
end IR;
diff --git a/src/lexer.adb b/src/lexer.adb
@@ -17,7 +17,7 @@ package body Lexer is
end Init;
---------------
- -- add token --
+ -- add token --
---------------
procedure Add_Token (L : in out Lexer; T : Token) is
@@ -25,7 +25,6 @@ package body Lexer is
L.Tokens.Append (T);
end Add_Token;
-
function Peek (L : in Lexer) return Character is
begin
if L.Pos > L.Source'Length then
diff --git a/src/nightshade.adb b/src/nightshade.adb
@@ -5,6 +5,7 @@ with Types;
with Lexer;
with Parser;
with Scope;
+with Typer;
procedure Nightshade is
begin
diff --git a/src/parser.adb b/src/parser.adb
@@ -126,7 +126,7 @@ package body Parser is
Name : Unbounded_String;
E : Expr_Ref;
Expressions : Expr_Vectors.Vector;
- CS : Call_Stmt;
+ CS : Call_Expr;
begin
T := Match (P, Ident);
@@ -144,7 +144,7 @@ package body Parser is
T := Match (P, R_Paren);
T := Match (P, Separator);
- CS := Call_Stmt'(Name => Name, Params => Expressions);
+ CS := Call_Expr'(Name => Name, Params => Expressions);
return Stmt'(Kind => Stmt_Call, Call => CS, Scope => null);
end;
@@ -306,14 +306,16 @@ package body Parser is
procedure Print_AST (Decls : Declaration_Vectors.Vector) is
begin
- Put_Line ("------------------------------ Print AST: ------------------------------------");
+ Put_Line
+ ("------------------------------ Print AST: ------------------------------------");
for Decl of Decls loop
if Decl.Kind = Function_Kind then
Put_Line ("Function: (at scope " & AST_Scope_Ref'Image (Decl.Scope) & " )");
Print_Func_decl (Decl.Func, 1);
end if;
end loop;
- Put_Line("-------------------------------------------------------------------------------");
+ Put_Line
+ ("-------------------------------------------------------------------------------");
end Print_AST;
end Parser;
diff --git a/src/scope.adb b/src/scope.adb
@@ -93,15 +93,43 @@ package body Scope is
end if;
end;
+ ----------------------
+ -- scope call param --
+ ----------------------
+
+ procedure Scope_Call (S : in out Sem; Func_Call : in Call_Expr);
+
+ procedure Scope_Expr_Ref (S : in out Sem; Expr : Expr_Ref) is
+ begin
+ case Expr.Kind is
+ when String_Literal =>
+ Put_Line("scoping string literal has no effect");
+ null; -- no need to scope literals
+
+ when Expr_Call =>
+ Scope_Call (S, Expr.Call);
+
+ when others =>
+ raise Program_Error with "scoping expr unknown TODO?";
+ end case;
+ end;
+
---------------------
-- scope func call --
---------------------
- procedure Scope_Call (S : in out Sem; Func_Call : in Call_Stmt) is
+ procedure Scope_Call (S : in out Sem; Func_Call : in Call_Expr) is
begin
-- determine whether the callee exist in scope or bail with error
Put_Line ("scoping call");
Scope_Contains_Or_Error (S.Scope, Func_Call.Name, SYM_FUNC);
+
+ for Param of Func_Call.Params loop
+ Scope_Expr_Ref (S, Param);
+ end loop;
+ -- Func_Call.Params
+
+ -- TODO scope the parameter's expression as part of the scope_call
end;
--------------------
diff --git a/src/typer.adb b/src/typer.adb
@@ -0,0 +1,8 @@
+package body Typer is
+
+ function Init (AST : Declaration_Vectors.Vector) return Typer is
+ begin
+ return Typer'(AST => AST);
+ end;
+
+end Typer;
diff --git a/src/typer.ads b/src/typer.ads
@@ -0,0 +1,10 @@
+with Types; use Types;
+
+package Typer is
+
+ type Typer is record
+ AST : Declaration_Vectors.Vector;
+ end record;
+
+ function Init (AST : Declaration_Vectors.Vector) return Typer;
+end Typer;
diff --git a/src/types.ads b/src/types.ads
@@ -61,7 +61,7 @@ package Types is
type Stmt_Kind is (Stmt_Call);
- type Call_Stmt is record
+ type Call_Expr is record
Name : Unbounded_String;
Params : Expr_Vectors.Vector;
end record;
@@ -70,7 +70,7 @@ package Types is
Scope : AST_Scope_Ref;
case Kind is
when Stmt_Call =>
- Call : Call_Stmt;
+ Call : Call_Expr;
-- when Stmt_If =>
-- Iff : If_Stmt;
@@ -83,11 +83,6 @@ package Types is
end case;
end record;
- type Call_Expr is record
- Callee : Unbounded_String;
- Params : Expr_Vectors.Vector;
- end record;
-
package Stmt_Vectors is new
Ada.Containers.Indefinite_Vectors (Index_Type => Natural, Element_Type => Stmt);
diff --git a/src/utils.ads b/src/utils.ads
@@ -1,4 +1,3 @@
package Utils is
function Load_Contents (File_Name : String) return String;
end Utils;
-