Misc changes

This commit is contained in:
Krzosa Karol
2022-12-31 14:16:46 +01:00
parent e07ad3c86d
commit 673db72e29
9 changed files with 174 additions and 76 deletions

View File

@@ -967,6 +967,7 @@ intern_string(Intern_Table *t, String string){
U64 hash = hash_string(string);
U8 *slot = (U8 *)map_get(&t->map, hash);
if(slot){
// @todo: Is this a cast bug: *(slot-sizeof(S64))? slot is u8 so truncates?
Intern_String result = {{slot, *(slot-sizeof(S64))}};
return result;
}

View File

@@ -5,8 +5,10 @@ rem cl main.cpp -I.. user32.lib
clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib
rem ubuntu run clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core.out
echo Building arms race
call examples/arms_race/build_arms_race.bat
main.exe -testing
rem echo Building arms race
rem call examples/arms_race/build_arms_race.bat
rem main examples/arms_race/arms_race.core
popd

View File

@@ -96,7 +96,24 @@ struct Ast_Atom: Ast_Expr{
// resolved_type is a solid type that
// can be use during code generation
// it cannot be untyped. (or at least thats the hope :)
INLINE_VALUE_FIELDS;
/*#import meta
meta.inline_value_fields()
*/
union {
Value value;
struct {
Ast_Type *type;
Ast_Decl *resolved_decl;
union {
bool bool_val;
F64 f64_val;
Intern_String intern_val;
BigInt big_int_val;
Ast_Type *type_val;
};
};
};
/*END*/
};
typedef U32 Ast_Call_Item_Flag;
@@ -287,7 +304,24 @@ struct Ast_Decl: Ast{
Ast_Lambda *lambda;
};
INLINE_VALUE_FIELDS;
/*#import meta
meta.inline_value_fields()
*/
union {
Value value;
struct {
Ast_Type *type;
Ast_Decl *resolved_decl;
union {
bool bool_val;
F64 f64_val;
Intern_String intern_val;
BigInt big_int_val;
Ast_Type *type_val;
};
};
};
/*END*/
};
//-----------------------------------------------------------------------------

View File

@@ -775,7 +775,7 @@ compile_to_c_code(){
prefixed_string_type = string_fmt(pctx->perm, "%QString", symbol_prefix);
if(single_header_library_mode){
gen(R"==(
gen(R"(
/*
Do this:
#define %Q_IMPLEMENTATION
@@ -792,13 +792,13 @@ compile_to_c_code(){
You can #define %QAssertMessage(x) to get more comprehensive error info
You can #define %QMemoryCopy(x) to avoid using default memory copy
*/
)==", single_header_library_name, single_header_library_name, single_header_library_name,
)", single_header_library_name, single_header_library_name, single_header_library_name,
symbol_prefix, symbol_prefix, symbol_prefix);
genln("#ifndef %Q_LIBRARY_HEADER ", single_header_library_name);
genln("#define %Q_LIBRARY_HEADER ", single_header_library_name);
}
gen(R"==(
gen(R"(
#include <stdint.h>
#include <stdbool.h>
@@ -833,7 +833,7 @@ typedef struct String{
}String;
)==");
)");
// Generate struct forward decls
Iter(&pctx->ordered_decls){

View File

@@ -21,56 +21,56 @@ for i in meta.token_simple_expr:
index += 1
*/
keyword_struct = l->intern("struct"_s);
keyword_union = l->intern("union"_s);
keyword_true = l->intern("true"_s);
keyword_default = l->intern("default"_s);
keyword_break = l->intern("break"_s);
keyword_false = l->intern("false"_s);
keyword_return = l->intern("return"_s);
keyword_switch = l->intern("switch"_s);
keyword_assert = l->intern("Assert"_s);
keyword_if = l->intern("if"_s);
keyword_elif = l->intern("elif"_s);
keyword_pass = l->intern("pass"_s);
keyword_else = l->intern("else"_s);
keyword_for = l->intern("for"_s);
keyword_enum = l->intern("enum"_s);
l->interns.first_keyword = keyword_struct.str;
l->interns.last_keyword = keyword_enum.str;
intern_typeof = l->intern("TypeOf"_s);
intern_sizeof = l->intern("SizeOf"_s);
intern_len = l->intern("Len"_s);
intern_alignof = l->intern("AlignOf"_s);
intern_foreign = l->intern("foreign"_s);
intern_strict = l->intern("strict"_s);
intern_void = l->intern("void"_s);
intern_flag = l->intern("flag"_s);
intern_it = l->intern("it"_s);
intern_load = l->intern("load"_s);
intern_import = l->intern("import"_s);
intern_link = l->intern("link"_s);
op_info_table[0].op = l->intern("*"_s);
op_info_table[1].op = l->intern("/"_s);
op_info_table[2].op = l->intern("%"_s);
op_info_table[3].op = l->intern("<<"_s);
op_info_table[4].op = l->intern(">>"_s);
op_info_table[5].op = l->intern("+"_s);
op_info_table[6].op = l->intern("-"_s);
op_info_table[7].op = l->intern("=="_s);
op_info_table[8].op = l->intern("<="_s);
op_info_table[9].op = l->intern(">="_s);
op_info_table[10].op = l->intern("<"_s);
op_info_table[11].op = l->intern(">"_s);
op_info_table[12].op = l->intern("!="_s);
op_info_table[13].op = l->intern("&"_s);
op_info_table[14].op = l->intern("|"_s);
op_info_table[15].op = l->intern("^"_s);
op_info_table[16].op = l->intern("&&"_s);
op_info_table[17].op = l->intern("||"_s);
op_info_table[18].op = l->intern("~"_s);
op_info_table[19].op = l->intern("!"_s);
/*END*/
keyword_struct = l->intern("struct"_s);
keyword_union = l->intern("union"_s);
keyword_true = l->intern("true"_s);
keyword_default = l->intern("default"_s);
keyword_break = l->intern("break"_s);
keyword_false = l->intern("false"_s);
keyword_return = l->intern("return"_s);
keyword_switch = l->intern("switch"_s);
keyword_assert = l->intern("Assert"_s);
keyword_if = l->intern("if"_s);
keyword_elif = l->intern("elif"_s);
keyword_pass = l->intern("pass"_s);
keyword_else = l->intern("else"_s);
keyword_for = l->intern("for"_s);
keyword_enum = l->intern("enum"_s);
l->interns.first_keyword = keyword_struct.str;
l->interns.last_keyword = keyword_enum.str;
intern_typeof = l->intern("TypeOf"_s);
intern_sizeof = l->intern("SizeOf"_s);
intern_len = l->intern("Len"_s);
intern_alignof = l->intern("AlignOf"_s);
intern_foreign = l->intern("foreign"_s);
intern_strict = l->intern("strict"_s);
intern_void = l->intern("void"_s);
intern_flag = l->intern("flag"_s);
intern_it = l->intern("it"_s);
intern_load = l->intern("load"_s);
intern_import = l->intern("import"_s);
intern_link = l->intern("link"_s);
op_info_table[0].op = l->intern("*"_s);
op_info_table[1].op = l->intern("/"_s);
op_info_table[2].op = l->intern("%"_s);
op_info_table[3].op = l->intern("<<"_s);
op_info_table[4].op = l->intern(">>"_s);
op_info_table[5].op = l->intern("+"_s);
op_info_table[6].op = l->intern("-"_s);
op_info_table[7].op = l->intern("=="_s);
op_info_table[8].op = l->intern("<="_s);
op_info_table[9].op = l->intern(">="_s);
op_info_table[10].op = l->intern("<"_s);
op_info_table[11].op = l->intern(">"_s);
op_info_table[12].op = l->intern("!="_s);
op_info_table[13].op = l->intern("&"_s);
op_info_table[14].op = l->intern("|"_s);
op_info_table[15].op = l->intern("^"_s);
op_info_table[16].op = l->intern("&&"_s);
op_info_table[17].op = l->intern("||"_s);
op_info_table[18].op = l->intern("~"_s);
op_info_table[19].op = l->intern("!"_s);
/*END*/
}
CORE_Static void

View File

@@ -1,7 +1,24 @@
struct Operand{
INLINE_VALUE_FIELDS;
/*#import meta
meta.inline_value_fields()
*/
union {
Value value;
struct {
Ast_Type *type;
Ast_Decl *resolved_decl;
union {
bool bool_val;
F64 f64_val;
Intern_String intern_val;
BigInt big_int_val;
Ast_Type *type_val;
};
};
};
/*END*/
// is_const is used to rewrite the tree and bound
// something to the const name at the end
U8 is_const : 1;

View File

@@ -52,20 +52,23 @@ enum Ast_Type_Kind{
#define CASE_FLOAT case TYPE_UNTYPED_FLOAT: case TYPE_F32: case TYPE_F64
#define CASE_STRING case TYPE_UNTYPED_STRING: case TYPE_STRING: case TYPE_POINTER
#define CASE_UNTYPED case TYPE_UNTYPED_INT: case TYPE_UNTYPED_BOOL: case TYPE_UNTYPED_FLOAT: case TYPE_UNTYPED_STRING
#define VALUE_FIELDS \
Ast_Type *type; \
Ast_Decl *resolved_decl; \
union{ \
bool bool_val; \
F64 f64_val; \
Intern_String intern_val; \
BigInt big_int_val;\
Ast_Type *type_val; \
};
#define INLINE_VALUE_FIELDS union{Value value; struct{VALUE_FIELDS};}
#define ARRAY_SIZE_SLICE (-1)
struct Value{VALUE_FIELDS};
struct Value {
/*#import meta
print(meta.value_struct_content)
*/
Ast_Type *type;
Ast_Decl *resolved_decl;
union {
bool bool_val;
F64 f64_val;
Intern_String intern_val;
BigInt big_int_val;
Ast_Type *type_val;
};
/*END*/
};
struct Ast;
struct Ast_Type;
@@ -73,7 +76,24 @@ struct Ast_Resolved_Member{
Intern_String name;
S32 offset;
B32 visited;
INLINE_VALUE_FIELDS;
/*#import meta
meta.inline_value_fields()
*/
union {
Value value;
struct {
Ast_Type *type;
Ast_Decl *resolved_decl;
union {
bool bool_val;
F64 f64_val;
Intern_String intern_val;
BigInt big_int_val;
Ast_Type *type_val;
};
};
};
/*END*/
};
struct Ast_Type{

26
meta.py
View File

@@ -128,4 +128,28 @@ interns = [
"load",
"import",
"link",
]
]
value_struct_content = """
Ast_Type *type;
Ast_Decl *resolved_decl;
union {
bool bool_val;
F64 f64_val;
Intern_String intern_val;
BigInt big_int_val;
Ast_Type *type_val;
};
""".strip()
def inline_value_fields():
print(f"""
union {{
Value value;
struct {{
{value_struct_content}
}};
}};
""".strip())

View File

@@ -2,8 +2,8 @@ import subprocess
import sys
import os
files = ["core_compiler.cpp", "core_compiler.h", "core_globals.cpp", "core_lexing.cpp", "core_generated.cpp", "modules/win32_multimedia.core"]
files = os.listdir(".")
files = [i for i in files if (i.endswith(".cpp") or i.endswith(".h")) and i != "base_unicode.cpp"]
for file_to_modify in files:
fd = open(file_to_modify, "r+")