nightshade

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

commit 4e772eedf013c3c1edfb1112e8e69a86e79c08a8
parent d4c3f486a7aad29db296477f82dd3bf46a2bf7cf
Author: citbl <citbl@citbl.org>
Date:   Mon, 22 Jun 2026 18:00:48 +1000

gen wip

Diffstat:
Asrc/gen.adb | 36++++++++++++++++++++++++++++++++++++
Asrc/gen.ads | 16++++++++++++++++
Msrc/nightshade.adb | 7+++++++
3 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/src/gen.adb b/src/gen.adb @@ -0,0 +1,36 @@ +with Ada.Text_IO; use Ada.Text_IO; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; + +package body Gen is + + function Init (AST : Declaration_Vectors.Vector) return Generator is + begin + return Generator'(AST => AST, Globals => To_Unbounded_String (""), Output => To_Unbounded_String ("")); + end; + + ------------------ + -- gen function -- + ------------------ + + procedure Gen_Function (GG : in out Generator; Func : in Func_Decl) is + begin + GG.Output := GG.Output & "export function w $" & Func.Name & "() {" & ASCII.LF; + GG.Output := GG.Output & "@start" & ASCII.LF; + GG.Output := GG.Output & "}" & ASCII.LF; + end; + + ------------ + -- gen IR -- + ------------ + + procedure Gen_IR (GG : in out Generator) is + begin + for Decl of GG.AST loop + if Decl.Kind = Function_Kind then + Gen_Function (GG, Decl.Func); + end if; + end loop; + Put_Line (To_String (GG.Globals)); + Put_Line (To_String (GG.Output)); + end; +end Gen; diff --git a/src/gen.ads b/src/gen.ads @@ -0,0 +1,16 @@ +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Types; use Types; + +package Gen is + + type Generator is record + AST : Declaration_Vectors.Vector; + Globals : Unbounded_String; + Output : Unbounded_String; + end record; + + function Init (AST : Declaration_vectors.vector) return Generator; + + procedure Gen_IR (GG : in out Generator); + +end Gen; diff --git a/src/nightshade.adb b/src/nightshade.adb @@ -6,6 +6,7 @@ with Lexer; with Parser; with AST_Scoper; with AST_Typer; +with Gen; procedure Nightshade is begin @@ -39,6 +40,12 @@ begin TypedAST : AST_Typer.Typer := AST_Typer.Init (P.AST); begin AST_Typer.Type_Check (TypedAST); + + declare + Generator : Gen.Generator := Gen.Init (P.AST); + begin + Gen.Gen_IR (Generator); + end; end; end; end;