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