aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-11-07 13:09:44 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2023-11-07 13:09:44 +0200
commit8dce541c96a329e3b12f3ea3794fcc8202fbd134 (patch)
tree0b086b998c9d392242acba0a7518fa3d535b1c56 /include
parentbb560b4201d8b813ed3999250845f365ff9d6c50 (diff)
downloadek-8dce541c96a329e3b12f3ea3794fcc8202fbd134.tar.gz
ek-8dce541c96a329e3b12f3ea3794fcc8202fbd134.zip
simplift syntax somewhat
+ Explicit macro expansion + Still have to simplify AST and type stuff, probably worth rewriting or something
Diffstat (limited to 'include')
-rw-r--r--include/ek/actualize.h26
-rw-r--r--include/ek/ast.h42
-rw-r--r--include/ek/scope.h2
3 files changed, 34 insertions, 36 deletions
diff --git a/include/ek/actualize.h b/include/ek/actualize.h
index d677a14..adc22ef 100644
--- a/include/ek/actualize.h
+++ b/include/ek/actualize.h
@@ -19,7 +19,7 @@
/**
* Check if two types match.
* A match is considered as identical types after alias, expression and
- * template expansion.
+ * trait expansion.
*
* @param a Type to compare against \p b.
* @param b Type to compare against \p a.
@@ -51,35 +51,35 @@ void replace_param_types(struct ast_node *param,
struct ast_node *arg_type);
/**
- * Replace templated type with actual type.
+ * Replace traitd type with actual type.
*
* @param type Templated type.
- * Keep in mind that a templated struct retains all template parameters, so
+ * Keep in mind that a traitd struct retains all trait parameters, so
* pass the struct itself.
* @param param_type Template parameter type to replace.
* @param arg_type Type to replace \p param_type with.
*/
-void init_template_type(struct ast_node *type, struct ast_node *param_type,
+void init_trait_type(struct ast_node *type, struct ast_node *param_type,
struct ast_node *arg_type);
/**
- * Replace templated parameter types.
+ * Replace traitd parameter types.
*
- * @param param List of parameters to replace templated types for.
+ * @param param List of parameters to replace traitd types for.
* @param param_type Types that match this are replaced with \p arg_type.
* @param arg_type Type to replace \p param_type with.
*/
-void init_template_types(struct ast_node *param, struct ast_node *param_type,
+void init_trait_types(struct ast_node *param, struct ast_node *param_type,
struct ast_node *arg_type);
/**
- * Extract template type, that is strip pointer/expression/alias stuff
- * and get the template itself from the type.
+ * Extract trait type, that is strip pointer/expression/alias stuff
+ * and get the trait itself from the type.
*
- * @param type Type to extract template from.
- * @return Pointer to template node when found, \c NULL otherwise.
+ * @param type Type to extract trait from.
+ * @return Pointer to trait node when found, \c NULL otherwise.
*/
-struct ast_node *extract_template(struct ast_node *type);
+struct ast_node *extract_trait(struct ast_node *type);
/**
* Extract typeof expression.
@@ -119,7 +119,7 @@ int actualize_main(struct scope *scope);
int actualize_temp_type(struct scope *scope, struct ast_node *type);
/**
- * Expand templates, typeofs, aliases and try to get the most
+ * Expand traits, typeofs, aliases and try to get the most
* basic representation.
*
* @param type Type to extract actual type from.
diff --git a/include/ek/ast.h b/include/ek/ast.h
index fa9f0c2..feece73 100644
--- a/include/ek/ast.h
+++ b/include/ek/ast.h
@@ -120,6 +120,7 @@ enum ast_node_type {
AST_DEFER,
/** Macro definition. */
AST_MACRO,
+ AST_MACRO_EXPANSION,
/** Reference to previous expression, i.e. \c @ */
AST_LAST,
/** Procedure definition. */
@@ -130,8 +131,6 @@ enum ast_node_type {
AST_LABEL,
/** Variable declaration/definition. */
AST_VAR,
- /** Lambda declaration/definition. */
- AST_LAMBDA,
/** For loop. */
AST_FOR,
/** Embed file contents. */
@@ -150,7 +149,7 @@ enum ast_node_type {
/** Alias definition. */
AST_ALIAS,
/** More like trait. @todo really come up with consistent naming. */
- AST_TEMPLATE,
+ AST_TRAIT,
/** Structure definition. */
AST_STRUCT,
/** If. */
@@ -208,7 +207,7 @@ enum ast_type_kind {
/** Typeof expression. */
AST_TYPE_TYPEOF,
/** Trait. */
- AST_TYPE_TEMPLATE,
+ AST_TYPE_TRAIT,
/** Alias. */
AST_TYPE_ALIAS,
/** Member, that is type element of some structure. */
@@ -217,8 +216,6 @@ enum ast_type_kind {
AST_TYPE_POINTER,
/** Union. */
AST_TYPE_UNION,
- /** Lambda. */
- AST_TYPE_LAMBDA,
/** Procedure, mainly used in trait definition. */
AST_TYPE_PROC,
/** Structure. */
@@ -236,7 +233,7 @@ enum ast_typedef_kind {
/** Alias. */
AST_TYPEDEF_ALIAS,
/** Trait. */
- AST_TYPEDEF_TEMPLATE,
+ AST_TYPEDEF_TRAIT,
};
/** Flags an AST node can have. */
@@ -335,11 +332,11 @@ struct ast_alias {
};
/** List of types that implements the template list belongs to. */
-struct template_implemented {
+struct trait_implemented {
/** A type that implements the template. */
struct ast_node *type;
/** Next type that implements the template. */
- struct template_implemented *next;
+ struct trait_implemented *next;
};
/**
@@ -347,13 +344,13 @@ struct template_implemented {
*
* @todo should templates take decls or should it just be for structures?
*/
-struct ast_template {
+struct ast_trait {
/** Name of trait. */
struct ast_node *id;
/** Body of trait. */
struct ast_node *body;
/** List of types that implement this trait. */
- struct template_implemented *impl_by;
+ struct trait_implemented *impl_by;
};
/** Cast. */
@@ -406,6 +403,11 @@ struct ast_macro {
struct ast_node *body;
};
+struct ast_macro_expansion {
+ struct ast_node *id;
+ struct ast_node *args;
+};
+
/** Procedure definition. */
struct ast_proc {
/** Procedure name. */
@@ -560,17 +562,10 @@ struct ast_type {
/** Trait. */
struct {
/** Trait definition. */
- struct ast_node *template;
+ struct ast_node *trait;
/** Type trait 'resolves' to. */
struct ast_node *actual;
- } template;
- /** Lambda. @todo add captures? */
- struct {
- /** Parameter types. */
- struct ast_node *params;
- /** Return type. */
- struct ast_node *ret;
- } lambda;
+ } trait;
/** Generic struct before actualization. */
struct {
/** Name of struct. */
@@ -756,6 +751,7 @@ struct ast_node {
struct ast_cast _cast;
/** Macro definition. */
struct ast_macro _macro;
+ struct ast_macro_expansion _macro_expansion;
/** Procedure definition. */
struct ast_proc _proc;
/** Goto. */
@@ -793,7 +789,7 @@ struct ast_node {
/** Alias. */
struct ast_alias _alias;
/** Trait definition. */
- struct ast_template _template;
+ struct ast_trait _trait;
/** Enum definition. */
struct ast_enum _enum;
/** Structure definition. */
@@ -1081,7 +1077,9 @@ struct ast_node *gen_alias(struct ast_node *id, struct ast_node *type);
* @param body Body.
* @return Corresponding AST node.
*/
-struct ast_node *gen_template(struct ast_node *id, struct ast_node *body);
+struct ast_node *gen_trait(struct ast_node *id, struct ast_node *body);
+
+struct ast_node *gen_macro_expansion(struct ast_node *id, struct ast_node *args);
/**
* Generate import;
diff --git a/include/ek/scope.h b/include/ek/scope.h
index 73da75e..422af0f 100644
--- a/include/ek/scope.h
+++ b/include/ek/scope.h
@@ -217,7 +217,7 @@ struct scope {
* @todo choose common terminology, sometimes the same thing is referred
* to as interfaces, sometimes templates, sometimes just type.
*/
- struct visible *templates;
+ struct visible *traits;
/** } */
/** { Callables, incl. variables. */