Skip to content

Commit 7d1bfdc

Browse files
authored
waPC support (#2)
1 parent 5a93589 commit 7d1bfdc

File tree

12 files changed

+3017
-296
lines changed

12 files changed

+3017
-296
lines changed

.github/workflows/build.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,50 @@ jobs:
2121
- uses: actions/setup-go@v3
2222
with:
2323
go-version: '1.19'
24-
24+
2525
- uses: acifani/setup-tinygo@v1
2626
with:
2727
tinygo-version: 0.25.0
2828

2929
- uses: actions/setup-go@v3
3030
with:
3131
go-version: '1.19'
32-
32+
3333
- name: Install wasm-opt
3434
run: |
3535
wget https://github.com/WebAssembly/binaryen/releases/download/version_110/binaryen-version_110-x86_64-linux.tar.gz
3636
tar -xvzf binaryen-version_110-x86_64-linux.tar.gz
3737
rm -rf binaryen-version_110-x86_64-linux.tar.gz
3838
cp binaryen-version_110/bin/wasm-opt /usr/local/bin
3939
rm -Rf binaryen-version_110
40-
40+
4141
- name: Install tinyjson
4242
run: go install github.com/CosmWasm/tinyjson/...@latest
4343

4444
- name: Install Apex CLI
45-
run: wget -q https://apexlang.io/install.sh -O - | /bin/bash
45+
run: |
46+
wget -q https://apexlang.io/install.sh -O - | /bin/bash
47+
apex install @wapc/codegen
4648
4749
- name: Apex code generation
4850
run: apex generate
49-
51+
5052
- name: Build WebAssembly parser
5153
run: |
5254
tinygo build -o apex-parser.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/apex-api/main.go
5355
wasm-opt -O apex-parser.wasm -o apex-parser.wasm
5456
57+
- name: Build waPC module
58+
run: |
59+
tinygo build -o apex-wapc.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/wapc/main.go
60+
wasm-opt -O apex-wapc.wasm -o apex-wapc.wasm
61+
5562
- name: Release
5663
uses: softprops/action-gh-release@v1
5764
if: startsWith(github.ref, 'refs/tags/')
5865
with:
5966
files: |
6067
apex-parser.wasm
68+
apex-wapc.wasm
69+
model.apexlang
6170
LICENSE.txt

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.PHONY: all wasm-cli wasm-api codegen
1+
.PHONY: all wasm-cli wasm-api wasm-wapc wasm-host codegen
22

3-
all: codegen wasm-cli wasm-api wasm-host
3+
all: codegen wasm-cli wasm-api wasm-wapc wasm-host
44

55
wasm-cli:
66
tinygo build -o apex-cli.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/apex-cli/main.go
@@ -11,6 +11,10 @@ wasm-api:
1111
wasm-opt -O apex-api.wasm -o apex-api.wasm
1212
cp apex-api.wasm cmd/host/apex-api.wasm
1313

14+
wasm-wapc:
15+
tinygo build -o apex-wapc.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/wapc/main.go
16+
wasm-opt -O apex-wapc.wasm -o apex-wapc.wasm
17+
1418
wasm-host:
1519
go build -o apex-host cmd/host/main.go
1620

apex.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
spec: model.apexlang
22
config:
33
package: model
4-
module: github.com/apexlang/apex-wasm
4+
module: github.com/apexlang/apex-go
55
generates:
66
model/model.go:
77
module: '@apexlang/codegen/go'
@@ -10,3 +10,15 @@ generates:
1010
writeTypeInfo: false
1111
runAfter:
1212
- command: tinyjson -all model/model.go
13+
model/msgpack.go:
14+
module: '@apexlang/codegen/go'
15+
visitorClass: MsgPackVisitor
16+
model/wapc.go:
17+
module: '@wapc/codegen/tinygo'
18+
visitorClass: ExportVisitor
19+
cmd/wapc/main.go:
20+
module: '@wapc/codegen/tinygo'
21+
visitorClass: MainVisitor
22+
config:
23+
import: github.com/apexlang/apex-go/model
24+
package: model

cmd/wapc/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"github.com/apexlang/apex-go/model"
5+
)
6+
7+
func main() {
8+
// Create providers
9+
resolverProvider := model.NewResolver()
10+
11+
// Create services
12+
parserService := model.NewParser(resolverProvider)
13+
14+
// Register services
15+
model.RegisterParser(parserService)
16+
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ require (
66
github.com/CosmWasm/tinyjson v0.9.0
77
github.com/iancoleman/strcase v0.2.0
88
github.com/tetratelabs/tinymem v0.1.0
9+
github.com/wapc/tinygo-msgpack v0.1.4
10+
github.com/wapc/wapc-guest-tinygo v0.3.3
911
)
1012

1113
require github.com/josharian/intern v1.0.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107 h1:GljFiJysL3S8SBhXWU47Emj34D3pVZgJ+Amj+jhM4fQ=
22
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107/go.mod h1:5+7QnSKrkIWnpIdhUT2t2EYzXnII3/3MlM0oDsBSbc8=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
34
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
45
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
56
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
67
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
8+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
710
github.com/tetratelabs/tinymem v0.1.0 h1:Qza1JAg9lquPPJ/CIei5qQYx7t18KLie83O2WR6CM58=
811
github.com/tetratelabs/tinymem v0.1.0/go.mod h1:WFFTZFhLod6lTL+UetFAopVbGaB+KFsVcIY+RUv7NeY=
12+
github.com/wapc/tinygo-msgpack v0.1.4 h1:oiwtclAGh/A+x024gCFXxey/iNtRmGaE+nvtyAw2vvo=
13+
github.com/wapc/tinygo-msgpack v0.1.4/go.mod h1:2P4rQimy/6oQAkytwC2LdtVjLJ2D1dYkQHejfCtZXZQ=
14+
github.com/wapc/wapc-guest-tinygo v0.3.3 h1:jLebiwjVSHLGnS+BRabQ6+XOV7oihVWAc05Hf1SbeR0=
15+
github.com/wapc/wapc-guest-tinygo v0.3.3/go.mod h1:mzM3CnsdSYktfPkaBdZ8v88ZlfUDEy5Jh5XBOV3fYcw=
16+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

model.apexlang

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
namespace "apexlang.v1"
22

3+
interface Parser @service @uses([Resolver]) {
4+
parse(source: string): ParserResult
5+
}
6+
7+
interface Resolver @dependency {
8+
resolve(location: string, from: string): string
9+
}
10+
11+
type ParserResult {
12+
namespace: Namespace?
13+
errors: [Error]?
14+
}
15+
16+
type Error {
17+
message: string
18+
positions: [u32]
19+
locations: [Location]
20+
}
21+
22+
type Location {
23+
line: u32
24+
column: u32
25+
}
26+
327
"Namespace encapsulates is used to identify and refer to elements contained in the Apex specification."
428
type Namespace {
529
name: string @quoted

model/model.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)