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

View File

@@ -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!");
}

View File

@@ -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");
}
}
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -159,16 +159,17 @@ int main(int argc, char **argv) {
#endif
// if (global_error_collector.count != 0) {
// return 1;
// }
#if 0
if (global_error_collector.count != 0) {
return 1;
}
// if (checker.parser->total_token_count < 2) {
// 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};

View File

@@ -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]);