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

@@ -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{

24
meta.py
View File

@@ -129,3 +129,27 @@ interns = [
"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+")