aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <github@gingerbill.org>2016-08-18 15:58:36 +0100
committerGinger Bill <github@gingerbill.org>2016-08-18 15:58:36 +0100
commitf931b089d5ce0374e36c3241176e4ef24953522e (patch)
tree034bcf331e049919b6ecd42ab48e19fc77993a16 /src
parent6b2cd1b33fafb18e052ebc5df19481232202607b (diff)
print_(f32|f64)
Diffstat (limited to 'src')
-rw-r--r--src/checker/checker.cpp6
-rw-r--r--src/checker/entity.cpp24
-rw-r--r--src/checker/expr.cpp24
-rw-r--r--src/checker/stmt.cpp18
-rw-r--r--src/codegen/ssa.cpp8
-rw-r--r--src/main.cpp7
-rw-r--r--src/tokenizer.cpp2
7 files changed, 40 insertions, 49 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp
index b37effb8f..100b480bd 100644
--- a/src/checker/checker.cpp
+++ b/src/checker/checker.cpp
@@ -210,7 +210,7 @@ void destroy_scope(Scope *scope) {
gb_for_array(i, scope->elements.entries) {
Entity *e =scope->elements.entries[i].value;
if (e->kind == Entity_Variable) {
- if (!e->variable.used) {
+ if (!e->Variable.used) {
#if 0
warning(e->token, "Unused variable `%.*s`", LIT(e->token.string));
#endif
@@ -314,7 +314,7 @@ void add_global_constant(gbAllocator a, String name, Type *type, ExactValue valu
Token token = {Token_Identifier};
token.string = name;
Entity *entity = alloc_entity(a, Entity_Constant, NULL, token, type);
- entity->constant.value = value;
+ entity->Constant.value = value;
add_global_entity(entity);
}
@@ -346,7 +346,7 @@ void init_universal_scope(void) {
Token token = {Token_Identifier};
token.string = builtin_procs[i].name;
Entity *entity = alloc_entity(a, Entity_Builtin, NULL, token, t_invalid);
- entity->builtin.id = id;
+ entity->Builtin.id = id;
add_global_entity(entity);
}
}
diff --git a/src/checker/entity.cpp b/src/checker/entity.cpp
index bd784bc4d..182bc1916 100644
--- a/src/checker/entity.cpp
+++ b/src/checker/entity.cpp
@@ -7,7 +7,6 @@ enum BuiltinProcId;
ENTITY_KIND(Constant), \
ENTITY_KIND(Variable), \
ENTITY_KIND(TypeName), \
- ENTITY_KIND(AliasName), \
ENTITY_KIND(Procedure), \
ENTITY_KIND(Builtin), \
ENTITY_KIND(Count),
@@ -38,16 +37,14 @@ struct Entity {
isize order;
union {
- struct { ExactValue value; } constant;
+ struct { ExactValue value; } Constant;
struct {
b8 visited;
b8 is_field;
b8 used;
- } variable;
- struct {} type_name;
- struct {} alias_name;
- struct {} procedure;
- struct { BuiltinProcId id; } builtin;
+ } Variable;
+ struct { b8 used; } Procedure;
+ struct { BuiltinProcId id; } Builtin;
};
};
@@ -74,7 +71,7 @@ Entity *make_entity_variable(gbAllocator a, Scope *parent, Token token, Type *ty
Entity *make_entity_constant(gbAllocator a, Scope *parent, Token token, Type *type, ExactValue value) {
Entity *entity = alloc_entity(a, Entity_Constant, parent, token, type);
- entity->constant.value = value;
+ entity->Constant.value = value;
return entity;
}
@@ -83,20 +80,15 @@ Entity *make_entity_type_name(gbAllocator a, Scope *parent, Token token, Type *t
return entity;
}
-Entity *make_entity_alias_name(gbAllocator a, Scope *parent, Token token, Type *type) {
- Entity *entity = alloc_entity(a, Entity_AliasName, parent, token, type);
- return entity;
-}
-
Entity *make_entity_param(gbAllocator a, Scope *parent, Token token, Type *type) {
Entity *entity = make_entity_variable(a, parent, token, type);
- entity->variable.used = true;
+ entity->Variable.used = true;
return entity;
}
Entity *make_entity_field(gbAllocator a, Scope *parent, Token token, Type *type) {
Entity *entity = make_entity_variable(a, parent, token, type);
- entity->variable.is_field = true;
+ entity->Variable.is_field = true;
return entity;
}
@@ -107,7 +99,7 @@ Entity *make_entity_procedure(gbAllocator a, Scope *parent, Token token, Type *s
Entity *make_entity_builtin(gbAllocator a, Scope *parent, Token token, Type *type, BuiltinProcId id) {
Entity *entity = alloc_entity(a, Entity_Builtin, parent, token, type);
- entity->builtin.id = id;
+ entity->Builtin.id = id;
return entity;
}
diff --git a/src/checker/expr.cpp b/src/checker/expr.cpp
index f03de5cbe..602035803 100644
--- a/src/checker/expr.cpp
+++ b/src/checker/expr.cpp
@@ -162,21 +162,20 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
add_declaration_dependency(c, e);
if (e->type == t_invalid)
return;
- o->value = e->constant.value;
+ o->value = e->Constant.value;
GB_ASSERT(o->value.kind != ExactValue_Invalid);
o->mode = Addressing_Constant;
break;
case Entity_Variable:
add_declaration_dependency(c, e);
- e->variable.used = true;
+ e->Variable.used = true;
if (e->type == t_invalid)
return;
o->mode = Addressing_Variable;
break;
case Entity_TypeName:
- case Entity_AliasName:
o->mode = Addressing_Type;
break;
@@ -186,7 +185,7 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
break;
case Entity_Builtin:
- o->builtin_id = e->builtin.id;
+ o->builtin_id = e->Builtin.id;
o->mode = Addressing_Builtin;
break;
@@ -665,7 +664,10 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
gbString err_str = NULL;
- defer (gb_string_free(err_str));
+ defer ({
+ if (err_str != NULL)
+ gb_string_free(err_str);
+ });
if (check_is_assignable_to(c, x, y->type) ||
check_is_assignable_to(c, y, x->type)) {
@@ -673,13 +675,13 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
switch (op.kind) {
case Token_CmpEq:
case Token_NotEq:
- defined = is_type_comparable(x->type);
+ defined = is_type_comparable(get_base_type(x->type));
break;
case Token_Lt:
case Token_Gt:
case Token_LtEq:
case Token_GtEq: {
- defined = is_type_ordered(x->type);
+ defined = is_type_ordered(get_base_type(x->type));
} break;
}
@@ -698,7 +700,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
gb_bprintf("mismatched types `%s` and `%s`", xt, yt));
}
- if (err_str) {
+ if (err_str != NULL) {
error(&c->error_collector, op, "Cannot compare expression, %s", err_str);
return;
}
@@ -893,8 +895,8 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
b32 is_const_expr = x->mode == Addressing_Constant;
b32 can_convert = false;
- if (is_const_expr && is_type_constant_type(type)) {
- Type *base_type = get_base_type(type);
+ Type *base_type = get_base_type(type);
+ if (is_const_expr && is_type_constant_type(base_type)) {
if (base_type->kind == Type_Basic) {
if (check_value_is_expressible(c, x->value, base_type, &x->value)) {
can_convert = true;
@@ -1274,7 +1276,7 @@ Entity *lookup_field(Type *type, AstNode *field_node, isize *index = NULL) {
case Type_Structure:
for (isize i = 0; i < type->structure.field_count; i++) {
Entity *f = type->structure.fields[i];
- GB_ASSERT(f->kind == Entity_Variable && f->variable.is_field);
+ GB_ASSERT(f->kind == Entity_Variable && f->Variable.is_field);
String str = f->token.string;
if (are_strings_equal(field_str, str)) {
if (index) *index = i;
diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp
index 3a059b2ab..54ef410c4 100644
--- a/src/checker/stmt.cpp
+++ b/src/checker/stmt.cpp
@@ -190,14 +190,14 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
ast_node(i, Ident, node);
e = scope_lookup_entity(c->context.scope, i->token.string);
if (e != NULL && e->kind == Entity_Variable) {
- used = e->variable.used; // TODO(bill): Make backup just in case
+ used = e->Variable.used; // TODO(bill): Make backup just in case
}
}
Operand op_b = {Addressing_Invalid};
check_expr(c, &op_b, lhs);
- if (e) e->variable.used = used;
+ if (e) e->Variable.used = used;
if (op_b.mode == Addressing_Invalid ||
op_b.type == t_invalid) {
@@ -325,18 +325,18 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) {
if (operand->mode == Addressing_Invalid)
return;
- e->constant.value = operand->value;
+ e->Constant.value = operand->value;
}
void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_expr) {
GB_ASSERT(e->type == NULL);
- if (e->variable.visited) {
+ if (e->Variable.visited) {
e->type = t_invalid;
return;
}
- e->variable.visited = true;
+ e->Variable.visited = true;
if (type_expr) {
Type *t = check_type(c, type_expr);
@@ -437,11 +437,11 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
GB_ASSERT(e->type == NULL);
GB_ASSERT(e->kind == Entity_Variable);
- if (e->variable.visited) {
+ if (e->Variable.visited) {
e->type = t_invalid;
return;
}
- e->variable.visited = true;
+ e->Variable.visited = true;
if (type_expr != NULL)
e->type = check_type(c, type_expr, NULL);
@@ -791,11 +791,11 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
for (isize i = 0; i < entity_count; i++) {
Entity *e = entities[i];
GB_ASSERT(e != NULL);
- if (e->variable.visited) {
+ if (e->Variable.visited) {
e->type = t_invalid;
continue;
}
- e->variable.visited = true;
+ e->Variable.visited = true;
if (e->type == NULL)
e->type = init_type;
diff --git a/src/codegen/ssa.cpp b/src/codegen/ssa.cpp
index fc927b735..be38b2c1b 100644
--- a/src/codegen/ssa.cpp
+++ b/src/codegen/ssa.cpp
@@ -1364,12 +1364,10 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t) {
// Pointer <-> int
if (is_type_pointer(src) && is_type_int_or_uint(dst)) {
- ssaValue *p = ssa_emit_load(proc, value);
- return ssa_emit(proc, ssa_make_instr_conv(proc, ssaConv_ptrtoint, p, src, dst));
+ return ssa_emit(proc, ssa_make_instr_conv(proc, ssaConv_ptrtoint, value, src, dst));
}
if (is_type_int_or_uint(src) && is_type_pointer(dst)) {
- ssaValue *i = ssa_emit_load(proc, value);
- return ssa_emit(proc, ssa_make_instr_conv(proc, ssaConv_inttoptr, i, src, dst));
+ return ssa_emit(proc, ssa_make_instr_conv(proc, ssaConv_inttoptr, value, src, dst));
}
// Pointer <-> Pointer
@@ -1708,7 +1706,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
Entity **found = map_get(&proc->module->info->uses, hash_pointer(p));
if (found && (*found)->kind == Entity_Builtin) {
Entity *e = *found;
- switch (e->builtin.id) {
+ switch (e->Builtin.id) {
case BuiltinProc_len: {
// len :: proc(Type) -> int
// NOTE(bill): len of an array is a constant expression
diff --git a/src/main.cpp b/src/main.cpp
index 271ddcf75..b641ac89d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -35,9 +35,8 @@ i32 win32_exec_command_line_app(char *fmt, ...) {
return cast(i32)exit_code;
} else {
// NOTE(bill): failed to create process
+ return -1;
}
-
- return 0;
}
int main(int argc, char **argv) {
@@ -79,19 +78,19 @@ int main(int argc, char **argv) {
isize base_name_len = gb_path_extension(output_name)-1 - output_name;
i32 exit_code = win32_exec_command_line_app(
- "opt -mem2reg %s -o %.*s.bc",
+ "../misc/llvm-bin/opt -mem2reg %s -o %.*s.bc",
output_name, cast(int)base_name_len, output_name);
if (exit_code == 0) {
win32_exec_command_line_app(
"clang -o %.*s.exe %.*s.bc -Wno-override-module "
"-lKernel32.lib -lUser32.lib -lGdi32.lib -lOpengl32.lib "
- "-l../c_libs/stb_image.lib"
,
cast(int)base_name_len, output_name,
cast(int)base_name_len, output_name);
if (run_output) {
win32_exec_command_line_app("%.*s.exe", cast(int)base_name_len, output_name);
}
+ } else {
}
return 0;
diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp
index 0a10cdce3..407d502f0 100644
--- a/src/tokenizer.cpp
+++ b/src/tokenizer.cpp
@@ -172,7 +172,7 @@ gb_no_inline void warning(Token token, char *fmt, ...) {
-
+// NOTE(bill): result == priority
i32 token_precedence(Token t) {
switch (t.kind) {
case Token_CmpOr: