From cdfaa643ccdc54e0fba3bc43536f33e5ae8debac Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 23 Feb 2019 23:30:03 +0000 Subject: [PATCH] Reimplement -collection; remove `static` from Odin tokenizer/parser in core library --- build.bat | 4 +-- core/odin/ast/ast.odin | 1 - core/odin/parser/parser.odin | 31 ----------------- core/odin/token/token.odin | 2 -- src/main.cpp | 65 ++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 36 deletions(-) diff --git a/build.bat b/build.bat index 402d8842c..58ae69f93 100644 --- a/build.bat +++ b/build.bat @@ -42,8 +42,8 @@ del *.ilk > NUL 2> NUL cl %compiler_settings% "src\main.cpp" ^ /link %linker_settings% -OUT:%exe_name% ^ - && odin run examples/demo/demo.odin + && odin run examples/demo/demo.odin -keep-temp-files del *.obj > NUL 2> NUL -:end_of_build \ No newline at end of file +:end_of_build diff --git a/core/odin/ast/ast.odin b/core/odin/ast/ast.odin index 784c89e6a..8c43ee8e3 100644 --- a/core/odin/ast/ast.odin +++ b/core/odin/ast/ast.odin @@ -365,7 +365,6 @@ Value_Decl :: struct { type: ^Expr, values: []^Expr, comment: ^Comment_Group, - is_static: bool, is_using: bool, is_mutable: bool, } diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 7c7a816c9..4c43a20e5 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -1033,37 +1033,6 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt { expect_semicolon(p, s); return s; - case token.Static: - docs := p.lead_comment; - tok := expect_token(p, token.Static); - - list := parse_lhs_expr_list(p); - if len(list) == 0 { - error(p, tok.pos, "illegal use of 'static' statement"); - expect_semicolon(p, nil); - return ast.new(ast.Bad_Stmt, tok.pos, end_pos(p.prev_tok)); - } - - expect_token_after(p, token.Colon, "identifier list"); - decl := parse_value_decl(p, list, docs); - if decl != nil do switch d in &decl.derived { - case ast.Value_Decl: - if d.is_mutable { - d.is_static = true; - } else { - error(p, tok.pos, "'static' may only be currently used with variable declarations"); - } - case: - error(p, tok.pos, "illegal use of 'static' statement"); - } - - error(p, tok.pos, "illegal use of 'static' statement"); - if decl != nil { - return decl; - } - - return ast.new(ast.Bad_Stmt, tok.pos, end_pos(p.prev_tok)); - case token.Using: docs := p.lead_comment; tok := expect_token(p, token.Using); diff --git a/core/odin/token/token.odin b/core/odin/token/token.odin index 46b3fc846..f52f6301e 100644 --- a/core/odin/token/token.odin +++ b/core/odin/token/token.odin @@ -139,7 +139,6 @@ using Kind :: enum u16 { Bit_Field, Bit_Set, Map, - Static, Dynamic, Auto_Cast, Cast, @@ -274,7 +273,6 @@ tokens := [Kind.COUNT]string { "bit_field", "bit_set", "map", - "static", "dynamic", "auto_cast", "cast", diff --git a/src/main.cpp b/src/main.cpp index fb88e9c34..beda80cad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -505,6 +505,71 @@ bool parse_build_flags(Array args) { break; } + case BuildFlag_Collection: { + GB_ASSERT(value.kind == ExactValue_String); + String str = value.value_string; + isize eq_pos = -1; + for (isize i = 0; i < str.len; i++) { + if (str[i] == '=') { + eq_pos = i; + break; + } + } + if (eq_pos < 0) { + gb_printf_err("Expected 'name=path', got '%.*s'\n", LIT(param)); + bad_flags = true; + break; + } + String name = substring(str, 0, eq_pos); + String path = substring(str, eq_pos+1, str.len); + if (name.len == 0 || path.len == 0) { + gb_printf_err("Expected 'name=path', got '%.*s'\n", LIT(param)); + bad_flags = true; + break; + } + + if (!string_is_valid_identifier(name)) { + gb_printf_err("Library collection name '%.*s' must be a valid identifier\n", LIT(name)); + bad_flags = true; + break; + } + + if (name == "_") { + gb_printf_err("Library collection name cannot be an underscore\n"); + bad_flags = true; + break; + } + + if (name == "system") { + gb_printf_err("Library collection name 'system' is reserved\n"); + bad_flags = true; + break; + } + + String prev_path = {}; + bool found = find_library_collection_path(name, &prev_path); + if (found) { + gb_printf_err("Library collection '%.*s' already exists with path '%.*s'\n", LIT(name), LIT(prev_path)); + bad_flags = true; + break; + } + + gbAllocator a = heap_allocator(); + String fullpath = path_to_fullpath(a, path); + if (!path_is_directory(fullpath)) { + gb_printf_err("Library collection '%.*s' path must be a directory, got '%.*s'\n", LIT(name), LIT(fullpath)); + gb_free(a, fullpath.text); + bad_flags = true; + break; + } + + add_library_collection(name, path); + + // NOTE(bill): Allow for multiple library collections + continue; + } + + case BuildFlag_Define: { GB_ASSERT(value.kind == ExactValue_String); String str = value.value_string;