]> git.bts.cx Git - sun.git/commitdiff
Groundwork for arrays mainline
authorBen Sherratt <redacted>
Mon, 27 May 2024 17:37:02 +0000 (18:37 +0100)
committerBen Sherratt <redacted>
Mon, 27 May 2024 17:37:02 +0000 (18:37 +0100)
runtime/src/sun/compiler/sun.y
runtime/src/sun/compiler/vm_generator.c
runtime/src/sun/tree/node.c
runtime/src/sun/tree/node.h
runtime/src/sun/tree/node_type.c
runtime/src/sun/tree/node_type.h
runtime/src/sun/tree/tree.c

index 2464ffac0abdb7ab0ac73dc5ace7169d48812573..c6acef02f8f26698ea6264978ff38a3c9a71f5d0 100644 (file)
@@ -114,7 +114,7 @@ statements_or_definitions
        ;*/
 
 function_definition
        ;*/
 
 function_definition
-       : IDENTIFIER IDENTIFIER '(' optional_parameter_definitions ')' '{' optional_statements '}' {
+       : type IDENTIFIER '(' optional_parameter_definitions ')' '{' optional_statements '}' {
                $$ = sltNodeMakeFunctionDefinition($1, $2, $4, $7);
        }
        ;
                $$ = sltNodeMakeFunctionDefinition($1, $2, $4, $7);
        }
        ;
@@ -136,7 +136,7 @@ parameter_definitions
        ;
 
 parameter_definition
        ;
 
 parameter_definition
-       : IDENTIFIER IDENTIFIER {
+       : type IDENTIFIER {
                $$ = sltNodeMakeFunctionParameterDefinition($1, $2);
        }
        ;
                $$ = sltNodeMakeFunctionParameterDefinition($1, $2);
        }
        ;
@@ -163,14 +163,23 @@ type_member_definition
        ;*/
 
 variable_definition
        ;*/
 
 variable_definition
-       : IDENTIFIER IDENTIFIER {
+       : type IDENTIFIER {
                $$ = sltNodeMakeVariableDefinition($1, $2, NULL);
        }
                $$ = sltNodeMakeVariableDefinition($1, $2, NULL);
        }
-       | IDENTIFIER IDENTIFIER '=' expression {
+       | type IDENTIFIER '=' expression {
                $$ = sltNodeMakeVariableDefinition($1, $2, $4);
        }
        ;
 
                $$ = sltNodeMakeVariableDefinition($1, $2, $4);
        }
        ;
 
+type
+       : IDENTIFIER {
+               $$ = $1;//sltNodeMakeTypeDefinition($1, 1);
+       }
+       | '[' type ':' INT ']' {
+               $$ = $2;//sltNodeMakeTypeDefinition($1, $2);
+       }
+       ;
+
 optional_statements
        : /* nothing */ {
                $$ = NULL;
 optional_statements
        : /* nothing */ {
                $$ = NULL;
@@ -414,7 +423,7 @@ postfix_expression
                $$ = sltNodeMakeFunctionCall($1, $3);
        }
        | postfix_expression '.' IDENTIFIER {
                $$ = sltNodeMakeFunctionCall($1, $3);
        }
        | postfix_expression '.' IDENTIFIER {
-               $$ = sltNodeMakeTypeAccess($1, $3);
+               $$ = sltNodeMakeMemberAccess($1, $3);
        }
        /*| postfix_expression postfix_unary_operator {
                $$ = sltNodeMakeUnaryOperation($1, $2);
        }
        /*| postfix_expression postfix_unary_operator {
                $$ = sltNodeMakeUnaryOperation($1, $2);
index 0309257792d04d4c0fb92d06991186ef1b1525b1..6a3cb19d42bd437a8238e613efd7ade23cd1c379 100644 (file)
@@ -288,7 +288,7 @@ static bool nodeTypeDefinesScope(SLTNodeType type) {
        switch (type) {
                case SLTNodeTypeModule:
                case SLTNodeTypeFunctionDefinition:
        switch (type) {
                case SLTNodeTypeModule:
                case SLTNodeTypeFunctionDefinition:
-               case SLTNodeTypeTypeDefinition:
+               case SLTNodeTypeUserDefinedTypeDefinition:
                case SLTNodeTypeForIteration:
                case SLTNodeTypeDoIteration:
                case SLTNodeTypeWhileIteration:
                case SLTNodeTypeForIteration:
                case SLTNodeTypeDoIteration:
                case SLTNodeTypeWhileIteration:
@@ -803,7 +803,7 @@ static SVMPointer generateExpressionInstructions(VMGeneratorOutputScope *generat
                        return r;
                }
 
                        return r;
                }
 
-               case SLTNodeTypeTypeAccess:
+               case SLTNodeTypeMemberAccess:
                        generator_assert_msg(false, "not implemented: %s", sltNodeToString(node));
                        return -1;
 
                        generator_assert_msg(false, "not implemented: %s", sltNodeToString(node));
                        return -1;
 
@@ -1021,7 +1021,7 @@ static size_t generateModuleInstructions(VMGeneratorOutputScope *generator, SLTN
                for (SLTNode *n = node->moduleStatementsAndDefinitions; n != NULL; n = n->sequenceNext) {
                        switch (n->sequenceNode->type) {
                                //case SLTNodeTypeVariableDefinition:
                for (SLTNode *n = node->moduleStatementsAndDefinitions; n != NULL; n = n->sequenceNext) {
                        switch (n->sequenceNode->type) {
                                //case SLTNodeTypeVariableDefinition:
-                               case SLTNodeTypeTypeDefinition:
+                               case SLTNodeTypeUserDefinedTypeDefinition:
                                case SLTNodeTypeFunctionDefinition:
                                        // Do nothing...
                                        break;
                                case SLTNodeTypeFunctionDefinition:
                                        // Do nothing...
                                        break;
index ad91732e504e514f01a83b4012bdca69a15dcbc9..f94f6e2471aa3ee0b53f37386fda1c755df34511 100644 (file)
@@ -93,8 +93,8 @@ SLTNode *sltNodeMakeArrayAccess(SLTNode *array, SLTNode *access) {
        return node;
 }
 
        return node;
 }
 
-SLTNode *sltNodeMakeTypeAccess(SLTNode *type, SLTNode *access) {
-       SLTNode *node = node_make(SLTNodeTypeTypeAccess);
+SLTNode *sltNodeMakeMemberAccess(SLTNode *type, SLTNode *access) {
+       SLTNode *node = node_make(SLTNodeTypeMemberAccess);
        node->typeAccessType = type;
        node->typeAccessAccess = access;
        return node;
        node->typeAccessType = type;
        node->typeAccessAccess = access;
        return node;
@@ -197,15 +197,17 @@ SLTNode *sltNodeMakeVariableDefinition(SLTNode *type, SLTNode *identifier, SLTNo
        return node;
 }
 
        return node;
 }
 
-SLTNode *sltNodeMakeTypeDefinition(SLTNode *identifier, SLTNode *members) {
-       SLTNode *node = node_make(SLTNodeTypeTypeDefinition);
+//extern SLTNode *sltNodeMakeTypeDefinition(SLTNode *identifier, SLTNode *dimension);
+
+SLTNode *sltNodeMakeUserDefinedTypeDefinition(SLTNode *identifier, SLTNode *members) {
+       SLTNode *node = node_make(SLTNodeTypeUserDefinedTypeDefinition);
        node->typeDefinitionIdentifier = identifier;
        node->typeDefinitionMembers = members;
        return node;
 }
 
        node->typeDefinitionIdentifier = identifier;
        node->typeDefinitionMembers = members;
        return node;
 }
 
-SLTNode *sltNodeMakeTypeMemberDefinition(SLTNode *type, SLTNode *identifier) {
-       SLTNode *node = node_make(SLTNodeTypeTypeMemberDefinition);
+SLTNode *sltNodeMakeUserDefinedTypeMemberDefinition(SLTNode *type, SLTNode *identifier) {
+       SLTNode *node = node_make(SLTNodeTypeUserDefinedTypeMemberDefinition);
        node->typeMemberDefinitionType = type;
        node->typeMemberDefinitionIdentifier = identifier;
        return node;
        node->typeMemberDefinitionType = type;
        node->typeMemberDefinitionIdentifier = identifier;
        return node;
index 11e40767bd68e448e7c40d8ed09bd2b1e05db7e1..fe0cdf4f980038832d50e6b9b3d334e9443151b6 100644 (file)
@@ -26,7 +26,7 @@ extern SLTNode *sltNodeMakeCompound(SLTNode *expression);
 extern SLTNode *sltNodeMakeArgument(SLTNode *expression);
 
 extern SLTNode *sltNodeMakeArrayAccess(SLTNode *array, SLTNode *access);
 extern SLTNode *sltNodeMakeArgument(SLTNode *expression);
 
 extern SLTNode *sltNodeMakeArrayAccess(SLTNode *array, SLTNode *access);
-extern SLTNode *sltNodeMakeTypeAccess(SLTNode *type, SLTNode *access);
+extern SLTNode *sltNodeMakeMemberAccess(SLTNode *type, SLTNode *access);
 
 extern SLTNode *sltNodeMakeFunctionCall(SLTNode *function, SLTNode *arguments);
 
 
 extern SLTNode *sltNodeMakeFunctionCall(SLTNode *function, SLTNode *arguments);
 
@@ -51,8 +51,10 @@ extern SLTNode *sltNodeMakeStatementBlock(SLTNode *contents);
 
 extern SLTNode *sltNodeMakeVariableDefinition(SLTNode *type, SLTNode *identifier, SLTNode *defaultExpression);
 
 
 extern SLTNode *sltNodeMakeVariableDefinition(SLTNode *type, SLTNode *identifier, SLTNode *defaultExpression);
 
-extern SLTNode *sltNodeMakeTypeDefinition(SLTNode *identifier, SLTNode *members);
-extern SLTNode *sltNodeMakeTypeMemberDefinition(SLTNode *type, SLTNode *identifier);
+//extern SLTNode *sltNodeMakeTypeDefinition(SLTNode *identifier, SLTNode *dimension);
+
+extern SLTNode *sltNodeMakeUserDefinedTypeDefinition(SLTNode *identifier, SLTNode *members);
+extern SLTNode *sltNodeMakeUserDefinedTypeMemberDefinition(SLTNode *type, SLTNode *identifier);
 
 extern SLTNode *sltNodeMakeFunctionDefinition(SLTNode *type, SLTNode *identifier, SLTNode *parameters, SLTNode *body);
 extern SLTNode *sltNodeMakeFunctionParameterDefinition(SLTNode *type, SLTNode *identifier);
 
 extern SLTNode *sltNodeMakeFunctionDefinition(SLTNode *type, SLTNode *identifier, SLTNode *parameters, SLTNode *body);
 extern SLTNode *sltNodeMakeFunctionParameterDefinition(SLTNode *type, SLTNode *identifier);
index 1dacf19a1dcd013427c498ec10a7fba7a5cedde9..d930bfe0a8c747b77d0ec33d70f8edc007ff4c87 100644 (file)
@@ -33,8 +33,8 @@ const char *sltNodeTypeToString(SLTNodeType nodeType) {
                case SLTNodeTypeArrayAccess:
                        return "ArrayAccess";
 
                case SLTNodeTypeArrayAccess:
                        return "ArrayAccess";
 
-               case SLTNodeTypeTypeAccess:
-                       return "TypeAccess";
+               case SLTNodeTypeMemberAccess:
+                       return "MemberAccess";
                
                case SLTNodeTypeFunctionCall:
                        return "FunctionCall";
                
                case SLTNodeTypeFunctionCall:
                        return "FunctionCall";
@@ -75,11 +75,11 @@ const char *sltNodeTypeToString(SLTNodeType nodeType) {
                case SLTNodeTypeVariableDefinition:
                        return "VariableDefinition";
 
                case SLTNodeTypeVariableDefinition:
                        return "VariableDefinition";
 
-               case SLTNodeTypeTypeDefinition:
-                       return "TypeDefinition";
+               case SLTNodeTypeUserDefinedTypeDefinition:
+                       return "UserDefinedTypeDefinition";
 
 
-               case SLTNodeTypeTypeMemberDefinition:
-                       return "TypeMemberDefinition";
+               case SLTNodeTypeUserDefinedTypeMemberDefinition:
+                       return "UserDefinedTypeMemberDefinition";
 
                case SLTNodeTypeFunctionDefinition:
                        return "FunctionDefinition";
 
                case SLTNodeTypeFunctionDefinition:
                        return "FunctionDefinition";
index 195d9e613c4a52c757a51714cf85d1298039e1fd..4a41ebfe6c3d6fc547449075f42073899069d686 100644 (file)
@@ -22,7 +22,7 @@ enum SLTNodeType {
        SLTNodeTypeArgument,
 
        SLTNodeTypeArrayAccess,
        SLTNodeTypeArgument,
 
        SLTNodeTypeArrayAccess,
-       SLTNodeTypeTypeAccess,
+       SLTNodeTypeMemberAccess,
 
        SLTNodeTypeFunctionCall,
 
 
        SLTNodeTypeFunctionCall,
 
@@ -47,8 +47,10 @@ enum SLTNodeType {
 
        SLTNodeTypeVariableDefinition,
 
 
        SLTNodeTypeVariableDefinition,
 
-       SLTNodeTypeTypeDefinition,
-       SLTNodeTypeTypeMemberDefinition,
+//     SLTNodeTypeArrayTypeDefinition,
+
+       SLTNodeTypeUserDefinedTypeDefinition,
+       SLTNodeTypeUserDefinedTypeMemberDefinition,
 
        SLTNodeTypeFunctionDefinition,
        SLTNodeTypeFunctionParameterDefinition,
 
        SLTNodeTypeFunctionDefinition,
        SLTNodeTypeFunctionParameterDefinition,
index 118f9c633ff032155a2c5f5987fa9e195f74ce88..9080d3a8005bdec72771cd71085b4386efbebe45 100644 (file)
@@ -58,7 +58,7 @@ SLTNode *sltTreeMap(SLTNode *root, SLTTreeMapCallback callback, SLTTreeMapCallba
                                n->arrayAccessAccess = sltTreeMap(n->arrayAccessAccess, callback, postCallback, userParameter);
                                break;
 
                                n->arrayAccessAccess = sltTreeMap(n->arrayAccessAccess, callback, postCallback, userParameter);
                                break;
 
-                       case SLTNodeTypeTypeAccess:
+                       case SLTNodeTypeMemberAccess:
                                n->typeAccessType = sltTreeMap(n->typeAccessType, callback, postCallback, userParameter);
                                n->typeAccessAccess = sltTreeMap(n->typeAccessAccess, callback, postCallback, userParameter);
                                break;
                                n->typeAccessType = sltTreeMap(n->typeAccessType, callback, postCallback, userParameter);
                                n->typeAccessAccess = sltTreeMap(n->typeAccessAccess, callback, postCallback, userParameter);
                                break;
@@ -115,12 +115,12 @@ SLTNode *sltTreeMap(SLTNode *root, SLTTreeMapCallback callback, SLTTreeMapCallba
                                n->variableDefinitionDefaultExpression = sltTreeMap(n->variableDefinitionDefaultExpression, callback, postCallback, userParameter);
                                break;
 
                                n->variableDefinitionDefaultExpression = sltTreeMap(n->variableDefinitionDefaultExpression, callback, postCallback, userParameter);
                                break;
 
-                       case SLTNodeTypeTypeDefinition:
+                       case SLTNodeTypeUserDefinedTypeDefinition:
                                n->typeDefinitionIdentifier = sltTreeMap(n->typeDefinitionIdentifier, callback, postCallback, userParameter);
                                n->typeDefinitionMembers = sltTreeMap(n->typeDefinitionMembers, callback, postCallback, userParameter);
                                break;
 
                                n->typeDefinitionIdentifier = sltTreeMap(n->typeDefinitionIdentifier, callback, postCallback, userParameter);
                                n->typeDefinitionMembers = sltTreeMap(n->typeDefinitionMembers, callback, postCallback, userParameter);
                                break;
 
-                       case SLTNodeTypeTypeMemberDefinition:
+                       case SLTNodeTypeUserDefinedTypeMemberDefinition:
                                n->typeMemberDefinitionType = sltTreeMap(n->typeMemberDefinitionType, callback, postCallback, userParameter);
                                n->typeMemberDefinitionIdentifier = sltTreeMap(n->typeMemberDefinitionIdentifier, callback, postCallback, userParameter);
                                break;
                                n->typeMemberDefinitionType = sltTreeMap(n->typeMemberDefinitionType, callback, postCallback, userParameter);
                                n->typeMemberDefinitionIdentifier = sltTreeMap(n->typeMemberDefinitionIdentifier, callback, postCallback, userParameter);
                                break;