Stabel

Check-in [f3dcfa50ab]
Login
Overview
Comment:Added tests to verify correct array implementation.
Timelines: family | ancestors | descendants | both | arrays
Files: files | file ages | folders
SHA3-256: f3dcfa50ab0833541e125531bf0623be9016b83302dd5330eff779578c0e446e
User & Date: robin.hansen on 2021-08-29 17:50:31
Other Links: branch diff | manifest | tags
Context
2021-08-30
17:02
It's now possible to reference arrays in the type system. check-in: 9b06579c64 user: robin.hansen tags: arrays
2021-08-29
17:50
Added tests to verify correct array implementation. check-in: f3dcfa50ab user: robin.hansen tags: arrays
17:32
Simplify implementation of array-get by using a block and break-if, instead of if instructions with ... check-in: 38a80b873f user: robin.hansen tags: arrays
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified tests/Test/Qualifier/Errors.elm from [904e91d942] to [064ee3fb26].

71
72
73
74
75
76
77













78
79
80
81
82
83
84
                            """
                            defstruct: BoxWrapper
                            : box Box
                            """
                    in
                    checkForError (noSuchTypeReferenceError "Box") source
            ]













        ]


noSuchWordReferenceError : String -> Problem -> Bool
noSuchWordReferenceError name problem =
    case problem of
        UnknownFunctionRef _ problemName ->







>
>
>
>
>
>
>
>
>
>
>
>
>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
                            """
                            defstruct: BoxWrapper
                            : box Box
                            """
                    in
                    checkForError (noSuchTypeReferenceError "Box") source
            ]
        , test "Wrong reference within array literal" <|
            \_ ->
                let
                    source =
                        """
                        def: main
                        : { one two }

                        def: one
                        : 1
                        """
                in
                checkForError (noSuchWordReferenceError "two") source
        ]


noSuchWordReferenceError : String -> Problem -> Bool
noSuchWordReferenceError name problem =
    case problem of
        UnknownFunctionRef _ problemName ->

Modified wasm_tests/array.test.js from [0d3ab8746c] to [89a278769b].

17
18
19
20
21
22
23














24
25
26
27
28
29
30
..
70
71
72
73
74
75
76
















77
78
79
80
81
82
83
        : { 1 2 3 4 5 } array-length
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(5);
});















test('Pushing', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : {}
          2 array-push
          1 array-push
................................................................................
          swap drop
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(7);
});

















test('Get succeess', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          1 array-get
          drop







>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        : { 1 2 3 4 5 } array-length
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(5);
});

test('Literal with function reference', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 1 five 3 } array-length

        def: five
        : 5
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(3);
});

test('Pushing', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : {}
          2 array-push
          1 array-push
................................................................................
          swap drop
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(7);
});

test('Get function value', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 six 7 }
          1 array-get
          swap drop

        def: six
        : 6
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(6);
});

test('Get succeess', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          1 array-get
          drop