Skip to content

Commit

Permalink
improvement for multiline trace messages
Browse files Browse the repository at this point in the history
  • Loading branch information
CrescentonC committed Dec 2, 2024
1 parent 90981d9 commit 839a573
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
9 changes: 6 additions & 3 deletions hkmc2/shared/src/test/mlscript-compile/Predef.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ const Predef$class = class Predef {
return undefined;
}
log(msg) {
let tmp, tmp1;
let tmp, tmp1, tmp2, tmp3, tmp4;
tmp = "| ".repeat(this.indentLvl);
tmp1 = tmp + msg;
return console.log(tmp1);
tmp1 = " ".repeat(this.indentLvl);
tmp2 = "\n" + tmp1;
tmp3 = msg.replaceAll("\n", tmp2);
tmp4 = tmp + tmp3;
return console.log(tmp4);
}
toString() { return "TraceLogger"; }
};
Expand Down
2 changes: 1 addition & 1 deletion hkmc2/shared/src/test/mlscript-compile/Predef.mls
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module TraceLogger with
set indentLvl = prev + 1
prev
fun resetIndent(n) = set indentLvl = n
fun log(msg) = console.log("| ".repeat(indentLvl) + msg)
fun log(msg) = console.log("| ".repeat(indentLvl) + msg.replaceAll("\n", "\n" + " ".repeat(indentLvl)))

class Test with
val y = 1
Expand Down
71 changes: 71 additions & 0 deletions hkmc2/shared/src/test/mlscript/codegen/TraceLog.mls
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,74 @@ fun toInt(x) = if x is
//│ > | return: 2
//│ > return: 'S(S(N: 0): 1): 2'
//│ = 'S(S(N: 0): 1): 2'


class Cls(a, b, c, d, e, f)
fun id(x, y) =
if y ==
0 then x
else id(x, y - 1)
id(Cls(
"aaaa",
"bbbb",
"cccc",
"dddd",
"eeee",
"ffff"
), 2)
//│ > calling: id(Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ > }, 2)
//│ > | calling: id(Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ > }, 1)
//│ > | | calling: id(Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ > }, 0)
//│ > | | return: Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ > }
//│ > | return: Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ > }
//│ > return: Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ > }
//│ > Cls {
//│ > a: 'aaaa',
//│ > b: 'bbbb',
//│ > c: 'cccc',
//│ > d: 'dddd',
//│ > e: 'eeee',
//│ > f: 'ffff'
//│ = }

0 comments on commit 839a573

Please sign in to comment.