Compiling again, with double import, main and everything
This commit is contained in:
2
base.kl
2
base.kl
@@ -50,5 +50,3 @@ commit :: (m: *OS_Memory, size: SizeU): Bool
|
|||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
entry :: ()
|
|
||||||
memory := reserve(size = 10000)
|
|
||||||
|
|||||||
@@ -156,6 +156,9 @@ gen_var(Ast_Decl *decl, B32 emit_value, B32 scope_names){
|
|||||||
function void
|
function void
|
||||||
gen_lambda(Intern_String name, Ast_Lambda *lambda){
|
gen_lambda(Intern_String name, Ast_Lambda *lambda){
|
||||||
bool is_foreign = is_flag_set(lambda->flags, AST_FOREIGN);
|
bool is_foreign = is_flag_set(lambda->flags, AST_FOREIGN);
|
||||||
|
if(name == pctx->intern("main"_s)){
|
||||||
|
is_foreign = true;
|
||||||
|
}
|
||||||
gen_simple_decl(lambda->type->func.ret, name, lambda->parent_scope, !is_foreign);
|
gen_simple_decl(lambda->type->func.ret, name, lambda->parent_scope, !is_foreign);
|
||||||
gen("(");
|
gen("(");
|
||||||
For(lambda->args){
|
For(lambda->args){
|
||||||
@@ -568,7 +571,7 @@ function String
|
|||||||
end_compilation(){
|
end_compilation(){
|
||||||
generating_time_begin = os_time();
|
generating_time_begin = os_time();
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
gen(R"==(
|
gen(R"==(
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -604,10 +607,6 @@ typedef struct String{
|
|||||||
}String;
|
}String;
|
||||||
#define LIT(x) (String){.str=(U8 *)x, .len=sizeof(x)-1}
|
#define LIT(x) (String){.str=(U8 *)x, .len=sizeof(x)-1}
|
||||||
|
|
||||||
void entry();
|
|
||||||
int main(){
|
|
||||||
entry();
|
|
||||||
}
|
|
||||||
)==");
|
)==");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
12
main.cpp
12
main.cpp
@@ -154,7 +154,6 @@ int main(int argument_count, char **arguments){
|
|||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
emit_line_directives = true;
|
|
||||||
if(argument_count > 1){
|
if(argument_count > 1){
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String name = string_fmt(scratch, "%s.kl", arguments[1]);
|
String name = string_fmt(scratch, "%s.kl", arguments[1]);
|
||||||
@@ -165,10 +164,10 @@ int main(int argument_count, char **arguments){
|
|||||||
Array<String> files = {scratch};
|
Array<String> files = {scratch};
|
||||||
files.add(name);
|
files.add(name);
|
||||||
String result = compile_files(files);
|
String result = compile_files(files);
|
||||||
FILE *f = fopen((const char *)c_filename.str, "w");
|
|
||||||
assert(f);
|
assert(f);
|
||||||
fprintf(f, "%.*s", (int)result.len, result.str);
|
|
||||||
fclose(f);
|
|
||||||
F64 begin = os_time();
|
F64 begin = os_time();
|
||||||
system((const char *)compiler_call.str);
|
system((const char *)compiler_call.str);
|
||||||
printf("\nCompile time: %f", os_time() - begin);
|
printf("\nCompile time: %f", os_time() - begin);
|
||||||
@@ -176,14 +175,15 @@ int main(int argument_count, char **arguments){
|
|||||||
system((const char *)run_program.str);
|
system((const char *)run_program.str);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
emit_line_directives = false;
|
||||||
F64 total_time = os_time();
|
F64 total_time = os_time();
|
||||||
begin_compilation();
|
begin_compilation();
|
||||||
Ast_Module *module = add_module(pctx->intern("base.kl"_s));
|
Ast_Module *module = add_module(pctx->intern("main.kl"_s));
|
||||||
parse_all_modules();
|
parse_all_modules();
|
||||||
assert(module);
|
assert(module);
|
||||||
resolve_everything_in_module(module);
|
resolve_everything_in_module(module);
|
||||||
String result = end_compilation();
|
String result = end_compilation();
|
||||||
printf("%s", result.str);
|
assert(os_write_file("program.c"_s, result));
|
||||||
printf("\nTotal time = %f", os_time() - total_time);
|
printf("\nTotal time = %f", os_time() - total_time);
|
||||||
printf("\nTotal parsing = %f", parsing_time_end - parsing_time_begin);
|
printf("\nTotal parsing = %f", parsing_time_end - parsing_time_begin);
|
||||||
printf("\nTotal resolving = %f", resolving_time_end - resolving_time_begin);
|
printf("\nTotal resolving = %f", resolving_time_end - resolving_time_begin);
|
||||||
|
|||||||
166
program.c
166
program.c
@@ -1,97 +1,71 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
typedef int8_t S8;
|
typedef int8_t S8;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
typedef int32_t S32;
|
typedef int32_t S32;
|
||||||
typedef int64_t S64;
|
typedef int64_t S64;
|
||||||
typedef uint8_t U8;
|
typedef uint8_t U8;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef uint32_t U32;
|
typedef uint32_t U32;
|
||||||
typedef uint64_t U64;
|
typedef uint64_t U64;
|
||||||
typedef S8 B8;
|
typedef S8 B8;
|
||||||
typedef S16 B16;
|
typedef S16 B16;
|
||||||
typedef S32 B32;
|
typedef S32 B32;
|
||||||
typedef S64 B64;
|
typedef S64 B64;
|
||||||
typedef U64 SizeU;
|
typedef U64 SizeU;
|
||||||
typedef S64 SizeS;
|
typedef S64 SizeS;
|
||||||
typedef float F32;
|
typedef float F32;
|
||||||
typedef double F64;
|
typedef double F64;
|
||||||
typedef S32 Bool;
|
typedef S32 Bool;
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
|
|
||||||
typedef struct Slice{
|
typedef struct Slice{
|
||||||
S64 len;
|
S64 len;
|
||||||
void *data;
|
void *data;
|
||||||
}Slice;
|
}Slice;
|
||||||
|
|
||||||
typedef struct String{
|
typedef struct String{
|
||||||
U8 *str;
|
U8 *str;
|
||||||
S64 len;
|
S64 len;
|
||||||
}String;
|
}String;
|
||||||
#define LIT(x) (String){.str=(U8 *)x, .len=sizeof(x)-1}
|
#define LIT(x) (String){.str=(U8 *)x, .len=sizeof(x)-1}
|
||||||
|
|
||||||
void entry();
|
|
||||||
int main(){
|
|
||||||
entry();
|
// Type SizeU = base_
|
||||||
}
|
|
||||||
|
typedef struct base_OS_Memory{
|
||||||
|
U64 base_commit;
|
||||||
// Type SizeU = base_
|
U64 base_reserve;
|
||||||
// constant int OS_PAGE_SIZE = 4096
|
U8 *base_data;
|
||||||
typedef struct base_OS_Memory{
|
}base_OS_Memory;
|
||||||
U64 base_commit;
|
U64 base_get_align_offset(U64 base_size, U64 base_align){
|
||||||
U64 base_reserve;
|
U64 base_mask = (base_align-1);
|
||||||
U8 *base_data;
|
U64 base_val = (base_size&base_mask);
|
||||||
}base_OS_Memory;
|
if((base_val!=0)){
|
||||||
typedef struct base_Arena{
|
base_val=(base_align-base_val);
|
||||||
base_OS_Memory base_memory;
|
}
|
||||||
U64 base_alignment;
|
return base_val;
|
||||||
U64 base_len;
|
}
|
||||||
}base_Arena;
|
U64 base_align_up(U64 base_size, U64 base_align){
|
||||||
U64 base_get_align_offset(U64 base_size, U64 base_align){
|
U64 base_result = (base_size+base_get_align_offset(base_size, base_align));
|
||||||
U64 base_mask = (base_align-1);
|
return base_result;
|
||||||
U64 base_val = (base_size&base_mask);
|
}
|
||||||
if((base_val!=0)){
|
// constant int OS_PAGE_SIZE = 4096
|
||||||
base_val=(base_align-base_val);
|
|
||||||
}
|
// Type LPVOID = (*Windows_)
|
||||||
return base_val;
|
// Type SIZE_T = Windows_
|
||||||
}
|
|
||||||
U64 base_align_up(U64 base_size, U64 base_align){
|
// Type DWORD = Windows_
|
||||||
U64 base_result = (base_size+base_get_align_offset(base_size, base_align));
|
/*foreign*/void *VirtualAlloc(void *Windows_lpAddress, U64 Windows_dwSize, U32 Windows_flAllocationType, U32 Windows_flProtect);
|
||||||
return base_result;
|
// constant int MEM_RESERVE = 2
|
||||||
}
|
// constant int PAGE_READWRITE = 4
|
||||||
// Type LPVOID = (*Windows_▬)
|
base_OS_Memory base_reserve(U64 base_size){
|
||||||
// Type SIZE_T = Windows_
|
base_OS_Memory base_result = (base_OS_Memory ){base_align_up(base_size, 4096)};
|
||||||
// Type DWORD = Windows_♫
|
base_result.base_data=((U8 *)VirtualAlloc(0, base_result.base_reserve, 2, 4));
|
||||||
/*foreign*/void *VirtualAlloc(void *Windows_lpAddress, U64 Windows_dwSize, U32 Windows_flAllocationType, U32 Windows_flProtect);
|
return base_result;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
U64 base_clamp_top_sizeu(U64 base_val, U64 base_max){
|
|
||||||
if((base_val>base_max)){
|
|
||||||
return base_max;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
int main(int main_argc, char **main_argv){
|
int main(int main_argc, char **main_argv){
|
||||||
Reference in New Issue
Block a user