commit de3424a9074a281fe7420b537f073bf55c316e06
parent 1a7fa73f0b8ef5d35c97df6c748f2b031ea93054
Author: citbl <citbl@citbl.org>
Date: Sun, 14 Jun 2026 23:43:31 +1000
fmt
Diffstat:
10 files changed, 24 insertions(+), 45 deletions(-)
diff --git a/makefile b/makefile
@@ -37,7 +37,8 @@ pedantic: clean
gnatmake -gnat2022 -gnatwa -o bin/nightshade src/nightshade.adb
fmt:
- gnatformat -w 90 src/*.adb src/*.ads
+ # 90
+ gnatformat -w 110 src/*.adb src/*.ads
err: clean
make 2>&1 | grep -w --color=always 'error'
diff --git a/src/lexer.adb b/src/lexer.adb
@@ -73,11 +73,7 @@ package body Lexer is
C := Peek (L);
if Is_Line_Terminator (C) then
-- we care about line return in this impl
- T :=
- (Kind => Separator,
- Lexeme => To_Unbounded_String (""),
- Line => L.Line,
- Col => L.Col);
+ T := (Kind => Separator, Lexeme => To_Unbounded_String (""), Line => L.Line, Col => L.Col);
Add_Token (L, T);
end if;
if Is_Space (C) or Is_Line_Terminator (C) or C = Character'Val (9) -- \t
diff --git a/src/parser.adb b/src/parser.adb
@@ -6,16 +6,14 @@ with Types; use Types;
package body Parser is
- function Init
- (File_Name : File_Name_Ref; Source : Source_Ref; Tokens : Token_Vector.Vector)
- return Parser
+ function Init (File_Name : File_Name_Ref; Source : Source_Ref; Tokens : Token_Vector.Vector) return Parser
is
P : constant Parser :=
- (Source => Source,
- File_Name => File_Name,
- Tokens => Tokens,
- Pos => 1,
- AST => Declaration_Vectors.Empty_Vector);
+ (Source => Source,
+ File_Name => File_Name,
+ Tokens => Tokens,
+ Pos => 1,
+ AST => Declaration_Vectors.Empty_Vector);
begin
return P;
end;
diff --git a/src/parser.ads b/src/parser.ads
@@ -12,7 +12,6 @@ package Parser is
end record;
function Init
- (File_Name : File_Name_Ref; Source : Source_Ref; Tokens : Types.Token_Vector.Vector)
- return Parser;
+ (File_Name : File_Name_Ref; Source : Source_Ref; Tokens : Types.Token_Vector.Vector) return Parser;
procedure Parse (P : in out Parser);
end Parser;
diff --git a/src/scope.adb b/src/scope.adb
@@ -36,14 +36,10 @@ package body Scope is
Print_Type : constant AST_Type_Info_Ref :=
new AST_Type_Info'
(Kind => TY_FUNC,
- Func =>
- (Return_Type => Void_Type, Params => new AST_Type_List'(1 => String_Type)));
+ Func => (Return_Type => Void_Type, Params => new AST_Type_List'(1 => String_Type)));
begin
Put_Line ("load std symbols");
- Info :=
- (Name => To_Unbounded_String ("print"),
- Kind => SYM_FUNC,
- Entity_Type => Print_Type);
+ Info := (Name => To_Unbounded_String ("print"), Kind => SYM_FUNC, Entity_Type => Print_Type);
S.Scope.Symbols.Include ("print", Info);
end;
@@ -65,8 +61,7 @@ package body Scope is
-- recursive
function Scope_Contains_Or_Error
- (Sc : AST_Scope_Ref; Name : Unbounded_String; Kind : AST_Symbol_Kind_Enum)
- return AST_Type_Info_Ref
+ (Sc : AST_Scope_Ref; Name : Unbounded_String; Kind : AST_Symbol_Kind_Enum) return AST_Type_Info_Ref
is
Info : AST_Symbol_Info;
begin
@@ -74,11 +69,7 @@ package body Scope is
Info := Sc.Symbols.Element (To_String (Name));
if Info.Kind = Kind then
Put_Line
- ("Found "
- & To_String (Name)
- & " of kind "
- & AST_Symbol_Kind_Enum'Image (Kind)
- & " in scope.");
+ ("Found " & To_String (Name) & " of kind " & AST_Symbol_Kind_Enum'Image (Kind) & " in scope.");
return Info.Entity_Type;
else
raise Program_Error
@@ -92,8 +83,7 @@ package body Scope is
Put_Line ("Not found in current scope, looking in parent...");
return Scope_Contains_Or_Error (Sc.Parent, Name, Kind);
else
- raise Program_Error
- with "Could not find symbol " & To_String (Name) & " in scope.";
+ raise Program_Error with "Could not find symbol " & To_String (Name) & " in scope.";
end if;
end;
@@ -166,6 +156,7 @@ package body Scope is
Scope_Call (S, Statement.Call);
Statement.Scope := S.Scope;
-- TODO when scoping adds a symbol, check whether it exists first: no shadowing.
+
end if;
end loop;
end;
diff --git a/src/scope.ads b/src/scope.ads
@@ -6,7 +6,7 @@ with Types; use Types;
package Scope is
type Scoper is record
- Scope : AST_Scope_Ref;
+ Scope : AST_Scope_Ref;
Scoped_AST : Declaration_Vectors.Vector;
end record;
diff --git a/src/types.ads b/src/types.ads
@@ -35,8 +35,7 @@ package Types is
Line, Col : Positive;
end record;
- package Token_Vector is new
- Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Token);
+ package Token_Vector is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Token);
type Expr;
type Expr_Ref is access Expr;
@@ -59,8 +58,7 @@ package Types is
Kind : Unbounded_String;
end record;
- package Param_Vectors is new
- Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Param);
+ package Param_Vectors is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Param);
package Expr_Vectors is new
Ada.Containers.Indefinite_Vectors (Index_Type => Natural, Element_Type => Expr_Ref);
@@ -141,8 +139,7 @@ package Types is
---------------------------
type AST_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_Kind_Enum is (TY_STRING, TY_INT, TY_FLOAT, TY_BOOL, TY_VOID, TY_FUNC, TY_ERROR);
type AST_Type_List is array (Positive range <>) of AST_Type_Info_Ref;
type AST_Type_List_Ref is access all AST_Type_List;
diff --git a/src/typing.adb b/src/typing.adb
@@ -5,8 +5,7 @@ package body Typing is
return Typer'(AST => AST);
end;
-
- procedure Type_Check(TT : in out Typer) is
+ procedure Type_Check (TT : in out Typer) is
begin
for Declaration of TT.AST loop
if Declaration.Kind = Function_Kind then
diff --git a/src/typing.ads b/src/typing.ads
@@ -8,6 +8,6 @@ package Typing is
function Init (AST : Declaration_Vectors.Vector) return Typer;
- procedure Type_Check(TT : in out Typer);
+ procedure Type_Check (TT : in out Typer);
end Typing;
diff --git a/src/utils.adb b/src/utils.adb
@@ -63,16 +63,14 @@ package body Utils 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 Utils;