diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-07-31 22:29:24 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 0f26e1d204d3a3026ca3edfc4c6bd9638b2632e7 (patch) | |
tree | de196ca25cf8f685e14b219198162d68c61efcfd /include | |
parent | fa2a9e79e21063137f863887adc88fc74d3573e2 (diff) |
Add nullable, add bytecode documentation
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 14 | ||||
-rw-r--r-- | include/bytecode/bytecode.h | 2 | ||||
-rw-r--r-- | include/nullable.h | 29 |
3 files changed, 41 insertions, 4 deletions
diff --git a/include/ast.h b/include/ast.h index 4c54766..6a40980 100644 --- a/include/ast.h +++ b/include/ast.h @@ -2,6 +2,7 @@ #define AMALGAM_AST_H #include "defs.h" +#include "nullable.h" #include "std/defs.h" #include "std/buffer_view.h" #include "std/buffer.h" @@ -17,6 +18,7 @@ #define AST_ERR -1 #define AST_ERR_DEF_DUP -20 +typedef struct Ast Ast; typedef struct FunctionSignature FunctionSignature; typedef struct FunctionCall FunctionCall; typedef struct StructDecl StructDecl; @@ -79,12 +81,14 @@ typedef struct { Parser *parser; /* Borrowed. This is the parser that is currently parsing the expression */ } AstResolveData; -typedef struct { +struct Ast { AstValue value; AstType type; AstResolveData resolve_data; SsaRegister ssa_reg; -} Ast; +}; + +DefineNullablePtrType(Ast); struct Scope { Buffer/*<Ast*>*/ ast_objects; @@ -156,7 +160,7 @@ struct LhsExpr { bool is_const; BufferView var_name; VariableType type; - Ast *rhs_expr; + NullablePtr(Ast) rhs_expr; }; struct AssignmentExpr { @@ -244,4 +248,8 @@ CHECK_RESULT int scope_add_child(Scope *self, Ast *child); /* longjump to compiler env on failure */ void scope_resolve(Scope *self, AstCompilerContext *context); + + +CHECK_RESULT bool resolved_type_is_func_decl(Ast *self); + #endif diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h index 32488cc..4c54fbd 100644 --- a/include/bytecode/bytecode.h +++ b/include/bytecode/bytecode.h @@ -11,7 +11,7 @@ /*doc(Opcode) Variable length opcodes. Sizes range from 1 to 4 bytes. # Instruction formats - Instructions can be in 6 different formats: + Instructions can be in 7 different formats: 1. 1 byte: Opcode(u8) 2. 2 bytes: Opcode(u8) + register(u8) 3. 3 bytes: Opcode(u8) + register(u8) + register(u8) diff --git a/include/nullable.h b/include/nullable.h new file mode 100644 index 0000000..6c4d3a7 --- /dev/null +++ b/include/nullable.h @@ -0,0 +1,29 @@ +#ifndef AMAL_NULLABLE_H +#define AMAL_NULLABLE_H + +struct __nullable_type_dummy{ int _; }; + +int assert_not_null(void *val); + +#ifdef DEBUG +#define DefineNullablePtrType(type) \ + typedef struct type##_nullable type##_nullable; \ + struct type##_nullable { \ + type *value; \ + } +#define NullablePtr(type) type##_nullable +#define nullable_unwrap(nullable_type) \ + (assert_not_null((nullable_type).value) ? ((nullable_type).value) : NULL) +#define nullable_assign(nullable_type, new_value) ((nullable_type).value = (new_value)) +#define is_not_null(nullable_type) ((nullable_type).value != NULL) +#define nullable_raw(nullable_type) ((nullable_type).value) +#else +#define DefineNullablePtrType(type) +#define NullablePtr(type) type* +#define nullable_unwrap(value) value +#define nullable_assign(nullable_type, new_value) ((nullable_type) = (new_value)) +#define is_not_null(nullable_type) ((nullable_type) != NULL) +#define nullable_raw(nullable_type) (nullable_type) +#endif + +#endif |