Browse Source

Reimplement -collection; remove `static` from Odin tokenizer/parser in core library

gingerBill 6 years ago
parent
commit
cdfaa643cc
5 changed files with 67 additions and 36 deletions
  1. 2 2
      build.bat
  2. 0 1
      core/odin/ast/ast.odin
  3. 0 31
      core/odin/parser/parser.odin
  4. 0 2
      core/odin/token/token.odin
  5. 65 0
      src/main.cpp

+ 2 - 2
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
+:end_of_build

+ 0 - 1
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,
 }

+ 0 - 31
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);

+ 0 - 2
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",

+ 65 - 0
src/main.cpp

@@ -505,6 +505,71 @@ bool parse_build_flags(Array<String> 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;