aboutsummaryrefslogtreecommitdiff
path: root/src/as_parser.h
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-03-16 20:01:42 +0800
committerMistivia <i@mistivia.com>2025-03-16 20:01:42 +0800
commitb83187f66175d93a0dba45f6d110ed94badac7c5 (patch)
tree22710b7a5278ac8a254ead30109f1dd9084d1022 /src/as_parser.h
parent1ce0d45242097a07b7a4ee539a074ec812851a58 (diff)
refactor using allocator pattern
Diffstat (limited to 'src/as_parser.h')
-rw-r--r--src/as_parser.h39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/as_parser.h b/src/as_parser.h
index 3306909..a3db024 100644
--- a/src/as_parser.h
+++ b/src/as_parser.h
@@ -2,6 +2,7 @@
#define FVM_AS_PARSER_H_
#include "as_tokenizer.h"
+#include "utils.h"
#include "as_op.h"
@@ -9,41 +10,41 @@ struct arg {
int64_t ival;
double fval;
};
-typedef struct arg Arg;
+typedef struct arg * Arg;
struct instr {
- Op op;
- Arg* arg;
+ enum op op;
+ Arg arg;
const char* tagName;
};
-typedef struct instr Instr;
+typedef struct instr *Instr;
struct label {
const char* name;
};
-typedef struct label Label;
+typedef struct label *Label;
struct stmt {
- Label* label;
- Instr* instr;
+ Label label;
+ Instr instr;
};
-typedef struct stmt Stmt;
+typedef struct stmt *Stmt;
struct stmts {
- Stmt** stmts;
+ Stmt* stmts;
};
-typedef struct stmts Stmts;
+typedef struct stmts *Stmts;
struct prog {
- Stmts *stmts;
+ Stmts stmts;
};
-typedef struct prog Prog;
-
-Prog* parseProg(TokenStream *ts);
-Stmt* parseStmt(TokenStream *ts);
-Stmts* parseStmts(TokenStream *ts);
-Instr* parseInstr(TokenStream *ts);
-Label* parseLabel(TokenStream *ts);
-Op parseOp(TokenStream *ts);
+typedef struct prog *Prog;
+
+Prog parseProg(Allocator alct, TokenStream ts);
+Stmt parseStmt(Allocator alct, TokenStream ts);
+Stmts parseStmts(Allocator alct, TokenStream ts);
+Instr parseInstr(Allocator alct, TokenStream ts);
+Label parseLabel(Allocator alct, TokenStream ts);
+enum op parseOp(Allocator alct, TokenStream ts);
#endif