Misc changes
This commit is contained in:
1
base.cpp
1
base.cpp
@@ -967,6 +967,7 @@ intern_string(Intern_Table *t, String string){
|
|||||||
U64 hash = hash_string(string);
|
U64 hash = hash_string(string);
|
||||||
U8 *slot = (U8 *)map_get(&t->map, hash);
|
U8 *slot = (U8 *)map_get(&t->map, hash);
|
||||||
if(slot){
|
if(slot){
|
||||||
|
// @todo: Is this a cast bug: *(slot-sizeof(S64))? slot is u8 so truncates?
|
||||||
Intern_String result = {{slot, *(slot-sizeof(S64))}};
|
Intern_String result = {{slot, *(slot-sizeof(S64))}};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
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
|
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
|
main.exe -testing
|
||||||
call examples/arms_race/build_arms_race.bat
|
|
||||||
|
rem echo Building arms race
|
||||||
|
rem call examples/arms_race/build_arms_race.bat
|
||||||
rem main examples/arms_race/arms_race.core
|
rem main examples/arms_race/arms_race.core
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
|||||||
38
core_ast.cpp
38
core_ast.cpp
@@ -96,7 +96,24 @@ struct Ast_Atom: Ast_Expr{
|
|||||||
// resolved_type is a solid type that
|
// resolved_type is a solid type that
|
||||||
// can be use during code generation
|
// can be use during code generation
|
||||||
// it cannot be untyped. (or at least thats the hope :)
|
// 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;
|
typedef U32 Ast_Call_Item_Flag;
|
||||||
@@ -287,7 +304,24 @@ struct Ast_Decl: Ast{
|
|||||||
Ast_Lambda *lambda;
|
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*/
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -775,7 +775,7 @@ compile_to_c_code(){
|
|||||||
|
|
||||||
prefixed_string_type = string_fmt(pctx->perm, "%QString", symbol_prefix);
|
prefixed_string_type = string_fmt(pctx->perm, "%QString", symbol_prefix);
|
||||||
if(single_header_library_mode){
|
if(single_header_library_mode){
|
||||||
gen(R"==(
|
gen(R"(
|
||||||
/*
|
/*
|
||||||
Do this:
|
Do this:
|
||||||
#define %Q_IMPLEMENTATION
|
#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 %QAssertMessage(x) to get more comprehensive error info
|
||||||
You can #define %QMemoryCopy(x) to avoid using default memory copy
|
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);
|
symbol_prefix, symbol_prefix, symbol_prefix);
|
||||||
genln("#ifndef %Q_LIBRARY_HEADER ", single_header_library_name);
|
genln("#ifndef %Q_LIBRARY_HEADER ", single_header_library_name);
|
||||||
genln("#define %Q_LIBRARY_HEADER ", single_header_library_name);
|
genln("#define %Q_LIBRARY_HEADER ", single_header_library_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
gen(R"==(
|
gen(R"(
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -833,7 +833,7 @@ typedef struct String{
|
|||||||
}String;
|
}String;
|
||||||
|
|
||||||
|
|
||||||
)==");
|
)");
|
||||||
|
|
||||||
// Generate struct forward decls
|
// Generate struct forward decls
|
||||||
Iter(&pctx->ordered_decls){
|
Iter(&pctx->ordered_decls){
|
||||||
|
|||||||
@@ -21,56 +21,56 @@ for i in meta.token_simple_expr:
|
|||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
*/
|
*/
|
||||||
keyword_struct = l->intern("struct"_s);
|
keyword_struct = l->intern("struct"_s);
|
||||||
keyword_union = l->intern("union"_s);
|
keyword_union = l->intern("union"_s);
|
||||||
keyword_true = l->intern("true"_s);
|
keyword_true = l->intern("true"_s);
|
||||||
keyword_default = l->intern("default"_s);
|
keyword_default = l->intern("default"_s);
|
||||||
keyword_break = l->intern("break"_s);
|
keyword_break = l->intern("break"_s);
|
||||||
keyword_false = l->intern("false"_s);
|
keyword_false = l->intern("false"_s);
|
||||||
keyword_return = l->intern("return"_s);
|
keyword_return = l->intern("return"_s);
|
||||||
keyword_switch = l->intern("switch"_s);
|
keyword_switch = l->intern("switch"_s);
|
||||||
keyword_assert = l->intern("Assert"_s);
|
keyword_assert = l->intern("Assert"_s);
|
||||||
keyword_if = l->intern("if"_s);
|
keyword_if = l->intern("if"_s);
|
||||||
keyword_elif = l->intern("elif"_s);
|
keyword_elif = l->intern("elif"_s);
|
||||||
keyword_pass = l->intern("pass"_s);
|
keyword_pass = l->intern("pass"_s);
|
||||||
keyword_else = l->intern("else"_s);
|
keyword_else = l->intern("else"_s);
|
||||||
keyword_for = l->intern("for"_s);
|
keyword_for = l->intern("for"_s);
|
||||||
keyword_enum = l->intern("enum"_s);
|
keyword_enum = l->intern("enum"_s);
|
||||||
l->interns.first_keyword = keyword_struct.str;
|
l->interns.first_keyword = keyword_struct.str;
|
||||||
l->interns.last_keyword = keyword_enum.str;
|
l->interns.last_keyword = keyword_enum.str;
|
||||||
intern_typeof = l->intern("TypeOf"_s);
|
intern_typeof = l->intern("TypeOf"_s);
|
||||||
intern_sizeof = l->intern("SizeOf"_s);
|
intern_sizeof = l->intern("SizeOf"_s);
|
||||||
intern_len = l->intern("Len"_s);
|
intern_len = l->intern("Len"_s);
|
||||||
intern_alignof = l->intern("AlignOf"_s);
|
intern_alignof = l->intern("AlignOf"_s);
|
||||||
intern_foreign = l->intern("foreign"_s);
|
intern_foreign = l->intern("foreign"_s);
|
||||||
intern_strict = l->intern("strict"_s);
|
intern_strict = l->intern("strict"_s);
|
||||||
intern_void = l->intern("void"_s);
|
intern_void = l->intern("void"_s);
|
||||||
intern_flag = l->intern("flag"_s);
|
intern_flag = l->intern("flag"_s);
|
||||||
intern_it = l->intern("it"_s);
|
intern_it = l->intern("it"_s);
|
||||||
intern_load = l->intern("load"_s);
|
intern_load = l->intern("load"_s);
|
||||||
intern_import = l->intern("import"_s);
|
intern_import = l->intern("import"_s);
|
||||||
intern_link = l->intern("link"_s);
|
intern_link = l->intern("link"_s);
|
||||||
op_info_table[0].op = l->intern("*"_s);
|
op_info_table[0].op = l->intern("*"_s);
|
||||||
op_info_table[1].op = l->intern("/"_s);
|
op_info_table[1].op = l->intern("/"_s);
|
||||||
op_info_table[2].op = l->intern("%"_s);
|
op_info_table[2].op = l->intern("%"_s);
|
||||||
op_info_table[3].op = l->intern("<<"_s);
|
op_info_table[3].op = l->intern("<<"_s);
|
||||||
op_info_table[4].op = l->intern(">>"_s);
|
op_info_table[4].op = l->intern(">>"_s);
|
||||||
op_info_table[5].op = l->intern("+"_s);
|
op_info_table[5].op = l->intern("+"_s);
|
||||||
op_info_table[6].op = l->intern("-"_s);
|
op_info_table[6].op = l->intern("-"_s);
|
||||||
op_info_table[7].op = l->intern("=="_s);
|
op_info_table[7].op = l->intern("=="_s);
|
||||||
op_info_table[8].op = l->intern("<="_s);
|
op_info_table[8].op = l->intern("<="_s);
|
||||||
op_info_table[9].op = l->intern(">="_s);
|
op_info_table[9].op = l->intern(">="_s);
|
||||||
op_info_table[10].op = l->intern("<"_s);
|
op_info_table[10].op = l->intern("<"_s);
|
||||||
op_info_table[11].op = l->intern(">"_s);
|
op_info_table[11].op = l->intern(">"_s);
|
||||||
op_info_table[12].op = l->intern("!="_s);
|
op_info_table[12].op = l->intern("!="_s);
|
||||||
op_info_table[13].op = l->intern("&"_s);
|
op_info_table[13].op = l->intern("&"_s);
|
||||||
op_info_table[14].op = l->intern("|"_s);
|
op_info_table[14].op = l->intern("|"_s);
|
||||||
op_info_table[15].op = l->intern("^"_s);
|
op_info_table[15].op = l->intern("^"_s);
|
||||||
op_info_table[16].op = l->intern("&&"_s);
|
op_info_table[16].op = l->intern("&&"_s);
|
||||||
op_info_table[17].op = l->intern("||"_s);
|
op_info_table[17].op = l->intern("||"_s);
|
||||||
op_info_table[18].op = l->intern("~"_s);
|
op_info_table[18].op = l->intern("~"_s);
|
||||||
op_info_table[19].op = l->intern("!"_s);
|
op_info_table[19].op = l->intern("!"_s);
|
||||||
/*END*/
|
/*END*/
|
||||||
}
|
}
|
||||||
|
|
||||||
CORE_Static void
|
CORE_Static void
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
|
|
||||||
|
|
||||||
struct Operand{
|
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
|
// is_const is used to rewrite the tree and bound
|
||||||
// something to the const name at the end
|
// something to the const name at the end
|
||||||
U8 is_const : 1;
|
U8 is_const : 1;
|
||||||
|
|||||||
48
core_types.h
48
core_types.h
@@ -52,20 +52,23 @@ enum Ast_Type_Kind{
|
|||||||
#define CASE_FLOAT case TYPE_UNTYPED_FLOAT: case TYPE_F32: case TYPE_F64
|
#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_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 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)
|
#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;
|
||||||
struct Ast_Type;
|
struct Ast_Type;
|
||||||
@@ -73,7 +76,24 @@ struct Ast_Resolved_Member{
|
|||||||
Intern_String name;
|
Intern_String name;
|
||||||
S32 offset;
|
S32 offset;
|
||||||
B32 visited;
|
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{
|
struct Ast_Type{
|
||||||
|
|||||||
24
meta.py
24
meta.py
@@ -129,3 +129,27 @@ interns = [
|
|||||||
"import",
|
"import",
|
||||||
"link",
|
"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())
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
files = os.listdir(".")
|
||||||
files = ["core_compiler.cpp", "core_compiler.h", "core_globals.cpp", "core_lexing.cpp", "core_generated.cpp", "modules/win32_multimedia.core"]
|
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:
|
for file_to_modify in files:
|
||||||
fd = open(file_to_modify, "r+")
|
fd = open(file_to_modify, "r+")
|
||||||
|
|||||||
Reference in New Issue
Block a user