nightshade

The nightshade programming language, compiler and tools (WIP)
Log | Files | Refs | README

commit 053d2c91df7f26b60462e21b8ce9c857ab64b2db
parent 6ece05c4f7c38cb172215f3dd9d3fc4c94bb3011
Author: citbl <citbl@citbl.org>
Date:   Sat, 13 Jun 2026 18:55:35 +1000

sem wip

Diffstat:
Msrc/sem.adb | 47+++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/sem.adb b/src/sem.adb @@ -1,8 +1,11 @@ -with Parser; use Parser; +with Parser; use Parser; with Ada.Containers.Indefinite_Vectors; +with Ada.Text_IO; use Ada.Text_IO; package body Sem is + procedure Load_STD_Symbols(S : in out Sem); + ---------- -- init -- ---------- @@ -14,6 +17,7 @@ package body Sem is begin Sc := new Scope'(Parent => null, Symbols => Symbols); S := (Scope => Sc, AST => AST); + Load_STD_Symbols (S); return S; end Init; @@ -23,6 +27,7 @@ package body Sem is procedure Load_STD_Symbols (S : in out Sem) is begin + Put_Line ("load std symbols"); S.Scope.Symbols.Include ("print", SYM_CALL); end; @@ -38,6 +43,41 @@ package body Sem is S.Scope := Sc; end; + ----------------------------- + -- scope contains or error -- + ----------------------------- + + procedure Scope_Contains_Or_Error + (Sc : Scope_Ref; Name : Unbounded_String; Kind : Symbol_Kind) + is + Kind_Found : Symbol_Kind; + begin + if Sc.Symbols.Contains (To_String (Name)) then + Kind_Found := Sc.Symbols.Element (To_String (Name)); + if Kind_Found = Kind then + Put_Line + ("Found " + & To_String (Name) + & " of kind " + & Symbol_Kind'Image (Kind) + & " in scope."); + return; + else + raise Program_Error + with + "Symbol found in scope was not of expected type " + & Symbol_Kind'Image (Kind) + & " but is in fact " + & Symbol_Kind'Image (Kind_Found); + end if; + elsif Sc.Parent /= null then + Scope_Contains_Or_Error (Sc.Parent, Name, Kind); + else + raise Program_Error + with "Could not find symbol " & To_String (Name) & " in scope."; + end if; + end; + --------------------- -- scope func call -- --------------------- @@ -45,7 +85,8 @@ package body Sem is procedure Scope_Call (S : in out Sem; Callee : in Call_Stmt) is begin -- determine whether the callee exist in scope or bail with error - + Put_Line ("scoping call wip"); + Scope_Contains_Or_Error (S.Scope, Callee.Name, SYM_CALL); null; end; @@ -67,6 +108,7 @@ package body Sem is -- go through statements and +scope var_decl and -scope calls for Statement of Fn.Stmts loop if Statement.Kind = Stmt_Call then + Put_Line ("scoping call"); Scope_Call (S, Statement.Call); end if; end loop; @@ -80,6 +122,7 @@ package body Sem is begin for Declaration of S.AST loop if Declaration.Kind = Function_Kind then + Put_Line ("scoping function"); Scope_Func (S, Declaration.Func); end if; null;