Stabel

Check-in [8175ad89cd]
Login
Overview
Comment:Include standard_library when running integration tests. Some tests still fail.
Timelines: family | ancestors | descendants | both | builtin-rewrite
Files: files | file ages | folders
SHA3-256: 8175ad89cd190f4288192b0769e2cf246cae3aa63e17e61f99ac54c372ad884e
User & Date: robin.hansen on 2021-10-06 15:42:08
Other Links: branch diff | manifest | tags
Context
2021-10-07
06:32
Update dependencies. check-in: ec22ca8835 user: robin.hansen tags: builtin-rewrite
2021-10-06
15:42
Include standard_library when running integration tests. Some tests still fail. check-in: 8175ad89cd user: robin.hansen tags: builtin-rewrite
2021-09-30
16:52
Fixed remaining Elm tests. check-in: 3dc236ef66 user: robin.hansen tags: builtin-rewrite
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/TestCompiler.elm from [8b48cbd435] to [65cb3d9afc].

141
142
143
144
145
146
147

148
149
150
151
152
153
154
...
212
213
214
215
216
217
218

219
220
221
222
223
224
225

        Ok ast ->
            let
                qualifierResult =
                    Qualifier.run
                        { packageName = ""
                        , modulePath = ""

                        , ast = ast
                        , externalModules = Dict.empty
                        , inProgressAST = emptyQualifierAst
                        }

                exportedFunctions =
                    Set.singleton opts.entryPoint
................................................................................
                |> formatParserErrors ParserProblem.toString

        Ok withAst ->
            let
                initialConfig =
                    { packageName = ""
                    , modulePath = ""

                    , ast =
                        { sourceReference = "test"
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions = Dict.empty
                        }
                    , externalModules = Dict.empty







>







 







>







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

        Ok ast ->
            let
                qualifierResult =
                    Qualifier.run
                        { packageName = ""
                        , modulePath = ""
                        , mangle = False
                        , ast = ast
                        , externalModules = Dict.empty
                        , inProgressAST = emptyQualifierAst
                        }

                exportedFunctions =
                    Set.singleton opts.entryPoint
................................................................................
                |> formatParserErrors ParserProblem.toString

        Ok withAst ->
            let
                initialConfig =
                    { packageName = ""
                    , modulePath = ""
                    , mangle = True
                    , ast =
                        { sourceReference = "test"
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions = Dict.empty
                        }
                    , externalModules = Dict.empty

Modified stdlib/src/core.stbl from [ae46c9c3bd] to [5ac7551356].

1




2
3
4
5
6
7











8
9
10
11
12
13
14
..
16
17
18
19
20
21
22
23
24












































25
26
27
28
29
30
31
32
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
defmodule:




exposing:
  Bool
  True
  True>
  False
  False>











  not
  select
  if
  dip
  over
  drop2
  split
................................................................................
  int=
  negate
  square
  inc
  dec
:

# Everything in core is imported into every module outside the standard library













































# booleans

defunion: Bool
: True
: False

defstruct: True
defstruct: False
................................................................................
: False
  rotate drop2

def: if
type: a... Bool [ a... -- b... ] [ a... -- b... ] -- b...
: select !

# stack manipulation

def: dip
type: a b [ a -- c ] -- c b
: swap rotate ! swap

def: over
type: a b -- a b a
................................................................................
type: a [ a -- b ] [ a -- c ] -- b c
: -rotate dup # [] [] a a
  -rotate ! # [] a c
  swap -rotate # c a []
  ! # c b
  swap
  
# numbers

defmulti: zero?
type: Int -- Bool
: Int( value 0 )
  drop True>
: Int
  drop False>

def: int=
type: Int Int -- Bool
: - zero?

>
>
>
>






>
>
>
>
>
>
>
>
>
>
>







 







|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







|







 







|



|







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
..
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
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
defmodule:
doc: """
Everything in this module is implicitly imported into every module outside
of the standard library.
"""
exposing:
  Bool
  True
  True>
  False
  False>
  +
  -
  *
  div
  =
  swap
  dup
  drop
  rotate
  -rotate
  !
  not
  select
  if
  dip
  over
  drop2
  split
................................................................................
  int=
  negate
  square
  inc
  dec
:

## Primitives

def: +
type: Int Int -- Int
: //stabel/hidden/int/+

def: -
type: Int Int -- Int
: //stabel/hidden/int/-

def: *
type: Int Int -- Int
: //stabel/hidden/int/*

def: div
type: Int Int -- Int
: //stabel/hidden/int/div

def: =
type: Int Int -- Int
: //stabel/hidden/int/=

def: swap
type: a b -- b a
: //stabel/hidden/stack/swap

def: dup
type: a -- a a
: //stabel/hidden/stack/dup

def: drop
type: a --
: //stabel/hidden/stack/drop

def: rotate
type: a b c -- c a b
: //stabel/hidden/stack/rotate

def: -rotate
type: a b c -- b c a
: //stabel/hidden/stack/-rotate

def: !
type: a... [ a... -- b... ] -- b...
: //stabel/hidden/stack/!

## Booleans

defunion: Bool
: True
: False

defstruct: True
defstruct: False
................................................................................
: False
  rotate drop2

def: if
type: a... Bool [ a... -- b... ] [ a... -- b... ] -- b...
: select !

## Stack manipulation

def: dip
type: a b [ a -- c ] -- c b
: swap rotate ! swap

def: over
type: a b -- a b a
................................................................................
type: a [ a -- b ] [ a -- c ] -- b c
: -rotate dup # [] [] a a
  -rotate ! # [] a c
  swap -rotate # c a []
  ! # c b
  swap
  
## Numbers

defmulti: zero?
type: Int -- Bool
: 0
  drop True>
: Int
  drop False>

def: int=
type: Int Int -- Bool
: - zero?

Modified stdlib/src/list.stbl from [d0bea91b6e] to [bf521e8b04].

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

def: of-three
type: a a a -- (NonEmpty a)
: Empty> >NonEmpty >NonEmpty >NonEmpty

def: ,
type: (List a) a -- (NonEmpty a)
: swap >NonEmpty

defmulti: fold
type: (List a) b [ a b -- b ] -- b
: Empty
  drop swap drop
: NonEmpty
  pair/>Pair
  swap # (Pair b quot) (NonEmpty a)
  [ first> ] [ rest> ] core/split # Pair first rest
  rotate swap # rest first Pair
  dup rotate # rest Pair first Pair
  pair/spill # rest Pair first b quot
  ! # rest Pair b
  swap pair/second> # rest b quot
  fold

def: reverse
type: (List a) -- (List a)
: Empty> [ >NonEmpty ] fold

def: fold-reverse
type: (List a) b [ a b -- b ] -- b
: -rotate reverse rotate fold







|




|


|

|
|

|
|








|
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

def: of-three
type: a a a -- (NonEmpty a)
: Empty> >NonEmpty >NonEmpty >NonEmpty

def: ,
type: (List a) a -- (NonEmpty a)
: core/swap >NonEmpty

defmulti: fold
type: (List a) b [ a b -- b ] -- b
: Empty
  core/drop core/swap core/drop
: NonEmpty
  pair/>Pair
  core/swap # (Pair b quot) (NonEmpty a)
  [ first> ] [ rest> ] core/split # Pair first rest
  core/rotate core/swap # rest first Pair
  core/dup core/rotate # rest Pair first Pair
  pair/spill # rest Pair first b quot
  core/! # rest Pair b
  core/swap pair/second> # rest b quot
  fold

def: reverse
type: (List a) -- (List a)
: Empty> [ >NonEmpty ] fold

def: fold-reverse
type: (List a) b [ a b -- b ] -- b
: core/-rotate reverse core/rotate fold

Modified stdlib/src/maybe.stbl from [11fdd7a2d5] to [0d0fb7d9a8].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
: Nothing

defstruct: Nothing

defmulti: map
type: (Maybe a) [ a -- b ] -- (Maybe b)
: a
  !
: Nothing
  drop

defmulti: when-nothing
type: (Maybe a) a -- a
: a
  drop
: Nothing
  swap drop








|
|
|




|

|

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
: Nothing

defstruct: Nothing

defmulti: map
type: (Maybe a) [ a -- b ] -- (Maybe b)
: a
  core/!
: Nothing
  core/drop

defmulti: when-nothing
type: (Maybe a) a -- a
: a
  core/drop
: Nothing
  core/swap core/drop

Modified stdlib/src/pair.stbl from [6c626d6606] to [abdd4bf1d3].

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

def: spill
type: (Pair a b) -- a b
: [ first> ] [ second> ] core/split

def: map
type: (Pair a b) [ a b -- c d ] -- (Pair c d)
: swap spill -rotate ! >Pair

def: map-first
type: (Pair a b) [ a -- c ] -- (Pair c b)
: core/over first> swap ! >first

def: map-second
type: (Pair a b) [ b -- c ] -- (Pair a c)
: core/over second> swap ! >second







|



|



|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

def: spill
type: (Pair a b) -- a b
: [ first> ] [ second> ] core/split

def: map
type: (Pair a b) [ a b -- c d ] -- (Pair c d)
: core/swap spill core/-rotate core/! >Pair

def: map-first
type: (Pair a b) [ a -- c ] -- (Pair c b)
: core/over first> core/swap core/! >first

def: map-second
type: (Pair a b) [ b -- c ] -- (Pair a c)
: core/over second> core/swap core/! >second

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

1
2
3




4
5
6
7
8
9
10



11

12
13
14
15
16
17
18
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
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
..
97
98
99
100
101
102
103









104
105
106
107
108
109
110
111
...
140
141
142
143
144
145
146






















const Compiler = require('./compiler.js');
const wabtInit = require('wabt');
const stripIndent = require('strip-indent');





exports.toWat = function toWat(entry, sourceCode) {
    return new Promise((resolve, reject) => {
        const compiler = Compiler.Elm.TestCompiler.init({
            flags: {
                __type: 'CompileString',
                entryPoint: entry,



                sourceCode: stripIndent(sourceCode)

            }
        });

        compiler.ports.compileFinished.subscribe(([ok, output]) => {
            if (ok) {
                if (output.indexOf('unreachable') >= 0) {
                    reject('output contains \'unreachable\' instruction');
................................................................................

function toProjectWat(payload) {
    return new Promise((resolve, reject) => {
        const compiler = Compiler.Elm.TestCompiler.init({
            flags: {
                __type: 'CompileProject',
                entryPoint: payload.entryPoint,
                modules: payload.modules.map((mod) => {
                    mod.source = stripIndent(mod.source)
                    return mod
                })
            }
        });

        compiler.ports.compileFinished.subscribe(([ok, output]) => {
            if (ok) {
                if (output.indexOf('unreachable') >= 0) {
                    reject('output contains \'unreachable\' instruction');
................................................................................
            }
        });
    });
}

exports.toProjectWat = toProjectWat;

exports.toStringWat = function toStringWat(entry, sourceCode) {
    return toProjectWat({
        entryPoint: `/author/sample/core/${entry}`,
        modules: [
            {
                package: 'stabel/standard_library',
                module: 'string',
                source: `
                    defmodule:
                    exposing: String from-bytes
                    :

                    defstruct: String
                    : content Array Int

                    def: from-bytes
                    type: (Array Int) -- String
                    : >String
                `
            },
            {
                package: 'author/sample',
                module: 'core',
                source: stripIndent(sourceCode)
            }
        ]
    });
}

exports.run = async function run(wat, functionName) {
    const wabt = await wabtInit();
    const wasmModule = wabt.parseWat('tmp', wat, {
        bulk_memory: true
    }).toBinary({}).buffer;

    const memory = new WebAssembly.Memory({
................................................................................
    const imports = {
        host: {
            memory: memory
        }
    };

    const program = await WebAssembly.instantiate(wasmModule, imports);









    program.instance.exports[functionName]();

    return new ExecutionResult(memory.buffer);
}

class ExecutionResult {
    constructor(memoryBuffer) {
        this.memoryView = new Uint32Array(memoryBuffer, 0, 512);
................................................................................

    typeIdForPointer(index) {
        const pointer = this.stackElement(index || 0);
        const wordPointer = pointer / 4;
        return this.memoryView[wordPointer];
    }
}

























>
>
>
>





|
|
>
>
>
|
>







 







|


|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
59
60
61
62
63
64
65





























66
67
68
69
70
71
72
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
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
const Compiler = require('./compiler.js');
const wabtInit = require('wabt');
const stripIndent = require('strip-indent');
const fs = require('fs');
const path = require('path');

const stdLib = loadStdLib();

exports.toWat = function toWat(entry, sourceCode) {
    return new Promise((resolve, reject) => {
        const compiler = Compiler.Elm.TestCompiler.init({
            flags: {
                __type: 'CompileProject',
                entryPoint: `/author/sample/test/${entry}`,
                modules: stdLib.concat([{
                    package: 'author/sample',
                    module: 'test',
                    source: stripIndent(sourceCode)
                }])
            }
        });

        compiler.ports.compileFinished.subscribe(([ok, output]) => {
            if (ok) {
                if (output.indexOf('unreachable') >= 0) {
                    reject('output contains \'unreachable\' instruction');
................................................................................

function toProjectWat(payload) {
    return new Promise((resolve, reject) => {
        const compiler = Compiler.Elm.TestCompiler.init({
            flags: {
                __type: 'CompileProject',
                entryPoint: payload.entryPoint,
                modules: stdLib.concat(payload.modules.map((mod) => {
                    mod.source = stripIndent(mod.source)
                    return mod
                }))
            }
        });

        compiler.ports.compileFinished.subscribe(([ok, output]) => {
            if (ok) {
                if (output.indexOf('unreachable') >= 0) {
                    reject('output contains \'unreachable\' instruction');
................................................................................
            }
        });
    });
}

exports.toProjectWat = toProjectWat;






























exports.run = async function run(wat, functionName) {
    const wabt = await wabtInit();
    const wasmModule = wabt.parseWat('tmp', wat, {
        bulk_memory: true
    }).toBinary({}).buffer;

    const memory = new WebAssembly.Memory({
................................................................................
    const imports = {
        host: {
            memory: memory
        }
    };

    const program = await WebAssembly.instantiate(wasmModule, imports);

    let exportedId = null;
    for (let id in program.instance.exports) {
        if (id.endsWith(functionName)) {
            exportedId = id;
            break;
        }
    }

    program.instance.exports[exportedId]();

    return new ExecutionResult(memory.buffer);
}

class ExecutionResult {
    constructor(memoryBuffer) {
        this.memoryView = new Uint32Array(memoryBuffer, 0, 512);
................................................................................

    typeIdForPointer(index) {
        const pointer = this.stackElement(index || 0);
        const wordPointer = pointer / 4;
        return this.memoryView[wordPointer];
    }
}


function loadStdLib() {
    const stdLibSrcPath = 'stdlib/src';

    // 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')
        };
    })
}

Modified wasm_tests/pattern_match.test.js from [5f9eb61ab9] to [edf563dadb].

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
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const compiler = require('./compiler.wrapper');

test('Basic pattern match', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Box
        : value Int

        defmulti: not
        : Box( value 0 )
          drop 1
        : Box
          drop 0

        def: main
        : 0 >Box not
    `);

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

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

test('Basic pattern match with default implementation', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Box
        : value Int

        defmulti: not
        : Box( value 0 )
          drop 1
        else: drop 0

        def: main
        : 0 >Box not
    `);

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

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

test('Basic pattern match reverse case', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Box
        : value Int

        defmulti: not
        : Box( value 0 )
          drop 1
        else: drop 0

        def: main
        : 1 >Box not
    `);

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

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

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

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

test('Unions as struct member', async () => {
    const wat = await compiler.toWat('main', `
        defunion: Bool
        : True
        : False

        defstruct: True
        defstruct: False

        defstruct: Box
        : value Bool

        defmulti: true?
        type: Box -- Bool
        : Box( value True )
          value>
        else: drop False>

        defmulti: as-int
        type: Bool -- Int
        : True
          drop 20
        : False
          drop 10

        def: main
        : True> >Box
          true? as-int
    `);

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

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

................................................................................
    const wat = await compiler.toWat('main', `
        defstruct: Box a
        : value BoxGen a

        defstruct: BoxGen a
        : value-g a

        defmulti: zero?
        type: (Box Int) -- Int
        : Box( value BoxGen )
          drop 1
        else: 
          drop 0

        def: main
        : 0 >BoxGen >Box
          zero?
    `);

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

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

................................................................................
    const wat = await compiler.toWat('main', `
        defstruct: Box a
        : value BoxGen a

        defstruct: BoxGen a
        : value-g a

        defmulti: zero?
        type: (Box Int) -- Int
        : Box( value BoxGen( value-g 0 ) )
          drop 1
        else: 
          drop 0

        def: main
        : 0 >BoxGen >Box
          zero?
    `);

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

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







|






|












|





|












|





|







 







|
|
|

|
|


|

|
|
|

|


|
|

|



|
|







 







|








|







 







|








|






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
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const compiler = require('./compiler.wrapper');

test('Basic pattern match', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Box
        : value Int

        defmulti: box-not
        : Box( value 0 )
          drop 1
        : Box
          drop 0

        def: main
        : 0 >Box box-not
    `);

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

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

test('Basic pattern match with default implementation', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Box
        : value Int

        defmulti: box-not
        : Box( value 0 )
          drop 1
        else: drop 0

        def: main
        : 0 >Box box-not
    `);

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

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

test('Basic pattern match reverse case', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Box
        : value Int

        defmulti: box-not
        : Box( value 0 )
          drop 1
        else: drop 0

        def: main
        : 1 >Box box-not
    `);

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

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

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

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

test('Unions as struct member', async () => {
    const wat = await compiler.toWat('main', `
        defunion: Choice
        : Yes
        : No

        defstruct: Yes
        defstruct: No

        defstruct: Box
        : value Choice

        defmulti: yes?
        type: Box -- Choice
        : Box( value Yes )
          value>
        else: drop No>

        defmulti: as-int
        type: Choice -- Int
        : Yes
          drop 20
        : No
          drop 10

        def: main
        : Yes> >Box
          yes? as-int
    `);

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

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

................................................................................
    const wat = await compiler.toWat('main', `
        defstruct: Box a
        : value BoxGen a

        defstruct: BoxGen a
        : value-g a

        defmulti: box-zero?
        type: (Box Int) -- Int
        : Box( value BoxGen )
          drop 1
        else: 
          drop 0

        def: main
        : 0 >BoxGen >Box
          box-zero?
    `);

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

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

................................................................................
    const wat = await compiler.toWat('main', `
        defstruct: Box a
        : value BoxGen a

        defstruct: BoxGen a
        : value-g a

        defmulti: box-zero?
        type: (Box Int) -- Int
        : Box( value BoxGen( value-g 0 ) )
          drop 1
        else: 
          drop 0

        def: main
        : 0 >BoxGen >Box
          box-zero?
    `);

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

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

Modified wasm_tests/string.test.js from [5d3dbc07b2] to [41c8ea7117].

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
const compiler = require('./compiler.wrapper');

test('Empty', async () => {
    const wat = await compiler.toStringWat('main', `
        def: main
        type: -- /string/String
        : ""
    `);

    const result = await compiler.run(wat, '/author/sample/core/main');

    expect(result.stringElement()).toBe("");
});

test('Sample', async () => {
    const wat = await compiler.toStringWat('main', `
        def: main
        type: -- /string/String
        : "This is a test"
    `);

    const result = await compiler.run(wat, '/author/sample/core/main');

    expect(result.stringElement()).toBe("This is a test");
});

test('Emoji', async () => {
    const wat = await compiler.toStringWat('main', `
        def: main
        type: -- /string/String
        : "💩"
    `);

    const result = await compiler.run(wat, '/author/sample/core/main');

    expect(result.stringElement()).toBe("💩");
});



|





|





|





|





|





|



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
const compiler = require('./compiler.wrapper');

test('Empty', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- /string/String
        : ""
    `);

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

    expect(result.stringElement()).toBe("");
});

test('Sample', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- /string/String
        : "This is a test"
    `);

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

    expect(result.stringElement()).toBe("This is a test");
});

test('Emoji', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        type: -- /string/String
        : "💩"
    `);

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

    expect(result.stringElement()).toBe("💩");
});