...
This commit is contained in:
@@ -298,73 +298,6 @@ any_to_string :: (val: Any) -> string {
|
||||
result;
|
||||
}
|
||||
|
||||
build_print :: (fmt: string) -> string {
|
||||
code := "result := \"\"; ";
|
||||
seg_start := 0;
|
||||
i := 0;
|
||||
arg_idx := 0;
|
||||
while i < fmt.len {
|
||||
if fmt[i] == 123 {
|
||||
if i + 1 < fmt.len {
|
||||
if fmt[i + 1] == 125 {
|
||||
if i > seg_start {
|
||||
code = concat(code, "result = concat(result, substr(fmt, ");
|
||||
code = concat(code, int_to_string(seg_start));
|
||||
code = concat(code, ", ");
|
||||
code = concat(code, int_to_string(i - seg_start));
|
||||
code = concat(code, ")); ");
|
||||
}
|
||||
code = concat(code, "result = concat(result, any_to_string(args[");
|
||||
code = concat(code, int_to_string(arg_idx));
|
||||
code = concat(code, "])); ");
|
||||
arg_idx += 1;
|
||||
i += 2;
|
||||
seg_start = i;
|
||||
} else if fmt[i + 1] == 123 {
|
||||
code = concat(code, "result = concat(result, substr(fmt, ");
|
||||
code = concat(code, int_to_string(seg_start));
|
||||
code = concat(code, ", ");
|
||||
code = concat(code, int_to_string(i - seg_start + 1));
|
||||
code = concat(code, ")); ");
|
||||
i += 2;
|
||||
seg_start = i;
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
} else if fmt[i] == 125 {
|
||||
if i + 1 < fmt.len {
|
||||
if fmt[i + 1] == 125 {
|
||||
code = concat(code, "result = concat(result, substr(fmt, ");
|
||||
code = concat(code, int_to_string(seg_start));
|
||||
code = concat(code, ", ");
|
||||
code = concat(code, int_to_string(i - seg_start + 1));
|
||||
code = concat(code, ")); ");
|
||||
i += 2;
|
||||
seg_start = i;
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
if seg_start < fmt.len {
|
||||
code = concat(code, "result = concat(result, substr(fmt, ");
|
||||
code = concat(code, int_to_string(seg_start));
|
||||
code = concat(code, ", ");
|
||||
code = concat(code, int_to_string(fmt.len - seg_start));
|
||||
code = concat(code, ")); ");
|
||||
}
|
||||
code = concat(code, "out(result);");
|
||||
code;
|
||||
}
|
||||
|
||||
build_format :: (fmt: string) -> string {
|
||||
code := "result := \"\"; ";
|
||||
seg_start := 0;
|
||||
@@ -428,7 +361,6 @@ build_format :: (fmt: string) -> string {
|
||||
code = concat(code, int_to_string(fmt.len - seg_start));
|
||||
code = concat(code, ")); ");
|
||||
}
|
||||
code = concat(code, "result;");
|
||||
code;
|
||||
}
|
||||
|
||||
@@ -437,7 +369,8 @@ format :: ($fmt: string, args: ..Any) -> string {
|
||||
}
|
||||
|
||||
print :: ($fmt: string, args: ..Any) {
|
||||
#insert build_print(fmt);
|
||||
#insert build_format(fmt);
|
||||
#insert "out(result);";
|
||||
}
|
||||
|
||||
List :: struct ($T: Type) {
|
||||
|
||||
Reference in New Issue
Block a user