Fix struct function ordering in c files

This commit is contained in:
Krzosa Karol
2022-06-17 11:46:05 +02:00
parent 218ca7266a
commit a77f0ee8fe
4 changed files with 47 additions and 49 deletions

View File

@@ -771,11 +771,6 @@ typedef struct String{
if(it->kind == AST_STRUCT){
genln("typedef struct %Q %Q;", it->name, it->name);
}
else if(it->kind == AST_LAMBDA){
genln("");
gen_lambda(it->name, it->lambda, false);
}
}
Scratch scratch;
@@ -808,9 +803,17 @@ typedef struct String{
global_indent--;
genln("} Tuple%llu;", type->type_id);
}
}
For(pctx->ordered_decls){
if(it->kind == AST_LAMBDA){
genln("");
gen_lambda(it->name, it->lambda, false);
}
}
For(pctx->ordered_decls){
genln("");
gen_ast(it);

View File

@@ -2,16 +2,8 @@ Os :: #import "os.kl"
SizeU :: #strict U64
arena_di: U64
ALLOCATOR_ACTION :: enum
ALLOCATE
RESIZE
FREE_ALL
Allocator :: struct
proc: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
Arena :: struct
allocator: Allocator
// allocator: Allocator
di: U64 // @debug_id
memory: Os.Memory
alignment: U64
@@ -59,6 +51,15 @@ arena_push_size :: (a: *Arena, size: SizeU): *void
arena_release :: (a: *Arena)
Os.release(&a.memory)
/*
ALLOCATOR_ACTION :: enum
ALLOCATE
RESIZE
FREE_ALL
Allocator :: struct
proc: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
arena_allocator_proc :: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
arena: *Arena = a->*Arena
if action == ALLOCATOR_ACTION.ALLOCATE
@@ -74,3 +75,4 @@ allocate :: (a: *Allocator, size: SizeU): *void
return a.proc(a, ALLOCATOR_ACTION.ALLOCATE, size, 0)
*/

View File

@@ -3,7 +3,7 @@
main :: (argc: int, argv: **char): int
arena: Arena
arena_init(&arena)
data: *S64 = allocate((&arena)->*Allocator, size_of(S64))
data: *S64 = arena_push_size(&arena, size_of(S64))
*data = 10
arena_release(&arena)

View File

@@ -10,51 +10,44 @@ UTF32_Result :: struct
out_str: U32
advance: S64
error : S64
UTF16_Result :: struct
out_str: [2]U16
len : S64
error : S64
utf8_to_utf32 :: (c: *U8, max_advance: S64): UTF32_Result
result: UTF32_Result
utf8_to_utf32 :: (c: *U8, max_advance: S64): U32, S64
out_str: U32
advance: S64
if (c[0] & 0b10000000) == 0
if max_advance >= 1
c0 := c[0]->U32
result.out_str = c0
result.advance = 1
else;; result.error = 1
out_str = c0
advance = 1
elif (c[0] & 0b11100000) == 0b11000000
if (c[1] & 0b11000000) == 0b10000000 // Continuation byte required
if max_advance >= 2
c0 := c[0]->U32; c1 := c[1]->U32
result.out_str = (c0 & 0b00011111) << 6 | (c1 & 0b00111111)
result.advance = 2
else;; result.error = 2
else;; result.error = 2
out_str = (c0 & 0b00011111) << 6 | (c1 & 0b00111111)
advance = 2
elif (c[0] & 0b11110000) == 0b11100000
if (c[1] & 0b11000000) == 0b10000000 && (c[2] & 0b11000000) == 0b10000000 // Two continuation bytes required
if max_advance >= 3
c0 := c[0]->U32; c1 := c[1]->U32; c2 := c[2]->U32
result.out_str = (c0 & 0b00001111) << 12 | (c1 & 0b00111111) << 6 | (c2 & 0b00111111)
result.advance = 3
else;; result.error = 3
else;; result.error = 3
out_str = (c0 & 0b00001111) << 12 | (c1 & 0b00111111) << 6 | (c2 & 0b00111111)
advance = 3
elif (c[0] & 0b11111000) == 0b11110000
if (c[1] & 0b11000000) == 0b10000000 && (c[2] & 0b11000000) == 0b10000000 && (c[3] & 0b11000000) == 0b10000000 // Three continuation bytes required
if max_advance >= 4
c0 := c[0]->U32; c1 := c[1]->U32; c2 := c[2]->U32; c3 := c[3]->U32
result.out_str = (c0 & 0b00001111) << 18 | (c1 & 0b00111111) << 12 | (c2 & 0b00111111) << 6 | (c3 & 0b00111111)
result.advance = 4
else;; result.error = 4
else;; result.error = 4
else;; result.error = 4
out_str = (c0 & 0b00001111) << 18 | (c1 & 0b00111111) << 12 | (c2 & 0b00111111) << 6 | (c3 & 0b00111111)
advance = 4
return result
return out_str, advance
UTF16_Result :: struct
out_str: [2]U16
len : S64
error : S64
utf32_to_utf16 :: (codepoint: U32): [2]U16, S64
str: [2]U16
len := 0
@@ -81,10 +74,10 @@ string_to_string16 :: (in: String): String16
alloc_size := (length_of(in)*2)+1
result := String16{str = allocate(alloc_size->U64)->*U16}
for i := 0, i < length_of(in)
decode := utf8_to_utf32(in_str + i, length_of(in) - i)
if !decode.error
i += decode.advance
s16, s16_len := utf32_to_utf16(decode.out_str)
s32, s32_len := utf8_to_utf32(in_str + i, length_of(in) - i)
if s32_len != 0
i += s32_len
s16, s16_len := utf32_to_utf16(s32)
if s16_len != 0
for j := 0, j < s16_len, j++
result.str[result.len++] = s16[j]
@@ -103,14 +96,14 @@ test_unicode :: ()
string_result := string_to_string16(string)
print(string_result)
result := utf8_to_utf32(&"A"[0], 1)
assert(result.out_str == 'A, "Invalid decode") // '
s32, s32_len := utf8_to_utf32(&"A"[0], 1)
assert(s32 == 'A, "Invalid decode") // '
result = utf8_to_utf32(&"ć"[0], 2)
assert(result.out_str == 0x107, "Invalid decode")
s32_2, s32_len_2 := utf8_to_utf32(&"ć"[0], 2)
assert(s32_2 == 0x107, "Invalid decode")
result = utf8_to_utf32(&"ó"[0], 2)
assert(result.out_str == 0xF3, "Invalid decode")
s32_3, s32_len_3 := utf8_to_utf32(&"ó"[0], 2)
assert(s32_3 == 0xF3, "Invalid decode")
Vec2I :: struct;; x: S64; y: S64
Vec2 :: struct;; x: F32; y: F32