treesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorPatrick2023-10-14 00:10:18 +0200
committerPatrick2023-10-14 00:10:18 +0200
commit2acf9a06e0a4952223418d73c82bc11baf2b47f1 (patch)
treefcdc646f1df9f4ba3132d5cb48fcc5ac74b09376
parentb6a32820fc2e8673e8fde790eee14ca249a24e28 (diff)
downloadiftint-2acf9a06e0a4952223418d73c82bc11baf2b47f1.tar.gz
iftint-2acf9a06e0a4952223418d73c82bc11baf2b47f1.zip
new node kinds
-rw-r--r--main3.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/main3.c b/main3.c
index b2c1e9d..40e6966 100644
--- 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;