Pseudocode: Generate fake values for Unit/Nothing-typed expressions

This commit is contained in:
Alexey Sedunov
2014-07-23 12:56:21 +04:00
parent 2d3ac9109b
commit 77bbf8f73b
72 changed files with 851 additions and 592 deletions
@@ -7,6 +7,9 @@ tailRecursive fun test() : Int {
}
}
---------------------
test() <v0>: * NEW: call(test(), test) -> <v0>
{ test() } <v0>: * COPY
=====================
{ // do nothing } !<v1>: *
test() <v0>: * NEW: call(test(), test) -> <v0>
{ test() } <v0>: * COPY
try { // do nothing } finally { test() } !<v1>: * COPY
{ try { // do nothing } finally { test() } } !<v1>: * COPY
=====================
@@ -7,5 +7,10 @@ tailRecursive fun test() : Int {
}
}
---------------------
test() <v0>: Int NEW: call(test(), test) -> <v0>
=====================
{ // do nothing } !<v2>: *
test() <v0>: Int NEW: call(test(), test) -> <v0>
return test() !<v1>: *
{ return test() } !<v1>: * COPY
try { // do nothing } finally { return test() } !<v2>: * COPY
{ try { // do nothing } finally { return test() } } !<v2>: * COPY
=====================
@@ -24,23 +24,23 @@ L0:
jf(L2|<v5>) NEXT:[read (Unit), r(sum) -> <v6>]
r(sum) -> <v6>
ret(*|<v6>) L1 NEXT:[<END>]
- jmp(L3) NEXT:[r(x) -> <v7>] PREV:[]
- jmp(L3) NEXT:[r(x) -> <v8>] PREV:[]
L2:
read (Unit) PREV:[jf(L2|<v5>)]
L3:
r(x) -> <v7>
r(1) -> <v8>
r(x) -> <v8>
r(1) -> <v9>
mark(x - 1)
call(x - 1, minus|<v7>, <v8>) -> <v9>
r(sum) -> <v10>
r(x) -> <v11>
call(x - 1, minus|<v8>, <v9>) -> <v10>
r(sum) -> <v11>
r(x) -> <v12>
mark(sum + x)
call(sum + x, plus|<v10>, <v11>) -> <v12>
call(sum + x, plus|<v11>, <v12>) -> <v13>
mark(sum(x - 1, sum + x))
call(sum(x - 1, sum + x), sum|<v9>, <v12>) -> <v13>
ret(*|<v13>) L1
call(sum(x - 1, sum + x), sum|<v10>, <v13>) -> <v14>
ret(*|<v14>) L1
L1:
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v6>) L1, ret(*|<v13>) L1]
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v6>) L1, ret(*|<v14>) L1]
error:
<ERROR> PREV:[]
sink:
+19 -15
View File
@@ -4,19 +4,23 @@ tailRecursive fun sum(x: Long, sum: Long): Long {
return sum(x - 1, sum + x)
}
---------------------
<v0>: Long NEW: magic[FAKE_INITIALIZER](x: Long) -> <v0>
<v1>: Long NEW: magic[FAKE_INITIALIZER](sum: Long) -> <v1>
x <v2>: OR{{<: Any}, {<: Any}} NEW: r(x) -> <v2>
0 <v3>: {<: Number} NEW: r(0) -> <v3>
toLong() <v4>: * NEW: call(toLong(), toLong|<v3>) -> <v4>
0.toLong() <v4>: * COPY
x == 0.toLong() <v5>: Boolean NEW: call(x == 0.toLong(), equals|<v2>, <v4>) -> <v5>
sum <v6>: Long NEW: r(sum) -> <v6>
x <v7>: Long NEW: r(x) -> <v7>
1 <v8>: Int NEW: r(1) -> <v8>
x - 1 <v9>: Long NEW: call(x - 1, minus|<v7>, <v8>) -> <v9>
sum <v10>: Long NEW: r(sum) -> <v10>
x <v11>: Long NEW: r(x) -> <v11>
sum + x <v12>: Long NEW: call(sum + x, plus|<v10>, <v11>) -> <v12>
sum(x - 1, sum + x) <v13>: Long NEW: call(sum(x - 1, sum + x), sum|<v9>, <v12>) -> <v13>
<v0>: Long NEW: magic[FAKE_INITIALIZER](x: Long) -> <v0>
<v1>: Long NEW: magic[FAKE_INITIALIZER](sum: Long) -> <v1>
x <v2>: OR{{<: Any}, {<: Any}} NEW: r(x) -> <v2>
0 <v3>: {<: Number} NEW: r(0) -> <v3>
toLong() <v4>: * NEW: call(toLong(), toLong|<v3>) -> <v4>
0.toLong() <v4>: * COPY
x == 0.toLong() <v5>: Boolean NEW: call(x == 0.toLong(), equals|<v2>, <v4>) -> <v5>
sum <v6>: Long NEW: r(sum) -> <v6>
return sum !<v7>: *
if (x == 0.toLong()) return sum !<v7>: * COPY
x <v8>: Long NEW: r(x) -> <v8>
1 <v9>: Int NEW: r(1) -> <v9>
x - 1 <v10>: Long NEW: call(x - 1, minus|<v8>, <v9>) -> <v10>
sum <v11>: Long NEW: r(sum) -> <v11>
x <v12>: Long NEW: r(x) -> <v12>
sum + x <v13>: Long NEW: call(sum + x, plus|<v11>, <v12>) -> <v13>
sum(x - 1, sum + x) <v14>: Long NEW: call(sum(x - 1, sum + x), sum|<v10>, <v13>) -> <v14>
return sum(x - 1, sum + x) !<v15>: *
{ if (x == 0.toLong()) return sum return sum(x - 1, sum + x) } !<v15>: * COPY
=====================
@@ -11,24 +11,25 @@ L0:
1 <START>
2 mark({ try { return foo() } catch (e: Throwable) { } })
mark(try { return foo() } catch (e: Throwable) { })
jmp?(L2 [onException]) NEXT:[v(e: Throwable), mark({ return foo() })]
jmp?(L2 [onException]) NEXT:[v(e: Throwable), mark({ return foo() })]
3 mark({ return foo() })
mark(foo())
call(foo(), foo) -> <v0>
ret(*|<v0>) L1 NEXT:[<END>]
- 2 jmp(L3 [afterCatches]) NEXT:[<END>] PREV:[]
ret(*|<v0>) L1 NEXT:[<END>]
- 2 jmp(L3 [afterCatches]) NEXT:[merge(try { return foo() } catch (e: Throwable) { }|!<v1>, !<v3>) -> <v4>] PREV:[]
L2 [onException]:
3 v(e: Throwable) PREV:[jmp?(L2 [onException])]
magic[FAKE_INITIALIZER](e: Throwable) -> <v1>
w(e|<v1>)
3 v(e: Throwable) PREV:[jmp?(L2 [onException])]
magic[FAKE_INITIALIZER](e: Throwable) -> <v2>
w(e|<v2>)
4 mark({ })
read (Unit)
3 jmp(L3 [afterCatches])
L1:
L3 [afterCatches]:
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v0>) L1, jmp(L3 [afterCatches])]
2 merge(try { return foo() } catch (e: Throwable) { }|!<v1>, !<v3>) -> <v4>
L1:
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v0>) L1, merge(try { return foo() } catch (e: Throwable) { }|!<v1>, !<v3>) -> <v4>]
error:
<ERROR> PREV:[]
<ERROR> PREV:[]
sink:
<SINK> PREV:[<ERROR>, <END>]
<SINK> PREV:[<ERROR>, <END>]
=====================
+7 -2
View File
@@ -7,6 +7,11 @@ tailRecursive fun foo() {
}
}
---------------------
<v1>: {<: Throwable} NEW: magic[FAKE_INITIALIZER](e: Throwable) -> <v1>
foo() <v0>: Unit NEW: call(foo(), foo) -> <v0>
<v2>: {<: Throwable} NEW: magic[FAKE_INITIALIZER](e: Throwable) -> <v2>
foo() <v0>: Unit NEW: call(foo(), foo) -> <v0>
return foo() !<v1>: *
{ return foo() } !<v1>: * COPY
{ } !<v3>: *
try { return foo() } catch (e: Throwable) { } <v4>: * NEW: merge(try { return foo() } catch (e: Throwable) { }|!<v1>, !<v3>) -> <v4>
{ try { return foo() } catch (e: Throwable) { } } <v4>: * COPY
=====================