Selaa lähdekoodia

New reference output.

master
Ian Piumarta 11 kuukautta sitten
vanhempi
commit
1fd5a0be12
2 muutettua tiedostoa jossa 18 lisäystä ja 18 poistoa
  1. +3
    -6
      test.ref
  2. +15
    -12
      test.txt

+ 3
- 6
test.ref Näytä tiedosto

@ -147,13 +147,10 @@ f();
f 102 ( 40 ) 41 32 { 123 32 p 112 r 114 i 105 n 110 t 116 ( 40 _ 95 _ 95 e 101 n 110 v 118 _ 95 _ 95 ( 40 ) 41 ) 41 32 } 125
10 f 102 ( 40 ) 41 ; 59
10
<<Binop>>
| operation: 15
| 0: 6
| 1: 7
42
42
6 * 7
42
42
MACRO table <<Object>>
| assert: <<Closure>>
| | environment: nil
@ -261,4 +258,4 @@ AST eval => 42
3: if (n < 2) nil else n * factorial(n - 1)
2: factorial(5)
1: { factorial(5) }
0: try { factorial(5) } catch (e) { { if (!eval(e.__function__ == "*")) { print("\nassertion failed: ", "e.__function__ == \"*\"", "\n"); exit(1) } }; { if (!eval(e.__kind__ == "type error")) { print("\nassertion failed: ", "e.__kind__ == \"type error\"", "\n"); exit(1) } }; { if (!eval(e.__message__ == "illegal operand types")) { print("\nassertion failed: ", "e.__message__ == \"illegal operand types\"", "\n"); exit(1) } }; { if (!eval(e.operand1 == 2)) { print("\nassertion failed: ", "e.operand1 == 2", "\n"); exit(1) } }; { if (!eval(e.operand2 == nil)) { print("\nassertion failed: ", "e.operand2 == nil", "\n"); exit(1) } }; print(e.__function__, ": ", e.__kind__, ": ", e.__message__, ": ", typeName(e.operand1), " and ", typeName(e.operand2), "\n"); let w = 2; let j = i; while (j /= 10 >= 0) { w += 1 }; for (i from len(e) - 1 to 0) print(pad(w, codeString(i)), ": ", codeString(e[i]), "\n") }
0: try { factorial(5) } catch (e) { { if (!eval(e.__function__ == "*")) { print("\nassertion failed: ", "e.__function__ == \"*\"", "\n"); exit(1) } }; { if (!eval(e.__kind__ == "type error")) { print("\nassertion failed: ", "e.__kind__ == \"type error\"", "\n"); exit(1) } }; { if (!eval(e.__message__ == "illegal operand types")) { print("\nassertion failed: ", "e.__message__ == \"illegal operand types\"", "\n"); exit(1) } }; { if (!eval(e.operand1 == 2)) { print("\nassertion failed: ", "e.operand1 == 2", "\n"); exit(1) } }; { if (!eval(e.operand2 == nil)) { print("\nassertion failed: ", "e.operand2 == nil", "\n"); exit(1) } }; print(e.__function__, ": ", e.__kind__, ": ", e.__message__, ": ", typeName(e.operand1), " and ", typeName(e.operand2), "\n"); backtrace(e) }

+ 15
- 12
test.txt Näytä tiedosto

@ -152,8 +152,8 @@ assert((0b1110 & 0b0111) == 0b0110);
nt = 0;
nf = 0;
t() { nt = nt + 1; #t }
f() { nf = nf + 1; nil }
t() { global nt += 1; #t }
f() { global nf += 1; nil }
refute(f() || f()); assert(nt == 0); assert(nf == 2);
assert(f() || t()); assert(nt == 1); assert(nf == 3);
@ -388,16 +388,23 @@ factorial(n) { if (n < 2) nil else n * factorial(n-1) }
typeName(x) {
if (!x) return "<Undefined>";
let name = "?";
let level = 1;
name = "?";
level = 1;
while (x && !x.allKeys().includes(#__name__)) x = x.__delegate__;
if (x.allKeys().includes(#__name__)) name = x.__name__.asString();
"<" * level + name + ">" * level;
}
pad(w, i) {
while (len(i) < w) i = " " + i;
i;
backtrace(e) {
pad(w, i) {
while (len(i) < w) i = " " + i;
i;
}
w = 2;
j = len(e);
while ((j /= 10) > 0) { ++w; } // w = 1+log10(j)
for (i from len(e) - 1 to 0)
print(pad(w, codeString(i)), ": ", codeString(e[i]), "\n");
}
try {
@ -410,9 +417,5 @@ catch (e) {
assert(e.operand1 == 2);
assert(e.operand2 == nil);
print(e.__function__, ": ", e.__kind__, ": ", e.__message__, ": ", typeName(e.operand1), " and ", typeName(e.operand2), "\n");
let w = 2;
let j = i;
while ( (j /= 10) > 0) { ++w; }
for (i from len(e) - 1 to 0)
print(pad(w, codeString(i)), ": ", codeString(e[i]), "\n");
backtrace(e);
}

Ladataan…
Peruuta
Tallenna