]> gitweb.ps.run Git - iftint/commitdiff
new node kinds
authorPatrick <patrick.schoenberger@posteo.de>
Fri, 13 Oct 2023 22:10:18 +0000 (00:10 +0200)
committerPatrick <patrick.schoenberger@posteo.de>
Fri, 13 Oct 2023 22:10:18 +0000 (00:10 +0200)
main3.c

diff --git a/main3.c b/main3.c
index b2c1e9d88a478c2619ed3701c0ae7689290bf210..40e6966bb5e022f3aec45fe3d4bb9296d501e1cc 100644 (file)
--- a/main3.c
+++ b/main3.c
@@ -1,6 +1,8 @@
-#include<stdint.h>
-#include<stdbool.h>
-#include<stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdarg.h>
+
 
 // Global defines
 
@@ -108,12 +110,16 @@ void vt100GetScreenSize(int * v, int * h) {
 // Node
 
 typedef enum NodeKind {
+    NK_Namespace,
+    NK_Struct,
     NK_Func,
-    NK_ArgList,
+    NK_VarList,
     NK_ExprList,
     NK_Var,
+    NK_Type,
     NK_Body,
     NK_If,
+    NK_While,
     NK_Num,
     NK_Str,
     NK_Call,
@@ -123,12 +129,16 @@ typedef enum NodeKind {
 } NodeKind;
 
 const char *NK_STRINGS[NK_COUNT] = {
+    "NK_Namespace",
+    "NK_Struct",
     "NK_Func",
-    "NK_ArgList",
+    "NK_VarList",
     "NK_ExprList",
     "NK_Var",
+    "NK_Type",
     "NK_Body",
     "NK_If",
+    "NK_While",
     "NK_Num",
     "NK_Str",
     "NK_Call",
@@ -219,16 +229,20 @@ void NodeDraw(Node *n, Node *selected) {
     if (n == selected) vt100EnableNegative();
     
     switch (n->kind) {
-    case NK_Func:    { printf("fn %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break;         }
-    case NK_ExprList:
-    case NK_ArgList: { printf("("); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(" "); NodeDraw(NodeGetChild(n, i), selected); } printf(")"); break; }
-    case NK_Var:     { printf("var %s", n->data); break;                                                                                                       }
-    case NK_Body:    { printf("{\n"); indent++; for (int i = 0; i < n->childCount; i++) { INDENT NodeDraw(NodeGetChild(n, i), selected); printf("\n"); } indent--; INDENT printf("}\n"); break;  }
-    case NK_If:      { printf("if "); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break;                     }
-    case NK_Num:     { printf("%s", n->data); break;                                                                                                     }
-    case NK_Str:     { printf("'%s'", n->data); break;                                                                                                     }
-    case NK_Call:    { printf("call %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); break;                                                             }
-    case NK_Op:      { if (n->childCount <= 1) printf("%s ", n->data); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(" %s ", n->data); NodeDraw(NodeGetChild(n, i), selected); } break;         }
+    case NK_Namespace: { break; }
+    case NK_Struct:    { break; }
+    case NK_Func:      { printf("fn %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break;         }
+    case NK_VarList:
+    case NK_ExprList:  { printf("("); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(", "); NodeDraw(NodeGetChild(n, i), selected); } printf(")"); break; }
+    case NK_Var:       { printf("[%s : ", n->data); NodeDraw(NodeGetChild(n, 0), selected); printf(); break;                                                                                                       }
+    case NK_Type:      { break; }
+    case NK_Body:      { printf("{\n"); indent++; for (int i = 0; i < n->childCount; i++) { INDENT NodeDraw(NodeGetChild(n, i), selected); printf("\n"); } indent--; INDENT printf("}\n"); break;  }
+    case NK_If:        { printf("if "); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break;                     }
+    case NK_While:     { printf("while "); NodeDraw(NodeGetChild(n, 0), selected); printf("\n"); INDENT NodeDraw(NodeGetChild(n, 1), selected); break; }
+    case NK_Num:       { printf("%s", n->data); break;                                                                                                     }
+    case NK_Str:       { printf("'%s'", n->data); break;                                                                                                     }
+    case NK_Call:      { printf("call %s ", n->data); NodeDraw(NodeGetChild(n, 0), selected); break;                                                             }
+    case NK_Op:        { if (n->childCount <= 1) printf("%s ", n->data); for (int i = 0; i < n->childCount; i++) { if (i != 0) printf(" %s ", n->data); NodeDraw(NodeGetChild(n, i), selected); } break;         }
     }
 
     vt100DisableNegative();
@@ -427,7 +441,7 @@ Node *GetNode(InputAction actions[NK_COUNT][IN_COUNT]) {
             case IA_MoveUp: { if (n->parent != NULL) n = n->parent; break; }
             case IA_MoveRight: { if (n->next != NULL) n = n->next; break; }
             
-            case IA_AddFunc: { NS(n1, n, NK_Func) NA(n2, n1, NK_ArgList)  NA(n3, n1, NK_Body) n = n1; mode = Mode_Editing; break; }
+            case IA_AddFunc: { NS(n1, n, NK_Func) NA(n2, n1, NK_VarList)  NA(n3, n1, NK_Body) n = n1; mode = Mode_Editing; break; }
             case IA_AddVar:  { NS(n1, n, NK_Var)                                              n = n1; mode = Mode_Editing; break; }
             case IA_AddIf:   { NA(n1, n, NK_If)   NA(n2, n1, NK_ExprList) NA(n3, n1, NK_Body) n = n1;                      break; }
             case IA_AddNum:  { NS(n1, n, NK_Num)                                              n = n1; mode = Mode_Editing; break; }
@@ -459,7 +473,7 @@ int main() {
     actions[NK_Func][IN_D] = IA_Delete;
     actions[NK_Func][IN_SPACE] = IA_StartEditing;
 
-    actions[NK_ArgList][IN_V] = IA_AddVar;
+    actions[NK_VarList][IN_V] = IA_AddVar;
     
     actions[NK_ExprList][IN_V] = IA_AddVar;
     actions[NK_ExprList][IN_I] = IA_AddIf;