Fixing generated names

This commit is contained in:
Krzosa Karol
2022-06-13 20:55:49 +02:00
parent 30f448a490
commit 3bbe5e5c2b
2 changed files with 86 additions and 121 deletions

123
program.c
View File

@@ -1,6 +1,7 @@
#include <stdint.h>
#include <stdio.h>
#include <math.h>
typedef int8_t S8;
typedef int16_t S16;
typedef int32_t S32;
@@ -18,6 +19,8 @@ typedef S64 SizeS;
typedef float F32;
typedef double F64;
typedef S32 Bool;
#define true 1
#define false 0
typedef struct Slice{
S64 len;
@@ -34,79 +37,61 @@ void entry();
int main(){
entry();
}
#line 0 "program.kl"
#line 1
#line 3
typedef struct Token{
U8 kind;
U8 *str;
S64 len;
/*enum Kind{
Number = 0,
};*/
}Token;
#line 12
String kind_name(U8 kind){
#line 15
if((kind==0)){
#line 14
return LIT("<Number>");
}
else{
#line 16
return LIT("<Unknown>");
// Type SizeU = base_
// constant int OS_PAGE_SIZE = 4096
typedef struct base_OS_Memory{
U64 base_commit;
U64 base_reserve;
U8 *base_data;
}base_OS_Memory;
typedef struct base_Arena{
base_OS_Memory base_memory;
U64 base_alignment;
U64 base_len;
}base_Arena;
U64 base_get_align_offset(U64 base_size, U64 base_align){
U64 base_mask = (base_align-1);
U64 base_val = (base_size&base_mask);
if((base_val!=0)){
base_val=(base_align-base_val);
}
return base_val;
}
#line 18
Bool is_numeric(U8 c){
#line 19
Bool result = ((c>=48)&&(c<=57));
#line 20
return result;
U64 base_align_up(U64 base_size, U64 base_align){
U64 base_result = (base_size+base_get_align_offset(base_size, base_align));
return base_result;
}
#line 22
void print_tokens(Slice tokens){
#line 23
for(S64 i = 0;(i<tokens.len);(i++)){
#line 24
Token *t = (&(((Token *)tokens.data)[i]));
#line 25
printf("%d. %.*s", i, ((S32 )t->len), t->str);
}
// Type LPVOID = (*Windows_▬)
// Type SIZE_T = Windows_
// Type DWORD = Windows_♫
/*foreign*/void *VirtualAlloc(void *Windows_lpAddress, U64 Windows_dwSize, U32 Windows_flAllocationType, U32 Windows_flProtect);
// constant int MEM_RESERVE = 2
// constant int PAGE_READWRITE = 4
base_OS_Memory base_reserve(U64 base_size){
base_OS_Memory base_result = (base_OS_Memory ){base_align_up(base_size, 4096)};
base_result.base_data=((U8 *)VirtualAlloc(0, base_result.base_reserve, 2, 4));
return base_result;
}
#line 27
void entry(){
#line 28
String string_to_lex = LIT("Identifier 2425525 Not_Number");
#line 29
Slice token_array = (Slice){32, (Token [32]){}};
#line 30
S64 token_count = 0;
#line 32
Token t = {};
#line 33
for(S64 i = 0;(i<string_to_lex.len);i+=1){
#line 34
if(is_numeric((string_to_lex.str[i]))){
#line 35
t.kind=0;
#line 36
t.str=(&(string_to_lex.str[i]));
#line 37
t.len=i;
#line 38
for(;is_numeric((string_to_lex.str[i]));){
#line 39
i+=1;
}
#line 40
t.len=(i-t.len);
#line 41
(((Token *)token_array.data)[(token_count++)])=t;
}
U64 base_clamp_top_sizeu(U64 base_val, U64 base_max){
if((base_val>base_max)){
return base_max;
}
#line 42
print_tokens(token_array);
return base_val;
}
// Type BOOL = Windows_♂
/*foreign*/int VirtualFree(void *Windows_lpAddress, U64 Windows_dwSize, U32 Windows_dwFreeType);
// constant int MEM_RELEASE = 6
Bool base_commit(base_OS_Memory *base_m, U64 base_size){
U64 base_commit_size = base_align_up(base_size, 4096);
U64 base_total_commit = (base_m->base_commit+base_commit_size);
U64 base_clamped_commit = base_clamp_top_sizeu(base_total_commit, base_m->base_reserve);
U64 base_adjusted_commit = (base_clamped_commit-base_m->base_commit);
if((base_adjusted_commit!=0)){
int base_result = VirtualFree(((void *)base_m->base_data), 0, 6);
base_m->base_commit+=base_adjusted_commit;
return true;
}
return false;
}