Generating proper C postfixes for types
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
|||||||
*.txt
|
*.txt
|
||||||
*.4c
|
*.4c
|
||||||
*.bin
|
*.bin
|
||||||
|
*.rdbg
|
||||||
|
|
||||||
*.c
|
*.c
|
||||||
backup*
|
backup*
|
||||||
|
|||||||
@@ -154,19 +154,39 @@ gen_string_simple_decl(Allocator *a, Ast_Type *ast, String name){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function String
|
||||||
|
get_type_postfix(Ast_Type *type){
|
||||||
|
switch(type->kind) {
|
||||||
|
case TYPE_F32: return "f"_s; break;
|
||||||
|
case TYPE_U64: return "ULL"_s; break;
|
||||||
|
case TYPE_S64: return "LL"_s; break;
|
||||||
|
case TYPE_F64:case TYPE_S8:case TYPE_S16:
|
||||||
|
case TYPE_S32:case TYPE_U8:case TYPE_U16:
|
||||||
|
case TYPE_INT:case TYPE_U32:case TYPE_CHAR:
|
||||||
|
return ""_s;
|
||||||
|
break;
|
||||||
|
invalid_default_case;
|
||||||
|
}
|
||||||
|
assert(!"Unhandled case or error");
|
||||||
|
return ""_s;
|
||||||
|
}
|
||||||
|
|
||||||
function B32
|
function B32
|
||||||
gen_value(Token *pos, Value a){
|
gen_value(Token *pos, Value a){
|
||||||
if(is_untyped(a.type)) compiler_error(pos, "Internal compiler error: Untyped got propagated to the codegen stage");
|
if(is_untyped(a.type)) compiler_error(pos, "Internal compiler error: Untyped got propagated to the codegen stage");
|
||||||
|
|
||||||
B32 result = true;
|
B32 result = true;
|
||||||
if(is_enum(a.type))
|
Ast_Type *type = a.type;
|
||||||
goto integer;
|
if(is_enum(a.type)){
|
||||||
switch(a.type->kind){
|
type = a.type->base;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(type->kind){
|
||||||
CASE_INT: {
|
CASE_INT: {
|
||||||
integer:
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
|
String postfix = get_type_postfix(type);
|
||||||
const char *string = bigint_to_error_string(scratch, &a.big_int_val, 10);
|
const char *string = bigint_to_error_string(scratch, &a.big_int_val, 10);
|
||||||
gen("%s", string);
|
gen("%s%Q", string, postfix);
|
||||||
}break;
|
}break;
|
||||||
case TYPE_POINTER:{
|
case TYPE_POINTER:{
|
||||||
if(a.type == type_pointer_to_char){
|
if(a.type == type_pointer_to_char){
|
||||||
@@ -181,7 +201,10 @@ gen_value(Token *pos, Value a){
|
|||||||
gen("(String){(U8 *)\"%Q\", %d}", a.intern_val, a.intern_val.len);
|
gen("(String){(U8 *)\"%Q\", %d}", a.intern_val, a.intern_val.len);
|
||||||
break;
|
break;
|
||||||
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
|
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
|
||||||
CASE_FLOAT: gen("%f", a.f64_val); break;
|
CASE_FLOAT: {
|
||||||
|
String postfix = get_type_postfix(type);
|
||||||
|
gen("%f%Q", a.f64_val, postfix);
|
||||||
|
}break;
|
||||||
case TYPE_TYPE: {
|
case TYPE_TYPE: {
|
||||||
gen("%d", a.type_val->type_id);
|
gen("%d", a.type_val->type_id);
|
||||||
}break;
|
}break;
|
||||||
|
|||||||
@@ -1,4 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
|
- [ ] Basic
|
||||||
|
- [ ] Pass size and alignment calculations to C ?
|
||||||
|
- [ ] Fix . operator lookups
|
||||||
|
- [ ] Combining casts with . operator
|
||||||
|
- [ ] Disable .len for Strings, are there other things that use this convention?
|
||||||
|
|
||||||
|
- [ ] Builtin data structures
|
||||||
|
- [ ] Fix Length etc. they should be function calls not operators
|
||||||
|
- [ ] Strings probably should have len() instead of string.len
|
||||||
|
- [ ] Slices
|
||||||
|
- [ ] Some way to take slice of data
|
||||||
|
- [ ] Tuples
|
||||||
|
- [ ] Dynamic arrays
|
||||||
|
- [ ] Hash tables
|
||||||
|
|
||||||
|
- [ ] C Codegen
|
||||||
|
- [ ] Function renaming to prevent colissions, we can't really touch other stuff cause I want it to be easily debuggable
|
||||||
|
|
||||||
|
- [ ] Programming constructs
|
||||||
|
- [ ] Using language construct
|
||||||
|
- [ ] Function polimorphism
|
||||||
|
- [ ] Operator Overloading
|
||||||
|
- [ ] Named loops and breaking out of them
|
||||||
|
|
||||||
|
- [ ] Bytecode interpreter
|
||||||
|
- [ ] Ir
|
||||||
|
- [ ] Interpreter
|
||||||
|
- [ ] Code generation
|
||||||
|
|
||||||
|
- [ ] Parametric Polymorphism
|
||||||
|
|
||||||
|
- [ ] Conditional compilation #if (maybe just do something like a conditional load or import?) #import "windows.kl" when os == "windows"
|
||||||
|
|
||||||
|
- [ ] Any
|
||||||
|
- [ ] Assigning to any values like ints etc. should work perhaps? But what type they should have?
|
||||||
|
- [ ] Var args using any
|
||||||
|
- [ ] Slice of Any should work well
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
2022.05.28 - On lambda expressions
|
2022.05.28 - On lambda expressions
|
||||||
@@ -56,43 +95,6 @@ For modules it's a bit different cause they should be distributed as valid.
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
- [ ] Basic
|
|
||||||
- [ ] Pass size and alignment calculations to C ?
|
|
||||||
- [ ] Fix . operator lookups
|
|
||||||
- [ ] Combining casts with . operator
|
|
||||||
|
|
||||||
- [ ] Builtin data structures
|
|
||||||
- [ ] Fix Length etc. they should be function calls not operators
|
|
||||||
- [ ] Strings probably should have len() instead of string.len
|
|
||||||
- [ ] Slices
|
|
||||||
- [ ] Some way to take slice of data
|
|
||||||
- [ ] Tuples
|
|
||||||
- [ ] Dynamic arrays
|
|
||||||
- [ ] Hash tables
|
|
||||||
|
|
||||||
- [ ] C Codegen
|
|
||||||
- [ ] Function renaming to prevent colissions, we can't really touch other stuff cause I want it to be easily debuggable
|
|
||||||
|
|
||||||
- [ ] Programming constructs
|
|
||||||
- [ ] Using language construct
|
|
||||||
- [ ] Function polimorphism
|
|
||||||
- [ ] Operator Overloading
|
|
||||||
- [ ] Named loops and breaking out of them
|
|
||||||
|
|
||||||
- [ ] Bytecode interpreter
|
|
||||||
- [ ] Ir
|
|
||||||
- [ ] Interpreter
|
|
||||||
- [ ] Code generation
|
|
||||||
|
|
||||||
- [ ] Parametric Polymorphism
|
|
||||||
|
|
||||||
- [ ] Conditional compilation #if (maybe just do something like a conditional load or import?) #import "windows.kl" when os == "windows"
|
|
||||||
|
|
||||||
|
|
||||||
- [ ] Any
|
|
||||||
- [ ] Assigning to any values like ints etc. should work perhaps? But what type they should have?
|
|
||||||
- [ ] Var args using any
|
|
||||||
- [ ] Slice of Any should work well
|
|
||||||
|
|
||||||
- [ ] Probably need to give Ast_Expr a Value field, then I can express Type nicely
|
- [ ] Probably need to give Ast_Expr a Value field, then I can express Type nicely
|
||||||
- [ ] I would love for String, slice, Any etc. to have their struct declarations in source files, I also would want for stuff like string.str to work without weird special cases
|
- [ ] I would love for String, slice, Any etc. to have their struct declarations in source files, I also would want for stuff like string.str to work without weird special cases
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ Raymarcher_Update :: ()
|
|||||||
|
|
||||||
if hit
|
if hit
|
||||||
Screen[x + y*X] = Vec3_ConvertToARGB({1, uv.y, 0})
|
Screen[x + y*X] = Vec3_ConvertToARGB({1, uv.y, 0})
|
||||||
|
|
||||||
|
else;; Screen[x + y*X] = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user