aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-20 18:53:47 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit5df7f92e715ba764ee57f65d78e73111492bb64c (patch)
tree87e25089674432d43d1ed8edad5c4c6ca3fd72b1 /src/ast.c
parent071bdd4d6facb8786f089882d53c127e6163e3ce (diff)
Add pub keyword, more import stuff, optimize hash map
Hash map now stores hash of keys to reduce the number of hash operations. Positive: faster insert/get. Negative: more space required (to store usize hash).
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/ast.c b/src/ast.c
index a51ae71..1bb1eb3 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -82,7 +82,8 @@ void structfield_init(StructField *self, BufferView name, BufferView type_name)
variable_init(&self->type, type_name);
}
-void lhsexpr_init(LhsExpr *self, bool is_const, BufferView var_name) {
+void lhsexpr_init(LhsExpr *self, bool is_pub, bool is_const, BufferView var_name) {
+ self->is_pub = is_pub;
self->is_const = is_const;
variable_init(&self->type, create_buffer_view_null());
self->var_name = var_name;
@@ -107,7 +108,6 @@ void number_init(Number *self, i64 value, bool is_integer) {
void variable_init(Variable *self, BufferView name) {
self->name = name;
- self->resolved_variable = ast_none();
}
void binop_init(Binop *self) {
@@ -171,7 +171,7 @@ void scope_resolve(Scope *self, AstCompilerContext *context) {
context->scope = self->parent;
}
-static Ast scope_get_resolved_variable(Scope *self, AstCompilerContext *context, BufferView name) {
+static LhsExpr* scope_get_resolved_variable(Scope *self, AstCompilerContext *context, BufferView name) {
Ast result;
bool exists;
Scope *prev_scope;
@@ -199,20 +199,13 @@ static Ast scope_get_resolved_variable(Scope *self, AstCompilerContext *context,
context->scope = prev_scope;
assert(result.type == AST_LHS);
- return result.value.lhs_expr->rhs_expr;
+ return result.value.lhs_expr;
}
-static void variable_resolve(Variable *self, AstCompilerContext *context, StructDecl **resolved_type) {
- self->resolved_variable = scope_get_resolved_variable(context->scope, context, self->name);
- /* TODO: Implement */
- if(self->resolved_variable.type == AST_STRUCT_DECL) {
- *resolved_type = self->resolved_variable.value.struct_decl;
- } else if(self->resolved_variable.type == AST_FUNCTION_DECL) {
- /* TODO: Set resolved type to function declaration return type */
- *resolved_type = NULL;
- } else {
- *resolved_type = NULL;
- }
+/* @resolved_type is the same field as the ast resolved_type for the variable @self */
+static void variable_resolve(Variable *self, AstCompilerContext *context, LhsExpr **resolved_type) {
+ /* TODO: Verify this is correct in all cases */
+ *resolved_type = scope_get_resolved_variable(context->scope, context, self->name);
}
static void lhs_resolve(Ast *self, AstCompilerContext *context) {
@@ -269,10 +262,9 @@ static void funccall_resolve(Ast *self, AstCompilerContext *context) {
}
static void structdecl_resolve(Ast *self, AstCompilerContext *context) {
- /* TODO: Implement */
+ /* TODO: What to do with resolved_type? */
StructDecl *struct_decl;
struct_decl = self->value.struct_decl;
- self->resolved_type = struct_decl;
scope_resolve(&struct_decl->body, context);
}