Fix problem with odin build

This commit is contained in:
Ginger Bill
2017-01-05 21:43:36 +00:00
parent 915b5cdab7
commit b07ee9ec23
6 changed files with 34 additions and 87 deletions
+1 -55
View File
@@ -1,59 +1,5 @@
#import "fmt.odin"; #import "fmt.odin";
main :: proc() { main :: proc() {
{ fmt.println("Hellope!");
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
}
}
} }
+8 -5
View File
@@ -510,12 +510,12 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) {
c->context.decl = d; c->context.decl = d;
switch (e->kind) { switch (e->kind) {
case Entity_Constant:
check_const_decl(c, e, d->type_expr, d->init_expr, named_type);
break;
case Entity_Variable: case Entity_Variable:
check_var_decl(c, e, d->entities, d->entity_count, d->type_expr, d->init_expr); check_var_decl(c, e, d->entities, d->entity_count, d->type_expr, d->init_expr);
break; break;
case Entity_Constant:
check_const_decl(c, e, d->type_expr, d->init_expr, named_type);
break;
case Entity_TypeName: case Entity_TypeName:
check_type_decl(c, e, d->type_expr, named_type); check_type_decl(c, e, d->type_expr, named_type);
break; break;
@@ -571,11 +571,14 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
push_procedure(c, type); push_procedure(c, type);
{ {
ast_node(bs, BlockStmt, body); ast_node(bs, BlockStmt, body);
// TODO(bill): Check declarations first (except mutable variable declarations)
check_stmt_list(c, bs->stmts, 0); check_stmt_list(c, bs->stmts, 0);
if (type->Proc.result_count > 0) { if (type->Proc.result_count > 0) {
if (!check_is_terminating(body)) { 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");
}
} }
} }
} }
+3 -5
View File
@@ -2642,14 +2642,12 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
return false; return false;
} }
AstNode *len = ce->args.e[1]; check_expr(c, &op, ce->args.e[1]);
check_expr(c, &op, len);
if (op.mode == Addressing_Invalid) { if (op.mode == Addressing_Invalid) {
return false; return false;
} }
if (!is_type_integer(op.type)) { if (!is_type_integer(base_enum_type(op.type))) {
gbString type_str = type_to_string(operand->type); gbString type_str = type_to_string(op.type);
error_node(call, "Length for `new_slice` must be an integer, got `%s`", type_str); error_node(call, "Length for `new_slice` must be an integer, got `%s`", type_str);
gb_string_free(type_str); gb_string_free(type_str);
return false; return false;
+6 -4
View File
@@ -651,11 +651,13 @@ bool type_has_nil(Type *t) {
switch (t->kind) { switch (t->kind) {
case Type_Basic: case Type_Basic:
return is_type_rawptr(t); return is_type_rawptr(t);
case Type_Slice:
case Type_Tuple: case Type_Proc:
return false; case Type_Pointer:
case Type_Maybe:
return true;
} }
return true; return false;
} }
+9 -8
View File
@@ -159,16 +159,17 @@ int main(int argc, char **argv) {
#endif #endif
// if (global_error_collector.count != 0) { #if 0
// return 1; if (global_error_collector.count != 0) {
// } return 1;
}
// if (checker.parser->total_token_count < 2) { if (checker.parser->total_token_count < 2) {
// return 1; return 1;
// } }
// ssa_generate(&checker.info, &build_context);
ssa_generate(&checker.info, &build_context);
#endif
#if 1 #if 1
irGen ir_gen = {0}; irGen ir_gen = {0};
+7 -10
View File
@@ -1854,7 +1854,7 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
// TODO(bill): Handle this // TODO(bill): Handle this
} }
Token open, close; Token open, close;
AstNode *indices[3] = {0}; AstNode *indices[2] = {0};
f->expr_level++; f->expr_level++;
open = expect_token(f, Token_OpenBracket); 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) { if (f->curr_token.kind != Token_Colon) {
indices[0] = parse_expr(f, false); indices[0] = parse_expr(f, false);
} }
isize colon_count = 0; bool is_index = true;
Token colons[2] = {0};
while (f->curr_token.kind == Token_Colon && colon_count < 1) { if (allow_token(f, Token_Colon)) {
colons[colon_count++] = f->curr_token; is_index = false;
next_token(f); if (f->curr_token.kind != Token_CloseBracket &&
if (f->curr_token.kind != Token_Colon &&
f->curr_token.kind != Token_CloseBracket &&
f->curr_token.kind != Token_EOF) { f->curr_token.kind != Token_EOF) {
indices[colon_count] = parse_expr(f, false); indices[1] = parse_expr(f, false);
} }
} }
f->expr_level--; f->expr_level--;
close = expect_token(f, Token_CloseBracket); close = expect_token(f, Token_CloseBracket);
if (colon_count == 0) { if (is_index) {
operand = make_index_expr(f, operand, indices[0], open, close); operand = make_index_expr(f, operand, indices[0], open, close);
} else { } else {
operand = make_slice_expr(f, operand, open, close, indices[0], indices[1]); operand = make_slice_expr(f, operand, open, close, indices[0], indices[1]);