From 1ec55565d6279b92122916b08c7bcad87f4e31ac Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sun, 1 Mar 2026 15:15:25 +1100 Subject: [PATCH] Start work on inline ground --- src/codegen/codegen.c | 5 +++++ src/parser/parser.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index 7d845a9..5235639 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -975,6 +975,10 @@ ResultType(GroundProgram, charptr) generateUseNode(SolsNode* node, SolsScope* sc return Success(GroundProgram, charptr, codegen.as.success); } +ResultType(GroundProgram, charptr) generateInlineGroundNode(SolsNode* node, SolsScope* scope) { + return Success(GroundProgram, charptr, groundParseFile(node->as.inlineGround)); +} + ResultType(GroundProgram, charptr) generateCode(SolsNode* node, SolsScope* scope) { GroundProgram program = groundCreateProgram(); @@ -1026,6 +1030,7 @@ ResultType(GroundProgram, charptr) generateCode(SolsNode* node, SolsScope* scope case SNT_FUNCTION_CALL: generate(FunctionCall); case SNT_RETURN: generate(Return); case SNT_USE: generate(Use); + case SNT_GROUND: generate(InlineGround); } return Success(GroundProgram, charptr, program); } diff --git a/src/parser/parser.c b/src/parser/parser.c index 3977067..f58210a 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -1571,6 +1571,20 @@ static inline ResultType(Nothing, charptr) parseUse(SolsParser* parser) { return Success(Nothing, charptr, {}); } +static inline ResultType(Nothing, charptr) parseInlineGround(SolsParser* parser) { + ResultType(SolsToken, Nothing) token = parserPeek(parser, 0); + if (token.error) { + return Error(Nothing, charptr, "ruh roh"); + } + ResultType(SolsNode, charptr) newNode = createSolsNode(SNT_GROUND, token.as.success.as.inlineGround); + if (newNode.error) { + return Error(Nothing, charptr, newNode.as.error); + } + + addChildToSolsNode(parser->currentParent, newNode.as.success); + return Success(Nothing, charptr, {}); +} + static inline ResultType(Nothing, charptr) parseOpenParen(SolsParser* parser) { return Error(Nothing, charptr, "WIP"); } @@ -1593,6 +1607,7 @@ ResultType(Nothing, charptr) parse(SolsParser* parser) { case STT_KW_PUTS: PARSER_HANDLE(Puts); case STT_KW_IF: PARSER_HANDLE(If); case STT_KW_WHILE: PARSER_HANDLE(While); + case STT_KW_GROUND: PARSER_HANDLE(InlineGround); case STT_KW_LAMBDA: PARSER_HANDLE(Lambda); case STT_KW_RETURN: PARSER_HANDLE(Return); case STT_KW_USE: PARSER_HANDLE(Use);