mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-30 03:10:06 +00:00
Change entity collection strategy
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
typedef struct BuildContext {
|
||||
String ODIN_OS; // target operating system
|
||||
String ODIN_ARCH; // target architecture
|
||||
String ODIN_VENDOR; // compiler vendor
|
||||
String ODIN_VERSION; // compiler version
|
||||
String ODIN_ROOT; // Odin ROOT
|
||||
|
||||
i64 word_size;
|
||||
i64 max_align;
|
||||
String llc_flags;
|
||||
String link_flags;
|
||||
} BuildContext;
|
||||
|
||||
String odin_root_dir(void) {
|
||||
String path = global_module_path;
|
||||
Array(wchar_t) path_buf;
|
||||
isize len, i;
|
||||
gbTempArenaMemory tmp;
|
||||
wchar_t *text;
|
||||
|
||||
if (global_module_path_set) {
|
||||
return global_module_path;
|
||||
}
|
||||
|
||||
array_init_count(&path_buf, heap_allocator(), 300);
|
||||
|
||||
len = 0;
|
||||
for (;;) {
|
||||
len = GetModuleFileNameW(NULL, &path_buf.e[0], path_buf.count);
|
||||
if (len == 0) {
|
||||
return make_string(NULL, 0);
|
||||
}
|
||||
if (len < path_buf.count) {
|
||||
break;
|
||||
}
|
||||
array_resize(&path_buf, 2*path_buf.count + 300);
|
||||
}
|
||||
|
||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
|
||||
text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||
|
||||
GetModuleFileNameW(NULL, text, len);
|
||||
path = string16_to_string(heap_allocator(), make_string16(text, len));
|
||||
for (i = path.len-1; i >= 0; i--) {
|
||||
u8 c = path.text[i];
|
||||
if (c == '/' || c == '\\') {
|
||||
break;
|
||||
}
|
||||
path.len--;
|
||||
}
|
||||
|
||||
global_module_path = path;
|
||||
global_module_path_set = true;
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
|
||||
array_free(&path_buf);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
void init_build_context(BuildContext *bc) {
|
||||
bc->ODIN_OS = str_lit("windows");
|
||||
bc->ODIN_ARCH = str_lit("amd64");
|
||||
bc->ODIN_VENDOR = str_lit("odin");
|
||||
bc->ODIN_VERSION = str_lit("0.0.3d");
|
||||
bc->ODIN_ROOT = odin_root_dir();
|
||||
|
||||
|
||||
if (str_eq(bc->ODIN_ARCH, str_lit("amd64"))) {
|
||||
bc->word_size = 8;
|
||||
bc->max_align = 16;
|
||||
bc->llc_flags = str_lit("-march=x86-64 ");
|
||||
bc->link_flags = str_lit("/machine:x64 ");
|
||||
} else if (str_eq(bc->ODIN_ARCH, str_lit("x86"))) {
|
||||
bc->word_size = 4;
|
||||
bc->max_align = 8;
|
||||
bc->llc_flags = str_lit("-march=x86 ");
|
||||
bc->link_flags = str_lit("/machine:x86 ");
|
||||
}
|
||||
}
|
||||
+55
-11
@@ -535,7 +535,7 @@ void add_global_string_constant(gbAllocator a, String name, String value) {
|
||||
}
|
||||
|
||||
|
||||
void init_universal_scope(void) {
|
||||
void init_universal_scope(BuildContext *bc) {
|
||||
// NOTE(bill): No need to free these
|
||||
gbAllocator a = heap_allocator();
|
||||
universal_scope = make_scope(NULL, a);
|
||||
@@ -555,11 +555,11 @@ void init_universal_scope(void) {
|
||||
add_global_entity(make_entity_nil(a, str_lit("nil"), t_untyped_nil));
|
||||
|
||||
// TODO(bill): Set through flags in the compiler
|
||||
add_global_string_constant(a, str_lit("ODIN_OS"), str_lit("windows"));
|
||||
add_global_string_constant(a, str_lit("ODIN_ARCH"), str_lit("amd64"));
|
||||
add_global_string_constant(a, str_lit("ODIN_VENDOR"), str_lit("odin"));
|
||||
add_global_string_constant(a, str_lit("ODIN_VERSION"), str_lit(VERSION_STRING));
|
||||
add_global_string_constant(a, str_lit("ODIN_ENDIAN"), str_lit("little"));
|
||||
add_global_string_constant(a, str_lit("ODIN_OS"), bc->ODIN_OS);
|
||||
add_global_string_constant(a, str_lit("ODIN_ARCH"), bc->ODIN_ARCH);
|
||||
add_global_string_constant(a, str_lit("ODIN_VENDOR"), bc->ODIN_VENDOR);
|
||||
add_global_string_constant(a, str_lit("ODIN_VERSION"), bc->ODIN_VERSION);
|
||||
add_global_string_constant(a, str_lit("ODIN_ROOT"), bc->ODIN_ROOT);
|
||||
|
||||
|
||||
// Builtin Procedures
|
||||
@@ -607,12 +607,13 @@ void destroy_checker_info(CheckerInfo *i) {
|
||||
}
|
||||
|
||||
|
||||
void init_checker(Checker *c, Parser *parser, BaseTypeSizes sizes) {
|
||||
void init_checker(Checker *c, Parser *parser, BuildContext *bc) {
|
||||
gbAllocator a = heap_allocator();
|
||||
|
||||
c->parser = parser;
|
||||
init_checker_info(&c->info);
|
||||
c->sizes = sizes;
|
||||
c->sizes.word_size = bc->word_size;
|
||||
c->sizes.max_align = bc->max_align;
|
||||
|
||||
array_init(&c->proc_stack, a);
|
||||
array_init(&c->procs, a);
|
||||
@@ -698,7 +699,10 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
||||
|
||||
if (mode == Addressing_Constant) {
|
||||
if (is_type_constant_type(type)) {
|
||||
GB_ASSERT(value.kind != ExactValue_Invalid);
|
||||
// if (value.kind == ExactValue_Invalid) {
|
||||
// TODO(bill): Is this correct?
|
||||
// return;
|
||||
// }
|
||||
if (!(type != t_invalid || is_type_constant_type(type))) {
|
||||
compiler_error("add_type_and_value - invalid type: %s", type_to_string(type));
|
||||
}
|
||||
@@ -1086,6 +1090,35 @@ void check_global_entities_by_kind(Checker *c, EntityKind kind) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void check_all_global_entities(Checker *c) {
|
||||
for_array(i, c->info.entities.entries) {
|
||||
MapDeclInfoEntry *entry = &c->info.entities.entries.e[i];
|
||||
Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
|
||||
DeclInfo *d = entry->value;
|
||||
|
||||
if (d->scope != e->scope) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_curr_ast_file(c, d->scope->file);
|
||||
if (e->kind != Entity_Procedure && str_eq(e->token.string, str_lit("main"))) {
|
||||
if (e->scope->is_init) {
|
||||
error(e->token, "`main` is reserved as the entry point procedure in the initial scope");
|
||||
continue;
|
||||
}
|
||||
} else if (e->scope->is_global && str_eq(e->token.string, str_lit("main"))) {
|
||||
error(e->token, "`main` is reserved as the entry point procedure in the initial scope");
|
||||
continue;
|
||||
}
|
||||
|
||||
Scope *prev_scope = c->context.scope;
|
||||
c->context.scope = d->scope;
|
||||
check_entity_decl(c, e, d, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void check_global_collect_entities(Checker *c, Scope *parent_scope, AstNodeArray nodes, MapScope *file_scopes) {
|
||||
for_array(decl_index, nodes) {
|
||||
AstNode *decl = nodes.e[decl_index];
|
||||
@@ -1120,6 +1153,9 @@ void check_global_collect_entities(Checker *c, Scope *parent_scope, AstNodeArray
|
||||
AstNode *name = cd->names.e[i];
|
||||
AstNode *value = cd->values.e[i];
|
||||
ExactValue v = {ExactValue_Invalid};
|
||||
if (name->kind != AstNode_Ident) {
|
||||
error_node(name, "A declaration's name but be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
||||
}
|
||||
Entity *e = make_entity_constant(c->allocator, parent_scope, name->Ident, NULL, v);
|
||||
e->identifier = name;
|
||||
DeclInfo *di = make_declaration_info(c->allocator, parent_scope);
|
||||
@@ -1161,6 +1197,9 @@ void check_global_collect_entities(Checker *c, Scope *parent_scope, AstNodeArray
|
||||
if (i < vd->values.count) {
|
||||
value = vd->values.e[i];
|
||||
}
|
||||
if (name->kind != AstNode_Ident) {
|
||||
error_node(name, "A declaration's name but be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
||||
}
|
||||
Entity *e = make_entity_variable(c->allocator, parent_scope, name->Ident, NULL);
|
||||
e->identifier = name;
|
||||
entities[entity_index++] = e;
|
||||
@@ -1386,13 +1425,18 @@ void check_parsed_files(Checker *c) {
|
||||
|
||||
check_import_entities(c, &file_scopes);
|
||||
|
||||
#if 0
|
||||
check_global_entities_by_kind(c, Entity_TypeName);
|
||||
check_global_entities_by_kind(c, Entity_Constant);
|
||||
init_preload_types(c);
|
||||
add_implicit_value(c, ImplicitValue_context, str_lit("context"), str_lit("__context"), t_context);
|
||||
check_global_entities_by_kind(c, Entity_Constant);
|
||||
check_global_entities_by_kind(c, Entity_Procedure);
|
||||
check_global_entities_by_kind(c, Entity_Variable);
|
||||
|
||||
#else
|
||||
check_all_global_entities(c);
|
||||
init_preload_types(c);
|
||||
add_implicit_value(c, ImplicitValue_context, str_lit("context"), str_lit("__context"), t_context);
|
||||
#endif
|
||||
|
||||
for (isize i = 1; i < ImplicitValue_Count; i++) {
|
||||
// NOTE(bill): First is invalid
|
||||
|
||||
@@ -121,10 +121,12 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (e->kind == Entity_Procedure) {
|
||||
check_proc_decl(c, e, d);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
CheckerContext prev = c->context;
|
||||
c->context.scope = d->scope;
|
||||
c->context.decl = d;
|
||||
@@ -139,6 +141,11 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc
|
||||
case Entity_TypeName:
|
||||
check_type_decl(c, e, d->type_expr, named_type, cycle_checker);
|
||||
break;
|
||||
#if 1
|
||||
case Entity_Procedure:
|
||||
check_proc_decl(c, e, d);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
c->context = prev;
|
||||
@@ -279,6 +286,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_e
|
||||
|
||||
Operand operand = {0};
|
||||
if (init_expr) {
|
||||
// check_expr_or_type(c, &operand, init_expr);
|
||||
check_expr(c, &operand, init_expr);
|
||||
}
|
||||
check_init_constant(c, e, &operand);
|
||||
|
||||
+3
-1
@@ -1060,7 +1060,9 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
|
||||
return;
|
||||
}
|
||||
o->value = e->Constant.value;
|
||||
GB_ASSERT(o->value.kind != ExactValue_Invalid);
|
||||
if (o->value.kind == ExactValue_Invalid) {
|
||||
return;
|
||||
}
|
||||
o->mode = Addressing_Constant;
|
||||
break;
|
||||
|
||||
|
||||
@@ -13,55 +13,6 @@ gb_global String global_module_path = {0};
|
||||
gb_global bool global_module_path_set = false;
|
||||
|
||||
|
||||
String get_module_dir() {
|
||||
String path = global_module_path;
|
||||
Array(wchar_t) path_buf;
|
||||
isize len, i;
|
||||
gbTempArenaMemory tmp;
|
||||
wchar_t *text;
|
||||
|
||||
if (global_module_path_set) {
|
||||
return global_module_path;
|
||||
}
|
||||
|
||||
array_init_count(&path_buf, heap_allocator(), 300);
|
||||
|
||||
len = 0;
|
||||
for (;;) {
|
||||
len = GetModuleFileNameW(NULL, &path_buf.e[0], path_buf.count);
|
||||
if (len == 0) {
|
||||
return make_string(NULL, 0);
|
||||
}
|
||||
if (len < path_buf.count) {
|
||||
break;
|
||||
}
|
||||
array_resize(&path_buf, 2*path_buf.count + 300);
|
||||
}
|
||||
|
||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
|
||||
text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||
|
||||
GetModuleFileNameW(NULL, text, len);
|
||||
path = string16_to_string(heap_allocator(), make_string16(text, len));
|
||||
for (i = path.len-1; i >= 0; i--) {
|
||||
u8 c = path.text[i];
|
||||
if (c == '/' || c == '\\') {
|
||||
break;
|
||||
}
|
||||
path.len--;
|
||||
}
|
||||
|
||||
global_module_path = path;
|
||||
global_module_path_set = true;
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
|
||||
array_free(&path_buf);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
String path_to_fullpath(gbAllocator a, String s) {
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
String16 string16 = string_to_string16(string_buffer_allocator, s);
|
||||
|
||||
@@ -306,6 +306,7 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y)
|
||||
case Token_Shr: c = a >> b; break;
|
||||
default: goto error;
|
||||
}
|
||||
|
||||
return make_exact_value_integer(c);
|
||||
} break;
|
||||
|
||||
|
||||
+10
-43
@@ -1,11 +1,11 @@
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
#define VERSION_STRING "v0.0.3d"
|
||||
|
||||
#include "common.c"
|
||||
#include "timings.c"
|
||||
#include "unicode.c"
|
||||
#include "build.c"
|
||||
#include "tokenizer.c"
|
||||
#include "parser.c"
|
||||
// #include "printer.c"
|
||||
@@ -59,39 +59,6 @@ i32 win32_exec_command_line_app(char *name, char *fmt, ...) {
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
typedef enum ArchKind {
|
||||
ArchKind_x64,
|
||||
ArchKind_x86,
|
||||
} ArchKind;
|
||||
|
||||
typedef struct ArchData {
|
||||
BaseTypeSizes sizes;
|
||||
String llc_flags;
|
||||
String link_flags;
|
||||
} ArchData;
|
||||
|
||||
ArchData make_arch_data(ArchKind kind) {
|
||||
ArchData data = {0};
|
||||
|
||||
switch (kind) {
|
||||
case ArchKind_x64:
|
||||
default:
|
||||
data.sizes.word_size = 8;
|
||||
data.sizes.max_align = 16;
|
||||
data.llc_flags = str_lit("-march=x86-64 ");
|
||||
data.link_flags = str_lit("/machine:x64 ");
|
||||
break;
|
||||
|
||||
case ArchKind_x86:
|
||||
data.sizes.word_size = 4;
|
||||
data.sizes.max_align = 8;
|
||||
data.llc_flags = str_lit("-march=x86 ");
|
||||
data.link_flags = str_lit("/machine:x86 ");
|
||||
break;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void usage(char *argv0) {
|
||||
gb_printf_err("%s is a tool for managing Odin source code\n", argv0);
|
||||
@@ -118,9 +85,10 @@ int main(int argc, char **argv) {
|
||||
init_string_buffer_memory();
|
||||
init_global_error_collector();
|
||||
|
||||
String module_dir = get_module_dir();
|
||||
BuildContext build_context = {0};
|
||||
init_build_context(&build_context);
|
||||
|
||||
init_universal_scope();
|
||||
init_universal_scope(&build_context);
|
||||
|
||||
char *init_filename = NULL;
|
||||
bool run_output = false;
|
||||
@@ -131,7 +99,7 @@ int main(int argc, char **argv) {
|
||||
} else if (str_eq(arg1, str_lit("build"))) {
|
||||
init_filename = argv[2];
|
||||
} else if (str_eq(arg1, str_lit("version"))) {
|
||||
gb_printf("%s version %s", argv[0], VERSION_STRING);
|
||||
gb_printf("%s version %.*s", argv[0], LIT(build_context.ODIN_VERSION));
|
||||
return 0;
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
@@ -157,9 +125,8 @@ int main(int argc, char **argv) {
|
||||
timings_start_section(&timings, str_lit("type check"));
|
||||
|
||||
Checker checker = {0};
|
||||
ArchData arch_data = make_arch_data(ArchKind_x64);
|
||||
|
||||
init_checker(&checker, &parser, arch_data.sizes);
|
||||
init_checker(&checker, &parser, &build_context);
|
||||
// defer (destroy_checker(&checker));
|
||||
|
||||
check_parsed_files(&checker);
|
||||
@@ -206,7 +173,7 @@ int main(int argc, char **argv) {
|
||||
// "-dce "
|
||||
// "-S "
|
||||
"",
|
||||
LIT(module_dir),
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
output_name, LIT(output));
|
||||
if (exit_code != 0) {
|
||||
return exit_code;
|
||||
@@ -220,10 +187,10 @@ int main(int argc, char **argv) {
|
||||
"%.*s "
|
||||
// "-debug-pass=Arguments "
|
||||
"",
|
||||
LIT(module_dir),
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output),
|
||||
optimization_level,
|
||||
LIT(arch_data.llc_flags));
|
||||
LIT(build_context.llc_flags));
|
||||
if (exit_code != 0) {
|
||||
return exit_code;
|
||||
}
|
||||
@@ -247,7 +214,7 @@ int main(int argc, char **argv) {
|
||||
" %.*s "
|
||||
"",
|
||||
LIT(output), LIT(output),
|
||||
lib_str, LIT(arch_data.link_flags));
|
||||
lib_str, LIT(build_context.link_flags));
|
||||
if (exit_code != 0) {
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
+32
-48
@@ -1169,11 +1169,13 @@ bool expect_semicolon_after_stmt(AstFile *f, AstNode *s) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// switch (f->curr_token.kind) {
|
||||
// case Token_EOF:
|
||||
// case Token_CloseBrace:
|
||||
// return true;
|
||||
// }
|
||||
if (f->curr_token.pos.line == f->prev_token.pos.line) {
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_EOF:
|
||||
case Token_CloseBrace:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (s != NULL) {
|
||||
syntax_error(f->prev_token, "Expected `;` after %.*s, got `%.*s`",
|
||||
@@ -1194,18 +1196,18 @@ AstNode * parse_body(AstFile *f);
|
||||
|
||||
AstNode *parse_identifier(AstFile *f) {
|
||||
Token token = f->curr_token;
|
||||
if (token.kind == Token_Identifier) {
|
||||
if (token.kind == Token_Ident) {
|
||||
next_token(f);
|
||||
} else {
|
||||
token.string = str_lit("_");
|
||||
expect_token(f, Token_Identifier);
|
||||
expect_token(f, Token_Ident);
|
||||
}
|
||||
return make_ident(f, token);
|
||||
}
|
||||
|
||||
AstNode *parse_tag_expr(AstFile *f, AstNode *expression) {
|
||||
Token token = expect_token(f, Token_Hash);
|
||||
Token name = expect_token(f, Token_Identifier);
|
||||
Token name = expect_token(f, Token_Ident);
|
||||
return make_tag_expr(f, token, name, expression);
|
||||
}
|
||||
|
||||
@@ -1401,7 +1403,7 @@ void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name, String *link_n
|
||||
AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
AstNode *operand = NULL; // Operand
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_Identifier:
|
||||
case Token_Ident:
|
||||
operand = parse_identifier(f);
|
||||
if (!lhs) {
|
||||
// TODO(bill): Handle?
|
||||
@@ -1456,7 +1458,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
|
||||
case Token_Hash: {
|
||||
Token token = expect_token(f, Token_Hash);
|
||||
Token name = expect_token(f, Token_Identifier);
|
||||
Token name = expect_token(f, Token_Ident);
|
||||
if (str_eq(name.string, str_lit("file"))) {
|
||||
Token token = name;
|
||||
token.kind = Token_String;
|
||||
@@ -1584,21 +1586,15 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
|
||||
bool loop = true;
|
||||
while (loop) {
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_OpenParen: {
|
||||
if (lhs) {
|
||||
// TODO(bill): Handle this shit! Is this even allowed in this language?!
|
||||
}
|
||||
case Token_OpenParen:
|
||||
operand = parse_call_expr(f, operand);
|
||||
} break;
|
||||
break;
|
||||
|
||||
case Token_Period: {
|
||||
Token token = f->curr_token;
|
||||
next_token(f);
|
||||
if (lhs) {
|
||||
// TODO(bill): handle this
|
||||
}
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_Identifier:
|
||||
case Token_Ident:
|
||||
operand = make_selector_expr(f, token, operand, parse_identifier(f));
|
||||
break;
|
||||
default: {
|
||||
@@ -1664,20 +1660,13 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
|
||||
operand = make_demaybe_expr(f, operand, expect_token(f, Token_Maybe));
|
||||
break;
|
||||
|
||||
case Token_OpenBrace: {
|
||||
case Token_OpenBrace:
|
||||
if (!lhs && is_literal_type(operand) && f->expr_level >= 0) {
|
||||
if (f->curr_token.pos.line == f->prev_token.pos.line) {
|
||||
// TODO(bill): This is a hack due to optional semicolons
|
||||
// TODO(bill): It's probably much better to solve this by changing
|
||||
// the syntax for struct literals and array literals
|
||||
operand = parse_literal_value(f, operand);
|
||||
} else {
|
||||
loop = false;
|
||||
}
|
||||
operand = parse_literal_value(f, operand);
|
||||
} else {
|
||||
loop = false;
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
|
||||
default:
|
||||
loop = false;
|
||||
@@ -1933,14 +1922,13 @@ AstNode *parse_type(AstFile *f) {
|
||||
}
|
||||
|
||||
|
||||
Token parse_procedure_signature(AstFile *f,
|
||||
AstNodeArray *params, AstNodeArray *results);
|
||||
Token parse_proc_signature(AstFile *f, AstNodeArray *params, AstNodeArray *results);
|
||||
|
||||
AstNode *parse_proc_type(AstFile *f) {
|
||||
AstNodeArray params = {0};
|
||||
AstNodeArray results = {0};
|
||||
|
||||
Token proc_token = parse_procedure_signature(f, ¶ms, &results);
|
||||
Token proc_token = parse_proc_signature(f, ¶ms, &results);
|
||||
|
||||
return make_proc_type(f, proc_token, params, results);
|
||||
}
|
||||
@@ -1949,7 +1937,7 @@ AstNode *parse_proc_type(AstFile *f) {
|
||||
AstNodeArray parse_parameter_list(AstFile *f) {
|
||||
AstNodeArray params = make_ast_node_array(f);
|
||||
|
||||
while (f->curr_token.kind == Token_Identifier ||
|
||||
while (f->curr_token.kind == Token_Ident ||
|
||||
f->curr_token.kind == Token_using) {
|
||||
bool is_using = false;
|
||||
if (allow_token(f, Token_using)) {
|
||||
@@ -2068,7 +2056,7 @@ AstNodeArray parse_record_params(AstFile *f, isize *decl_count_, bool using_allo
|
||||
|
||||
AstNode *parse_identifier_or_type(AstFile *f, u32 flags) {
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_Identifier: {
|
||||
case Token_Ident: {
|
||||
AstNode *e = parse_identifier(f);
|
||||
while (f->curr_token.kind == Token_Period) {
|
||||
Token token = f->curr_token;
|
||||
@@ -2128,7 +2116,7 @@ AstNode *parse_identifier_or_type(AstFile *f, u32 flags) {
|
||||
bool is_packed = false;
|
||||
bool is_ordered = false;
|
||||
while (allow_token(f, Token_Hash)) {
|
||||
Token tag = expect_token_after(f, Token_Identifier, "`#`");
|
||||
Token tag = expect_token_after(f, Token_Ident, "`#`");
|
||||
if (str_eq(tag.string, str_lit("packed"))) {
|
||||
if (is_packed) {
|
||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||
@@ -2268,9 +2256,9 @@ AstNodeArray parse_results(AstFile *f) {
|
||||
return results;
|
||||
}
|
||||
|
||||
Token parse_procedure_signature(AstFile *f,
|
||||
AstNodeArray *params,
|
||||
AstNodeArray *results) {
|
||||
Token parse_proc_signature(AstFile *f,
|
||||
AstNodeArray *params,
|
||||
AstNodeArray *results) {
|
||||
Token proc_token = expect_token(f, Token_proc);
|
||||
expect_token(f, Token_OpenParen);
|
||||
*params = parse_parameter_list(f);
|
||||
@@ -2292,11 +2280,7 @@ AstNode *parse_body(AstFile *f) {
|
||||
|
||||
|
||||
AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name) {
|
||||
AstNodeArray params = {0};
|
||||
AstNodeArray results = {0};
|
||||
|
||||
parse_procedure_signature(f, ¶ms, &results);
|
||||
AstNode *proc_type = make_proc_type(f, proc_token, params, results);
|
||||
AstNode *proc_type = parse_proc_type(f);
|
||||
|
||||
AstNode *body = NULL;
|
||||
u64 tags = 0;
|
||||
@@ -2736,7 +2720,7 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
Token token = f->curr_token;
|
||||
switch (token.kind) {
|
||||
// Operands
|
||||
case Token_Identifier:
|
||||
case Token_Ident:
|
||||
case Token_Integer:
|
||||
case Token_Float:
|
||||
case Token_Rune:
|
||||
@@ -2827,7 +2811,7 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
case Token_Hash: {
|
||||
AstNode *s = NULL;
|
||||
Token hash_token = expect_token(f, Token_Hash);
|
||||
Token name = expect_token(f, Token_Identifier);
|
||||
Token name = expect_token(f, Token_Ident);
|
||||
String tag = name.string;
|
||||
if (str_eq(tag, str_lit("shared_global_scope"))) {
|
||||
if (f->curr_proc == NULL) {
|
||||
@@ -2878,10 +2862,10 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_Period:
|
||||
import_name = f->curr_token;
|
||||
import_name.kind = Token_Identifier;
|
||||
import_name.kind = Token_Ident;
|
||||
next_token(f);
|
||||
break;
|
||||
case Token_Identifier:
|
||||
case Token_Ident:
|
||||
import_name = f->curr_token;
|
||||
next_token(f);
|
||||
break;
|
||||
@@ -3100,7 +3084,7 @@ String get_fullpath_relative(gbAllocator a, String base_dir, String path) {
|
||||
}
|
||||
|
||||
String get_fullpath_core(gbAllocator a, String path) {
|
||||
String module_dir = get_module_dir();
|
||||
String module_dir = odin_root_dir();
|
||||
String res = {0};
|
||||
|
||||
char core[] = "core/";
|
||||
|
||||
@@ -5300,7 +5300,7 @@ void ssa_gen_tree(ssaGen *s) {
|
||||
|
||||
|
||||
{
|
||||
Token token = {Token_Identifier};
|
||||
Token token = {Token_Ident};
|
||||
i32 id = cast(i32)entry_index;
|
||||
char name_base[] = "__$enum_values";
|
||||
isize name_len = gb_size_of(name_base) + 10;
|
||||
@@ -5314,7 +5314,7 @@ void ssa_gen_tree(ssaGen *s) {
|
||||
map_ssa_value_set(&m->members, hash_string(token.string), value_array);
|
||||
}
|
||||
{
|
||||
Token token = {Token_Identifier};
|
||||
Token token = {Token_Ident};
|
||||
i32 id = cast(i32)entry_index;
|
||||
char name_base[] = "__$enum_names";
|
||||
isize name_len = gb_size_of(name_base) + 10;
|
||||
|
||||
+5
-2
@@ -1001,8 +1001,11 @@ void ssa_print_instr(ssaFileBuffer *f, ssaModule *m, ssaValue *value) {
|
||||
|
||||
default: {
|
||||
if (!is_type_float(elem_type)) {
|
||||
if (is_type_unsigned(elem_type)) ssa_fprintf(f, "u");
|
||||
else ssa_fprintf(f, "s");
|
||||
if (is_type_unsigned(elem_type)) {
|
||||
ssa_fprintf(f, "u");
|
||||
} else {
|
||||
ssa_fprintf(f, "s");
|
||||
}
|
||||
}
|
||||
|
||||
switch (bo->op) {
|
||||
|
||||
+6
-5
@@ -4,7 +4,7 @@
|
||||
TOKEN_KIND(Token_Comment, "Comment"), \
|
||||
\
|
||||
TOKEN_KIND(Token__LiteralBegin, "_LiteralBegin"), \
|
||||
TOKEN_KIND(Token_Identifier, "Identifier"), \
|
||||
TOKEN_KIND(Token_Ident, "Identifier"), \
|
||||
TOKEN_KIND(Token_Integer, "Integer"), \
|
||||
TOKEN_KIND(Token_Float, "Float"), \
|
||||
TOKEN_KIND(Token_Rune, "Rune"), \
|
||||
@@ -157,10 +157,10 @@ typedef struct Token {
|
||||
} Token;
|
||||
|
||||
Token empty_token = {Token_Invalid};
|
||||
Token blank_token = {Token_Identifier, {cast(u8 *)"_", 1}};
|
||||
Token blank_token = {Token_Ident, {cast(u8 *)"_", 1}};
|
||||
|
||||
Token make_token_ident(String s) {
|
||||
Token t = {Token_Identifier, s};
|
||||
Token t = {Token_Ident, s};
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -311,8 +311,9 @@ typedef struct Tokenizer {
|
||||
void tokenizer_err(Tokenizer *t, char *msg, ...) {
|
||||
va_list va;
|
||||
isize column = t->read_curr - t->line+1;
|
||||
if (column < 1)
|
||||
if (column < 1) {
|
||||
column = 1;
|
||||
}
|
||||
|
||||
gb_printf_err("%.*s(%td:%td) Syntax error: ", LIT(t->fullpath), t->line_count, column);
|
||||
|
||||
@@ -628,7 +629,7 @@ Token tokenizer_get_token(Tokenizer *t) {
|
||||
|
||||
curr_rune = t->curr_rune;
|
||||
if (rune_is_letter(curr_rune)) {
|
||||
token.kind = Token_Identifier;
|
||||
token.kind = Token_Ident;
|
||||
while (rune_is_letter(t->curr_rune) || rune_is_digit(t->curr_rune)) {
|
||||
advance_to_next_rune(t);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user