Stabel

Check-in [b5b13855e1]
Login
Overview
Comment:Fixed several new tests by adding an array module to the standard_library.
Timelines: family | ancestors | descendants | both | builtin-rewrite
Files: files | file ages | folders
SHA3-256: b5b13855e1d37dec27484d3ee0879f9ae70aae245c1d75ccc3335840b7d1ef7e
User & Date: robin.hansen on 2021-10-07 17:34:46
Other Links: branch diff | manifest | tags
Context
2021-10-08
09:36
Add array module, which I forgot in previous commit. Also change maybe type to not have a generic me... check-in: 421178a365 user: robin.hansen tags: builtin-rewrite
2021-10-07
17:34
Fixed several new tests by adding an array module to the standard_library. check-in: b5b13855e1 user: robin.hansen tags: builtin-rewrite
06:32
Update dependencies. check-in: ec22ca8835 user: robin.hansen tags: builtin-rewrite
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified stdlib/stabel.json from [3deb26f18d] to [ddd5fdde34].

3
4
5
6
7
8
9

10
11
12
13
14
    "version": "0.2.1",
    "language-version": "0.2.0",
    "exposed-modules": [
        "core",
        "maybe",
        "pair",
        "list",

        "string"
    ],
    "dependencies": {},
    "package-paths": []
}







>





3
4
5
6
7
8
9
10
11
12
13
14
15
    "version": "0.2.1",
    "language-version": "0.2.0",
    "exposed-modules": [
        "core",
        "maybe",
        "pair",
        "list",
        "array",
        "string"
    ],
    "dependencies": {},
    "package-paths": []
}

Modified wasm_tests/array.test.js from [f6c84686e8] to [7c0618317d].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
98
99
100
101
102
103
104
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
239
240
241
242
243
244
245
246
247
248
249
250
251
252
const compiler = require('./compiler.wrapper');

test('Empty', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : {} array-length
    `);

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

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

test('Simple literal', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 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
          array-length
    `);

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

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

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

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

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

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

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

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

test('Get last', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          2 array-get
          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
    `);

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

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

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

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

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

test('Set works', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 8 }
          20
          2 array-set
          2 array-get
          swap drop
    `);

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

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

test('Type annotation', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- Int
        : { 5 6 7 8 } array-length
    `);

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

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

test('Type tightening', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- Int
        : empty array-length

        def: empty
        type: -- (Array Int)
        : {}
    `);

    const result = await compiler.run(wat, 'main');
................................................................................
        defunion: Test
        : Int
        : Array Int

        def: main
        type: -- Int
        : { 5 { 1 2 3 } }
          1 array-get
          swap drop
          to-num

        defmulti: to-num
        type: Test -- Int
        : Int
          # do nothing
        : Array
          array-length
    `);

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

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

................................................................................
        defunion: Test
        : Int
        : Array Int

        def: main
        type: -- Int
        : { 5 { 1 2 3 } }
          0 array-get
          swap drop
          to-num

        defmulti: to-num
        type: Test -- Int
        : Int
          # do nothing
        : Array
          array-length
    `);

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

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

................................................................................
          to-num

        defmulti: to-num
        type: Test -- Int
        : Int
          # do nothing
        : Array
          array-length
    `);

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

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





|










|










|







 







|
|
|











|
|











|
|











|
|











|
|







 







|
|




|







|
|












|
|
|











|











|







 







|
|







|







 







|
|







|







 







|






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
98
99
100
101
102
103
104
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
239
240
241
242
243
244
245
246
247
248
249
250
251
252
const compiler = require('./compiler.wrapper');

test('Empty', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : {} /array/length
    `);

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

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

test('Simple literal', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 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
          /array/length
    `);

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

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

test('Get first', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          0 /array/get
          0 /maybe/when-nothing
    `);

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

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

test('Get second', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          1 /array/get
          0 /maybe/when-nothing
    `);

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

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

test('Get last', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          2 /array/get
          0 /maybe/when-nothing
    `);

    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
          0 /maybe/when-nothing

        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
          0 /maybe/when-nothing
    `);

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

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

test('Get out of lower bound', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          0 1 -
          /array/get
          0 /maybe/when-nothing
    `);

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

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

test('Set works', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 8 }
          20
          2 /array/set
          2 /array/get
          0 /maybe/when-nothing
    `);

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

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

test('Type annotation', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- Int
        : { 5 6 7 8 } /array/length
    `);

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

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

test('Type tightening', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- Int
        : empty /array/length

        def: empty
        type: -- (Array Int)
        : {}
    `);

    const result = await compiler.run(wat, 'main');
................................................................................
        defunion: Test
        : Int
        : Array Int

        def: main
        type: -- Int
        : { 5 { 1 2 3 } }
          1 /array/get
          0 /maybe/when-nothing
          to-num

        defmulti: to-num
        type: Test -- Int
        : Int
          # do nothing
        : Array
          /array/length
    `);

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

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

................................................................................
        defunion: Test
        : Int
        : Array Int

        def: main
        type: -- Int
        : { 5 { 1 2 3 } }
          0 /array/get
          0 /maybe/when-nothing
          to-num

        defmulti: to-num
        type: Test -- Int
        : Int
          # do nothing
        : Array
          /array/length
    `);

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

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

................................................................................
          to-num

        defmulti: to-num
        type: Test -- Int
        : Int
          # do nothing
        : Array
          /array/length
    `);

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

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

Modified wasm_tests/compiler.wrapper.js from [7fecc2bfc7] to [ea1069ebe7].

139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156

    // ordering is important
    const files = [
        'core.stbl',
        'pair.stbl',
        'maybe.stbl',
        'list.stbl',

        'string.stbl'
    ];

    return files.map((module) => {
        return {
            package: 'stabel/standard_library',
            module: module.replace(".stbl", ""),
            source: fs.readFileSync(path.join(stdLibSrcPath, module), 'utf-8')
        };
    })
}







>











139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

    // ordering is important
    const files = [
        'core.stbl',
        'pair.stbl',
        'maybe.stbl',
        'list.stbl',
        'array.stbl',
        'string.stbl'
    ];

    return files.map((module) => {
        return {
            package: 'stabel/standard_library',
            module: module.replace(".stbl", ""),
            source: fs.readFileSync(path.join(stdLibSrcPath, module), 'utf-8')
        };
    })
}