Skip to content

Commit 7dea5d8

Browse files
committed
feat: add fixed-length list support and update related functionality
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 3a6404f commit 7dea5d8

19 files changed

Lines changed: 208 additions & 41 deletions

File tree

‎.github/workflows/macos.yml‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
name: MacOS
22

3-
# Disabled: Known to fail
4-
# To re-enable, uncomment the 'on:' section below
53
on:
6-
workflow_dispatch: # Manual trigger only
7-
# push:
8-
# branches:
9-
# - trunk
10-
# - main
11-
# pull_request:
12-
# branches:
13-
# - trunk
14-
# - main
4+
push:
5+
branches:
6+
- trunk
7+
- main
8+
pull_request:
9+
branches:
10+
- trunk
11+
- main
12+
workflow_dispatch:
1513

1614
env:
1715
CTEST_OUTPUT_ON_FAILURE: 1
@@ -43,8 +41,8 @@ jobs:
4341
target/
4442
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4543

46-
- name: Cache vcpkg registry
47-
uses: actions/cache@v4
44+
- name: Restore vcpkg registry
45+
uses: actions/cache/restore@v4
4846
with:
4947
path: |
5048
build/vcpkg_installed/
@@ -81,6 +79,15 @@ jobs:
8179
echo "Running wit-stub-generation-test (failures expected and will be reported)..."
8280
ctest -VV -R "wit-stub-generation-test"
8381
82+
- name: Save vcpkg registry
83+
if: always()
84+
uses: actions/cache/save@v4
85+
with:
86+
path: |
87+
build/vcpkg_installed/
88+
build/vcpkg_packages/
89+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
90+
8491
- name: Upload error logs
8592
if: ${{ failure() || cancelled() }}
8693
uses: actions/upload-artifact@v4

‎.github/workflows/release.yml‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ jobs:
9393
target/
9494
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
9595

96-
- name: Cache vcpkg registry
97-
if: always()
98-
uses: actions/cache@v4
96+
- name: Restore vcpkg registry
97+
uses: actions/cache/restore@v4
9998
with:
10099
path: |
101100
build/vcpkg_installed/
@@ -116,6 +115,15 @@ jobs:
116115
run: |
117116
cmake --build --preset ${{ matrix.build-preset }}
118117
118+
- name: Save vcpkg registry
119+
if: always()
120+
uses: actions/cache/save@v4
121+
with:
122+
path: |
123+
build/vcpkg_installed/
124+
build/vcpkg_packages/
125+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
126+
119127
- name: Create Packages
120128
working-directory: build
121129
run: |

‎.github/workflows/ubuntu.yml‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
matrix:
2727
include:
2828
- os: "ubuntu-24.04"
29+
- os: "ubuntu-26.04"
2930
fail-fast: false
3031

3132
runs-on: ${{ matrix.os }}
@@ -44,18 +45,17 @@ jobs:
4445
~/.cargo/registry/cache/
4546
~/.cargo/git/db/
4647
target/
47-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
48+
key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4849

49-
- name: Cache vcpkg registry
50-
if: always()
51-
uses: actions/cache@v4
50+
- name: Restore vcpkg registry
51+
uses: actions/cache/restore@v4
5252
with:
5353
path: |
5454
build/vcpkg_installed/
5555
build/vcpkg_packages/
56-
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
56+
key: ${{ matrix.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
5757
restore-keys: |
58-
${{ runner.os }}-vcpkg-
58+
${{ matrix.os }}-vcpkg-
5959
6060
- name: install dependencies
6161
run: |
@@ -89,6 +89,15 @@ jobs:
8989
with:
9090
token: ${{ secrets.CODECOV_TOKEN }}
9191

92+
- name: Save vcpkg registry
93+
if: always()
94+
uses: actions/cache/save@v4
95+
with:
96+
path: |
97+
build/vcpkg_installed/
98+
build/vcpkg_packages/
99+
key: ${{ matrix.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
100+
92101
- name: Upload error logs
93102
if: ${{ failure() || cancelled() }}
94103
uses: actions/upload-artifact@v4

‎.github/workflows/windows.yml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ jobs:
4848
target/
4949
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
5050

51-
- name: Cache vcpkg registry
52-
uses: actions/cache@v4
51+
- name: Restore vcpkg registry
52+
uses: actions/cache/restore@v4
5353
with:
5454
path: |
5555
build/vcpkg_installed/
@@ -89,6 +89,15 @@ jobs:
8989
Set-Location "$env:SHORT_WORKSPACE/build"
9090
& ctest -C Debug -VV
9191
92+
- name: Save vcpkg registry
93+
if: always()
94+
uses: actions/cache/save@v4
95+
with:
96+
path: |
97+
build/vcpkg_installed/
98+
build/vcpkg_packages/
99+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('./vcpkg*.json') }}
100+
92101
- name: Remove short workspace mapping
93102
if: always()
94103
run: |

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This repository contains a C++ ABI implementation of the WebAssembly Component M
1616

1717
### OS
1818
- [x] Ubuntu 24.04
19+
- [x] Ubuntu 26.04
1920
- [ ] MacOS 13
2021
- [ ] MacOS 14 (Arm)
2122
- [ ] Windows 2019
@@ -36,6 +37,7 @@ This repository contains a C++ ABI implementation of the WebAssembly Component M
3637
- [x] Char
3738
- [x] Strings (UTF-8, UTF-16, Latin-1+UTF-16)
3839
- [x] List
40+
- [x] Fixed-length list (`cmcpp::fixed_list_t<T, N>`)
3941
- [x] Map
4042
- [x] Record
4143
- [x] Tuple

‎docs/spec-alignment.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
This document tracks alignment between the upstream Component Model spec/reference (in `ref/component-model`) and this library’s C++ entrypoints.
44

5+
- Upstream baseline: `2bed77e4228841c1d2721996d3ecc169ff96b158`
56
- Upstream references:
67
- `ref/component-model/design/mvp/CanonicalABI.md`
78
- `ref/component-model/design/mvp/Concurrency.md`
@@ -53,11 +54,11 @@ This document tracks alignment between the upstream Component Model spec/referen
5354

5455
## Thread built-ins (upstream)
5556

56-
These are referenced by the upstream spec/reference but do not currently have direct C++ canonical built-in entrypoints in this repo:
57+
These additional thread built-ins are implemented by direct C++ canonical entrypoints:
5758

58-
- `thread.new_ref` / `thread.new-ref` (implemented: `cmcpp::canon_thread_new_ref`)
59-
- `thread.new-indirect` (implemented: `cmcpp::canon_thread_new_indirect`)
60-
- `thread.spawn-ref` (implemented: `cmcpp::canon_thread_spawn_ref`)
61-
- `thread.spawn-indirect` (implemented: `cmcpp::canon_thread_spawn_indirect`)
62-
- `thread.switch-to` (implemented: `cmcpp::canon_thread_switch_to`)
63-
- `thread.available-parallelism` (implemented: `cmcpp::canon_thread_available_parallelism`)
59+
- `thread.new-ref`: `cmcpp::canon_thread_new_ref`
60+
- `thread.new-indirect`: `cmcpp::canon_thread_new_indirect`
61+
- `thread.spawn-ref`: `cmcpp::canon_thread_spawn_ref`
62+
- `thread.spawn-indirect`: `cmcpp::canon_thread_spawn_indirect`
63+
- `thread.switch-to`: `cmcpp::canon_thread_switch_to`
64+
- `thread.available-parallelism`: `cmcpp::canon_thread_available_parallelism`

‎grammar/Wit.g4‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ importItem
5757
externType
5858
: funcType ';'
5959
| 'interface' '{' interfaceItems* '}'
60+
| usePath ';'
6061
;
6162

6263
// Item: include ---
@@ -352,6 +353,9 @@ keyword
352353
Identifier: LETTER (LETTER | DIGIT | '-')*
353354
;
354355

356+
NUM_ID: '0' | POSITIVE_DIGIT | POSITIVE_DIGIT DIGITS
357+
;
358+
355359
// Semver: https://semver.org/
356360
VALID_SEMVER
357361
: VERSION_CORE
@@ -401,9 +405,6 @@ ALPHANUM_ID
401405
| ID_CHARS NON_DIGIT ID_CHARS
402406
;
403407

404-
NUM_ID: '0' | POSITIVE_DIGIT | POSITIVE_DIGIT DIGITS
405-
;
406-
407408
ID_CHARS: ID_CHAR | ID_CHAR ID_CHARS
408409
;
409410

‎include/cmcpp.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cmcpp/tuple.hpp>
1313
#include <cmcpp/record.hpp>
1414
#include <cmcpp/list.hpp>
15+
#include <cmcpp/fixed_list.hpp>
1516
#include <cmcpp/map.hpp>
1617
#include <cmcpp/variant.hpp>
1718
#include <cmcpp/func.hpp>

‎include/cmcpp/fixed_list.hpp‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef CMCPP_FIXED_LIST_HPP
2+
#define CMCPP_FIXED_LIST_HPP
3+
4+
#include "context.hpp"
5+
#include "lift.hpp"
6+
#include "load.hpp"
7+
#include "lower.hpp"
8+
#include "store.hpp"
9+
10+
namespace cmcpp
11+
{
12+
template <FixedList T>
13+
inline void store(LiftLowerContext &cx, const T &values, uint32_t ptr)
14+
{
15+
using Element = typename ValTrait<T>::inner_type;
16+
for (size_t i = 0; i < values.size(); ++i)
17+
{
18+
cmcpp::store(cx, values[i], ptr + i * ValTrait<Element>::size);
19+
}
20+
}
21+
22+
template <FixedList T>
23+
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &values)
24+
{
25+
WasmValVector flat;
26+
flat.reserve(ValTrait<T>::flat_types_len);
27+
for (const auto &value : values)
28+
{
29+
auto element_flat = cmcpp::lower_flat(cx, value);
30+
flat.insert(flat.end(), element_flat.begin(), element_flat.end());
31+
}
32+
return flat;
33+
}
34+
35+
template <FixedList T>
36+
inline T load(const LiftLowerContext &cx, uint32_t ptr)
37+
{
38+
using Element = typename ValTrait<T>::inner_type;
39+
T values{};
40+
for (size_t i = 0; i < values.size(); ++i)
41+
{
42+
values[i] = cmcpp::load<Element>(cx, ptr + i * ValTrait<Element>::size);
43+
}
44+
return values;
45+
}
46+
47+
template <FixedList T>
48+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
49+
{
50+
using Element = typename ValTrait<T>::inner_type;
51+
T values{};
52+
for (auto &value : values)
53+
{
54+
value = cmcpp::lift_flat<Element>(cx, vi);
55+
}
56+
return values;
57+
}
58+
}
59+
60+
#endif

‎include/cmcpp/lift.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace cmcpp
2828
template <List T>
2929
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
3030

31+
template <FixedList T>
32+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
33+
3134
template <Flags T>
3235
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi);
3336

0 commit comments

Comments
 (0)