nightshade

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

commit adfe90e9356cbe9be7be652aa43959e9b822d0c6
parent cc4cb4225f40b614f55c3978170c3f2ed9de7a7f
Author: citbl <citbl@citbl.org>
Date:   Sat, 13 Jun 2026 15:32:30 +1000

sem wip

Diffstat:
Msrc/nightshade.adb | 2+-
Msrc/parser.adb | 8++++----
Msrc/parser.ads | 14+++++++-------
Msrc/sem.adb | 48++++++++++++++++++++++++++++++++++++++++++------
Msrc/sem.ads | 6+++---
5 files changed, 57 insertions(+), 21 deletions(-)

diff --git a/src/nightshade.adb b/src/nightshade.adb @@ -29,7 +29,7 @@ begin Parser.Print_AST (P); declare - S : Sem.Sem := Sem.Init(P.Top_Program); + S : Sem.Sem := Sem.Init(P.Declarations); begin Sem.Analysis(S); end; diff --git a/src/parser.adb b/src/parser.adb @@ -13,7 +13,7 @@ package body Parser is File_Name => File_Name, Tokens => Tokens, Pos => 1, - Top_Program => Top_Level_Vectors.Empty_Vector); + Declarations => Declaration_Vectors.Empty_Vector); begin return P; end; @@ -229,7 +229,7 @@ package body Parser is ------------------- procedure Parse_Program (P : in out Parser) is - TL : Top_Level_Vectors.Vector; + TL : Declaration_Vectors.Vector; T : Token; Counter : Positive := 1; begin @@ -245,7 +245,7 @@ package body Parser is exit when T.Kind = EOF or (T.Kind = Keyword and T.Lexeme = "end"); end loop; - P.Top_Program := TL; + P.Declarations := TL; Put_Line ("done parsing"); end; @@ -297,7 +297,7 @@ package body Parser is procedure Print_AST (P : Parser) is begin Put_Line ("print AST:"); - for Decl of P.Top_Program loop + for Decl of P.Declarations loop if Decl.Kind = Function_Kind then Put_Line ("Function:"); Print_Func_decl (Decl.Func, 1); diff --git a/src/parser.ads b/src/parser.ads @@ -59,11 +59,6 @@ package Parser is Params : Expr_Vectors.Vector; end record; - type Call_Expr is record - Callee : Unbounded_String; - Params : Expr_Vectors.Vector; - end record; - type Stmt (Kind : Stmt_Kind) is record case Kind is when Stmt_Call => @@ -82,6 +77,11 @@ package Parser is -- type Stmt_Ref is access Stmt; + 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); @@ -123,14 +123,14 @@ package Parser is end case; end record; - package Top_Level_Vectors is new + package Declaration_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type => Natural, Element_Type => Decl); type Parser is record Source : Source_Ref; File_Name : File_Name_Ref; Tokens : Lexer.Token_Vector.Vector; - Top_Program : Top_Level_Vectors.Vector; + Declarations : Declaration_Vectors.Vector; Pos : Positive; end record; diff --git a/src/sem.adb b/src/sem.adb @@ -1,25 +1,61 @@ +with Parser; use Parser; +with Ada.Containers.Indefinite_Vectors; + package body Sem is ---------- -- init -- ---------- - function Init (Top_Program : Top_Level_Vectors.Vector) return Sem is + function Init (AST : Declaration_Vectors.Vector) return Sem is Symbols : Symbols_Map.Map; - S : constant Sem := (Symbols => Symbols, Top_Program => Top_Program); + S : constant Sem := (Symbols => Symbols, AST => AST); begin return S; end Init; + --------------------- + -- scope func call -- + --------------------- + + procedure Scope_Call (S : in out Sem) is + begin + null; + end; + + -------------------- + -- scope var decl -- + -------------------- + + procedure Scope_Var_Decl (S : in out Sem) is + begin + null; + end; + + ---------------- + -- scope func -- + ---------------- + + procedure Scope_Func (S : in out Sem; Func : in Func_Decl) is + begin + null; + end; + -------------- -- analysis -- -------------- - procedure Analysis(S: Sem) is + procedure Analysis (S : in out Sem) is begin - null; + for X of S.AST loop + if X.Kind = Function_Kind then + Scope_Func(S, X.Func); + end if; + null; + end loop; + -- for X in S.Top_Program loop + -- null; -- TODO + -- end loop; end Analysis; - - end Sem; diff --git a/src/sem.ads b/src/sem.ads @@ -28,19 +28,19 @@ package Sem is type Sem is record Symbols : Symbols_Map.Map; - Top_Program : Top_Level_Vectors.Vector; + AST : Declaration_Vectors.Vector; end record; ---------- -- init -- ---------- - function Init (Top_Program : Top_Level_Vectors.Vector) return Sem; + function Init (AST : Declaration_Vectors.Vector) return Sem; -------------- -- analysis -- -------------- - procedure Analysis(S: Sem); + procedure Analysis(S: in out Sem); end Sem;