diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-12-06 18:14:40 +0200 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-12-06 18:14:40 +0200 |
commit | e5fda1c96af409065fedbe032b0f7908d9f312ac (patch) | |
tree | 9558506a84f45c3b3e24c0cfd4ae5e43c973d04a /include | |
parent | 471ef9b710f88765d871ab079f8485ba0268201d (diff) | |
download | fwd-e5fda1c96af409065fedbe032b0f7908d9f312ac.tar.gz fwd-e5fda1c96af409065fedbe032b0f7908d9f312ac.zip |
add types to parser
+ No actual type checking is implemented as of yet, but with references
and pointers I should be able to start playing around with checking
move semantics and so on
+ Might at some point also look into type propagation for let,
annoying to have to specify the same thing twice.
Diffstat (limited to 'include')
-rw-r--r-- | include/fwd/ast.h | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/include/fwd/ast.h b/include/fwd/ast.h index c124ac1..34fcd64 100644 --- a/include/fwd/ast.h +++ b/include/fwd/ast.h @@ -30,7 +30,7 @@ struct src_loc { struct ast; enum type_kind { - TYPE_ID = 1, TYPE_CONSTRUCT + TYPE_ID = 1, TYPE_CONSTRUCT, TYPE_REF, TYPE_PTR, TYPE_CALLABLE }; struct type { @@ -52,6 +52,8 @@ struct type { enum ast_kind { /** Creating new variable. */ AST_LET = 1, + /** If statement */ + AST_IF, /** Call procedure. */ AST_CALL, /** Procedure definition. */ @@ -248,6 +250,17 @@ static inline bool is_const(struct ast *x) #define tgen_construct(id, args, loc) \ tgen_type(TYPE_CONSTRUCT, args, id, loc) +#define tptr_base(x) return_t0(x, TYPE_PTR) +#define tgen_ptr(base, loc) \ + tgen_type(TYPE_PTR, base, NULL, loc) + +#define tref_base(x) return_t0(x, TYPE_REF) +#define tgen_ref(base, loc) \ + tgen_type(TYPE_REF, base, NULL, loc) + +#define tcallable_args(x) return_t0(x, TYPE_CALLABLE) +#define tgen_callable(args, loc) \ + tgen_type(TYPE_CALLABLE, args, NULL, loc) #define closure_bindings(x) return_a0(x, AST_CLOSURE) #define closure_body(x) return_a1(x, AST_CLOSURE) @@ -288,8 +301,8 @@ static inline bool is_const(struct ast *x) #define var_id(x) return_s(x, AST_VAR_DEF) #define var_type(x) return_t2(x, AST_VAR_DEF) #define var_init(x) return_a0(x, AST_VAR_DEF) -#define gen_var(id, loc) \ - gen_ast(AST_VAR_DEF, NULL, NULL, NULL, NULL, NULL, id, 0, 0., loc) +#define gen_var(id, type, loc) \ + gen_ast(AST_VAR_DEF, NULL, NULL, NULL, NULL, type, id, 0, 0., loc) #define block_body(x) return_a0(x, AST_BLOCK) #define gen_block(body, loc) \ @@ -315,10 +328,10 @@ static inline bool is_const(struct ast *x) #define gen_const_bool(i, loc) \ gen_ast(AST_CONST_BOOL, NULL, NULL, NULL, NULL, NULL, NULL, i, 0., loc) -#define let_id(x) return_s(x, AST_LET) -#define let_expr(x) return_a0(x, AST_LET) -#define gen_let(id, from, loc) \ - gen_str1(AST_LET, id, from, loc) +#define let_var(x) return_a0(x, AST_LET) +#define let_expr(x) return_a1(x, AST_LET) +#define gen_let(var, from, loc) \ + gen2(AST_LET, var, from, loc) #define init_args(x) return_t2(x, AST_INIT) #define init_body(x) return_a0(x, AST_INIT) @@ -326,6 +339,12 @@ static inline bool is_const(struct ast *x) #define gen_init(id, targs, body, loc) \ gen_str_type1(AST_INIT, id, targs, body, loc) +#define if_cond(x) return_a0(x, AST_IF) +#define if_body(x) return_a1(x, AST_IF) +#define if_else(x) return_a2(x, AST_IF) +#define gen_if(cond, body, els, loc) \ + gen3(AST_IF, cond, body, els, loc) + #define id_str(x) return_s(x, AST_ID) #define gen_id(id, loc) \ gen_str(AST_ID, id, loc) |