-#include<stdint.h>
-#include<stdbool.h>
-#include<stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdarg.h>
+
// Global defines
// 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,
} 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",
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();
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; }
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;