From 0d1f312ae214a36ebdc08455ac3bbba25c8e3cce Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 28 May 2024 00:12:32 +0200 Subject: [PATCH 1/6] fixed: various implementation faults fixed typo of parameter added function struct to group their declaration and definitons added block to function definiton added operands to cast and operators --- src/set/types.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/set/types.h b/src/set/types.h index 52744a1..6fcc02c 100644 --- a/src/set/types.h +++ b/src/set/types.h @@ -69,6 +69,8 @@ typedef Type* ReferenceType; typedef struct BoxType_t BoxType; +typedef struct Block_t Block; + typedef struct BoxMember_t { const char* name; Type* type; @@ -88,6 +90,7 @@ typedef struct BoxType_t { } BoxType; typedef struct Variable_t Variable; +typedef struct Expression_t Expression; typedef struct BoxAccess_t { // list of recursive box accesses @@ -168,7 +171,7 @@ typedef struct ParameterDefinition_t { ParameterDeclaration declaration; // value to initalize the declaration with // NOTE: type of initializer and declaration MUST be equal - TypeValue initializer; + Expression initializer; AST_NODE_PTR nodePtr; } ParameterDefinition; @@ -189,15 +192,37 @@ typedef struct Parameter_t { ParameterDefinition definiton; } impl; AST_NODE_PTR nodePtr; -} Paramer; +} Parameter; // fix typo + +typedef enum FunctionKind_t { + FunctionDeclarationKind, + FunctionDefinitionKind +} FunctionKind; typedef struct FunctionDefinition_t { // hashtable of parameters // associates a parameters name (const char*) with its parameter declaration (ParameterDeclaration) GArray* parameter; AST_NODE_PTR nodePtr; + // body of function + Block body; } FunctionDefinition; +typedef struct FunctionDeclaration_t { + // hashtable of parameters + // associates a parameters name (const char*) with its parameter declaration (ParameterDeclaration) + GArray* parameter; + AST_NODE_PTR nodePtr; +} FunctionDeclaration; + +typedef struct Function_t { + FunctionKind kind; + union FunctionImplementation { + FunctionDefinition definition; + FunctionDeclaration declaration; + } impl; +} Function; + // .------------------------------------------------. // | Variables | // '------------------------------------------------' @@ -222,7 +247,7 @@ typedef struct VariableDeclaration_t { */ typedef struct VariableDefiniton_t { VariableDeclaration declaration; - TypeValue initializer; + Expression initializer; AST_NODE_PTR nodePtr; } VariableDefiniton; @@ -258,6 +283,7 @@ typedef struct Variable_t { */ typedef struct TypeCast_t { Type targetType; + Expression* operand; AST_NODE_PTR nodePtr; } TypeCast; @@ -270,6 +296,7 @@ typedef struct TypeCast_t { */ typedef struct Transmute_t { Type targetType; + Expression* operand; AST_NODE_PTR nodePtr; } Transmute; @@ -358,6 +385,7 @@ typedef struct Operation_t { LogicalOperator logical; BitwiseOperator bitwise; } impl; + Expression* operands; AST_NODE_PTR nodePtr; } Operation; From 1aa82062687510dc689d59868e58299eb0175d26 Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 28 May 2024 12:36:33 +0200 Subject: [PATCH 2/6] fixed: missing kind in statement --- src/set/types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/set/types.h b/src/set/types.h index 52744a1..aedb167 100644 --- a/src/set/types.h +++ b/src/set/types.h @@ -471,6 +471,7 @@ typedef enum StatementKind_t { } StatementKind; typedef struct Statement_t { + StatementKind kind; union StatementImplementation { FunctionCall call; FunctionBoxCall boxCall; From f590e3c42ea94f81cd06ca5ef8aba892ace07111 Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 28 May 2024 13:44:40 +0200 Subject: [PATCH 3/6] fixed: missing box member access in assignment --- src/set/types.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/set/types.h b/src/set/types.h index 828783a..cc230f0 100644 --- a/src/set/types.h +++ b/src/set/types.h @@ -484,8 +484,22 @@ typedef struct Branch_t { // | Statements | // '------------------------------------------------' +typedef enum AssignmentKind_t { + // direct access to a variable + AssignmentKindVariable, + // access to a member of a box + // can be nested such as: foo.bar.kee + AssignmentKindBoxMember +} AssignmentKind; + +// Can either be a direct variable access or +// a nested box member access typedef struct Assignment_t { Variable* variable; + AssignmentKind kind; + union AssignmentImplementation_t { + BoxAccess accees; + } impl; Expression value; AST_NODE_PTR nodePtr; } Assignment; From 0fe3fb68a6a482295686d394d15992dabdb53fda Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 28 May 2024 13:57:13 +0200 Subject: [PATCH 4/6] reverted: removed box access from assignment --- src/set/types.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/set/types.h b/src/set/types.h index cc230f0..0b92e2b 100644 --- a/src/set/types.h +++ b/src/set/types.h @@ -96,6 +96,8 @@ typedef struct BoxAccess_t { // list of recursive box accesses // contains a list of BoxMembers (each specifying their own type, name and box type) GArray* member; + // box variable to access + Variable* variable; AST_NODE_PTR nodePtr; } BoxAccess; @@ -263,7 +265,7 @@ typedef struct Variable_t { union VariableImplementation { VariableDeclaration declaration; VariableDefiniton definiton; - BoxMember member; + BoxAccess member; } impl; AST_NODE_PTR nodePtr; } Variable; @@ -484,22 +486,8 @@ typedef struct Branch_t { // | Statements | // '------------------------------------------------' -typedef enum AssignmentKind_t { - // direct access to a variable - AssignmentKindVariable, - // access to a member of a box - // can be nested such as: foo.bar.kee - AssignmentKindBoxMember -} AssignmentKind; - -// Can either be a direct variable access or -// a nested box member access typedef struct Assignment_t { Variable* variable; - AssignmentKind kind; - union AssignmentImplementation_t { - BoxAccess accees; - } impl; Expression value; AST_NODE_PTR nodePtr; } Assignment; From 8494df56cd0e7107fdc7d9ba77f16f1ac934e93b Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 29 May 2024 21:21:03 +0200 Subject: [PATCH 5/6] feature: added name to function --- src/set/types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/set/types.h b/src/set/types.h index 6fcc02c..974542e 100644 --- a/src/set/types.h +++ b/src/set/types.h @@ -206,6 +206,8 @@ typedef struct FunctionDefinition_t { AST_NODE_PTR nodePtr; // body of function Block body; + // name of function + const char* name; } FunctionDefinition; typedef struct FunctionDeclaration_t { From 875574eb690e2ee9f0ef22904de7c07b6a2d0955 Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 29 May 2024 21:24:17 +0200 Subject: [PATCH 6/6] fixed: added type to expressions --- src/set/types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/set/types.h b/src/set/types.h index 974542e..1bead83 100644 --- a/src/set/types.h +++ b/src/set/types.h @@ -404,6 +404,8 @@ typedef enum ExpressionKind_t { typedef struct Expression_t { ExpressionKind kind; + // type of resulting data + Type* result; union ExpressionImplementation_t { Operation operation; TypeCast typecast;