Codegen multiple line strings

This commit is contained in:
Krzosa Karol
2022-09-30 16:05:19 +02:00
parent b17027f431
commit b1d05bc203
6 changed files with 25 additions and 13 deletions

View File

@@ -99,20 +99,20 @@ Release :: (m: *Memory)
- [ ] Dynamic arrays - [ ] Dynamic arrays
- [ ] Hash tables - [ ] Hash tables
- [ ] Tuples - [ ] Tuples
- [x] Beginnings
- [x] Multiple return values from a function - [x] Multiple return values from a function
- [ ] But do we actually want this?
- [ ] Some kind of tuple expressions - [ ] Some kind of tuple expressions
- [ ] Using tuples as single values without unpacking - [ ] Using tuples as single values without unpacking
- [ ] Generics / Parametric polymorphism - [ ] Generics / Parametric polymorphism
- [ ] Function overloading
- [x] Operator overloading - [x] Operator overloading
- [x] Binary operators - [x] Binary operators
- [x] Unary operators - [x] Unary operators
- [x] Bulletproof
- [ ] Assignment expressions? - [ ] Assignment expressions?
- [ ] Bulletproof
- [ ] Platforms - [ ] Platforms
- [x] Windows - [x] Windows

View File

@@ -1479,4 +1479,3 @@ template<class T>
bool should_we_continue(List_Iter<T> *iter){ bool should_we_continue(List_Iter<T> *iter){
return iter->item != 0; return iter->item != 0;
} }

View File

@@ -471,7 +471,3 @@ string_from_cstring(char *string){
return result; return result;
} }

View File

@@ -197,9 +197,18 @@ gen_value(Token *pos, Value a){
gen("0x%llx", pointer_value); gen("0x%llx", pointer_value);
} }
}break; }break;
case TYPE_STRING: case TYPE_STRING:{
gen("(String){(U8 *)\"%Q\", %d}", a.intern_val, a.intern_val.len); int length = 0;
break; gen("(String){(U8 *)\"");
for(int i = 0; i < a.intern_val.len; i++){
if(a.intern_val.str[i] == '\n'){length += 2; gen("\\n");}
else if(a.intern_val.str[i] == '\r'){length += 2; gen("\\r");}
else{length += 1; gen("%c", a.intern_val.str[i]);}
}
gen("\", %d}", length);
}break;
CASE_BOOL: { CASE_BOOL: {
a.bool_val ? gen("true"):gen("false"); a.bool_val ? gen("true"):gen("false");
}break; }break;

View File

@@ -5,7 +5,6 @@
- [ ] '.' Operator doesn't handle expressions inside the dot chain, no good, so casts don't work - [ ] '.' Operator doesn't handle expressions inside the dot chain, no good, so casts don't work
- [ ] Basic - [ ] Basic
- [ ] Introduce List to reduce heap allocations and make it more arena friendly, can we get rid of heap completly?
- [ ] Detecting if return was called - [ ] Detecting if return was called
- [ ] Builtin data structures - [ ] Builtin data structures
@@ -146,6 +145,7 @@ For modules it's a bit different cause they should be distributed as valid.
## Done ## Done
- [x] Introduce List to reduce heap allocations and make it more arena friendly, can we get rid of heap completly?
- [x] Function renaming to prevent colissions, we can't really touch other stuff cause I want it to be easily debuggable - [x] Function renaming to prevent colissions, we can't really touch other stuff cause I want it to be easily debuggable
- [x] Fix Length etc. they should be function calls not operators - [x] Fix Length etc. they should be function calls not operators
- [x] Idea to fix overshoot when debugging and it goes to the close bracket and there is not enough line directives. Store the last outputed line and propagate it on the close brace etc. - [x] Idea to fix overshoot when debugging and it goes to the close bracket and there is not enough line directives. Store the last outputed line and propagate it on the close brace etc.

View File

@@ -18,4 +18,12 @@ main :: (): int
Assert(d.x == -3 && d.y == -4 && d.z == -5) Assert(d.x == -3 && d.y == -4 && d.z == -5)
e := c - d e := c - d
Assert(e.x == 6 && e.y == 8 && e.z == 10) Assert(e.x == 6 && e.y == 8 && e.z == 10)
test_string := "
Memes
"
return 0 return 0