Skip to content

Commit

Permalink
minits fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jul 25, 2024
1 parent dd37f7b commit 8e98c0d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
30 changes: 19 additions & 11 deletions tools/minits/minits.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,10 @@ function value_type(value) {
if (arrow > -1) {
let base = value.substring(0, arrow);
let type = value_types.get(base);
value = value.substring(arrow + 2, value.length);
let member = value.substring(arrow + 2, value.length);
let struct_value_types = struct_types.get(type);
if (struct_value_types != null) {
return struct_value_types.get(value);
return struct_value_types.get(member);
}
}
return value_types.get(value);
Expand Down Expand Up @@ -1284,15 +1284,16 @@ function write_fn_declarations() {
let fn_name = get_token();
let ret = function_return_type();

if (fn_name === "main") {
fn_name = "_main";
}
else if (fn_name === "(") { // Anonymous function
fn_name = last_fn_name + "_1";
if (fn_name === "(") { // Anonymous function
fn_name = last_fn_name + "_" + (pos - 1);
pos--;
}

last_fn_name = fn_name;
else {
if (fn_name === "main") {
fn_name = "_main";
}
last_fn_name = fn_name;
}

// Params
let _param_pos = 0;
Expand Down Expand Up @@ -1464,15 +1465,14 @@ function write_function() {
tabs = 1;
new_line = true;
let mark_as_root = null;
let anon_fn = fn_name;
let nested = [];

while (true) {
pos++;
let token = get_token();

if (token === "function") { // Begin nested function
anon_fn += "_1";
let anon_fn = fn_name + "_" + pos;
out("&" + anon_fn);
if (get_token(-1) === "=") {
out(";\n");
Expand All @@ -1483,6 +1483,14 @@ function write_function() {
strings.push("");
let fn_decl = fn_declarations.get(anon_fn);
out(fn_decl + "{\n");

let find = fn_decl.substring(0, fn_decl.indexOf("("));
let fn_pos = parseInt(find.substring(find.lastIndexOf("_") + 1, find.length));
let _pos = pos;
pos = fn_pos;
set_fn_param_types();
pos = _pos;

nested.push(1);
continue;
}
Expand Down
30 changes: 19 additions & 11 deletions tools/minits/minits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,10 @@ function value_type(value: string): string {
if (arrow > -1) {
let base: string = substring(value, 0, arrow);
let type: string = map_get(value_types, base);
value = substring(value, arrow + 2, value.length);
let member: string = substring(value, arrow + 2, value.length);
let struct_value_types: map_t<string, string> = map_get(struct_types, type);
if (struct_value_types != null) {
return map_get(struct_value_types, value);
return map_get(struct_value_types, member);
}
}
return map_get(value_types, value);
Expand Down Expand Up @@ -1324,15 +1324,16 @@ function write_fn_declarations() {
let fn_name: string = get_token();
let ret: string = function_return_type();

if (fn_name == "main") {
fn_name = "_main";
}
else if (fn_name == "(") { // Anonymous function
fn_name = last_fn_name + "_1";
if (fn_name == "(") { // Anonymous function
pos--;
fn_name = last_fn_name + "_" + pos;
}
else {
if (fn_name == "main") {
fn_name = "_main";
}
last_fn_name = fn_name;
}

last_fn_name = fn_name;

// Params
let _param_pos: i32 = 0;
Expand Down Expand Up @@ -1503,15 +1504,14 @@ function write_function() {
tabs = 1;
new_line = true;
let mark_as_root: string = null;
let anon_fn: string = fn_name;
fnested.length = 0;

while (true) {
pos++;
let token: string = get_token();

if (token == "function") { // Begin nested function
anon_fn += "_1";
let anon_fn: string = fn_name + "_" + pos;
out("&" + anon_fn);
if (get_token(-1) == "=") {
out(";\n");
Expand All @@ -1522,6 +1522,14 @@ function write_function() {
array_push(strings, "");
let fn_decl: string = map_get(fn_declarations, anon_fn);
out(fn_decl + "{\n");

let find: string = substring(fn_decl, 0, string_index_of(fn_decl, "("));
let fn_pos: i32 = parse_int(substring(find, string_last_index_of(find, "_") + 1, find.length));
let _pos: i32 = pos;
pos = fn_pos;
set_fn_param_types();
pos = _pos;

array_push(fnested, 1);
continue;
}
Expand Down

0 comments on commit 8e98c0d

Please sign in to comment.