Strings galore!

This commit is contained in:
gingerBill
2016-08-05 21:07:25 +01:00
parent 4a303b5c3e
commit ba238c569a
12 changed files with 473 additions and 312 deletions
+9 -5
View File
@@ -456,8 +456,9 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
}
TypeAndValue tv = {};
tv.type = type;
tv.type = type;
tv.value = value;
tv.mode = mode;
map_set(&i->types, hash_pointer(expression), tv);
}
@@ -522,7 +523,8 @@ void pop_procedure(Checker *c) {
}
void add_curr_ast_file(Checker *c, AstFile *file) {
gb_zero_item(&c->error_collector);
TokenPos zero_pos = {};
c->error_collector.prev = zero_pos;
c->curr_ast_file = file;
}
@@ -672,10 +674,12 @@ void check_parsed_files(Checker *c) {
u64 key = entry->key;
AstNode *expr = cast(AstNode *)cast(uintptr)key;
ExpressionInfo *info = &entry->value;
if (is_type_typed(info->type)) {
GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
if (info != NULL && expr != NULL) {
if (is_type_typed(info->type)) {
GB_PANIC("%s (type %s) is typed!", expr_to_string(expr), info->type);
}
add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
}
add_type_and_value(&c->info, expr, info->mode, info->type, info->value);
}
}
+21 -13
View File
@@ -11,6 +11,7 @@ void convert_to_typed (Checker *c, Operand *operand, Type *targ
gbString expr_to_string (AstNode *expression);
void check_entity_decl (Checker *c, Entity *e, DeclInfo *decl, Type *named_type);
void check_proc_body (Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body);
void update_expr_type (Checker *c, AstNode *e, Type *type, b32 final);
void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
@@ -664,7 +665,10 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
y->mode == Addressing_Constant) {
x->value = make_exact_value_bool(compare_exact_values(op, x->value, y->value));
} else {
// TODO(bill): What should I do?
x->mode = Addressing_Value;
update_expr_type(c, x->expr, default_type(x->type), true);
update_expr_type(c, y->expr, default_type(y->type), true);
}
x->type = t_untyped_bool;
@@ -770,33 +774,35 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
}
void update_expr_type(Checker *c, AstNode *e, Type *type) {
ExpressionInfo *found = map_get(&c->info.untyped, hash_pointer(e));
if (!found)
void update_expr_type(Checker *c, AstNode *e, Type *type, b32 final) {
u64 key = hash_pointer(e);
ExpressionInfo *found = map_get(&c->info.untyped, key);
if (found == NULL)
return;
switch (e->kind) {
case_ast_node(ue, UnaryExpr, e);
if (found->value.kind != ExactValue_Invalid)
break;
update_expr_type(c, ue->expr, type);
break;
update_expr_type(c, ue->expr, type, final);
case_end;
case_ast_node(be, BinaryExpr, e);
if (found->value.kind != ExactValue_Invalid)
break;
if (!token_is_comparison(be->op)) {
update_expr_type(c, be->left, type);
update_expr_type(c, be->right, type);
update_expr_type(c, be->left, type, final);
update_expr_type(c, be->right, type, final);
}
case_end;
}
if (is_type_untyped(type)) {
if (!final && is_type_untyped(type)) {
found->type = get_base_type(type);
map_set(&c->info.untyped, key, *found);
} else {
found->type = type;
map_remove(&c->info.untyped, key);
add_type_and_value(&c->info, e, found->mode, type, found->value);
}
}
@@ -838,7 +844,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
if (is_type_numeric(x) && is_type_numeric(y)) {
if (x < y) {
operand->type = target_type;
update_expr_type(c, operand->expr, target_type);
update_expr_type(c, operand->expr, target_type, false);
}
} else if (x != y) {
convert_untyped_error(c, operand, target_type);
@@ -1479,10 +1485,10 @@ b32 check_castable_to(Checker *c, Operand *operand, Type *y) {
}
// []byte/[]u8 <-> string
if (is_type_byte_slice(xb) && is_type_string(yb)) {
if (is_type_u8_slice(xb) && is_type_string(yb)) {
return true;
}
if (is_type_string(xb) && is_type_byte_slice(yb)) {
if (is_type_string(xb) && is_type_u8_slice(yb)) {
return true;
}
@@ -1722,6 +1728,8 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ
if (o->mode == Addressing_Constant) {
max_count = o->value.value_string.len;
}
if (o->mode != Addressing_Variable)
o->mode = Addressing_Value;
o->type = t_u8;
}
break;
+7 -7
View File
@@ -26,7 +26,7 @@ enum BasicKind {
Basic_Count,
Basic_byte = Basic_u8,
// Basic_byte = Basic_u8,
Basic_rune = Basic_i32,
};
@@ -242,7 +242,7 @@ gb_global Type basic_types[] = {
};
gb_global Type basic_type_aliases[] = {
{Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, STR_LIT("byte")}},
// {Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, STR_LIT("byte")}},
{Type_Basic, {Basic_rune, BasicFlag_Integer, STR_LIT("rune")}},
};
@@ -268,7 +268,7 @@ gb_global Type *t_untyped_float = &basic_types[Basic_UntypedFloat];
gb_global Type *t_untyped_pointer = &basic_types[Basic_UntypedPointer];
gb_global Type *t_untyped_string = &basic_types[Basic_UntypedString];
gb_global Type *t_untyped_rune = &basic_types[Basic_UntypedRune];
gb_global Type *t_byte = &basic_type_aliases[Basic_byte];
// gb_global Type *t_byte = &basic_type_aliases[Basic_byte];
gb_global Type *t_rune = &basic_type_aliases[Basic_rune];
@@ -343,9 +343,9 @@ b32 is_type_rawptr(Type *t) {
return t->basic.kind == Basic_rawptr;
return false;
}
b32 is_type_byte(Type *t) {
b32 is_type_u8(Type *t) {
if (t->kind == Type_Basic)
return t->basic.kind == Basic_byte;
return t->basic.kind == Basic_u8;
return false;
}
b32 is_type_slice(Type *t) {
@@ -353,9 +353,9 @@ b32 is_type_slice(Type *t) {
}
b32 is_type_byte_slice(Type *t) {
b32 is_type_u8_slice(Type *t) {
if (t->kind == Type_Slice)
return is_type_byte(t->slice.elem);
return is_type_u8(t->slice.elem);
return false;
}
+3 -3
View File
@@ -7,14 +7,14 @@ struct ssaGen {
};
b32 ssa_gen_init(ssaGen *s, Checker *c) {
if (c->error_collector.count > 0)
if (c->error_collector.count != 0)
return false;
gb_for_array(i, c->parser->files) {
AstFile *f = &c->parser->files[i];
if (f->error_collector.count > 0)
if (f->error_collector.count != 0)
return false;
if (f->tokenizer.error_count > 0)
if (f->tokenizer.error_count != 0)
return false;
}
+9 -5
View File
@@ -440,12 +440,13 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
case ssaInstr_Call: {
auto *call = &instr->call;
if (call->type) {
Type *result_type = call->type->proc.results;
if (result_type) {
ssa_fprintf(f, "%%%d = ", value->id);
}
ssa_fprintf(f, "call ");
if (call->type) {
ssa_print_type(f, m->sizes, call->type);
if (result_type) {
ssa_print_type(f, m->sizes, result_type);
} else {
ssa_fprintf(f, "void");
}
@@ -454,14 +455,17 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
ssa_fprintf(f, "(");
auto *params = &call->type->proc.params->tuple;
for (isize i = 0; i < call->arg_count; i++) {
ssaValue *arg = call->args[i];
Type *t = ssa_value_type(arg);
Entity *e = params->variables[i];
GB_ASSERT(e != NULL);
Type *t = e->type;
if (i > 0) {
ssa_fprintf(f, ", ");
}
ssa_print_type(f, m->sizes, t);
ssa_fprintf(f, " ");
ssaValue *arg = call->args[i];
ssa_print_value(f, m, arg, t);
}
ssa_fprintf(f, ")\n");
+50 -39
View File
@@ -7,6 +7,7 @@ struct ssaValue;
struct ssaModule {
CheckerInfo *info;
BaseTypeSizes sizes;
gbArena arena;
gbAllocator allocator;
String layout;
@@ -244,7 +245,10 @@ ssaLvalue ssa_make_lvalue_address(ssaValue *value, AstNode *expr) {
void ssa_module_init(ssaModule *m, Checker *c) {
m->allocator = gb_heap_allocator();
isize token_count = c->parser->total_token_count;
isize arena_size = 3 * token_count * gb_size_of(ssaValue);
gb_arena_init_from_allocator(&m->arena, gb_heap_allocator(), arena_size);
m->allocator = gb_arena_allocator(&m->arena);
m->info = &c->info;
m->sizes = c->sizes;
@@ -255,6 +259,7 @@ void ssa_module_init(ssaModule *m, Checker *c) {
void ssa_module_destroy(ssaModule *m) {
map_destroy(&m->values);
map_destroy(&m->members);
gb_arena_free(&m->arena);
}
void ssa_module_add_value(ssaModule *m, Entity *e, ssaValue *v) {
@@ -279,6 +284,8 @@ Type *ssa_instr_type(ssaInstr *instr) {
return instr->binary_op.type;
case ssaInstr_Conv:
return instr->conv.to;
case ssaInstr_Call:
return instr->call.type;
}
return NULL;
}
@@ -303,6 +310,9 @@ void ssa_instr_set_type(ssaInstr *instr, Type *type) {
case ssaInstr_Conv:
instr->conv.to = type;
break;
case ssaInstr_Call:
instr->call.type = type;
break;
}
}
@@ -355,8 +365,6 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *a_type);
ssaValue *ssa_alloc_value(gbAllocator a, ssaValueKind kind) {
ssaValue *v = gb_alloc_item(a, ssaValue);
v->kind = kind;
@@ -733,7 +741,7 @@ void ssa_end_procedure_body(ssaProcedure *proc) {
case ssaInstr_Unreachable:
continue;
case ssaInstr_Call:
if (instr->call.type == NULL) {
if (instr->call.type->proc.results == NULL) {
continue;
}
break;
@@ -993,7 +1001,7 @@ ssaValue *ssa_emit_string(ssaProcedure *proc, ssaValue *elem, ssaValue *len) {
Type *t_u8_ptr = ssa_value_type(elem);
GB_ASSERT(t_u8_ptr->kind == Type_Pointer);
GB_ASSERT(is_type_byte(t_u8_ptr->pointer.elem));
GB_ASSERT(is_type_u8(t_u8_ptr->pointer.elem));
ssaValue *str = ssa_add_local_generated(proc, t_string);
ssaValue *str_elem = ssa_emit_struct_gep(proc, str, v_zero32, t_u8_ptr);
@@ -1074,14 +1082,14 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t) {
// []byte/[]u8 <-> string
if (is_type_byte_slice(src) && is_type_string(dst)) {
if (is_type_u8_slice(src) && is_type_string(dst)) {
ssaValue *slice = ssa_add_local_generated(proc, src);
ssa_emit_store(proc, slice, value);
ssaValue *elem = ssa_slice_elem(proc, slice);
ssaValue *len = ssa_slice_len(proc, slice);
return ssa_emit_string(proc, elem, len);
}
if (is_type_string(src) && is_type_byte_slice(dst)) {
if (is_type_string(src) && is_type_u8_slice(dst)) {
ssaValue *str = ssa_add_local_generated(proc, src);
ssa_emit_store(proc, str, value);
ssaValue *elem = ssa_string_elem(proc, str);
@@ -1276,6 +1284,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
#endif
ssaValue *call = ssa_make_instr_call(proc, value, args, arg_count, tv->type);
ssa_value_set_type(call, proc_type_);
return ssa_emit(proc, call);
case_end;
@@ -1318,26 +1327,25 @@ ssaValue *ssa_build_expr(ssaProcedure *proc, AstNode *expr) {
expr = unparen_expr(expr);
TypeAndValue *tv = map_get(&proc->module->info->types, hash_pointer(expr));
if (tv) {
if (tv->value.kind != ExactValue_Invalid) {
if (tv->value.kind == ExactValue_String) {
ssaValue *array = ssa_add_global_string_array(proc, tv->value);
ssaValue *elem = ssa_array_elem(proc, array);
return ssa_emit_string(proc, elem, ssa_array_len(proc, array));
}
return ssa_make_value_constant(proc->module->allocator, tv->type, tv->value);
}
GB_ASSERT_NOT_NULL(tv);
ssaValue *value = NULL;
if (tv->mode == Addressing_Variable) {
value = ssa_lvalue_load(ssa_build_addr(proc, expr), proc);
} else {
value = ssa_build_single_expr(proc, expr, tv);
if (tv->value.kind != ExactValue_Invalid) {
if (tv->value.kind == ExactValue_String) {
ssaValue *array = ssa_add_global_string_array(proc, tv->value);
ssaValue *elem = ssa_array_elem(proc, array);
return ssa_emit_string(proc, elem, ssa_array_len(proc, array));
}
return value;
return ssa_make_value_constant(proc->module->allocator, tv->type, tv->value);
}
return NULL;
ssaValue *value = NULL;
if (tv->mode == Addressing_Variable) {
value = ssa_lvalue_load(ssa_build_addr(proc, expr), proc);
} else {
value = ssa_build_single_expr(proc, expr, tv);
}
return value;
}
@@ -1383,33 +1391,35 @@ ssaLvalue ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
case_ast_node(ie, IndexExpr, expr);
ssaValue *v = NULL;
Type *t = get_base_type(type_of_expr(proc->module->info, ie->expr));
ssaValue *elem = NULL;
switch (t->kind) {
case Type_Array: {
ssaValue *array = ssa_lvalue_address(ssa_build_addr(proc, ie->expr), proc);
ssaValue *index = ssa_emit_conv(proc, ssa_build_expr(proc, ie->index), t_int);
ssaValue *elem = ssa_array_elem(proc, array);
v = ssa_emit_ptr_offset(proc, elem, index);
elem = ssa_array_elem(proc, array);
} break;
case Type_Slice: {
ssaValue *slice = ssa_lvalue_address(ssa_build_addr(proc, ie->expr), proc);
ssaValue *index = ssa_emit_conv(proc, ssa_build_expr(proc, ie->index), t_int);
ssaValue *elem = ssa_slice_elem(proc, slice);
v = ssa_emit_ptr_offset(proc, elem, index);
elem = ssa_slice_elem(proc, slice);
} break;
case Type_Basic: { // Basic_string
ssaValue *str = ssa_lvalue_address(ssa_build_addr(proc, ie->expr), proc);
ssaValue *index = ssa_emit_conv(proc, ssa_build_expr(proc, ie->index), t_int);
ssaValue *elem = ssa_string_elem(proc, str);
v = ssa_emit_ptr_offset(proc, elem, index);
TypeAndValue *tv = map_get(&proc->module->info->types, hash_pointer(ie->expr));
if (tv->mode == Addressing_Constant) {
ssaValue *array = ssa_add_global_string_array(proc, tv->value);
elem = ssa_array_elem(proc, array);
} else {
ssaLvalue lval = ssa_build_addr(proc, ie->expr);
ssaValue *str = ssa_lvalue_address(lval, proc);
elem = ssa_string_elem(proc, str);
}
} break;
case Type_Pointer: {
ssaValue *ptr = ssa_emit_load(proc, ssa_lvalue_address(ssa_build_addr(proc, ie->expr), proc));
ssaValue *index = ssa_emit_conv(proc, ssa_build_expr(proc, ie->index), t_int);
v = ssa_emit_ptr_offset(proc, ptr, index);
elem = ssa_emit_load(proc, ssa_lvalue_address(ssa_build_addr(proc, ie->expr), proc));
} break;
}
// NOTE(bill): lvalue address encodes the pointer, thus the deref
ssaValue *index = ssa_emit_conv(proc, ssa_build_expr(proc, ie->index), t_int);
v = ssa_emit_ptr_offset(proc, elem, index);
ssa_value_set_type(v, type_deref(ssa_value_type(v)));
return ssa_make_lvalue_address(v, expr);
case_end;
@@ -1425,7 +1435,8 @@ ssaLvalue ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
case_end;
}
GB_PANIC("Unexpected address expression");
GB_PANIC("Unexpected address expression\n"
"\tAstNode: %.*s\n", LIT(ast_node_strings[expr->kind]));
ssaLvalue blank = {ssaLvalue_Blank};
return blank;
+1 -1
View File
@@ -27,11 +27,11 @@ int main(int argc, char **argv) {
// print_ast(parser.files[0].declarations, 0);
Checker checker = {};
init_checker(&checker, &parser);
defer (destroy_checker(&checker));
check_parsed_files(&checker);
ssaGen ssa = {};
if (ssa_gen_init(&ssa, &checker)) {
defer (ssa_gen_destroy(&ssa));
+3
View File
@@ -62,6 +62,7 @@ struct Parser {
gbArray(AstFile) files;
gbArray(String) imports;
isize import_index;
isize total_token_count;
};
enum DeclKind {
@@ -2137,8 +2138,10 @@ ParseFileError parse_files(Parser *p, char *init_filename) {
}
parse_file(p, &file);
gb_array_append(p->files, file);
p->total_token_count += gb_array_count(file.tokens);
}
return ParseFile_None;
}
+88 -88
View File
@@ -26,98 +26,98 @@ b32 rune_is_whitespace(Rune r) {
}
#define TOKEN_KINDS \
TOKEN_KIND(Invalid, "Invalid"), \
TOKEN_KIND(EOF, "EOF"), \
TOKEN_KIND(Token_Invalid, "Invalid"), \
TOKEN_KIND(Token_EOF, "EOF"), \
\
TOKEN_KIND(_LiteralBegin, "_LiteralBegin"), \
TOKEN_KIND(Identifier, "Identifier"), \
TOKEN_KIND(Integer, "Integer"), \
TOKEN_KIND(Float, "Float"), \
TOKEN_KIND(Rune, "Rune"), \
TOKEN_KIND(String, "String"), \
TOKEN_KIND(_LiteralEnd, "_LiteralEnd"), \
TOKEN_KIND(Token__LiteralBegin, "_LiteralBegin"), \
TOKEN_KIND(Token_Identifier, "Identifier"), \
TOKEN_KIND(Token_Integer, "Integer"), \
TOKEN_KIND(Token_Float, "Float"), \
TOKEN_KIND(Token_Rune, "Rune"), \
TOKEN_KIND(Token_String, "String"), \
TOKEN_KIND(Token__LiteralEnd, "_LiteralEnd"), \
\
TOKEN_KIND(_OperatorBegin, "_OperatorBegin"), \
TOKEN_KIND(Eq, "="), \
TOKEN_KIND(Not, "!"), \
TOKEN_KIND(Hash, "#"), \
TOKEN_KIND(At, "@"), \
TOKEN_KIND(Pointer, "^"), \
TOKEN_KIND(Add, "+"), \
TOKEN_KIND(Sub, "-"), \
TOKEN_KIND(Mul, "*"), \
TOKEN_KIND(Quo, "/"), \
TOKEN_KIND(Mod, "%"), \
TOKEN_KIND(And, "&"), \
TOKEN_KIND(Or, "|"), \
TOKEN_KIND(Xor, "~"), \
TOKEN_KIND(AndNot, "&~"), \
TOKEN_KIND(_AssignOpBegin, "_AssignOpBegin"), \
TOKEN_KIND(AddEq, "+="), \
TOKEN_KIND(SubEq, "-="), \
TOKEN_KIND(MulEq, "*="), \
TOKEN_KIND(QuoEq, "/="), \
TOKEN_KIND(ModEq, "%="), \
TOKEN_KIND(AndEq, "&="), \
TOKEN_KIND(OrEq, "|="), \
TOKEN_KIND(XorEq, "~="), \
TOKEN_KIND(AndNotEq, "&~="), \
TOKEN_KIND(_AssignOpEnd, "_AssignOpEnd"), \
TOKEN_KIND(Increment, "++"), \
TOKEN_KIND(Decrement, "--"), \
TOKEN_KIND(ArrowRight, "->"), \
TOKEN_KIND(ArrowLeft, "<-"), \
TOKEN_KIND(CmpAnd, "&&"), \
TOKEN_KIND(CmpOr, "||"), \
TOKEN_KIND(CmpAndEq, "&&="), \
TOKEN_KIND(CmpOrEq, "||="), \
TOKEN_KIND(Token__OperatorBegin, "_OperatorBegin"), \
TOKEN_KIND(Token_Eq, "="), \
TOKEN_KIND(Token_Not, "!"), \
TOKEN_KIND(Token_Hash, "#"), \
TOKEN_KIND(Token_At, "@"), \
TOKEN_KIND(Token_Pointer, "^"), \
TOKEN_KIND(Token_Add, "+"), \
TOKEN_KIND(Token_Sub, "-"), \
TOKEN_KIND(Token_Mul, "*"), \
TOKEN_KIND(Token_Quo, "/"), \
TOKEN_KIND(Token_Mod, "%"), \
TOKEN_KIND(Token_And, "&"), \
TOKEN_KIND(Token_Or, "|"), \
TOKEN_KIND(Token_Xor, "~"), \
TOKEN_KIND(Token_AndNot, "&~"), \
TOKEN_KIND(Token__AssignOpBegin, "_AssignOpBegin"), \
TOKEN_KIND(Token_AddEq, "+="), \
TOKEN_KIND(Token_SubEq, "-="), \
TOKEN_KIND(Token_MulEq, "*="), \
TOKEN_KIND(Token_QuoEq, "/="), \
TOKEN_KIND(Token_ModEq, "%="), \
TOKEN_KIND(Token_AndEq, "&="), \
TOKEN_KIND(Token_OrEq, "|="), \
TOKEN_KIND(Token_XorEq, "~="), \
TOKEN_KIND(Token_AndNotEq, "&~="), \
TOKEN_KIND(Token__AssignOpEnd, "_AssignOpEnd"), \
TOKEN_KIND(Token_Increment, "++"), \
TOKEN_KIND(Token_Decrement, "--"), \
TOKEN_KIND(Token_ArrowRight, "->"), \
TOKEN_KIND(Token_ArrowLeft, "<-"), \
TOKEN_KIND(Token_CmpAnd, "&&"), \
TOKEN_KIND(Token_CmpOr, "||"), \
TOKEN_KIND(Token_CmpAndEq, "&&="), \
TOKEN_KIND(Token_CmpOrEq, "||="), \
\
TOKEN_KIND(_ComparisonBegin, "_ComparisonBegin"), \
TOKEN_KIND(CmpEq, "=="), \
TOKEN_KIND(NotEq, "!="), \
TOKEN_KIND(Lt, "<"), \
TOKEN_KIND(Gt, ">"), \
TOKEN_KIND(LtEq, "<="), \
TOKEN_KIND(GtEq, ">="), \
TOKEN_KIND(_ComparisonEnd, "_ComparisonEnd"), \
TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \
TOKEN_KIND(Token_CmpEq, "=="), \
TOKEN_KIND(Token_NotEq, "!="), \
TOKEN_KIND(Token_Lt, "<"), \
TOKEN_KIND(Token_Gt, ">"), \
TOKEN_KIND(Token_LtEq, "<="), \
TOKEN_KIND(Token_GtEq, ">="), \
TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \
\
TOKEN_KIND(OpenParen, "("), \
TOKEN_KIND(CloseParen, ")"), \
TOKEN_KIND(OpenBracket, "["), \
TOKEN_KIND(CloseBracket, "]"), \
TOKEN_KIND(OpenBrace, "{"), \
TOKEN_KIND(CloseBrace, "}"), \
TOKEN_KIND(Colon, ":"), \
TOKEN_KIND(Semicolon, ";"), \
TOKEN_KIND(Period, "."), \
TOKEN_KIND(Comma, ","), \
TOKEN_KIND(Ellipsis, "..."), \
TOKEN_KIND(_OperatorEnd, "_OperatorEnd"), \
TOKEN_KIND(Token_OpenParen, "("), \
TOKEN_KIND(Token_CloseParen, ")"), \
TOKEN_KIND(Token_OpenBracket, "["), \
TOKEN_KIND(Token_CloseBracket, "]"), \
TOKEN_KIND(Token_OpenBrace, "{"), \
TOKEN_KIND(Token_CloseBrace, "}"), \
TOKEN_KIND(Token_Colon, ":"), \
TOKEN_KIND(Token_Semicolon, ";"), \
TOKEN_KIND(Token_Period, "."), \
TOKEN_KIND(Token_Comma, ","), \
TOKEN_KIND(Token_Ellipsis, "..."), \
TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
\
TOKEN_KIND(_KeywordBegin, "_KeywordBegin"), \
TOKEN_KIND(type, "type"), \
TOKEN_KIND(alias, "alias"), \
TOKEN_KIND(proc, "proc"), \
TOKEN_KIND(match, "match"), \
TOKEN_KIND(break, "break"), \
TOKEN_KIND(continue, "continue"), \
TOKEN_KIND(fallthrough, "fallthrough"), \
TOKEN_KIND(case, "case"), \
TOKEN_KIND(if, "if"), \
TOKEN_KIND(else, "else"), \
TOKEN_KIND(for, "for"), \
TOKEN_KIND(defer, "defer"), \
TOKEN_KIND(return, "return"), \
TOKEN_KIND(import, "import"), \
TOKEN_KIND(cast, "cast"), \
TOKEN_KIND(struct, "struct"), \
TOKEN_KIND(union, "union"), \
TOKEN_KIND(enum, "enum"), \
TOKEN_KIND(_KeywordEnd, "_KeywordEnd"), \
TOKEN_KIND(Count, "")
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
TOKEN_KIND(Token_type, "type"), \
TOKEN_KIND(Token_alias, "alias"), \
TOKEN_KIND(Token_proc, "proc"), \
TOKEN_KIND(Token_match, "match"), \
TOKEN_KIND(Token_break, "break"), \
TOKEN_KIND(Token_continue, "continue"), \
TOKEN_KIND(Token_fallthrough, "fallthrough"), \
TOKEN_KIND(Token_case, "case"), \
TOKEN_KIND(Token_if, "if"), \
TOKEN_KIND(Token_else, "else"), \
TOKEN_KIND(Token_for, "for"), \
TOKEN_KIND(Token_defer, "defer"), \
TOKEN_KIND(Token_return, "return"), \
TOKEN_KIND(Token_import, "import"), \
TOKEN_KIND(Token_cast, "cast"), \
TOKEN_KIND(Token_struct, "struct"), \
TOKEN_KIND(Token_union, "union"), \
TOKEN_KIND(Token_enum, "enum"), \
TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \
TOKEN_KIND(Token_Count, "")
enum TokenKind {
#define TOKEN_KIND(e, s) GB_JOIN2(Token_, e)
#define TOKEN_KIND(e, s) e
TOKEN_KINDS
#undef TOKEN_KIND
};
@@ -162,10 +162,10 @@ Token empty_token = {Token_Invalid};
struct ErrorCollector {
TokenPos prev;
isize count;
i64 count;
};
void error(ErrorCollector *ec, Token token, char *fmt, ...) {
gb_no_inline void error(ErrorCollector *ec, Token token, char *fmt, ...) {
ec->count++;
// NOTE(bill): Duplicate error, skip it
if (!token_pos_are_equal(ec->prev, token.pos)) {
@@ -181,7 +181,7 @@ void error(ErrorCollector *ec, Token token, char *fmt, ...) {
}
}
void warning(Token token, char *fmt, ...) {
gb_no_inline void warning(Token token, char *fmt, ...) {
va_list va;
va_start(va, fmt);
gb_printf_err("%.*s(%td:%td) Warning: %s\n",