chore: migrate to local repo and fix CI #189

Merged
james merged 2 commits from migrate into main 2023-07-28 08:48:57 +12:00
36 changed files with 455 additions and 234 deletions

236
.drone.yml Normal file
View file

@ -0,0 +1,236 @@
kind: pipeline
type: docker
name: build
steps:
- name: restore ASDF cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
mount:
- .asdf
- name: restore bundle cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'bundle-{{ checksum "Gemfile.lock" }}-{{ checksum ".tool-versions" }}'
mount:
- .bundle
- name: install dependencies
image: code.harton.nz/james/asdf_container:latest
pull: "always"
environment:
ASDF_DATA_DIR: /drone/src/.asdf
BUNDLE_CACHE_PATH: /drone/src/.bundle
depends_on:
- restore ASDF cache
- restore bundle cache
commands:
- apt-get update
- apt-get install -y wabt
- rm -rf /var/cache/apt
- mkdir -p bin
- cp -v /usr/bin/wat2wasm bin/
- cp -v /usr/bin/wasm-validate bin/
- asdf_install
- rm -rf .asdf/downloads
- asdf bundle install
- name: store ASDF cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
depends_on:
- install dependencies
settings:
rebuild: true
override: false
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
mount:
- .asdf
- name: store bundle cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
depends_on:
- install dependencies
settings:
rebuild: true
override: false
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'bundle-{{ checksum "Gemfile.lock" }}-{{ checksum ".tool-versions" }}'
mount:
- .bundle
- name: store WABT cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
depends_on:
- install dependencies
settings:
rebuild: true
override: false
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'wabt'
mount:
- bin
---
kind: pipeline
type: docker
name: test
depends_on:
- build
steps:
- name: restore ASDF cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
mount:
- .asdf
- name: restore bundle cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'bundle-{{ checksum "Gemfile.lock" }}-{{ checksum ".tool-versions" }}'
mount:
- .bundle
- name: restore WABT cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'wabt'
mount:
- bin
- name: rubocop
image: code.harton.nz/james/asdf_container:latest
pull: "always"
environment:
BUNDLE_CACHE_PATH: /drone/src/.bundle
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- restore ASDF cache
- restore bundle cache
commands:
- asdf bundle exec rubocop
- name: rspec
image: code.harton.nz/james/asdf_container:latest
pull: "always"
environment:
BUNDLE_CACHE_PATH: /drone/src/.bundle
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- restore ASDF cache
- restore bundle cache
commands:
- export PATH=/drone/src/bin:$PATH
- asdf bundle exec rspec

View file

@ -1,32 +0,0 @@
image: ruby:latest
stages:
- test
- release
before_script:
- apt-get update && apt-get install wabt && rm -rf /var/cache/apt
- bundle install
test:
stage: test
script:
- bundle exec rspec
rubocop:
stage: test
script:
- bundle exec rspec
release:
stage: release
only:
- /^v[0-9]+\.[0-9]+\.[0-9]+$/
except:
- branches
script:
- gem build
artifacts:
name: "wag-$CI_COMMIT_TAG.gem"
paths:
- wag-*.gem

View file

@ -30,3 +30,7 @@ Style/Documentation:
Style/OptionalArguments: Style/OptionalArguments:
Enabled: false Enabled: false
AllCops:
NewCops: enable
SuggestExtensions: false

1
.tool-versions Normal file
View file

@ -0,0 +1 @@
ruby 3.1.2

View file

@ -59,6 +59,7 @@ GEM
unicode-display_width (2.4.2) unicode-display_width (2.4.2)
PLATFORMS PLATFORMS
arm64-darwin-22
x86_64-linux x86_64-linux
DEPENDENCIES DEPENDENCIES

View file

@ -7,8 +7,8 @@ It is closely modeled after WAT, the WebAssembly text format, and at this stage
generates WAT and compiles and validates it using [the WebAssembly Binary Toolkit][1]. generates WAT and compiles and validates it using [the WebAssembly Binary Toolkit][1].
Due to the flexibility of WAT this library is very flexible in what structures Due to the flexibility of WAT this library is very flexible in what structures
it allows you to create. Be aware that you can build modules which are not it allows you to create. Be aware that you can build modules which are not
valid WASM. Always validate your modules by using `#to_wasm.valid?`. valid WASM. Always validate your modules by using `#to_wasm.valid?`.
## Keyword conflict ## Keyword conflict
@ -20,7 +20,7 @@ of `public_send`, etc.
## Folding ## Folding
WAG supports generating both the "folded" and "unfolded" variants of the WAT WAG supports generating both the "folded" and "unfolded" variants of the WAT
language. As an example here are two implementations of Euclid's Greatest language. As an example here are two implementations of Euclid's Greatest
Common Divisor algorithm: Common Divisor algorithm:
### Example of unfolded generation ### Example of unfolded generation
@ -68,6 +68,7 @@ end
``` ```
### Example of folded generation ### Example of folded generation
```ruby ```ruby
folded = WAG::Module.new.build do folded = WAG::Module.new.build do
func(:gcd) do func(:gcd) do
@ -154,7 +155,6 @@ Or install it yourself as:
$ gem install wag $ gem install wag
## Development ## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@ -163,7 +163,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
## Contributing ## Contributing
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/jimsy/wag. Bug reports and pull requests are welcome at https://code.harton.nz/james/wag.
## License ## License
@ -172,7 +172,7 @@ This software is licensed under the terms of the
this package for the terms. this package for the terms.
This license actively proscribes this software being used by and for some This license actively proscribes this software being used by and for some
industries, countries and activities. If your usage of this software doesn't industries, countries and activities. If your usage of this software doesn't
comply with the terms of this license, then [contact me](mailto:james@harton.nz) comply with the terms of this license, then [contact me](mailto:james@harton.nz)
with the details of your use-case to organise the purchase of a license - the with the details of your use-case to organise the purchase of a license - the
cost of which may include a donation to a suitable charity or NGO. cost of which may include a donation to a suitable charity or NGO.

View file

@ -12,7 +12,7 @@ module WAG
end end
def to_sexpr def to_sexpr
[:data, [:"i32.const", offset], value] [:data, [:'i32.const', offset], value]
end end
end end
end end

View file

@ -12,7 +12,7 @@ module WAG
end end
def to_sexpr def to_sexpr
[:elem, [:"i32.const", table_id]].concat(labels.map(&:to_sexpr)) [:elem, [:'i32.const', table_id]].concat(labels.map(&:to_sexpr))
end end
end end
end end

View file

@ -26,7 +26,7 @@ module WAG
@desc @desc
end end
def table(number, type = :anyfunc, &block) def table(number, type = :funcref, &block)
@desc = Table.new(number, type) @desc = Table.new(number, type)
@desc.instance_exec(&block) if block @desc.instance_exec(&block) if block
@desc @desc

View file

@ -29,7 +29,7 @@ module WAG
@desc @desc
end end
def table(number, type = :anyfunc, &block) def table(number, type = :funcref, &block)
@desc = Table.new(number, type) @desc = Table.new(number, type)
@desc.instance_exec(&block) if block @desc.instance_exec(&block) if block
@desc @desc

View file

@ -8,6 +8,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -8,6 +8,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -8,6 +8,7 @@ module WAG
def initialize(*labels) def initialize(*labels)
@labels = labels.map { |label| WAG::Label.from(label) } @labels = labels.map { |label| WAG::Label.from(label) }
super()
end end
def to_sexpr def to_sexpr

View file

@ -8,6 +8,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(literal) def initialize(literal)
@literal = literal.to_f @literal = literal.to_f
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(literal) def initialize(literal)
@literal = literal.to_f @literal = literal.to_f
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(literal) def initialize(literal)
@literal = literal.to_i @literal = literal.to_i
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(literal) def initialize(literal)
@literal = literal.to_i @literal = literal.to_i
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -9,6 +9,7 @@ module WAG
def initialize(label) def initialize(label)
@label = WAG::Label.from(label) @label = WAG::Label.from(label)
super()
end end
def to_sexpr def to_sexpr

View file

@ -16,8 +16,8 @@ module WAG
@types = [] @types = []
end end
def build(&block) def build(&)
instance_exec(&block) instance_exec(&)
self self
end end
@ -76,14 +76,14 @@ module WAG
func func
end end
def table(elements, type = :anyfunc, &block) def table(elements, type = :funcref, &block)
table = Table.new(elements, type) table = Table.new(elements, type)
@tables << table @tables << table
table.instance_exec(&block) if block table.instance_exec(&block) if block
table table
end end
def to_sexpr # rubocop:disable Metrics/AbcSize, Metrics/MethodLength def to_sexpr # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
mod = [:module] mod = [:module]
mod.concat(@imports.map(&:to_sexpr)) mod.concat(@imports.map(&:to_sexpr))
mod.concat(@exports.map(&:to_sexpr)) mod.concat(@exports.map(&:to_sexpr))

View file

@ -5,7 +5,7 @@ module WAG
include WAG::Encodable include WAG::Encodable
attr_reader :elements, :type attr_reader :elements, :type
def initialize(elements, type = :anyfunc) def initialize(elements, type = :funcref)
@elements = elements @elements = elements
@type = type @type = type
end end

View file

@ -1,3 +0,0 @@
{
"extends": ["gitlab>jimsy/renovate"]
}

View file

@ -45,7 +45,7 @@ RSpec.describe 'WAT code generation' do
memory(:mem, 1) memory(:mem, 1)
table(16, :anyfunc) table(16, :funcref)
elem(0, :dead, :dead, :dead, :alive, :dead, :dead, :dead, :dead, elem(0, :dead, :dead, :dead, :alive, :dead, :dead, :dead, :dead,
:dead, :dead, :dead, :alive, :alive, :dead, :dead, :dead, :dead, :dead, :dead, :alive, :alive, :dead, :dead, :dead,

View file

@ -10,6 +10,6 @@ RSpec.describe WAG::Data do
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:data, [:"i32.const", offset], value] } it { is_expected.to eq [:data, [:'i32.const', offset], value] }
end end
end end

View file

@ -11,12 +11,12 @@ RSpec.describe WAG::Element do
context 'When the element has no labels' do context 'When the element has no labels' do
let(:labels) { [] } let(:labels) { [] }
it { is_expected.to eq [:elem, [:"i32.const", table_id]] } it { is_expected.to eq [:elem, [:'i32.const', table_id]] }
end end
context 'When the element has no labels' do context 'When the element has no labels' do
let(:labels) { %i[l0 l1 l2] } let(:labels) { %i[l0 l1 l2] }
it { is_expected.to eq [:elem, [:"i32.const", table_id], :$l0, :$l1, :$l2] } it { is_expected.to eq [:elem, [:'i32.const', table_id], :$l0, :$l1, :$l2] }
end end
end end
end end

View file

@ -19,12 +19,12 @@ RSpec.describe WAG::Export do
describe 'When exporting a table' do describe 'When exporting a table' do
before do before do
export.table(1, :anyfunc) export.table(1, :funcref)
end end
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:export, 'marty', [:table, 1, :anyfunc]] } it { is_expected.to eq [:export, 'marty', [:table, 1, :funcref]] }
end end
end end

View file

@ -73,7 +73,7 @@ RSpec.describe WAG::Function do
context 'When the function has a body' do context 'When the function has a body' do
before { function.i64.const(13) } before { function.i64.const(13) }
it { is_expected.to eq [:func, "$#{label}".to_sym, [:"i64.const", 13]] } it { is_expected.to eq [:func, "$#{label}".to_sym, [:'i64.const', 13]] }
end end
end end
end end

View file

@ -19,12 +19,12 @@ RSpec.describe WAG::Import do
describe 'When importing a table' do describe 'When importing a table' do
before do before do
import.table(1, :anyfunc) import.table(1, :funcref)
end end
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:import, 'marty', 'mcfly', [:table, 1, :anyfunc]] } it { is_expected.to eq [:import, 'marty', 'mcfly', [:table, 1, :funcref]] }
end end
end end

View file

@ -17,177 +17,177 @@ INSTRUCTIONS = { unreachable: 0x00,
call_indirect: 0x11, call_indirect: 0x11,
drop: 0x1a, drop: 0x1a,
select: 0x1b, select: 0x1b,
"local.get": 0x20, 'local.get': 0x20,
"local.set": 0x21, 'local.set': 0x21,
"local.tee": 0x22, 'local.tee': 0x22,
"global.get": 0x23, 'global.get': 0x23,
"global.set": 0x24, 'global.set': 0x24,
"i32.load": 0x28, 'i32.load': 0x28,
"i64.load": 0x29, 'i64.load': 0x29,
"f32.load": 0x2a, 'f32.load': 0x2a,
"f64.load": 0x2b, 'f64.load': 0x2b,
"i32.load8_s": 0x2c, 'i32.load8_s': 0x2c,
"i32.load8_u": 0x2d, 'i32.load8_u': 0x2d,
"i32.load16_s": 0x2e, 'i32.load16_s': 0x2e,
"i32.load16_u": 0x2f, 'i32.load16_u': 0x2f,
"i64.load8_s": 0x30, 'i64.load8_s': 0x30,
"i64.load8_u": 0x31, 'i64.load8_u': 0x31,
"i64.load16_s": 0x32, 'i64.load16_s': 0x32,
"i64.load16_u": 0x33, 'i64.load16_u': 0x33,
"i64.load32_s": 0x34, 'i64.load32_s': 0x34,
"i64.load32_u": 0x35, 'i64.load32_u': 0x35,
"i32.store": 0x36, 'i32.store': 0x36,
"i64.store": 0x37, 'i64.store': 0x37,
"f32.store": 0x38, 'f32.store': 0x38,
"f64.store": 0x39, 'f64.store': 0x39,
"i32.store8": 0x3a, 'i32.store8': 0x3a,
"i32.store16": 0x3b, 'i32.store16': 0x3b,
"i64.store8": 0x3c, 'i64.store8': 0x3c,
"i64.store16": 0x3d, 'i64.store16': 0x3d,
"i64.store32": 0x3e, 'i64.store32': 0x3e,
"memory.size": 0x3f, 'memory.size': 0x3f,
"memory.grow": 0x40, 'memory.grow': 0x40,
"i32.const": 0x41, 'i32.const': 0x41,
"i64.const": 0x42, 'i64.const': 0x42,
"f32.const": 0x43, 'f32.const': 0x43,
"f64.const": 0x44, 'f64.const': 0x44,
"i32.eqz": 0x45, 'i32.eqz': 0x45,
"i32.eq": 0x46, 'i32.eq': 0x46,
"i32.ne": 0x47, 'i32.ne': 0x47,
"i32.lt_s": 0x48, 'i32.lt_s': 0x48,
"i32.lt_u": 0x49, 'i32.lt_u': 0x49,
"i32.gt_s": 0x4a, 'i32.gt_s': 0x4a,
"i32.gt_u": 0x4b, 'i32.gt_u': 0x4b,
"i32.le_s": 0x4c, 'i32.le_s': 0x4c,
"i32.le_u": 0x4d, 'i32.le_u': 0x4d,
"i32.ge_s": 0x4e, 'i32.ge_s': 0x4e,
"i32.ge_u": 0x4f, 'i32.ge_u': 0x4f,
"i64.eqz": 0x50, 'i64.eqz': 0x50,
"i64.eq": 0x51, 'i64.eq': 0x51,
"i64.ne": 0x52, 'i64.ne': 0x52,
"i64.lt_s": 0x53, 'i64.lt_s': 0x53,
"i64.lt_u": 0x54, 'i64.lt_u': 0x54,
"i64.gt_s": 0x55, 'i64.gt_s': 0x55,
"i64.gt_u": 0x56, 'i64.gt_u': 0x56,
"i64.le_s": 0x57, 'i64.le_s': 0x57,
"i64.le_u": 0x58, 'i64.le_u': 0x58,
"i64.ge_s": 0x59, 'i64.ge_s': 0x59,
"i64.ge_u": 0x5a, 'i64.ge_u': 0x5a,
"f32.eq": 0x5b, 'f32.eq': 0x5b,
"f32.ne": 0x5c, 'f32.ne': 0x5c,
"f32.lt": 0x5d, 'f32.lt': 0x5d,
"f32.gt": 0x5e, 'f32.gt': 0x5e,
"f32.le": 0x5f, 'f32.le': 0x5f,
"f32.ge": 0x60, 'f32.ge': 0x60,
"f64.eq": 0x61, 'f64.eq': 0x61,
"f64.ne": 0x62, 'f64.ne': 0x62,
"f64.lt": 0x63, 'f64.lt': 0x63,
"f64.gt": 0x64, 'f64.gt': 0x64,
"f64.le": 0x65, 'f64.le': 0x65,
"f64.ge": 0x66, 'f64.ge': 0x66,
"i32.clz": 0x67, 'i32.clz': 0x67,
"i32.ctz": 0x68, 'i32.ctz': 0x68,
"i32.popcnt": 0x69, 'i32.popcnt': 0x69,
"i32.add": 0x6a, 'i32.add': 0x6a,
"i32.sub": 0x6b, 'i32.sub': 0x6b,
"i32.mul": 0x6c, 'i32.mul': 0x6c,
"i32.div_s": 0x6d, 'i32.div_s': 0x6d,
"i32.div_u": 0x6e, 'i32.div_u': 0x6e,
"i32.rem_s": 0x6f, 'i32.rem_s': 0x6f,
"i32.rem_u": 0x70, 'i32.rem_u': 0x70,
"i32.and": 0x71, 'i32.and': 0x71,
"i32.or": 0x72, 'i32.or': 0x72,
"i32.xor": 0x73, 'i32.xor': 0x73,
"i32.shl": 0x74, 'i32.shl': 0x74,
"i32.shr_s": 0x75, 'i32.shr_s': 0x75,
"i32.shr_u": 0x76, 'i32.shr_u': 0x76,
"i32.rotl": 0x77, 'i32.rotl': 0x77,
"i32.rotr": 0x78, 'i32.rotr': 0x78,
"i64.clz": 0x79, 'i64.clz': 0x79,
"i64.ctz": 0x7a, 'i64.ctz': 0x7a,
"i64.popcnt": 0x7b, 'i64.popcnt': 0x7b,
"i64.add": 0x7c, 'i64.add': 0x7c,
"i64.sub": 0x7d, 'i64.sub': 0x7d,
"i64.mul": 0x7e, 'i64.mul': 0x7e,
"i64.div_s": 0x7f, 'i64.div_s': 0x7f,
"i64.div_u": 0x80, 'i64.div_u': 0x80,
"i64.rem_s": 0x81, 'i64.rem_s': 0x81,
"i64.rem_u": 0x82, 'i64.rem_u': 0x82,
"i64.and": 0x83, 'i64.and': 0x83,
"i64.or": 0x84, 'i64.or': 0x84,
"i64.xor": 0x85, 'i64.xor': 0x85,
"i64.shl": 0x86, 'i64.shl': 0x86,
"i64.shr_s": 0x87, 'i64.shr_s': 0x87,
"i64.shr_u": 0x88, 'i64.shr_u': 0x88,
"i64.rotl": 0x89, 'i64.rotl': 0x89,
"i64.rotr": 0x8a, 'i64.rotr': 0x8a,
"f32.abs": 0x8b, 'f32.abs': 0x8b,
"f32.neg": 0x8c, 'f32.neg': 0x8c,
"f32.ceil": 0x8d, 'f32.ceil': 0x8d,
"f32.floor": 0x8e, 'f32.floor': 0x8e,
"f32.trunc": 0x8f, 'f32.trunc': 0x8f,
"f32.nearest": 0x90, 'f32.nearest': 0x90,
"f32.sqrt": 0x91, 'f32.sqrt': 0x91,
"f32.add": 0x92, 'f32.add': 0x92,
"f32.sub": 0x93, 'f32.sub': 0x93,
"f32.mul": 0x94, 'f32.mul': 0x94,
"f32.div": 0x95, 'f32.div': 0x95,
"f32.min": 0x96, 'f32.min': 0x96,
"f32.max": 0x97, 'f32.max': 0x97,
"f32.copysign": 0x98, 'f32.copysign': 0x98,
"f64.abs": 0x99, 'f64.abs': 0x99,
"f64.neg": 0x9a, 'f64.neg': 0x9a,
"f64.ceil": 0x9b, 'f64.ceil': 0x9b,
"f64.floor": 0x9c, 'f64.floor': 0x9c,
"f64.trunc": 0x9d, 'f64.trunc': 0x9d,
"f64.nearest": 0x9e, 'f64.nearest': 0x9e,
"f64.sqrt": 0x9f, 'f64.sqrt': 0x9f,
"f64.add": 0xa0, 'f64.add': 0xa0,
"f64.sub": 0xa1, 'f64.sub': 0xa1,
"f64.mul": 0xa2, 'f64.mul': 0xa2,
"f64.div": 0xa3, 'f64.div': 0xa3,
"f64.min": 0xa4, 'f64.min': 0xa4,
"f64.max": 0xa5, 'f64.max': 0xa5,
"f64.copysign": 0xa6, 'f64.copysign': 0xa6,
"i32.wrap_i64": 0xa7, 'i32.wrap_i64': 0xa7,
"i32.trunc_f32_s": 0xa8, 'i32.trunc_f32_s': 0xa8,
"i32.trunc_f32_u": 0xa9, 'i32.trunc_f32_u': 0xa9,
"i32.trunc_f64_s": 0xaa, 'i32.trunc_f64_s': 0xaa,
"i32.trunc_f64_u": 0xab, 'i32.trunc_f64_u': 0xab,
"i64.extend_i32_s": 0xac, 'i64.extend_i32_s': 0xac,
"i64.extend_i32_u": 0xad, 'i64.extend_i32_u': 0xad,
"i64.trunc_f32_s": 0xae, 'i64.trunc_f32_s': 0xae,
"i64.trunc_f32_u": 0xaf, 'i64.trunc_f32_u': 0xaf,
"i64.trunc_f64_s": 0xb0, 'i64.trunc_f64_s': 0xb0,
"i64.trunc_f64_u": 0xb1, 'i64.trunc_f64_u': 0xb1,
"f32.convert_i32_s": 0xb2, 'f32.convert_i32_s': 0xb2,
"f32.convert_i32_u": 0xb3, 'f32.convert_i32_u': 0xb3,
"f32.convert_i64_s": 0xb4, 'f32.convert_i64_s': 0xb4,
"f32.convert_i64_u": 0xb5, 'f32.convert_i64_u': 0xb5,
"f32.demote_f64": 0xb6, 'f32.demote_f64': 0xb6,
"f64.convert_i32_s": 0xb7, 'f64.convert_i32_s': 0xb7,
"f64.convert_i32_u": 0xb8, 'f64.convert_i32_u': 0xb8,
"f64.convert_i64_s": 0xb9, 'f64.convert_i64_s': 0xb9,
"f64.convert_i64_u": 0xba, 'f64.convert_i64_u': 0xba,
"f64.promote_f32": 0xbb, 'f64.promote_f32': 0xbb,
"i32.reinterpret_f32": 0xbc, 'i32.reinterpret_f32': 0xbc,
"i64.reinterpret_f64": 0xbd, 'i64.reinterpret_f64': 0xbd,
"f32.reinterpret_i32": 0xbe, 'f32.reinterpret_i32': 0xbe,
"f64.reinterpret_i64": 0xbf }.freeze 'f64.reinterpret_i64': 0xbf }.freeze
REQUIRED_ARGS = { REQUIRED_ARGS = {
br: [:label], br: [:label],
br_if: [:label], br_if: [:label],
call: [:label], call: [:label],
"local.get": [:label], 'local.get': [:label],
"local.set": [:label], 'local.set': [:label],
"local.tee": [:label], 'local.tee': [:label],
"global.get": [:label], 'global.get': [:label],
"global.set": [:label], 'global.set': [:label],
"i32.const": [13], 'i32.const': [13],
"i64.const": [13], 'i64.const': [13],
"f32.const": [13.0], 'f32.const': [13.0],
"f64.const": [13.0] 'f64.const': [13.0]
}.freeze }.freeze
INSTRUCTIONS.each do |(instruction_name, op_code)| INSTRUCTIONS.each do |(instruction_name, op_code)|

View file

@ -78,7 +78,7 @@ RSpec.describe WAG::Module do
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:module, [:elem, [:"i32.const", 1], :$foo1, :$foo2]] } it { is_expected.to eq [:module, [:elem, [:'i32.const', 1], :$foo1, :$foo2]] }
end end
end end
@ -89,7 +89,7 @@ RSpec.describe WAG::Module do
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:module, [:data, [:"i32.const", 16], 'Hello World']] } it { is_expected.to eq [:module, [:data, [:'i32.const', 16], 'Hello World']] }
end end
end end
@ -115,7 +115,7 @@ RSpec.describe WAG::Module do
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:module, [:table, 16, :anyfunc]] } it { is_expected.to eq [:module, [:table, 16, :funcref]] }
end end
end end
end end

View file

@ -8,6 +8,6 @@ RSpec.describe WAG::Table do
describe '#to_sexpr' do describe '#to_sexpr' do
subject { super().to_sexpr } subject { super().to_sexpr }
it { is_expected.to eq [:table, elements, :anyfunc] } it { is_expected.to eq [:table, elements, :funcref] }
end end
end end

View file

@ -6,19 +6,19 @@ Gem::Specification.new do |spec|
spec.name = 'wag' spec.name = 'wag'
spec.version = WAG::VERSION spec.version = WAG::VERSION
spec.authors = ['James Harton'] spec.authors = ['James Harton']
spec.email = ['james@automat.nz'] spec.email = ['james@harton.nz']
spec.summary = 'WebAssembly Generator' spec.summary = 'WebAssembly Generator'
spec.description = 'Generate and compile WebAssembly code from Ruby' spec.description = 'Generate and compile WebAssembly code from Ruby'
spec.homepage = 'https://gitlab.com/jimsy/wag' spec.homepage = 'https://code.harton.nz/james/wag'
spec.license = 'Hippocratic' spec.license = 'Hippocratic'
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0') spec.required_ruby_version = Gem::Requirement.new('>= 3.1')
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
spec.metadata['homepage_uri'] = spec.homepage spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://gitlab.com/jimsy/wag' spec.metadata['source_code_uri'] = 'https://code.harton.nz/james/wag'
spec.metadata['changelog_uri'] = 'https://gitlab.com/jimsy/wag' spec.metadata['changelog_uri'] = 'https://code.harton.nz/james/wag'
# Specify which files should be added to the gem when it is released. The `git # Specify which files should be added to the gem when it is released. The `git
# ls-files -z` loads the files in the RubyGem that have been added into git. # ls-files -z` loads the files in the RubyGem that have been added into git.
@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib'] spec.require_paths = ['lib']
spec.add_runtime_dependency('dry-inflector', '~> 0.2.0') spec.add_runtime_dependency('dry-inflector', '~> 0.2.0')
spec.metadata['rubygems_mfa_required'] = 'true'
end end