diff --git a/G.globals.kl b/G.globals.kl index 11a7a15..a16786f 100644 --- a/G.globals.kl +++ b/G.globals.kl @@ -31,6 +31,7 @@ imp_array_c: [5]S64 = {[0] = 1, [2] = 2, [1] = 0} // @todo this should be illega string: *char = "string" first_letter := string[0] decl_char: char = 55 +thing: *void //----------------------------------------------------------------------------- // Pointers diff --git a/ccodegen.cpp b/ccodegen.cpp index f777756..c7ba2d8 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -480,7 +480,7 @@ compile_files(Array filename){ resolve_package(it); } -#if 1 +#if 0 gen(R"==( #include #include diff --git a/compiler.h b/compiler.h index ebe140e..a5e4b96 100644 --- a/compiler.h +++ b/compiler.h @@ -84,8 +84,6 @@ enum Token_Kind{ TK_Integer, TK_Keyword, - TK_FOREIGN, - TK_Pointer = TK_Mul, TK_Dereference = TK_BitAnd, diff --git a/lexing.cpp b/lexing.cpp index 02ca865..40f9911 100644 --- a/lexing.cpp +++ b/lexing.cpp @@ -139,7 +139,6 @@ lex_parse_ident(Intern_Table *table, Lex_Stream *s, Token *t){ while(lex_is_alphanumeric(lexc(s)) || lexc(s) == '_') lex_advance(s); lex_set_len(s,t); - t->intern_val = intern_string(table, t->string); } #define CASE2(op, OpName, Assign) \ @@ -353,11 +352,12 @@ lex__stream(Lexer *lexer){ CASE3('|', TK_BitOr, TK_OrAssign, TK_Or); case '#': { + t.kind = TK_Pound; lex_parse_ident(table, s, &t); - if(t.intern_val.str == intern_foreign.str){ - t.kind = TK_FOREIGN; - } - else token_error(&t, "Unrecognized #note"_s); + t.str += 1; + t.len -= 1; + t.intern_val = intern_string(table, t.string); + if(t.len == 0) token_error(&t, "Macro token without content"_s); }break; case '.': { @@ -509,6 +509,7 @@ lex__stream(Lexer *lexer){ case 'x':case 'Z':case 'z':case 'Y':case 'y':case '_': { t.kind = TK_Identifier; lex_parse_ident(table, s, &t); + t.intern_val = intern_string(table, t.string); if(lex_is_keyword(table, t.intern_val)){ t.kind = TK_Keyword; } @@ -625,7 +626,6 @@ name(Token_Kind kind){ case TK_Float: return "Float"; case TK_Integer: return "int"; case TK_Keyword: return "Keyword"; - case TK_FOREIGN: return "#foreign"; case CLOSE_SCOPE: return "Close_Scope"; case OPEN_SCOPE: return "Open_Scope"; case SAME_SCOPE: return "Same_Scope"; diff --git a/main.cpp b/main.cpp index 5b98711..9abf2dd 100644 --- a/main.cpp +++ b/main.cpp @@ -211,7 +211,7 @@ int main(int argument_count, char **arguments){ // files.add("order2.kl"_s); // files.add("new_types.kl"_s); // files.add("enums.kl"_s); - files.add("G.globals.kl"_s); + files.add("Windows.kl"_s); // files.add("euler.kl"_s); String result = compile_files(files); printf("%s", result.str); diff --git a/parsing.cpp b/parsing.cpp index 0b8b5d1..a06e847 100644 --- a/parsing.cpp +++ b/parsing.cpp @@ -79,6 +79,17 @@ token_is_keyword(Intern_String keyword, S64 lookahead = 0){ return 0; } +function Token * +token_match_pound(String string){ + Token *token = token_get(); + if(token->kind == TK_Pound){ + if(string_compare(token->intern_val.s, string)){ + return token_next(); + } + } + return 0; +} + function Token * token_match(Token_Kind kind){ Token *token = token_get(); @@ -329,7 +340,8 @@ parse_lambda(Token *token){ } token_expect(TK_CloseParen); Ast_Expr *ret = parse_optional_type(); - Token *foreign = token_match(TK_FOREIGN); + + Token *foreign = token_match_pound("foreign"_s); Ast_Scope *scope = token_is(OPEN_SCOPE) ? parse_stmt_scope() : 0; Ast_Lambda *result = ast_lambda(token, params, ret, scope); if(foreign) set_flag(result->flags, AST_FOREIGN); diff --git a/types.h b/types.h index ce5de6b..0557cfe 100644 --- a/types.h +++ b/types.h @@ -135,6 +135,7 @@ name(Ast_Type *type){ case TYPE_F32: return "F32"; case TYPE_F64: return "F64"; case TYPE_S8: return "S8"; + case TYPE_INT: return "int"; case TYPE_S16: return "S16"; case TYPE_S32: return "S32"; case TYPE_S64: return "S64";