nightshade

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

commit c9fe5a0e42eff86c6223a1d0380137a297075da9
parent 59ceb6aebfcd759d88ab887870cf76b08cdf40ed
Author: citbl <citbl@citbl.org>
Date:   Sat, 13 Jun 2026 21:21:59 +1000

sem add signature to functions

Diffstat:
Msrc/sem.adb | 32++++++++++++++++++++++----------
Msrc/sem.ads | 46+++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/src/sem.adb b/src/sem.adb @@ -4,7 +4,7 @@ with Ada.Text_IO; use Ada.Text_IO; package body Sem is - procedure Load_STD_Symbols(S : in out Sem); + procedure Load_STD_Symbols (S : in out Sem); ---------- -- init -- @@ -26,9 +26,21 @@ package body Sem is ----------------------- procedure Load_STD_Symbols (S : in out Sem) is + Info : Symbol_Info; + Int_Type : constant Type_Info_Ref := new Type_Info'(Kind => TY_INT); + String_Type : constant Type_Info_Ref := new Type_Info'(Kind => TY_STRING); + Bool_Type : constant Type_Info_Ref := new Type_Info'(Kind => TY_BOOL); + Void_Type : constant Type_Info_Ref := new Type_Info'(Kind => TY_VOID); + Error_Type : constant Type_Info_Ref := new Type_Info'(Kind => TY_ERROR); + Print_Type : constant Type_Info_Ref := + new Type_Info' + (Kind => TY_FUNC, + Func => + (Return_Type => Void_Type, Params => new Type_List'(1 => String_Type))); begin Put_Line ("load std symbols"); - S.Scope.Symbols.Include ("print", SYM_CALL); + Info := (Kind => SYM_FUNC, Typ => Print_Type); + S.Scope.Symbols.Include ("print", Info); end; -------------------------- @@ -48,27 +60,27 @@ package body Sem is ----------------------------- procedure Scope_Contains_Or_Error - (Sc : Scope_Ref; Name : Unbounded_String; Kind : Symbol_Kind) + (Sc : Scope_Ref; Name : Unbounded_String; Kind : Symbol_Kind_Enum) is - Kind_Found : Symbol_Kind; + Info : Symbol_Info; begin if Sc.Symbols.Contains (To_String (Name)) then - Kind_Found := Sc.Symbols.Element (To_String (Name)); - if Kind_Found = Kind then + Info := Sc.Symbols.Element (To_String (Name)); + if Info.Kind = Kind then Put_Line ("Found " & To_String (Name) & " of kind " - & Symbol_Kind'Image (Kind) + & Symbol_Kind_Enum'Image (Kind) & " in scope."); return; else raise Program_Error with "Symbol found in scope was not of expected type " - & Symbol_Kind'Image (Kind) + & Symbol_Kind_Enum'Image (Kind) & " but is in fact " - & Symbol_Kind'Image (Kind_Found); + & Symbol_Kind_Enum'Image (Info.Kind); end if; elsif Sc.Parent /= null then Scope_Contains_Or_Error (Sc.Parent, Name, Kind); @@ -86,7 +98,7 @@ package body Sem 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); + Scope_Contains_Or_Error (S.Scope, Callee.Name, SYM_FUNC); null; end; diff --git a/src/sem.ads b/src/sem.ads @@ -6,16 +6,52 @@ with Ada.Strings.Hash; package Sem is - type Symbol_Kind is (SYM_CALL, SYM_VAR, SYM_LET); + type Type_Info; + type Function_Info; - ---------------------------------------- - -- dictionary of String : Symbol_Info -- - ---------------------------------------- + type Type_Info_Ref is access all Type_Info; + type Function_Info_Ref is access all Function_Info; + + type Symbol_Kind_Enum is (SYM_FUNC, SYM_VAR, SYM_LET); + type Type_Kind_Enum is (TY_STRING, TY_INT, TY_FLOAT, TY_BOOL, TY_VOID, TY_FUNC, TY_ERROR); + + type Type_List is array (Positive range <>) of Type_Info_Ref; + type Type_List_Ref is access all Type_List; + + type Function_Info is record + Params : Type_List_Ref; + Return_Type : Type_Info_Ref; + end record; + + type Type_Info (Kind : Type_Kind_Enum := TY_ERROR) is record + case Kind is + when TY_FUNC => + Func : Function_Info; + + when others => + null; + end case; + end record; + + + -------------------------------- + -- symbol info ----------------- + -- made of kind and type info -- + -------------------------------- + + type Symbol_Info is record + Kind : Symbol_Kind_Enum; + Typ : Type_Info_Ref; + end record; + + ------------------------------------- + -- hashmap of String : Symbol_Info -- + ------------------------------------- package Symbols_Map is new Ada.Containers.Indefinite_Hashed_Maps (Key_Type => String, - Element_Type => Symbol_Kind, + Element_Type => Symbol_Info, -- symbol's info Hash => Ada.Strings.Hash, Equivalent_Keys => "=");