Fix file load order and allow when statements at file scope

This commit is contained in:
Ginger Bill
2017-09-20 20:38:32 +01:00
parent 333db4dc94
commit d2c1c719bd
6 changed files with 624 additions and 335 deletions

View File

@@ -19,6 +19,4 @@ if [[ "$(uname)" == "Darwin" ]]; then
other_args="${other_args} -liconv"
fi
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin
./odin run code/demo.odin
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin && ./odin run examples/demo.odin

View File

@@ -22,11 +22,11 @@ when ODIN_OS == "windows" {
}
when ODIN_OS == "windows" {
c_long :: u32;
c_ulong :: u32;
} else when size_of(uint) == 4 {
c_long :: u32;
c_ulong :: u32;
} else {
c_long :: u64;
c_ulong :: u64;
}
c_longlong :: i64;

View File

@@ -1,5 +1,3 @@
import "core:fmt.odin";
import "core:os.odin";
import "core:raw.odin";
foreign __llvm_core {
@@ -146,7 +144,6 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
total_size := size + alignment;
if len(arena.memory) + total_size > cap(arena.memory) {
fmt.fprintln(os.stderr, "Arena out of memory");
return nil;
}

View File

@@ -1,26 +1,25 @@
import "core:fmt.odin";
import "core:strconv.odin";
import "core:mem.odin";
import "core:atomics.odin";
import "core:bits.odin";
import "core:hash.odin";
import "core:math.odin";
import "core:opengl.odin";
import "core:os.odin";
import "core:raw.odin";
import "core:sort.odin";
import "core:strings.odin";
import "core:sync.odin";
import "core:types.odin";
import "core:utf8.odin";
import "core:utf16.odin";
import "core:utf8.odin";
// import "core:sync.odin";
when ODIN_OS == "windows" {
import "core:atomics.odin";
import "core:opengl.odin";
import "core:thread.odin";
import win32 "core:sys/windows.odin";
}
general_stuff :: proc() {
{ // `do` for inline statmes rather than block
foo :: proc() do fmt.println("Foo!");
@@ -585,6 +584,7 @@ threading_example :: proc() {
}
}
main :: proc() {
when false {
fmt.println("\n# general_stuff"); general_stuff();

File diff suppressed because it is too large Load Diff

View File

@@ -37,6 +37,7 @@ struct ImportedFile {
struct AstFile {
isize id;
String fullpath;
gbArena arena;
Tokenizer tokenizer;
Array<Token> tokens;
@@ -51,6 +52,7 @@ struct AstFile {
bool allow_range; // NOTE(bill): Ranges are only allowed in certain cases
bool in_foreign_block;
bool allow_type;
isize when_level;
Array<AstNode *> decls;
ImportedFileKind file_kind;
@@ -249,6 +251,8 @@ AST_NODE_KIND(_ComplexStmtBegin, "", i32) \
AstNode *cond; \
AstNode *body; \
AstNode *else_stmt; \
bool is_cond_determined; \
bool determined_cond; \
}) \
AST_NODE_KIND(ReturnStmt, "return statement", struct { \
Token token; \
@@ -328,27 +332,30 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
AstNode * foreign_library; \
Token open, close; \
Array<AstNode *> decls; \
CommentGroup docs; \
bool been_handled; \
CommentGroup docs; \
}) \
AST_NODE_KIND(Label, "label", struct { \
Token token; \
AstNode *name; \
}) \
AST_NODE_KIND(ValueDecl, "value declaration", struct { \
Array<AstNode *> names; \
AstNode * type; \
Array<AstNode *> values; \
u64 flags; \
bool is_mutable; \
CommentGroup docs; \
CommentGroup comment; \
Array<AstNode *> names; \
AstNode * type; \
Array<AstNode *> values; \
u64 flags; \
bool is_mutable; \
bool been_handled; \
CommentGroup docs; \
CommentGroup comment; \
}) \
AST_NODE_KIND(ImportDecl, "import declaration", struct { \
Token token; \
bool is_using; \
Token relpath; \
String fullpath; \
Token import_name; \
bool is_using; \
bool been_handled; \
CommentGroup docs; \
CommentGroup comment; \
}) \
@@ -356,6 +363,7 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
Token token; \
Token relpath; \
String fullpath; \
bool been_handled; \
CommentGroup docs; \
CommentGroup comment; \
}) \
@@ -364,6 +372,7 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
Token filepath; \
Token library_name; \
String base_dir; \
bool been_handled; \
CommentGroup docs; \
CommentGroup comment; \
}) \
@@ -3993,7 +4002,10 @@ AstNode *parse_when_stmt(AstFile *f) {
AstNode *else_stmt = nullptr;
isize prev_level = f->expr_level;
isize when_level = f->when_level;
defer (f->when_level = when_level);
f->expr_level = -1;
f->when_level += 1;
cond = parse_expr(f, false);
@@ -4028,6 +4040,11 @@ AstNode *parse_when_stmt(AstFile *f) {
}
}
// if (f->curr_proc == nullptr && f->when_level > 1) {
// syntax_error(token, "Nested when statements are not currently supported at the file scope");
// return ast_bad_stmt(f, token, f->curr_token);
// }
return ast_when_stmt(f, token, cond, body, else_stmt);
}
@@ -4635,11 +4652,11 @@ Array<AstNode *> parse_stmt_list(AstFile *f) {
ParseFileError init_ast_file(AstFile *f, String fullpath) {
fullpath = string_trim_whitespace(fullpath); // Just in case
if (!string_has_extension(fullpath, str_lit("odin"))) {
f->fullpath = string_trim_whitespace(fullpath); // Just in case
if (!string_has_extension(f->fullpath, str_lit("odin"))) {
return ParseFile_WrongExtension;
}
TokenizerInitError err = init_tokenizer(&f->tokenizer, fullpath);
TokenizerInitError err = init_tokenizer(&f->tokenizer, f->fullpath);
if (err != TokenizerInit_None) {
switch (err) {
case TokenizerInit_NotExists: