From 1076413d032257e7bcd1fb62ebd4f617a97e44de Mon Sep 17 00:00:00 2001 From: James Harton Date: Fri, 28 Jul 2023 07:57:02 +1200 Subject: [PATCH 1/2] chore: migrate to local. --- .drone.yml | 236 +++++++++++++++++++++++++ .gitlab-ci.yml | 32 ---- .tool-versions | 1 + Gemfile.lock | 1 + README.md | 12 +- lib/wag/export.rb | 2 +- lib/wag/import.rb | 2 +- lib/wag/module.rb | 2 +- lib/wag/table.rb | 2 +- renovate.json | 3 - spec/acceptance/code_validates_spec.rb | 2 +- spec/wag/export_spec.rb | 4 +- spec/wag/import_spec.rb | 4 +- spec/wag/module_spec.rb | 2 +- spec/wag/table_spec.rb | 2 +- wag.gemspec | 8 +- 16 files changed, 259 insertions(+), 56 deletions(-) create mode 100644 .drone.yml delete mode 100644 .gitlab-ci.yml create mode 100644 .tool-versions delete mode 100644 renovate.json diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..75902f5 --- /dev/null +++ b/.drone.yml @@ -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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 795a068..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -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 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..0b2d858 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.1.2 diff --git a/Gemfile.lock b/Gemfile.lock index 6f6a574..d89424e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,6 +59,7 @@ GEM unicode-display_width (2.4.2) PLATFORMS + arm64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/README.md b/README.md index 2777a0a..9938c42 100644 --- a/README.md +++ b/README.md @@ -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]. 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 -valid WASM. Always validate your modules by using `#to_wasm.valid?`. +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?`. ## Keyword conflict @@ -20,7 +20,7 @@ of `public_send`, etc. ## Folding 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: ### Example of unfolded generation @@ -68,6 +68,7 @@ end ``` ### Example of folded generation + ```ruby folded = WAG::Module.new.build do func(:gcd) do @@ -154,7 +155,6 @@ Or install it yourself as: $ gem install wag - ## 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. @@ -163,7 +163,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## 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 @@ -172,7 +172,7 @@ This software is licensed under the terms of the this package for the terms. 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) 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. diff --git a/lib/wag/export.rb b/lib/wag/export.rb index 2c73772..69cf2cf 100644 --- a/lib/wag/export.rb +++ b/lib/wag/export.rb @@ -26,7 +26,7 @@ module WAG @desc end - def table(number, type = :anyfunc, &block) + def table(number, type = :funcref, &block) @desc = Table.new(number, type) @desc.instance_exec(&block) if block @desc diff --git a/lib/wag/import.rb b/lib/wag/import.rb index a4ee138..e642932 100644 --- a/lib/wag/import.rb +++ b/lib/wag/import.rb @@ -29,7 +29,7 @@ module WAG @desc end - def table(number, type = :anyfunc, &block) + def table(number, type = :funcref, &block) @desc = Table.new(number, type) @desc.instance_exec(&block) if block @desc diff --git a/lib/wag/module.rb b/lib/wag/module.rb index feae59a..ef2a9fb 100644 --- a/lib/wag/module.rb +++ b/lib/wag/module.rb @@ -76,7 +76,7 @@ module WAG func end - def table(elements, type = :anyfunc, &block) + def table(elements, type = :funcref, &block) table = Table.new(elements, type) @tables << table table.instance_exec(&block) if block diff --git a/lib/wag/table.rb b/lib/wag/table.rb index 9105dad..38e1934 100644 --- a/lib/wag/table.rb +++ b/lib/wag/table.rb @@ -5,7 +5,7 @@ module WAG include WAG::Encodable attr_reader :elements, :type - def initialize(elements, type = :anyfunc) + def initialize(elements, type = :funcref) @elements = elements @type = type end diff --git a/renovate.json b/renovate.json deleted file mode 100644 index a932bc9..0000000 --- a/renovate.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["gitlab>jimsy/renovate"] -} diff --git a/spec/acceptance/code_validates_spec.rb b/spec/acceptance/code_validates_spec.rb index 0556568..6c676b1 100644 --- a/spec/acceptance/code_validates_spec.rb +++ b/spec/acceptance/code_validates_spec.rb @@ -45,7 +45,7 @@ RSpec.describe 'WAT code generation' do memory(:mem, 1) - table(16, :anyfunc) + table(16, :funcref) elem(0, :dead, :dead, :dead, :alive, :dead, :dead, :dead, :dead, :dead, :dead, :dead, :alive, :alive, :dead, :dead, :dead, diff --git a/spec/wag/export_spec.rb b/spec/wag/export_spec.rb index 457886b..7cc4728 100644 --- a/spec/wag/export_spec.rb +++ b/spec/wag/export_spec.rb @@ -19,12 +19,12 @@ RSpec.describe WAG::Export do describe 'When exporting a table' do before do - export.table(1, :anyfunc) + export.table(1, :funcref) end describe '#to_sexpr' do 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 diff --git a/spec/wag/import_spec.rb b/spec/wag/import_spec.rb index e2145cb..8508015 100644 --- a/spec/wag/import_spec.rb +++ b/spec/wag/import_spec.rb @@ -19,12 +19,12 @@ RSpec.describe WAG::Import do describe 'When importing a table' do before do - import.table(1, :anyfunc) + import.table(1, :funcref) end describe '#to_sexpr' do 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 diff --git a/spec/wag/module_spec.rb b/spec/wag/module_spec.rb index c06d172..645e80a 100644 --- a/spec/wag/module_spec.rb +++ b/spec/wag/module_spec.rb @@ -115,7 +115,7 @@ RSpec.describe WAG::Module do describe '#to_sexpr' do 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 diff --git a/spec/wag/table_spec.rb b/spec/wag/table_spec.rb index bcbd8df..4c2eb49 100644 --- a/spec/wag/table_spec.rb +++ b/spec/wag/table_spec.rb @@ -8,6 +8,6 @@ RSpec.describe WAG::Table do describe '#to_sexpr' do subject { super().to_sexpr } - it { is_expected.to eq [:table, elements, :anyfunc] } + it { is_expected.to eq [:table, elements, :funcref] } end end diff --git a/wag.gemspec b/wag.gemspec index 8b966ae..2172ba9 100644 --- a/wag.gemspec +++ b/wag.gemspec @@ -6,19 +6,19 @@ Gem::Specification.new do |spec| spec.name = 'wag' spec.version = WAG::VERSION spec.authors = ['James Harton'] - spec.email = ['james@automat.nz'] + spec.email = ['james@harton.nz'] spec.summary = 'WebAssembly Generator' 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.required_ruby_version = Gem::Requirement.new('>= 2.3.0') # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://gitlab.com/jimsy/wag' - spec.metadata['changelog_uri'] = 'https://gitlab.com/jimsy/wag' + spec.metadata['source_code_uri'] = 'https://code.harton.nz/james/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 # ls-files -z` loads the files in the RubyGem that have been added into git. -- 2.45.2 From f7370ac26480e7b436a49be7269b4a9aa492645a Mon Sep 17 00:00:00 2001 From: James Harton Date: Fri, 28 Jul 2023 08:41:10 +1200 Subject: [PATCH 2/2] chore: Rubocop fixes. --- .rubocop.yml | 4 + lib/wag/data.rb | 2 +- lib/wag/element.rb | 2 +- lib/wag/instructions/br.rb | 1 + lib/wag/instructions/br_if.rb | 1 + lib/wag/instructions/br_table.rb | 1 + lib/wag/instructions/call.rb | 1 + lib/wag/instructions/f32/const.rb | 1 + lib/wag/instructions/f64/const.rb | 1 + lib/wag/instructions/global/get.rb | 1 + lib/wag/instructions/global/set.rb | 1 + lib/wag/instructions/i32/const.rb | 1 + lib/wag/instructions/i64/const.rb | 1 + lib/wag/instructions/local/get.rb | 1 + lib/wag/instructions/local/set.rb | 1 + lib/wag/instructions/local/tee.rb | 1 + lib/wag/module.rb | 6 +- spec/wag/data_spec.rb | 2 +- spec/wag/element_spec.rb | 4 +- spec/wag/function_spec.rb | 2 +- spec/wag/instructions_spec.rb | 332 ++++++++++++++--------------- spec/wag/module_spec.rb | 4 +- wag.gemspec | 3 +- 23 files changed, 196 insertions(+), 178 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6ebab00..adab9d5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -30,3 +30,7 @@ Style/Documentation: Style/OptionalArguments: Enabled: false + +AllCops: + NewCops: enable + SuggestExtensions: false diff --git a/lib/wag/data.rb b/lib/wag/data.rb index b8d64cd..a18680d 100644 --- a/lib/wag/data.rb +++ b/lib/wag/data.rb @@ -12,7 +12,7 @@ module WAG end def to_sexpr - [:data, [:"i32.const", offset], value] + [:data, [:'i32.const', offset], value] end end end diff --git a/lib/wag/element.rb b/lib/wag/element.rb index 2669ccd..a860aa6 100644 --- a/lib/wag/element.rb +++ b/lib/wag/element.rb @@ -12,7 +12,7 @@ module WAG end 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 diff --git a/lib/wag/instructions/br.rb b/lib/wag/instructions/br.rb index f782b4d..a85bdeb 100644 --- a/lib/wag/instructions/br.rb +++ b/lib/wag/instructions/br.rb @@ -8,6 +8,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/br_if.rb b/lib/wag/instructions/br_if.rb index b14f7af..4f52c9a 100644 --- a/lib/wag/instructions/br_if.rb +++ b/lib/wag/instructions/br_if.rb @@ -8,6 +8,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/br_table.rb b/lib/wag/instructions/br_table.rb index 9e864d6..5aa97d9 100644 --- a/lib/wag/instructions/br_table.rb +++ b/lib/wag/instructions/br_table.rb @@ -8,6 +8,7 @@ module WAG def initialize(*labels) @labels = labels.map { |label| WAG::Label.from(label) } + super() end def to_sexpr diff --git a/lib/wag/instructions/call.rb b/lib/wag/instructions/call.rb index eb22b05..b8ca229 100644 --- a/lib/wag/instructions/call.rb +++ b/lib/wag/instructions/call.rb @@ -8,6 +8,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/f32/const.rb b/lib/wag/instructions/f32/const.rb index ed02e92..328c794 100644 --- a/lib/wag/instructions/f32/const.rb +++ b/lib/wag/instructions/f32/const.rb @@ -9,6 +9,7 @@ module WAG def initialize(literal) @literal = literal.to_f + super() end def to_sexpr diff --git a/lib/wag/instructions/f64/const.rb b/lib/wag/instructions/f64/const.rb index 6868173..b84a4c7 100644 --- a/lib/wag/instructions/f64/const.rb +++ b/lib/wag/instructions/f64/const.rb @@ -9,6 +9,7 @@ module WAG def initialize(literal) @literal = literal.to_f + super() end def to_sexpr diff --git a/lib/wag/instructions/global/get.rb b/lib/wag/instructions/global/get.rb index 9c0844e..feebdc0 100644 --- a/lib/wag/instructions/global/get.rb +++ b/lib/wag/instructions/global/get.rb @@ -9,6 +9,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/global/set.rb b/lib/wag/instructions/global/set.rb index 8aa868c..c933e4c 100644 --- a/lib/wag/instructions/global/set.rb +++ b/lib/wag/instructions/global/set.rb @@ -9,6 +9,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/i32/const.rb b/lib/wag/instructions/i32/const.rb index 5ae6c47..e582a7f 100644 --- a/lib/wag/instructions/i32/const.rb +++ b/lib/wag/instructions/i32/const.rb @@ -9,6 +9,7 @@ module WAG def initialize(literal) @literal = literal.to_i + super() end def to_sexpr diff --git a/lib/wag/instructions/i64/const.rb b/lib/wag/instructions/i64/const.rb index 5b061e4..16026db 100644 --- a/lib/wag/instructions/i64/const.rb +++ b/lib/wag/instructions/i64/const.rb @@ -9,6 +9,7 @@ module WAG def initialize(literal) @literal = literal.to_i + super() end def to_sexpr diff --git a/lib/wag/instructions/local/get.rb b/lib/wag/instructions/local/get.rb index e7deeaa..ef797b0 100644 --- a/lib/wag/instructions/local/get.rb +++ b/lib/wag/instructions/local/get.rb @@ -9,6 +9,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/local/set.rb b/lib/wag/instructions/local/set.rb index 895d5f4..d5898b7 100644 --- a/lib/wag/instructions/local/set.rb +++ b/lib/wag/instructions/local/set.rb @@ -9,6 +9,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/instructions/local/tee.rb b/lib/wag/instructions/local/tee.rb index 48f99e2..310b4dc 100644 --- a/lib/wag/instructions/local/tee.rb +++ b/lib/wag/instructions/local/tee.rb @@ -9,6 +9,7 @@ module WAG def initialize(label) @label = WAG::Label.from(label) + super() end def to_sexpr diff --git a/lib/wag/module.rb b/lib/wag/module.rb index ef2a9fb..67b6fbf 100644 --- a/lib/wag/module.rb +++ b/lib/wag/module.rb @@ -16,8 +16,8 @@ module WAG @types = [] end - def build(&block) - instance_exec(&block) + def build(&) + instance_exec(&) self end @@ -83,7 +83,7 @@ module WAG table 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.concat(@imports.map(&:to_sexpr)) mod.concat(@exports.map(&:to_sexpr)) diff --git a/spec/wag/data_spec.rb b/spec/wag/data_spec.rb index fd1a758..5902f5b 100644 --- a/spec/wag/data_spec.rb +++ b/spec/wag/data_spec.rb @@ -10,6 +10,6 @@ RSpec.describe WAG::Data do describe '#to_sexpr' do 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 diff --git a/spec/wag/element_spec.rb b/spec/wag/element_spec.rb index 0a78950..4ece336 100644 --- a/spec/wag/element_spec.rb +++ b/spec/wag/element_spec.rb @@ -11,12 +11,12 @@ RSpec.describe WAG::Element do context 'When the element has no labels' do let(:labels) { [] } - it { is_expected.to eq [:elem, [:"i32.const", table_id]] } + it { is_expected.to eq [:elem, [:'i32.const', table_id]] } end context 'When the element has no labels' do 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 diff --git a/spec/wag/function_spec.rb b/spec/wag/function_spec.rb index 59b5f44..a1eef0c 100644 --- a/spec/wag/function_spec.rb +++ b/spec/wag/function_spec.rb @@ -73,7 +73,7 @@ RSpec.describe WAG::Function do context 'When the function has a body' do 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 diff --git a/spec/wag/instructions_spec.rb b/spec/wag/instructions_spec.rb index e82c9b6..d686907 100644 --- a/spec/wag/instructions_spec.rb +++ b/spec/wag/instructions_spec.rb @@ -17,177 +17,177 @@ INSTRUCTIONS = { unreachable: 0x00, call_indirect: 0x11, drop: 0x1a, select: 0x1b, - "local.get": 0x20, - "local.set": 0x21, - "local.tee": 0x22, - "global.get": 0x23, - "global.set": 0x24, - "i32.load": 0x28, - "i64.load": 0x29, - "f32.load": 0x2a, - "f64.load": 0x2b, - "i32.load8_s": 0x2c, - "i32.load8_u": 0x2d, - "i32.load16_s": 0x2e, - "i32.load16_u": 0x2f, - "i64.load8_s": 0x30, - "i64.load8_u": 0x31, - "i64.load16_s": 0x32, - "i64.load16_u": 0x33, - "i64.load32_s": 0x34, - "i64.load32_u": 0x35, - "i32.store": 0x36, - "i64.store": 0x37, - "f32.store": 0x38, - "f64.store": 0x39, - "i32.store8": 0x3a, - "i32.store16": 0x3b, - "i64.store8": 0x3c, - "i64.store16": 0x3d, - "i64.store32": 0x3e, - "memory.size": 0x3f, - "memory.grow": 0x40, - "i32.const": 0x41, - "i64.const": 0x42, - "f32.const": 0x43, - "f64.const": 0x44, - "i32.eqz": 0x45, - "i32.eq": 0x46, - "i32.ne": 0x47, - "i32.lt_s": 0x48, - "i32.lt_u": 0x49, - "i32.gt_s": 0x4a, - "i32.gt_u": 0x4b, - "i32.le_s": 0x4c, - "i32.le_u": 0x4d, - "i32.ge_s": 0x4e, - "i32.ge_u": 0x4f, - "i64.eqz": 0x50, - "i64.eq": 0x51, - "i64.ne": 0x52, - "i64.lt_s": 0x53, - "i64.lt_u": 0x54, - "i64.gt_s": 0x55, - "i64.gt_u": 0x56, - "i64.le_s": 0x57, - "i64.le_u": 0x58, - "i64.ge_s": 0x59, - "i64.ge_u": 0x5a, - "f32.eq": 0x5b, - "f32.ne": 0x5c, - "f32.lt": 0x5d, - "f32.gt": 0x5e, - "f32.le": 0x5f, - "f32.ge": 0x60, - "f64.eq": 0x61, - "f64.ne": 0x62, - "f64.lt": 0x63, - "f64.gt": 0x64, - "f64.le": 0x65, - "f64.ge": 0x66, - "i32.clz": 0x67, - "i32.ctz": 0x68, - "i32.popcnt": 0x69, - "i32.add": 0x6a, - "i32.sub": 0x6b, - "i32.mul": 0x6c, - "i32.div_s": 0x6d, - "i32.div_u": 0x6e, - "i32.rem_s": 0x6f, - "i32.rem_u": 0x70, - "i32.and": 0x71, - "i32.or": 0x72, - "i32.xor": 0x73, - "i32.shl": 0x74, - "i32.shr_s": 0x75, - "i32.shr_u": 0x76, - "i32.rotl": 0x77, - "i32.rotr": 0x78, - "i64.clz": 0x79, - "i64.ctz": 0x7a, - "i64.popcnt": 0x7b, - "i64.add": 0x7c, - "i64.sub": 0x7d, - "i64.mul": 0x7e, - "i64.div_s": 0x7f, - "i64.div_u": 0x80, - "i64.rem_s": 0x81, - "i64.rem_u": 0x82, - "i64.and": 0x83, - "i64.or": 0x84, - "i64.xor": 0x85, - "i64.shl": 0x86, - "i64.shr_s": 0x87, - "i64.shr_u": 0x88, - "i64.rotl": 0x89, - "i64.rotr": 0x8a, - "f32.abs": 0x8b, - "f32.neg": 0x8c, - "f32.ceil": 0x8d, - "f32.floor": 0x8e, - "f32.trunc": 0x8f, - "f32.nearest": 0x90, - "f32.sqrt": 0x91, - "f32.add": 0x92, - "f32.sub": 0x93, - "f32.mul": 0x94, - "f32.div": 0x95, - "f32.min": 0x96, - "f32.max": 0x97, - "f32.copysign": 0x98, - "f64.abs": 0x99, - "f64.neg": 0x9a, - "f64.ceil": 0x9b, - "f64.floor": 0x9c, - "f64.trunc": 0x9d, - "f64.nearest": 0x9e, - "f64.sqrt": 0x9f, - "f64.add": 0xa0, - "f64.sub": 0xa1, - "f64.mul": 0xa2, - "f64.div": 0xa3, - "f64.min": 0xa4, - "f64.max": 0xa5, - "f64.copysign": 0xa6, - "i32.wrap_i64": 0xa7, - "i32.trunc_f32_s": 0xa8, - "i32.trunc_f32_u": 0xa9, - "i32.trunc_f64_s": 0xaa, - "i32.trunc_f64_u": 0xab, - "i64.extend_i32_s": 0xac, - "i64.extend_i32_u": 0xad, - "i64.trunc_f32_s": 0xae, - "i64.trunc_f32_u": 0xaf, - "i64.trunc_f64_s": 0xb0, - "i64.trunc_f64_u": 0xb1, - "f32.convert_i32_s": 0xb2, - "f32.convert_i32_u": 0xb3, - "f32.convert_i64_s": 0xb4, - "f32.convert_i64_u": 0xb5, - "f32.demote_f64": 0xb6, - "f64.convert_i32_s": 0xb7, - "f64.convert_i32_u": 0xb8, - "f64.convert_i64_s": 0xb9, - "f64.convert_i64_u": 0xba, - "f64.promote_f32": 0xbb, - "i32.reinterpret_f32": 0xbc, - "i64.reinterpret_f64": 0xbd, - "f32.reinterpret_i32": 0xbe, - "f64.reinterpret_i64": 0xbf }.freeze + 'local.get': 0x20, + 'local.set': 0x21, + 'local.tee': 0x22, + 'global.get': 0x23, + 'global.set': 0x24, + 'i32.load': 0x28, + 'i64.load': 0x29, + 'f32.load': 0x2a, + 'f64.load': 0x2b, + 'i32.load8_s': 0x2c, + 'i32.load8_u': 0x2d, + 'i32.load16_s': 0x2e, + 'i32.load16_u': 0x2f, + 'i64.load8_s': 0x30, + 'i64.load8_u': 0x31, + 'i64.load16_s': 0x32, + 'i64.load16_u': 0x33, + 'i64.load32_s': 0x34, + 'i64.load32_u': 0x35, + 'i32.store': 0x36, + 'i64.store': 0x37, + 'f32.store': 0x38, + 'f64.store': 0x39, + 'i32.store8': 0x3a, + 'i32.store16': 0x3b, + 'i64.store8': 0x3c, + 'i64.store16': 0x3d, + 'i64.store32': 0x3e, + 'memory.size': 0x3f, + 'memory.grow': 0x40, + 'i32.const': 0x41, + 'i64.const': 0x42, + 'f32.const': 0x43, + 'f64.const': 0x44, + 'i32.eqz': 0x45, + 'i32.eq': 0x46, + 'i32.ne': 0x47, + 'i32.lt_s': 0x48, + 'i32.lt_u': 0x49, + 'i32.gt_s': 0x4a, + 'i32.gt_u': 0x4b, + 'i32.le_s': 0x4c, + 'i32.le_u': 0x4d, + 'i32.ge_s': 0x4e, + 'i32.ge_u': 0x4f, + 'i64.eqz': 0x50, + 'i64.eq': 0x51, + 'i64.ne': 0x52, + 'i64.lt_s': 0x53, + 'i64.lt_u': 0x54, + 'i64.gt_s': 0x55, + 'i64.gt_u': 0x56, + 'i64.le_s': 0x57, + 'i64.le_u': 0x58, + 'i64.ge_s': 0x59, + 'i64.ge_u': 0x5a, + 'f32.eq': 0x5b, + 'f32.ne': 0x5c, + 'f32.lt': 0x5d, + 'f32.gt': 0x5e, + 'f32.le': 0x5f, + 'f32.ge': 0x60, + 'f64.eq': 0x61, + 'f64.ne': 0x62, + 'f64.lt': 0x63, + 'f64.gt': 0x64, + 'f64.le': 0x65, + 'f64.ge': 0x66, + 'i32.clz': 0x67, + 'i32.ctz': 0x68, + 'i32.popcnt': 0x69, + 'i32.add': 0x6a, + 'i32.sub': 0x6b, + 'i32.mul': 0x6c, + 'i32.div_s': 0x6d, + 'i32.div_u': 0x6e, + 'i32.rem_s': 0x6f, + 'i32.rem_u': 0x70, + 'i32.and': 0x71, + 'i32.or': 0x72, + 'i32.xor': 0x73, + 'i32.shl': 0x74, + 'i32.shr_s': 0x75, + 'i32.shr_u': 0x76, + 'i32.rotl': 0x77, + 'i32.rotr': 0x78, + 'i64.clz': 0x79, + 'i64.ctz': 0x7a, + 'i64.popcnt': 0x7b, + 'i64.add': 0x7c, + 'i64.sub': 0x7d, + 'i64.mul': 0x7e, + 'i64.div_s': 0x7f, + 'i64.div_u': 0x80, + 'i64.rem_s': 0x81, + 'i64.rem_u': 0x82, + 'i64.and': 0x83, + 'i64.or': 0x84, + 'i64.xor': 0x85, + 'i64.shl': 0x86, + 'i64.shr_s': 0x87, + 'i64.shr_u': 0x88, + 'i64.rotl': 0x89, + 'i64.rotr': 0x8a, + 'f32.abs': 0x8b, + 'f32.neg': 0x8c, + 'f32.ceil': 0x8d, + 'f32.floor': 0x8e, + 'f32.trunc': 0x8f, + 'f32.nearest': 0x90, + 'f32.sqrt': 0x91, + 'f32.add': 0x92, + 'f32.sub': 0x93, + 'f32.mul': 0x94, + 'f32.div': 0x95, + 'f32.min': 0x96, + 'f32.max': 0x97, + 'f32.copysign': 0x98, + 'f64.abs': 0x99, + 'f64.neg': 0x9a, + 'f64.ceil': 0x9b, + 'f64.floor': 0x9c, + 'f64.trunc': 0x9d, + 'f64.nearest': 0x9e, + 'f64.sqrt': 0x9f, + 'f64.add': 0xa0, + 'f64.sub': 0xa1, + 'f64.mul': 0xa2, + 'f64.div': 0xa3, + 'f64.min': 0xa4, + 'f64.max': 0xa5, + 'f64.copysign': 0xa6, + 'i32.wrap_i64': 0xa7, + 'i32.trunc_f32_s': 0xa8, + 'i32.trunc_f32_u': 0xa9, + 'i32.trunc_f64_s': 0xaa, + 'i32.trunc_f64_u': 0xab, + 'i64.extend_i32_s': 0xac, + 'i64.extend_i32_u': 0xad, + 'i64.trunc_f32_s': 0xae, + 'i64.trunc_f32_u': 0xaf, + 'i64.trunc_f64_s': 0xb0, + 'i64.trunc_f64_u': 0xb1, + 'f32.convert_i32_s': 0xb2, + 'f32.convert_i32_u': 0xb3, + 'f32.convert_i64_s': 0xb4, + 'f32.convert_i64_u': 0xb5, + 'f32.demote_f64': 0xb6, + 'f64.convert_i32_s': 0xb7, + 'f64.convert_i32_u': 0xb8, + 'f64.convert_i64_s': 0xb9, + 'f64.convert_i64_u': 0xba, + 'f64.promote_f32': 0xbb, + 'i32.reinterpret_f32': 0xbc, + 'i64.reinterpret_f64': 0xbd, + 'f32.reinterpret_i32': 0xbe, + 'f64.reinterpret_i64': 0xbf }.freeze REQUIRED_ARGS = { br: [:label], br_if: [:label], call: [:label], - "local.get": [:label], - "local.set": [:label], - "local.tee": [:label], - "global.get": [:label], - "global.set": [:label], - "i32.const": [13], - "i64.const": [13], - "f32.const": [13.0], - "f64.const": [13.0] + 'local.get': [:label], + 'local.set': [:label], + 'local.tee': [:label], + 'global.get': [:label], + 'global.set': [:label], + 'i32.const': [13], + 'i64.const': [13], + 'f32.const': [13.0], + 'f64.const': [13.0] }.freeze INSTRUCTIONS.each do |(instruction_name, op_code)| diff --git a/spec/wag/module_spec.rb b/spec/wag/module_spec.rb index 645e80a..62c62d8 100644 --- a/spec/wag/module_spec.rb +++ b/spec/wag/module_spec.rb @@ -78,7 +78,7 @@ RSpec.describe WAG::Module do describe '#to_sexpr' do 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 @@ -89,7 +89,7 @@ RSpec.describe WAG::Module do describe '#to_sexpr' do 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 diff --git a/wag.gemspec b/wag.gemspec index 2172ba9..80bf103 100644 --- a/wag.gemspec +++ b/wag.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = 'Generate and compile WebAssembly code from Ruby' spec.homepage = 'https://code.harton.nz/james/wag' 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'" @@ -32,4 +32,5 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_runtime_dependency('dry-inflector', '~> 0.2.0') + spec.metadata['rubygems_mfa_required'] = 'true' end -- 2.45.2