mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Fix file load order and allow when statements at file scope
This commit is contained in:
@@ -19,6 +19,4 @@ if [[ "$(uname)" == "Darwin" ]]; then
|
|||||||
other_args="${other_args} -liconv"
|
other_args="${other_args} -liconv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin
|
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin && ./odin run examples/demo.odin
|
||||||
|
|
||||||
./odin run code/demo.odin
|
|
||||||
|
|||||||
+3
-3
@@ -22,11 +22,11 @@ when ODIN_OS == "windows" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
when ODIN_OS == "windows" {
|
when ODIN_OS == "windows" {
|
||||||
c_long :: u32;
|
c_ulong :: u32;
|
||||||
} else when size_of(uint) == 4 {
|
} else when size_of(uint) == 4 {
|
||||||
c_long :: u32;
|
c_ulong :: u32;
|
||||||
} else {
|
} else {
|
||||||
c_long :: u64;
|
c_ulong :: u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
c_longlong :: i64;
|
c_longlong :: i64;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import "core:fmt.odin";
|
|
||||||
import "core:os.odin";
|
|
||||||
import "core:raw.odin";
|
import "core:raw.odin";
|
||||||
|
|
||||||
foreign __llvm_core {
|
foreign __llvm_core {
|
||||||
@@ -146,7 +144,6 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
|
|||||||
total_size := size + alignment;
|
total_size := size + alignment;
|
||||||
|
|
||||||
if len(arena.memory) + total_size > cap(arena.memory) {
|
if len(arena.memory) + total_size > cap(arena.memory) {
|
||||||
fmt.fprintln(os.stderr, "Arena out of memory");
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -1,26 +1,25 @@
|
|||||||
import "core:fmt.odin";
|
import "core:fmt.odin";
|
||||||
import "core:strconv.odin";
|
import "core:strconv.odin";
|
||||||
import "core:mem.odin";
|
import "core:mem.odin";
|
||||||
import "core:atomics.odin";
|
|
||||||
import "core:bits.odin";
|
import "core:bits.odin";
|
||||||
import "core:hash.odin";
|
import "core:hash.odin";
|
||||||
import "core:math.odin";
|
import "core:math.odin";
|
||||||
import "core:opengl.odin";
|
|
||||||
import "core:os.odin";
|
import "core:os.odin";
|
||||||
import "core:raw.odin";
|
import "core:raw.odin";
|
||||||
import "core:sort.odin";
|
import "core:sort.odin";
|
||||||
import "core:strings.odin";
|
import "core:strings.odin";
|
||||||
import "core:sync.odin";
|
|
||||||
import "core:types.odin";
|
import "core:types.odin";
|
||||||
import "core:utf8.odin";
|
|
||||||
import "core:utf16.odin";
|
import "core:utf16.odin";
|
||||||
|
import "core:utf8.odin";
|
||||||
|
// import "core:sync.odin";
|
||||||
|
|
||||||
when ODIN_OS == "windows" {
|
when ODIN_OS == "windows" {
|
||||||
|
import "core:atomics.odin";
|
||||||
|
import "core:opengl.odin";
|
||||||
import "core:thread.odin";
|
import "core:thread.odin";
|
||||||
import win32 "core:sys/windows.odin";
|
import win32 "core:sys/windows.odin";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
general_stuff :: proc() {
|
general_stuff :: proc() {
|
||||||
{ // `do` for inline statmes rather than block
|
{ // `do` for inline statmes rather than block
|
||||||
foo :: proc() do fmt.println("Foo!");
|
foo :: proc() do fmt.println("Foo!");
|
||||||
@@ -585,6 +584,7 @@ threading_example :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
when false {
|
when false {
|
||||||
fmt.println("\n# general_stuff"); general_stuff();
|
fmt.println("\n# general_stuff"); general_stuff();
|
||||||
|
|||||||
+586
-309
File diff suppressed because it is too large
Load Diff
+29
-12
@@ -37,6 +37,7 @@ struct ImportedFile {
|
|||||||
|
|
||||||
struct AstFile {
|
struct AstFile {
|
||||||
isize id;
|
isize id;
|
||||||
|
String fullpath;
|
||||||
gbArena arena;
|
gbArena arena;
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer;
|
||||||
Array<Token> tokens;
|
Array<Token> tokens;
|
||||||
@@ -51,6 +52,7 @@ struct AstFile {
|
|||||||
bool allow_range; // NOTE(bill): Ranges are only allowed in certain cases
|
bool allow_range; // NOTE(bill): Ranges are only allowed in certain cases
|
||||||
bool in_foreign_block;
|
bool in_foreign_block;
|
||||||
bool allow_type;
|
bool allow_type;
|
||||||
|
isize when_level;
|
||||||
|
|
||||||
Array<AstNode *> decls;
|
Array<AstNode *> decls;
|
||||||
ImportedFileKind file_kind;
|
ImportedFileKind file_kind;
|
||||||
@@ -249,6 +251,8 @@ AST_NODE_KIND(_ComplexStmtBegin, "", i32) \
|
|||||||
AstNode *cond; \
|
AstNode *cond; \
|
||||||
AstNode *body; \
|
AstNode *body; \
|
||||||
AstNode *else_stmt; \
|
AstNode *else_stmt; \
|
||||||
|
bool is_cond_determined; \
|
||||||
|
bool determined_cond; \
|
||||||
}) \
|
}) \
|
||||||
AST_NODE_KIND(ReturnStmt, "return statement", struct { \
|
AST_NODE_KIND(ReturnStmt, "return statement", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
@@ -328,27 +332,30 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
|
|||||||
AstNode * foreign_library; \
|
AstNode * foreign_library; \
|
||||||
Token open, close; \
|
Token open, close; \
|
||||||
Array<AstNode *> decls; \
|
Array<AstNode *> decls; \
|
||||||
CommentGroup docs; \
|
bool been_handled; \
|
||||||
|
CommentGroup docs; \
|
||||||
}) \
|
}) \
|
||||||
AST_NODE_KIND(Label, "label", struct { \
|
AST_NODE_KIND(Label, "label", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
AstNode *name; \
|
AstNode *name; \
|
||||||
}) \
|
}) \
|
||||||
AST_NODE_KIND(ValueDecl, "value declaration", struct { \
|
AST_NODE_KIND(ValueDecl, "value declaration", struct { \
|
||||||
Array<AstNode *> names; \
|
Array<AstNode *> names; \
|
||||||
AstNode * type; \
|
AstNode * type; \
|
||||||
Array<AstNode *> values; \
|
Array<AstNode *> values; \
|
||||||
u64 flags; \
|
u64 flags; \
|
||||||
bool is_mutable; \
|
bool is_mutable; \
|
||||||
CommentGroup docs; \
|
bool been_handled; \
|
||||||
CommentGroup comment; \
|
CommentGroup docs; \
|
||||||
|
CommentGroup comment; \
|
||||||
}) \
|
}) \
|
||||||
AST_NODE_KIND(ImportDecl, "import declaration", struct { \
|
AST_NODE_KIND(ImportDecl, "import declaration", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
bool is_using; \
|
|
||||||
Token relpath; \
|
Token relpath; \
|
||||||
String fullpath; \
|
String fullpath; \
|
||||||
Token import_name; \
|
Token import_name; \
|
||||||
|
bool is_using; \
|
||||||
|
bool been_handled; \
|
||||||
CommentGroup docs; \
|
CommentGroup docs; \
|
||||||
CommentGroup comment; \
|
CommentGroup comment; \
|
||||||
}) \
|
}) \
|
||||||
@@ -356,6 +363,7 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
|
|||||||
Token token; \
|
Token token; \
|
||||||
Token relpath; \
|
Token relpath; \
|
||||||
String fullpath; \
|
String fullpath; \
|
||||||
|
bool been_handled; \
|
||||||
CommentGroup docs; \
|
CommentGroup docs; \
|
||||||
CommentGroup comment; \
|
CommentGroup comment; \
|
||||||
}) \
|
}) \
|
||||||
@@ -364,6 +372,7 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
|
|||||||
Token filepath; \
|
Token filepath; \
|
||||||
Token library_name; \
|
Token library_name; \
|
||||||
String base_dir; \
|
String base_dir; \
|
||||||
|
bool been_handled; \
|
||||||
CommentGroup docs; \
|
CommentGroup docs; \
|
||||||
CommentGroup comment; \
|
CommentGroup comment; \
|
||||||
}) \
|
}) \
|
||||||
@@ -3993,7 +4002,10 @@ AstNode *parse_when_stmt(AstFile *f) {
|
|||||||
AstNode *else_stmt = nullptr;
|
AstNode *else_stmt = nullptr;
|
||||||
|
|
||||||
isize prev_level = f->expr_level;
|
isize prev_level = f->expr_level;
|
||||||
|
isize when_level = f->when_level;
|
||||||
|
defer (f->when_level = when_level);
|
||||||
f->expr_level = -1;
|
f->expr_level = -1;
|
||||||
|
f->when_level += 1;
|
||||||
|
|
||||||
cond = parse_expr(f, false);
|
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);
|
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) {
|
ParseFileError init_ast_file(AstFile *f, String fullpath) {
|
||||||
fullpath = string_trim_whitespace(fullpath); // Just in case
|
f->fullpath = string_trim_whitespace(fullpath); // Just in case
|
||||||
if (!string_has_extension(fullpath, str_lit("odin"))) {
|
if (!string_has_extension(f->fullpath, str_lit("odin"))) {
|
||||||
return ParseFile_WrongExtension;
|
return ParseFile_WrongExtension;
|
||||||
}
|
}
|
||||||
TokenizerInitError err = init_tokenizer(&f->tokenizer, fullpath);
|
TokenizerInitError err = init_tokenizer(&f->tokenizer, f->fullpath);
|
||||||
if (err != TokenizerInit_None) {
|
if (err != TokenizerInit_None) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case TokenizerInit_NotExists:
|
case TokenizerInit_NotExists:
|
||||||
|
|||||||
Reference in New Issue
Block a user