Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Feature todo list in order:
- format string
- http server
- __eq
- {{ ... }} (value-scopes)
- <{ ... } (value-scopes)
- __before_free
- strict ownership types
- shared ownership types
Expand Down
4 changes: 2 additions & 2 deletions lib/src/fs/mime.ki
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
global g_mimes : ?Map[String];
fn mime(extension_no_dot: &String) String {

let mimes = g_mimes ?? {{
let mimes = g_mimes ?? <{
let mimes = Map[String]{};

mimes.set("aac", "audio/aac");
Expand Down Expand Up @@ -84,7 +84,7 @@ fn mime(extension_no_dot: &String) String {
let ref = share(mimes);
g_mimes = mimes;
return ref;
}};
};

let mime = mimes.get(extension_no_dot) !? "application/octet-stream";
//println("MI:"+mime);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/http/router.ki
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ class Router[T] {
throw invalid_route;
}

let find = blocks.get(key) !? {{
let find = blocks.get(key) !? <{
let v = RouteBlock[T]{ blocks: Map[RouteBlock[T]]{} };
let ref = share(v);
blocks.set(key, v);
return ref @as RouteBlock[T];
}};
};

block = find;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/net/socket-tcp.ki
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ class SocketTCP async {

fn connect() +Connection !connection_failed {

let c = this.connection ?? {{
let c = this.connection ?? <{
let c = Connection {
fd: this.fd
open: false,
};
let res = share(c);
this.connection = c;
return res;
}};
};

if !c.open {
#if OS == win
Expand Down
26 changes: 13 additions & 13 deletions lib/src/type/array.ki
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

use mem;

macro array {
input {
"[]" type;
"{}" values @repeat;
}
output {
"{{\n"
"let array = Array[%type].new();\n"
"array.push(%values);\n"
"return array;\n"
"}}"
}
}
// macro array {
// input {
// "[]" type;
// "{}" values @repeat;
// }
// output {
// "<{\n"
// "let array = Array[%type].new();\n"
// "array.push(%values);\n"
// "return array;\n"
// "}"
// }
// }

class Array[T] {
~size: uxx;
Expand Down
26 changes: 13 additions & 13 deletions lib/src/type/map.ki
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

macro map {
input {
"[]" type;
"{}" values @repeat @replace("=>", ",");
}
output {
"{{\n"
"let map = Map[%type].new();\n"
"map.set(%values);\n"
"return map;\n"
"}}"
}
}
// macro map {
// input {
// "[]" type;
// "{}" values @repeat @replace("=>", ",");
// }
// output {
// "<{\n"
// "let map = Map[%type].new();\n"
// "map.set(%values);\n"
// "return map;\n"
// "}"
// }
// }

// TODO : Use hash maps
class Map[T] {
Expand Down
23 changes: 23 additions & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,26 @@ int array_find(Array *arr, void *item, int type) {
}
return -1;
}
int array_find_x(Array *arr, void *item, int type, int start, int end) {
int x = start;
while (x < end) {
uintptr_t *adr = arr->data + (x * sizeof(void *));
if (type == arr_find_adr) {
if (*adr == (uintptr_t)item)
return x;
} else if (type == arr_find_str) {
char *a = (char *)*adr;
char *b = (char *)item;
if (strcmp(a, b) == 0)
return x;
} else if (type == arr_find_int) {
if ((int)(*adr) == *(int *)item)
return x;
} else {
die("array.c invalid search type");
}
x++;
}
return -1;
}

43 changes: 12 additions & 31 deletions src/build/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void cmd_build(int argc, char *argv[], LspData *lsp_data) {
b->alc = alc;
b->alc_io = alc_io;
b->alc_ast = alc_make();
b->token = al(alc, KI_TOKEN_MAX);
b->sbuf = al(alc, 2000);
b->lsp = lsp_data;
//
Expand Down Expand Up @@ -199,7 +198,7 @@ void cmd_build(int argc, char *argv[], LspData *lsp_data) {
strcat(cache_buf, optimize ? "1" : "0");
strcat(cache_buf, debug ? "1" : "0");
strcat(cache_buf, test ? "1" : "0");
simple_hash(cache_buf, cache_hash);
ctxhash(cache_buf, cache_hash);
strcpy(cache_dir, get_storage_path());
strcat(cache_dir, "/cache/");

Expand Down Expand Up @@ -279,17 +278,9 @@ void cmd_build(int argc, char *argv[], LspData *lsp_data) {
b->link_static = link_static;
//
b->type_void = type_gen_void(alc);

#ifdef WIN32
LARGE_INTEGER frequency;
LARGE_INTEGER start;
LARGE_INTEGER end;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
#else
struct timeval begin, end;
gettimeofday(&begin, NULL);
#endif
//
b->time_lex = 0;
b->time_fs = 0;

// Init main:main
Config *main_cfg = NULL;
Expand Down Expand Up @@ -319,6 +310,8 @@ void cmd_build(int argc, char *argv[], LspData *lsp_data) {
loader_load_nsc(pkc_ki, "mem");
loader_load_nsc(pkc_ki, "os");

unsigned long start = microtime();

// Compile ki lib
compile_loop(b, 1); // Scan identifiers

Expand Down Expand Up @@ -347,31 +340,19 @@ void cmd_build(int argc, char *argv[], LspData *lsp_data) {
}
}

#ifdef WIN32
QueryPerformanceCounter(&end);
double time_ast = (double)(end.QuadPart - start.QuadPart) / frequency.QuadPart;
#else
gettimeofday(&end, NULL);
double time_ast = (double)(end.tv_usec - begin.tv_usec) / 1000000 + (double)(end.tv_sec - begin.tv_sec);
#endif

if (verbose > 0) {
printf("⌚ Parse + IR gen: %.3fs\n", time_ast);
printf("⌚ Lexer: %.3fs\n", (double)b->time_lex / 1000000);
printf("⌚ Parser: %.3fs\n", (double)b->time_parse / 1000000);
printf("⌚ IR Gen: %.3fs\n", (double)b->time_ir / 1000000);
printf("⌚ File IO: %.3fs\n", (double)b->time_fs / 1000000);
// printf("⌚ Other: %.3fs\n", (double)(microtime() - start - b->time_lex - b->time_parse - b->time_fs - b->time_ir) / 1000000);
}

// Linker stage
stage_5(b);

#ifdef WIN32
QueryPerformanceCounter(&end);
double time_all = (double)(end.QuadPart - start.QuadPart) / frequency.QuadPart;
#else
gettimeofday(&end, NULL);
double time_all = (double)(end.tv_usec - begin.tv_usec) / 1000000 + (double)(end.tv_sec - begin.tv_sec);
#endif

if (!run_code || b->verbose > 0) {
printf("✅ Compiled in: %.3fs\n", time_all);
printf("✅ Compiled in: %.3fs\n", (double)(microtime() - start) / 1000000);
}

// Flush all output
Expand Down
5 changes: 2 additions & 3 deletions src/build/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Class *class_get_generic_class(Class *class, Array *types) {
str_append_chars(hash_buf, type_buf);
}
char *hash_content = str_to_chars(alc, hash_buf);
simple_hash(hash_content, hash);
ctxhash(hash_content, hash);

Class *gclass = map_get(class->generics, hash);
if (!gclass) {
Expand Down Expand Up @@ -553,14 +553,13 @@ Class *class_get_generic_class(Class *class, Array *types) {

Array *read_generic_types(Fc *fc, Scope *scope, Class *class) {
//
char *token = fc->token;
tok_expect(fc, "[", true, true);
Array *types = array_make(fc->alc, class->generic_names->length + 1);
while (true) {
Type *type = read_type(fc, fc->alc, scope, true, true, rtc_default);
array_push(types, type);

tok(fc, token, true, true);
char *token = tok(fc, true, true);
if (strcmp(token, ",") != 0 && strcmp(token, "]") != 0) {
sprintf(fc->sbuf, "Unexpected token '%s'", token);
fc_error(fc);
Expand Down
8 changes: 0 additions & 8 deletions src/build/var.c → src/build/decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ Decl *decl_init(Allocator *alc, Scope *scope, char *name, Type *type, Value *val
return v;
}

Var *var_init(Allocator *alc, Decl *decl, Type *type) {
//
Var *v = al(alc, sizeof(Var));
v->decl = decl;
v->type = type;
return v;
}

Arg *arg_init(Allocator *alc, char *name, Type *type) {
//
Arg *v = al(alc, sizeof(Arg));
Expand Down
Loading