aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-01-05 21:43:36 +0000
committerGinger Bill <bill@gingerbill.org>2017-01-05 21:43:36 +0000
commitb07ee9ec233bcdcc64e45788b85653c51e184523 (patch)
tree7ef43991e009830d10999cabf0bc5b896acc2a7a
parent915b5cdab7ae87ce38a6119f5c7e73aa0faaefa3 (diff)
Fix problem with `odin build`
-rw-r--r--code/demo.odin56
-rw-r--r--src/checker/decl.c13
-rw-r--r--src/checker/expr.c8
-rw-r--r--src/checker/types.c10
-rw-r--r--src/main.c17
-rw-r--r--src/parser.c17
6 files changed, 34 insertions, 87 deletions
diff --git a/code/demo.odin b/code/demo.odin
index f1d3398f8..25ca072cb 100644
--- a/code/demo.odin
+++ b/code/demo.odin
@@ -1,59 +1,5 @@
#import "fmt.odin";
main :: proc() {
- {
- Byte_Size :: enum f64 {
- _, // Ignore first value
- KB = 1<<(10*iota),
- MB,
- GB,
- TB,
- PB,
- }
-
- using Byte_Size;
- fmt.println(KB, MB, GB, TB, PB);
- }
- {
- x := if 1 < 2 {
- y := 123;
- give y-2;
- } else {
- give 0;
- };
-
- x += {
- x := 2;
- give x;
- };
-
- fmt.println("x =", x);
- }
- {
- list := []int{1, 4, 7, 3, 7, 2, 1};
- for value : list {
- fmt.println(value);
- }
- for val, idx : 12 ..< 17 {
- fmt.println(val, idx);
- }
- msg := "Hellope";
- for value : msg {
- fmt.println(value);
- }
- }
- {
- i := 0;
- while i < 2 {
- i += 1;
- }
-
- // Idiom to emulate C-style for loops
- while x := 0; x < 2 {
- defer x += 1;
- // Body of code
- // ++ and -- have been removed
- }
- }
+ fmt.println("Hellope!");
}
-
diff --git a/src/checker/decl.c b/src/checker/decl.c
index 36e6c440c..9f683cf29 100644
--- a/src/checker/decl.c
+++ b/src/checker/decl.c
@@ -510,12 +510,12 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) {
c->context.decl = d;
switch (e->kind) {
- case Entity_Constant:
- check_const_decl(c, e, d->type_expr, d->init_expr, named_type);
- break;
case Entity_Variable:
check_var_decl(c, e, d->entities, d->entity_count, d->type_expr, d->init_expr);
break;
+ case Entity_Constant:
+ check_const_decl(c, e, d->type_expr, d->init_expr, named_type);
+ break;
case Entity_TypeName:
check_type_decl(c, e, d->type_expr, named_type);
break;
@@ -571,11 +571,14 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
push_procedure(c, type);
{
ast_node(bs, BlockStmt, body);
- // TODO(bill): Check declarations first (except mutable variable declarations)
check_stmt_list(c, bs->stmts, 0);
if (type->Proc.result_count > 0) {
if (!check_is_terminating(body)) {
- error(bs->close, "Missing return statement at the end of the procedure");
+ if (token.kind == Token_Ident) {
+ error(bs->close, "Missing return statement at the end of the procedure `%.*s`", LIT(token.string));
+ } else {
+ error(bs->close, "Missing return statement at the end of the procedure");
+ }
}
}
}
diff --git a/src/checker/expr.c b/src/checker/expr.c
index cf27f0ff4..2c772d149 100644
--- a/src/checker/expr.c
+++ b/src/checker/expr.c
@@ -2642,14 +2642,12 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
return false;
}
- AstNode *len = ce->args.e[1];
-
- check_expr(c, &op, len);
+ check_expr(c, &op, ce->args.e[1]);
if (op.mode == Addressing_Invalid) {
return false;
}
- if (!is_type_integer(op.type)) {
- gbString type_str = type_to_string(operand->type);
+ if (!is_type_integer(base_enum_type(op.type))) {
+ gbString type_str = type_to_string(op.type);
error_node(call, "Length for `new_slice` must be an integer, got `%s`", type_str);
gb_string_free(type_str);
return false;
diff --git a/src/checker/types.c b/src/checker/types.c
index 89cda3d02..74c2fa981 100644
--- a/src/checker/types.c
+++ b/src/checker/types.c
@@ -651,11 +651,13 @@ bool type_has_nil(Type *t) {
switch (t->kind) {
case Type_Basic:
return is_type_rawptr(t);
-
- case Type_Tuple:
- return false;
+ case Type_Slice:
+ case Type_Proc:
+ case Type_Pointer:
+ case Type_Maybe:
+ return true;
}
- return true;
+ return false;
}
diff --git a/src/main.c b/src/main.c
index db238235c..b340f4bc6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -159,16 +159,17 @@ int main(int argc, char **argv) {
#endif
- // if (global_error_collector.count != 0) {
- // return 1;
- // }
-
- // if (checker.parser->total_token_count < 2) {
- // return 1;
- // }
+#if 0
+ if (global_error_collector.count != 0) {
+ return 1;
+ }
- // ssa_generate(&checker.info, &build_context);
+ if (checker.parser->total_token_count < 2) {
+ return 1;
+ }
+ ssa_generate(&checker.info, &build_context);
+#endif
#if 1
irGen ir_gen = {0};
diff --git a/src/parser.c b/src/parser.c
index 96978d1c4..3fd2d61c2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1854,7 +1854,7 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
// TODO(bill): Handle this
}
Token open, close;
- AstNode *indices[3] = {0};
+ AstNode *indices[2] = {0};
f->expr_level++;
open = expect_token(f, Token_OpenBracket);
@@ -1862,23 +1862,20 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
if (f->curr_token.kind != Token_Colon) {
indices[0] = parse_expr(f, false);
}
- isize colon_count = 0;
- Token colons[2] = {0};
+ bool is_index = true;
- while (f->curr_token.kind == Token_Colon && colon_count < 1) {
- colons[colon_count++] = f->curr_token;
- next_token(f);
- if (f->curr_token.kind != Token_Colon &&
- f->curr_token.kind != Token_CloseBracket &&
+ if (allow_token(f, Token_Colon)) {
+ is_index = false;
+ if (f->curr_token.kind != Token_CloseBracket &&
f->curr_token.kind != Token_EOF) {
- indices[colon_count] = parse_expr(f, false);
+ indices[1] = parse_expr(f, false);
}
}
f->expr_level--;
close = expect_token(f, Token_CloseBracket);
- if (colon_count == 0) {
+ if (is_index) {
operand = make_index_expr(f, operand, indices[0], open, close);
} else {
operand = make_slice_expr(f, operand, open, close, indices[0], indices[1]);