aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-03-17 02:12:02 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2025-03-17 02:12:02 +0200
commit78bf3e039d77e3eb0d5e394273adb69b2b70a76d (patch)
tree0ed6f2058e348dbd18b0baa9c4ee442206191096 /include
parent2367a8b63c3bcfe62d1aaf7d82c0ab3622f3b16c (diff)
downloadfwd-78bf3e039d77e3eb0d5e394273adb69b2b70a76d.tar.gz
fwd-78bf3e039d77e3eb0d5e394273adb69b2b70a76d.zip
detect leaks
Diffstat (limited to 'include')
-rw-r--r--include/fwd/ast.h45
-rw-r--r--include/fwd/scope.h6
2 files changed, 46 insertions, 5 deletions
diff --git a/include/fwd/ast.h b/include/fwd/ast.h
index 726b5e3..5f2b7cb 100644
--- a/include/fwd/ast.h
+++ b/include/fwd/ast.h
@@ -32,7 +32,7 @@ struct ast;
enum type_kind {
TYPE_ID = 1, TYPE_CONSTRUCT, TYPE_REF, TYPE_PTR, TYPE_CLOSURE,
- TYPE_PURE_CLOSURE, TYPE_FUNC_PTR, TYPE_VOID
+ TYPE_PURE_CLOSURE, TYPE_FUNC_PTR, TYPE_VOID, TYPE_ERR
};
struct type {
@@ -59,6 +59,14 @@ enum ast_kind {
AST_LET = 1,
/** If statement */
AST_IF,
+ /** Nil check */
+ AST_NIL,
+ /* Owning check */
+ AST_OWN,
+ /** Err branch */
+ AST_ERR_BRANCH,
+ /** Error throwing */
+ AST_ERROR,
/** Call procedure. */
AST_CALL,
/** Procedure definition. */
@@ -266,6 +274,7 @@ static inline bool is_trivially_copyable(struct type *type)
switch (type->k) {
case TYPE_REF:
case TYPE_PTR:
+ case TYPE_ERR:
case TYPE_FUNC_PTR:
case TYPE_PURE_CLOSURE:
/** @todo primitive types */
@@ -309,6 +318,9 @@ static inline bool is_trivially_copyable(struct type *type)
#define tgen_void(loc) \
tgen_type(TYPE_VOID, NULL, NULL, loc)
+#define tgen_err(loc) \
+ tgen_type(TYPE_ERR, NULL, NULL, loc)
+
#define tid_str(x) return_id(x, TYPE_ID)
#define tgen_id(id, loc) \
tgen_type(TYPE_ID, NULL, id, loc)
@@ -359,8 +371,9 @@ static inline bool is_trivially_copyable(struct type *type)
#define call_expr(x) return_a0(x, AST_CALL)
#define call_args(x) return_a1(x, AST_CALL)
-#define gen_call(expr, args, loc) \
- gen2(AST_CALL, expr, args, loc)
+#define call_err(x) return_a2(x, AST_CALL)
+#define gen_call(expr, args, err, loc) \
+ gen3(AST_CALL, expr, args, err, loc)
#define proc_id(x) return_s(x, AST_PROC_DEF)
#define proc_params(x) return_a0(x, AST_PROC_DEF)
@@ -379,9 +392,20 @@ static inline bool is_trivially_copyable(struct type *type)
#define gen_var(id, type, loc) \
gen_ast(AST_VAR_DEF, NULL, NULL, NULL, NULL, type, id, 0, 0., loc)
+#define err_branch_id(x) return_s(x, AST_ERR_BRANCH)
+#define err_branch_body(x) return_a0(x, AST_ERR_BRANCH)
+#define gen_err_branch(id, body, loc) \
+ gen_ast(AST_ERR_BRANCH, body, NULL, NULL, NULL, NULL, id, 0, 0., loc)
+
+#define error_str(x) return_s(x, AST_ERROR)
+#define error_id(x) return_a0(x, AST_ERROR)
+#define gen_error(str, id, loc) \
+ gen_ast(AST_ERROR, id, NULL, NULL, NULL, NULL, str, 0, 0., loc)
+
#define block_body(x) return_a0(x, AST_BLOCK)
-#define gen_block(body, loc) \
- gen1(AST_BLOCK, body, loc)
+#define block_error(x) return_a1(x, AST_BLOCK)
+#define gen_block(body, err, loc) \
+ gen2(AST_BLOCK, body, err, loc)
#define str_val(x) return_s(x, AST_CONST_STR)
#define gen_const_str(s, loc) \
@@ -420,6 +444,17 @@ static inline bool is_trivially_copyable(struct type *type)
#define gen_if(cond, body, els, loc) \
gen3(AST_IF, cond, body, els, loc)
+#define nil_var(x) return_s(x, AST_NIL)
+#define nil_body(x) return_a1(x, AST_NIL)
+#define nil_ref(x) return_a2(x, AST_NIL)
+#define gen_nil(var, body, ref, loc) \
+ gen_ast(AST_NIL, NULL, body, ref, NULL, NULL, var, 0, 0., loc)
+
+#define own_id(x) return_s(x, AST_OWN)
+#define own_body(x) return_a1(x, AST_OWN)
+#define gen_own(var, body, loc) \
+ gen_ast(AST_OWN, NULL, body, NULL, NULL, NULL, var, 0, 0., loc)
+
#define id_str(x) return_s(x, AST_ID)
#define gen_id(id, loc) \
gen_str(AST_ID, id, loc)
diff --git a/include/fwd/scope.h b/include/fwd/scope.h
index 6a78793..2e71cdb 100644
--- a/include/fwd/scope.h
+++ b/include/fwd/scope.h
@@ -32,6 +32,10 @@ struct visible {
struct visible *next;
};
+enum scope_flags {
+ SCOPE_PROC = (1 << 0),
+};
+
/**
* Scope.
* Responsible for keeping track of visibilities and
@@ -60,6 +64,8 @@ struct scope {
struct scope *children;
struct visible *symbols;
+
+ enum scope_flags flags;
};
/**