aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ek/actualize.h2
-rw-r--r--include/ek/ast.h14
-rw-r--r--include/ek/debug.h1
-rw-r--r--include/ek/scope.h58
4 files changed, 25 insertions, 50 deletions
diff --git a/include/ek/actualize.h b/include/ek/actualize.h
index 9dc5948..1519287 100644
--- a/include/ek/actualize.h
+++ b/include/ek/actualize.h
@@ -27,6 +27,8 @@
*/
int types_match(struct type *a, struct type *b);
+int type_lists_match(struct type *a, struct type *b);
+
/**
* Analyze raw AST, assumed to be file scope.
* The analysis phase collects top level objects, types, procedures, etc.
diff --git a/include/ek/ast.h b/include/ek/ast.h
index 59101ba..c1276b5 100644
--- a/include/ek/ast.h
+++ b/include/ek/ast.h
@@ -398,6 +398,7 @@ static inline bool is_primitive(struct type *t)
#define return_a2(x, kind) *({assert((x)->k == kind); &(x)->a2;})
#define return_a3(x, kind) *({assert((x)->k == kind); &(x)->a3;})
+#define return_id(x, kind) *({assert((x)->k == kind); &(x)->id;})
#define return_t0(x, kind) *({assert((x)->k == kind); &(x)->t0;})
#define return_t1(x, kind) *({assert((x)->k == kind); &(x)->t1;})
/* note that this one is in ast, the other two are in type */
@@ -609,7 +610,7 @@ static inline bool is_primitive(struct type *t)
#define gen_const_bool(i, loc) \
gen_ast(AST_CONST_BOOL, NULL, NULL, NULL, NULL, NULL, NULL, i, loc)
-#define init_args(x) return_t1(x, AST_INIT)
+#define init_args(x) return_t2(x, AST_INIT)
#define init_body(x) return_a0(x, AST_INIT)
#define init_id(x) return_s(x, AST_INIT)
#define gen_init(id, targs, body, loc) \
@@ -637,11 +638,14 @@ static inline bool is_primitive(struct type *t)
#define tgen_ptr(base, loc) \
tgen1(TYPE_PTR, base, loc)
-#define construct_id(x) return_t0(x, TYPE_CONSTRUCT)
-#define construct_atypes(x) return_t1(x, TYPE_CONSTRUCT)
+#define construct_id(x) return_id(x, TYPE_CONSTRUCT)
+#define construct_atypes(x) return_t0(x, TYPE_CONSTRUCT)
#define tgen_construct(id, atypes, loc) \
tgen_str1(TYPE_CONSTRUCT, id, atypes, loc)
+#define tstruct_params(x) return_t0(x, TYPE_STRUCT)
+#define ttrait_params(x) return_t0(x, TYPE_TRAIT)
+
struct ast *clone_ast(struct ast *n);
struct ast *clone_ast_list(struct ast *l);
@@ -654,8 +658,8 @@ void ast_dump(int depth, struct ast *node);
void type_dump_list(struct type *root);
void type_dump(struct type *node);
-void ast_append(struct ast *list, struct ast *elem);
-void type_append(struct type *list, struct type *elem);
+void ast_append(struct ast **list, struct ast *elem);
+void type_append(struct type **list, struct type *elem);
struct ast *ast_prepend(struct ast *list, struct ast *elem);
struct type *type_prepend(struct type *list, struct type *elem);
diff --git a/include/ek/debug.h b/include/ek/debug.h
index 19ed044..72b5e9e 100644
--- a/include/ek/debug.h
+++ b/include/ek/debug.h
@@ -106,6 +106,7 @@ void semantic_warn(struct file_ctx ctx, struct ast *node, const char *fmt,
void semantic_error(struct file_ctx ctx, struct ast *node, const char *fmt,
...);
void type_error(struct file_ctx ctx, struct type *type, const char *fmt, ...);
+void loc_error(struct file_ctx ctx, struct src_loc loc, const char *fmt, ...);
/**
* Print internal error.
diff --git a/include/ek/scope.h b/include/ek/scope.h
index b747288..a119451 100644
--- a/include/ek/scope.h
+++ b/include/ek/scope.h
@@ -41,12 +41,11 @@ struct visible {
struct visible *next;
};
-/** Actualized nodes visible to scope. */
-struct actual {
- /** Actualized AST node. */
+struct expanded {
struct ast *node;
- /** Next actual node. */
- struct actual *next;
+ struct type *types;
+ struct ast *expd;
+ struct expanded *next;
};
struct type_defs {
@@ -82,11 +81,7 @@ struct scope {
/** List of child scopes. */
struct scope *children;
- /**
- * List of generic structs with actual arguments to generate before
- * lowering
- */
- struct actual *actuals;
+ struct expanded *expanded;
struct visible *symbols;
struct visible *macros;
@@ -103,30 +98,6 @@ struct scope {
struct scope *create_scope();
/**
- * Create actuals list.
- * Since actuals are shared in the file scope, many scopes may share the actuals
- * list. Only the file scope is allowed to destroy the actual list.
- *
- * @return Empty actual list.
- */
-struct actual *create_actuals();
-
-/**
- * Destroy the list of actuals and actuals in list.
- *
- * @param actuals List of actuals to destroy.
- */
-void destroy_actuals(struct actual *actuals);
-
-/**
- * Destroy list of visibles.
- *
- * @param scope Scope list belongs to.
- * @param visible List of visibles to destroy.
- */
-void destroy_visible(struct visible *visible);
-
-/**
* Destroy scope.
* Destroys all lists the scope owns and frees the scope.
*
@@ -188,16 +159,6 @@ unsigned scope_flags(struct scope *scope, enum scope_flags flags);
void scope_add_scope(struct scope *parent, struct scope *child);
/**
- * Add actualized AST node to scope.
- * Will make the actualized node visible to all scopes in the file scope.
- *
- * @param scope Scope to add \p node to.
- * @param node Actualized AST node.
- * @return \c 0 when succesful, non-zero otherwise.
- */
-int scope_add_actual(struct scope *scope, struct ast *node);
-
-/**
* Add variable to scope.
* Propagates public variables up the file scope chain as references.
*
@@ -247,7 +208,7 @@ int scope_add_macro(struct scope *scope, struct ast *macro);
*/
int scope_add_trait(struct scope *scope, struct ast *trait);
-int scope_resolve(struct scope *scope);
+int scope_add_expd_struct(struct scope *scope, struct ast *def, struct type *types, struct ast *expanded);
/**
* Find a variable with ID in \p scope.
@@ -322,6 +283,8 @@ struct ast *scope_find_alias(struct scope *scope, char *id);
*/
struct ast *scope_find_trait(struct scope *scope, char *id);
+struct ast *scope_find_expd_struct(struct scope *scope, struct ast *def, struct type *types);
+
/**
* Find a variable with ID visible to \p scope.
*
@@ -382,7 +345,12 @@ struct ast *file_scope_find_alias(struct scope *scope, char *id);
*/
struct ast *file_scope_find_trait(struct scope *scope, char *id);
+struct ast *file_scope_find_expd_struct(struct scope *scope, struct ast *def, struct type *types);
+
#define foreach_visible(iter, init) \
for (struct visible *iter = init; iter; iter = iter->next)
+#define foreach_expanded(iter, init) \
+ for (struct expanded *iter = init; iter; iter = iter->next)
+
#endif /* SCOPE_H */