Stabel

Check-in [df837b4584]
Login
Overview
Comment:Added array integration test, and implemented two of the array built ins.
Timelines: family | ancestors | descendants | both | arrays
Files: files | file ages | folders
SHA3-256: df837b45848f6702c86b5d6cf3de2d9c550c4a26d0e84e81c37675fb426ac9b5
User & Date: robin.hansen on 2021-08-23 17:28:37
Other Links: branch diff | manifest | tags
Context
2021-08-23
17:37
Fix regression in codegen due to a wrong available function id constant. check-in: e726f26c61 user: robin.hansen tags: arrays
17:28
Added array integration test, and implemented two of the array built ins. check-in: df837b4584 user: robin.hansen tags: arrays
16:56
Fill in missing pieces in type checker and codegen. Should be ready to implement array builtins. check-in: 73bcd35203 user: robin.hansen tags: arrays
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Codegen/BaseModule.elm from [ec6af68d9f] to [f7e03d54e9].

610
611
612
613
614
615
616
617
618
619







620
621
622
623
624
625
626
627



628
629
630
631
632
633
634

635
636
637
      }

    -- ARRAY
    , { id = 20
      , name = arrayEmptyFn
      , args = []
      , results = []
      , locals = []
      , instructions =
            []







      }
    , { id = 21
      , name = arrayLengthFn
      , args = []
      , results = []
      , locals = []
      , instructions =
            []



      }
    , { id = 22
      , name = arrayPushFn
      , args = []
      , results = []
      , locals = []
      , instructions =

            []
      }
    ]







|

|
>
>
>
>
>
>
>







|
>
>
>







>



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
      }

    -- ARRAY
    , { id = 20
      , name = arrayEmptyFn
      , args = []
      , results = []
      , locals = [ Wasm.Int32 ]
      , instructions =
            [ Wasm.I32_Const 4 -- Just enough space for length variable
            , callAllocFn
            , Wasm.Local_Tee 0 -- Save output instance
            , Wasm.I32_Const 0
            , Wasm.I32_Store -- Set length to 0
            , Wasm.Local_Get 0
            , callStackPushFn
            ]
      }
    , { id = 21
      , name = arrayLengthFn
      , args = []
      , results = []
      , locals = []
      , instructions =
            [ callStackPopFn
            , Wasm.I32_Load
            , callStackPushFn
            ]
      }
    , { id = 22
      , name = arrayPushFn
      , args = []
      , results = []
      , locals = []
      , instructions =
            -- TODO
            []
      }
    ]

Modified src/Stabel/Qualifier.elm from [38a212f63a] to [286af5303d].

116
117
118
119
120
121
122

123
124
125
126
127
128
129
        , ( "=", Builtin.Equal )
        , ( "swap", Builtin.StackSwap )
        , ( "dup", Builtin.StackDuplicate )
        , ( "drop", Builtin.StackDrop )
        , ( "rotate", Builtin.StackRightRotate )
        , ( "-rotate", Builtin.StackLeftRotate )
        , ( "!", Builtin.Apply )

        ]


type alias RunConfig =
    { packageName : String
    , modulePath : String
    , ast : Parser.AST







>







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
        , ( "=", Builtin.Equal )
        , ( "swap", Builtin.StackSwap )
        , ( "dup", Builtin.StackDuplicate )
        , ( "drop", Builtin.StackDrop )
        , ( "rotate", Builtin.StackRightRotate )
        , ( "-rotate", Builtin.StackLeftRotate )
        , ( "!", Builtin.Apply )
        , ( "array-length", Builtin.ArrayLength )
        ]


type alias RunConfig =
    { packageName : String
    , modulePath : String
    , ast : Parser.AST

Added wasm_tests/array.test.js version [f7afc2c637].





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const compiler = require('./compiler.wrapper');

test('Simple literal', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : { 1 2 3 4 5 } array-length
    `);

    console.log(wat);

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

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