Skip to content

Commit

Permalink
Tested nested arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-mike committed Jun 10, 2020
1 parent 6352aac commit 08e881a
Show file tree
Hide file tree
Showing 10 changed files with 2,746 additions and 1,883 deletions.
4 changes: 2 additions & 2 deletions dist-c/microvium.c
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ static void gc_traceValue(vm_TsGCCollectionState* gc, Value value) {
CODE_COVERAGE(201); // Hit
gc_traceValueOnNewTraceStack(gc, value);
} else {
CODE_COVERAGE_UNTESTED(407); // Not hit
CODE_COVERAGE(407); // Hit
*gc->pTraceStackItem++ = value;
}
}
Expand Down Expand Up @@ -2736,7 +2736,7 @@ static void gc_traceValueOnNewTraceStack(vm_TsGCCollectionState* gc, Value value
// While there are items on the stack to be processed
while (gc->pTraceStackItem != traceStack) {
uint8_t itemIndex = gc->pTraceStackItem - traceStack;
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 1/2
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 2/2
// Pop item off stack
uint16_t pAllocation = *(--(gc->pTraceStackItem));

Expand Down
4 changes: 2 additions & 2 deletions native-vm/microvium.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ static void gc_traceValue(vm_TsGCCollectionState* gc, Value value) {
CODE_COVERAGE(201); // Hit
gc_traceValueOnNewTraceStack(gc, value);
} else {
CODE_COVERAGE_UNTESTED(407); // Not hit
CODE_COVERAGE(407); // Hit
*gc->pTraceStackItem++ = value;
}
}
Expand Down Expand Up @@ -1944,7 +1944,7 @@ static void gc_traceValueOnNewTraceStack(vm_TsGCCollectionState* gc, Value value
// While there are items on the stack to be processed
while (gc->pTraceStackItem != traceStack) {
uint8_t itemIndex = gc->pTraceStackItem - traceStack;
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 1/2
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 2/2
// Pop item off stack
uint16_t pAllocation = *(--(gc->pTraceStackItem));

Expand Down
1,106 changes: 638 additions & 468 deletions test/end-to-end/artifacts/arrays/1.post-load.mvm-bc.disassembly

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions test/end-to-end/artifacts/arrays/1.post-load.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export 0 = &function ['./test/end-to-end/tests/arrays.test.mvms:run'];
slot ['./test/end-to-end/tests/arrays.test.mvms:a'] = &allocation 6;
slot ['./test/end-to-end/tests/arrays.test.mvms:b'] = &allocation 7;
slot ['./test/end-to-end/tests/arrays.test.mvms:c'] = &allocation 8;
slot ['./test/end-to-end/tests/arrays.test.mvms:d'] = &allocation 9;
slot ['./test/end-to-end/tests/arrays.test.mvms:init'] = &function ['./test/end-to-end/tests/arrays.test.mvms:init'];
slot ['./test/end-to-end/tests/arrays.test.mvms:testArrays'] = &function ['./test/end-to-end/tests/arrays.test.mvms:testArrays'];
slot ['global:assert'] = host function 2;
Expand Down Expand Up @@ -46,6 +47,46 @@ function ['./test/end-to-end/tests/arrays.test.mvms:init']() {
LoadVar(index 0);
StoreGlobal(name './test/end-to-end/tests/arrays.test.mvms:c');
Pop(count 1);
ArrayNew();
LoadVar(index 0);
Literal(lit 0);
ArrayNew();
LoadVar(index 3);
Literal(lit 0);
ArrayNew();
LoadVar(index 6);
Literal(lit 0);
Literal(lit 1);
ObjectSet();
LoadVar(index 6);
Literal(lit 1);
Literal(lit 2);
ObjectSet();
ObjectSet();
LoadVar(index 3);
Literal(lit 1);
ArrayNew();
LoadVar(index 6);
Literal(lit 0);
Literal(lit 3);
ObjectSet();
LoadVar(index 6);
Literal(lit 1);
Literal(lit 4);
ObjectSet();
ObjectSet();
LoadVar(index 3);
Literal(lit 2);
Literal(lit 5);
ObjectSet();
ObjectSet();
LoadVar(index 0);
Literal(lit 1);
Literal(lit 6);
ObjectSet();
LoadVar(index 0);
StoreGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Pop(count 1);
Literal(lit undefined);
Return();
}
Expand Down Expand Up @@ -511,6 +552,103 @@ function ['./test/end-to-end/tests/arrays.test.mvms:testArrays']() {
Literal(lit 30);
Call(count 3);
Pop(count 1);
// See that the nested arrays are correct
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 'length');
ObjectGet();
Literal(lit 2);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 'length');
ObjectGet();
Literal(lit 3);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 0);
ObjectGet();
Literal(lit 'length');
ObjectGet();
Literal(lit 2);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 0);
ObjectGet();
Literal(lit 0);
ObjectGet();
Literal(lit 1);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 0);
ObjectGet();
Literal(lit 1);
ObjectGet();
Literal(lit 2);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 1);
ObjectGet();
Literal(lit 0);
ObjectGet();
Literal(lit 3);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 1);
ObjectGet();
Literal(lit 1);
ObjectGet();
Literal(lit 4);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 0);
ObjectGet();
Literal(lit 2);
ObjectGet();
Literal(lit 5);
Call(count 3);
Pop(count 1);
LoadGlobal(name 'global:assertEqual');
Literal(lit undefined);
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
Literal(lit 1);
ObjectGet();
Literal(lit 6);
Call(count 3);
Pop(count 1);
// Reset the arrays to their initial state, because this test runs multiple
// times (before and after the snapshot)
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:init');
Expand All @@ -536,6 +674,22 @@ function ['<builtin>:Array_push']() {
Return();
}

allocation 10 = [
&allocation 11,
&allocation 12,
5,
];

allocation 11 = [
1,
2,
];

allocation 12 = [
3,
4,
];

allocation 3 = {
push: &function ['<builtin>:Array_push'],
};
Expand All @@ -554,4 +708,9 @@ allocation 8 = [
,
3,
,
];

allocation 9 = [
&allocation 10,
6,
];
Loading

0 comments on commit 08e881a

Please sign in to comment.