Skip to content

Commit 08e881a

Browse files
committed
Tested nested arrays
1 parent 6352aac commit 08e881a

File tree

10 files changed

+2746
-1883
lines changed

10 files changed

+2746
-1883
lines changed

dist-c/microvium.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ static void gc_traceValue(vm_TsGCCollectionState* gc, Value value) {
26812681
CODE_COVERAGE(201); // Hit
26822682
gc_traceValueOnNewTraceStack(gc, value);
26832683
} else {
2684-
CODE_COVERAGE_UNTESTED(407); // Not hit
2684+
CODE_COVERAGE(407); // Hit
26852685
*gc->pTraceStackItem++ = value;
26862686
}
26872687
}
@@ -2736,7 +2736,7 @@ static void gc_traceValueOnNewTraceStack(vm_TsGCCollectionState* gc, Value value
27362736
// While there are items on the stack to be processed
27372737
while (gc->pTraceStackItem != traceStack) {
27382738
uint8_t itemIndex = gc->pTraceStackItem - traceStack;
2739-
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 1/2
2739+
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 2/2
27402740
// Pop item off stack
27412741
uint16_t pAllocation = *(--(gc->pTraceStackItem));
27422742

native-vm/microvium.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ static void gc_traceValue(vm_TsGCCollectionState* gc, Value value) {
18891889
CODE_COVERAGE(201); // Hit
18901890
gc_traceValueOnNewTraceStack(gc, value);
18911891
} else {
1892-
CODE_COVERAGE_UNTESTED(407); // Not hit
1892+
CODE_COVERAGE(407); // Hit
18931893
*gc->pTraceStackItem++ = value;
18941894
}
18951895
}
@@ -1944,7 +1944,7 @@ static void gc_traceValueOnNewTraceStack(vm_TsGCCollectionState* gc, Value value
19441944
// While there are items on the stack to be processed
19451945
while (gc->pTraceStackItem != traceStack) {
19461946
uint8_t itemIndex = gc->pTraceStackItem - traceStack;
1947-
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 1/2
1947+
TABLE_COVERAGE(itemIndex - 1 ? 1 : 0, 2, 491); // Hit 2/2
19481948
// Pop item off stack
19491949
uint16_t pAllocation = *(--(gc->pTraceStackItem));
19501950

test/end-to-end/artifacts/arrays/1.post-load.mvm-bc.disassembly

Lines changed: 638 additions & 468 deletions
Large diffs are not rendered by default.

test/end-to-end/artifacts/arrays/1.post-load.snapshot

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export 0 = &function ['./test/end-to-end/tests/arrays.test.mvms:run'];
33
slot ['./test/end-to-end/tests/arrays.test.mvms:a'] = &allocation 6;
44
slot ['./test/end-to-end/tests/arrays.test.mvms:b'] = &allocation 7;
55
slot ['./test/end-to-end/tests/arrays.test.mvms:c'] = &allocation 8;
6+
slot ['./test/end-to-end/tests/arrays.test.mvms:d'] = &allocation 9;
67
slot ['./test/end-to-end/tests/arrays.test.mvms:init'] = &function ['./test/end-to-end/tests/arrays.test.mvms:init'];
78
slot ['./test/end-to-end/tests/arrays.test.mvms:testArrays'] = &function ['./test/end-to-end/tests/arrays.test.mvms:testArrays'];
89
slot ['global:assert'] = host function 2;
@@ -46,6 +47,46 @@ function ['./test/end-to-end/tests/arrays.test.mvms:init']() {
4647
LoadVar(index 0);
4748
StoreGlobal(name './test/end-to-end/tests/arrays.test.mvms:c');
4849
Pop(count 1);
50+
ArrayNew();
51+
LoadVar(index 0);
52+
Literal(lit 0);
53+
ArrayNew();
54+
LoadVar(index 3);
55+
Literal(lit 0);
56+
ArrayNew();
57+
LoadVar(index 6);
58+
Literal(lit 0);
59+
Literal(lit 1);
60+
ObjectSet();
61+
LoadVar(index 6);
62+
Literal(lit 1);
63+
Literal(lit 2);
64+
ObjectSet();
65+
ObjectSet();
66+
LoadVar(index 3);
67+
Literal(lit 1);
68+
ArrayNew();
69+
LoadVar(index 6);
70+
Literal(lit 0);
71+
Literal(lit 3);
72+
ObjectSet();
73+
LoadVar(index 6);
74+
Literal(lit 1);
75+
Literal(lit 4);
76+
ObjectSet();
77+
ObjectSet();
78+
LoadVar(index 3);
79+
Literal(lit 2);
80+
Literal(lit 5);
81+
ObjectSet();
82+
ObjectSet();
83+
LoadVar(index 0);
84+
Literal(lit 1);
85+
Literal(lit 6);
86+
ObjectSet();
87+
LoadVar(index 0);
88+
StoreGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
89+
Pop(count 1);
4990
Literal(lit undefined);
5091
Return();
5192
}
@@ -511,6 +552,103 @@ function ['./test/end-to-end/tests/arrays.test.mvms:testArrays']() {
511552
Literal(lit 30);
512553
Call(count 3);
513554
Pop(count 1);
555+
// See that the nested arrays are correct
556+
LoadGlobal(name 'global:assertEqual');
557+
Literal(lit undefined);
558+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
559+
Literal(lit 'length');
560+
ObjectGet();
561+
Literal(lit 2);
562+
Call(count 3);
563+
Pop(count 1);
564+
LoadGlobal(name 'global:assertEqual');
565+
Literal(lit undefined);
566+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
567+
Literal(lit 0);
568+
ObjectGet();
569+
Literal(lit 'length');
570+
ObjectGet();
571+
Literal(lit 3);
572+
Call(count 3);
573+
Pop(count 1);
574+
LoadGlobal(name 'global:assertEqual');
575+
Literal(lit undefined);
576+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
577+
Literal(lit 0);
578+
ObjectGet();
579+
Literal(lit 0);
580+
ObjectGet();
581+
Literal(lit 'length');
582+
ObjectGet();
583+
Literal(lit 2);
584+
Call(count 3);
585+
Pop(count 1);
586+
LoadGlobal(name 'global:assertEqual');
587+
Literal(lit undefined);
588+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
589+
Literal(lit 0);
590+
ObjectGet();
591+
Literal(lit 0);
592+
ObjectGet();
593+
Literal(lit 0);
594+
ObjectGet();
595+
Literal(lit 1);
596+
Call(count 3);
597+
Pop(count 1);
598+
LoadGlobal(name 'global:assertEqual');
599+
Literal(lit undefined);
600+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
601+
Literal(lit 0);
602+
ObjectGet();
603+
Literal(lit 0);
604+
ObjectGet();
605+
Literal(lit 1);
606+
ObjectGet();
607+
Literal(lit 2);
608+
Call(count 3);
609+
Pop(count 1);
610+
LoadGlobal(name 'global:assertEqual');
611+
Literal(lit undefined);
612+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
613+
Literal(lit 0);
614+
ObjectGet();
615+
Literal(lit 1);
616+
ObjectGet();
617+
Literal(lit 0);
618+
ObjectGet();
619+
Literal(lit 3);
620+
Call(count 3);
621+
Pop(count 1);
622+
LoadGlobal(name 'global:assertEqual');
623+
Literal(lit undefined);
624+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
625+
Literal(lit 0);
626+
ObjectGet();
627+
Literal(lit 1);
628+
ObjectGet();
629+
Literal(lit 1);
630+
ObjectGet();
631+
Literal(lit 4);
632+
Call(count 3);
633+
Pop(count 1);
634+
LoadGlobal(name 'global:assertEqual');
635+
Literal(lit undefined);
636+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
637+
Literal(lit 0);
638+
ObjectGet();
639+
Literal(lit 2);
640+
ObjectGet();
641+
Literal(lit 5);
642+
Call(count 3);
643+
Pop(count 1);
644+
LoadGlobal(name 'global:assertEqual');
645+
Literal(lit undefined);
646+
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:d');
647+
Literal(lit 1);
648+
ObjectGet();
649+
Literal(lit 6);
650+
Call(count 3);
651+
Pop(count 1);
514652
// Reset the arrays to their initial state, because this test runs multiple
515653
// times (before and after the snapshot)
516654
LoadGlobal(name './test/end-to-end/tests/arrays.test.mvms:init');
@@ -536,6 +674,22 @@ function ['<builtin>:Array_push']() {
536674
Return();
537675
}
538676

677+
allocation 10 = [
678+
&allocation 11,
679+
&allocation 12,
680+
5,
681+
];
682+
683+
allocation 11 = [
684+
1,
685+
2,
686+
];
687+
688+
allocation 12 = [
689+
3,
690+
4,
691+
];
692+
539693
allocation 3 = {
540694
push: &function ['<builtin>:Array_push'],
541695
};
@@ -554,4 +708,9 @@ allocation 8 = [
554708
,
555709
3,
556710
,
711+
];
712+
713+
allocation 9 = [
714+
&allocation 10,
715+
6,
557716
];

0 commit comments

Comments
 (0)