diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 320e79b..2f6a4c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ image: ruby:latest before_script: + - apt-get update && apt-get install wabt && rm -rf /var/cache/apt - bundle install test: diff --git a/lib/wag.rb b/lib/wag.rb index e731437..2370992 100644 --- a/lib/wag.rb +++ b/lib/wag.rb @@ -6,7 +6,7 @@ module WAG class Error < StandardError; end # Your code goes here... - require 'wag/wat' + require 'wag/encodable' require 'wag/inflector' require 'wag/instructable' @@ -26,11 +26,17 @@ module WAG require 'wag/instruction' require 'wag/label' require 'wag/local_instructions' + require 'wag/local' require 'wag/memory_instructions' require 'wag/memory' require 'wag/module' require 'wag/param' require 'wag/result' require 'wag/table' + require 'wag/then' require 'wag/type' + + require 'wag/wabt' + require 'wag/wasm' + require 'wag/wat' end diff --git a/lib/wag/data.rb b/lib/wag/data.rb index ab15727..b8d64cd 100644 --- a/lib/wag/data.rb +++ b/lib/wag/data.rb @@ -2,7 +2,7 @@ module WAG class Data - include WAG::WAT + include WAG::Encodable attr_reader :offset, :value diff --git a/lib/wag/element.rb b/lib/wag/element.rb index 48fc59e..2669ccd 100644 --- a/lib/wag/element.rb +++ b/lib/wag/element.rb @@ -2,7 +2,7 @@ module WAG class Element - include WAG::WAT + include WAG::Encodable attr_reader :table_id, :labels diff --git a/lib/wag/encodable.rb b/lib/wag/encodable.rb new file mode 100644 index 0000000..f8cc742 --- /dev/null +++ b/lib/wag/encodable.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module WAG + # A simple mixin which formats s-expressions as WAT. + module Encodable + def to_wat + WAG::WAT.new(wat_encode(to_sexpr)) + end + + def to_wasm + to_wat.to_wasm + end + + private + + def wat_encode(data) + return "(#{data.map { |e| wat_encode(e) }.join(' ')})" if data.is_a?(Enumerable) + return data.inspect if data.is_a?(String) + + data.to_s + end + end +end diff --git a/lib/wag/export.rb b/lib/wag/export.rb index e469081..2c73772 100644 --- a/lib/wag/export.rb +++ b/lib/wag/export.rb @@ -2,7 +2,7 @@ module WAG class Export - include WAG::WAT + include WAG::Encodable attr_reader :name, :desc @@ -26,7 +26,7 @@ module WAG @desc end - def table(number, type = :funcref, &block) + def table(number, type = :anyfunc, &block) @desc = Table.new(number, type) @desc.instance_exec(&block) if block @desc diff --git a/lib/wag/function.rb b/lib/wag/function.rb index 368fb7c..a3e7a76 100644 --- a/lib/wag/function.rb +++ b/lib/wag/function.rb @@ -2,7 +2,7 @@ module WAG class Function - include WAG::WAT + include WAG::Encodable prepend WAG::Instructable attr_reader :label, :params diff --git a/lib/wag/global.rb b/lib/wag/global.rb index dcb2e28..e061e83 100644 --- a/lib/wag/global.rb +++ b/lib/wag/global.rb @@ -2,7 +2,7 @@ module WAG class Global - include WAG::WAT + include WAG::Encodable attr_reader :label, :type diff --git a/lib/wag/import.rb b/lib/wag/import.rb index 6c1ecba..a4ee138 100644 --- a/lib/wag/import.rb +++ b/lib/wag/import.rb @@ -2,7 +2,7 @@ module WAG class Import - include WAG::WAT + include WAG::Encodable attr_reader :module_name, :name, :desc @@ -29,7 +29,7 @@ module WAG @desc end - def table(number, type = :funcref, &block) + def table(number, type = :anyfunc, &block) @desc = Table.new(number, type) @desc.instance_exec(&block) if block @desc diff --git a/lib/wag/instructable.rb b/lib/wag/instructable.rb index 58bd6c6..c90c3fd 100644 --- a/lib/wag/instructable.rb +++ b/lib/wag/instructable.rb @@ -14,6 +14,12 @@ module WAG end end + # Alias Ruby keywords because reasons. + alias if_ if + alias else_ else + alias end_ end + alias loop_ loop + def f32 WAG::F32Instructions.new(instructions) end @@ -22,8 +28,12 @@ module WAG WAG::F64Instructions.new(instructions) end - def local - WAG::LocalInstructions.new(instructions) + def local(*args) + return WAG::LocalInstructions.new(instructions) if args.empty? + + instruction = WAG::Local.new(*args) + instructions << instruction + instruction end def i32 @@ -39,7 +49,10 @@ module WAG end def to_sexpr - super().concat(instructions.map(&:to_sexpr)) + value = super() + return value if instructions.empty? + + Array(value).concat(instructions.map(&:to_sexpr)) end private diff --git a/lib/wag/instructions/base.rb b/lib/wag/instructions/base.rb index 19ed6bc..5049d47 100644 --- a/lib/wag/instructions/base.rb +++ b/lib/wag/instructions/base.rb @@ -3,8 +3,7 @@ module WAG module Instruction class Base - include WAG::WAT - prepend WAG::Instructable + include WAG::Encodable def self.instruction(op_code) klass = Class.new(self) diff --git a/lib/wag/instructions/block.rb b/lib/wag/instructions/block.rb index ed01198..2575ff2 100644 --- a/lib/wag/instructions/block.rb +++ b/lib/wag/instructions/block.rb @@ -3,6 +3,8 @@ module WAG module Instruction class Block < Base.instruction(0x02) + prepend WAG::Instructable + def result(*types) return @result if types.empty? @@ -10,9 +12,9 @@ module WAG end def to_sexpr - [:block].tap do |expr| - expr << @result.to_sexpr if @result - end + return [name, @result.to_sexpr] if @result + + [name] end end end diff --git a/lib/wag/instructions/br.rb b/lib/wag/instructions/br.rb index 097e676..f782b4d 100644 --- a/lib/wag/instructions/br.rb +++ b/lib/wag/instructions/br.rb @@ -3,6 +3,7 @@ module WAG module Instruction class Br < Base.instruction(0x0c) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/br_if.rb b/lib/wag/instructions/br_if.rb index 168e0b0..b14f7af 100644 --- a/lib/wag/instructions/br_if.rb +++ b/lib/wag/instructions/br_if.rb @@ -3,6 +3,7 @@ module WAG module Instruction class BrIf < Base.instruction(0x0d) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/br_table.rb b/lib/wag/instructions/br_table.rb index a8252d4..9e864d6 100644 --- a/lib/wag/instructions/br_table.rb +++ b/lib/wag/instructions/br_table.rb @@ -3,6 +3,7 @@ module WAG module Instruction class BrTable < Base.instruction(0x0e) + prepend WAG::Instructable attr_reader :label def initialize(*labels) diff --git a/lib/wag/instructions/call.rb b/lib/wag/instructions/call.rb index 0f832aa..eb22b05 100644 --- a/lib/wag/instructions/call.rb +++ b/lib/wag/instructions/call.rb @@ -3,6 +3,16 @@ module WAG module Instruction class Call < Base.instruction(0x10) + prepend WAG::Instructable + attr_reader :label + + def initialize(label) + @label = WAG::Label.from(label) + end + + def to_sexpr + [:call, label.to_sexpr] + end end end end diff --git a/lib/wag/instructions/call_indirect.rb b/lib/wag/instructions/call_indirect.rb index c3db913..16d2cc0 100644 --- a/lib/wag/instructions/call_indirect.rb +++ b/lib/wag/instructions/call_indirect.rb @@ -3,6 +3,16 @@ module WAG module Instruction class CallIndirect < Base.instruction(0x11) + prepend WAG::Instructable + def result(*types) + @result = WAG::Result.new(*types) + end + + def to_sexpr + return [name, @result.to_sexpr] if @result + + super() + end end end end diff --git a/lib/wag/instructions/else.rb b/lib/wag/instructions/else.rb index 0d0bce9..41501b5 100644 --- a/lib/wag/instructions/else.rb +++ b/lib/wag/instructions/else.rb @@ -3,6 +3,7 @@ module WAG module Instruction class Else < Base.instruction(0x05) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/abs.rb b/lib/wag/instructions/f32/abs.rb index 83b288b..4f1eadb 100644 --- a/lib/wag/instructions/f32/abs.rb +++ b/lib/wag/instructions/f32/abs.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Abs < Base.instruction(0x8b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/add.rb b/lib/wag/instructions/f32/add.rb index 6729612..fb4eb9e 100644 --- a/lib/wag/instructions/f32/add.rb +++ b/lib/wag/instructions/f32/add.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Add < Base.instruction(0x92) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/ceil.rb b/lib/wag/instructions/f32/ceil.rb index 26bbfac..da4781f 100644 --- a/lib/wag/instructions/f32/ceil.rb +++ b/lib/wag/instructions/f32/ceil.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Ceil < Base.instruction(0x8d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/const.rb b/lib/wag/instructions/f32/const.rb index abea7f5..ed02e92 100644 --- a/lib/wag/instructions/f32/const.rb +++ b/lib/wag/instructions/f32/const.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Const < Base.instruction(0x43) + prepend WAG::Instructable attr_reader :literal def initialize(literal) diff --git a/lib/wag/instructions/f32/convert_i32_s.rb b/lib/wag/instructions/f32/convert_i32_s.rb index 9150387..348f749 100644 --- a/lib/wag/instructions/f32/convert_i32_s.rb +++ b/lib/wag/instructions/f32/convert_i32_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class ConvertI32S < Base.instruction(0xb2) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/convert_i32_u.rb b/lib/wag/instructions/f32/convert_i32_u.rb index cd92def..9165918 100644 --- a/lib/wag/instructions/f32/convert_i32_u.rb +++ b/lib/wag/instructions/f32/convert_i32_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class ConvertI32U < Base.instruction(0xb3) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/convert_i64_s.rb b/lib/wag/instructions/f32/convert_i64_s.rb index 0e48838..b05a2f8 100644 --- a/lib/wag/instructions/f32/convert_i64_s.rb +++ b/lib/wag/instructions/f32/convert_i64_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class ConvertI64S < Base.instruction(0xb4) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/convert_i64_u.rb b/lib/wag/instructions/f32/convert_i64_u.rb index 4d2db5b..dbbc3b0 100644 --- a/lib/wag/instructions/f32/convert_i64_u.rb +++ b/lib/wag/instructions/f32/convert_i64_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class ConvertI64U < Base.instruction(0xb5) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/copysign.rb b/lib/wag/instructions/f32/copysign.rb index 744e764..e416bf4 100644 --- a/lib/wag/instructions/f32/copysign.rb +++ b/lib/wag/instructions/f32/copysign.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Copysign < Base.instruction(0x98) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/demote_f64.rb b/lib/wag/instructions/f32/demote_f64.rb index 99ef7a8..4d4cce8 100644 --- a/lib/wag/instructions/f32/demote_f64.rb +++ b/lib/wag/instructions/f32/demote_f64.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class DemoteF64 < Base.instruction(0xb6) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/div.rb b/lib/wag/instructions/f32/div.rb index 57904b6..d36d49f 100644 --- a/lib/wag/instructions/f32/div.rb +++ b/lib/wag/instructions/f32/div.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Div < Base.instruction(0x95) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/eq.rb b/lib/wag/instructions/f32/eq.rb index 77bd1de..2f78701 100644 --- a/lib/wag/instructions/f32/eq.rb +++ b/lib/wag/instructions/f32/eq.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Eq < Base.instruction(0x5b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/floor.rb b/lib/wag/instructions/f32/floor.rb index 6b21ee1..7ac036c 100644 --- a/lib/wag/instructions/f32/floor.rb +++ b/lib/wag/instructions/f32/floor.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Floor < Base.instruction(0x8e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/ge.rb b/lib/wag/instructions/f32/ge.rb index afea461..02f3e64 100644 --- a/lib/wag/instructions/f32/ge.rb +++ b/lib/wag/instructions/f32/ge.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Ge < Base.instruction(0x60) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/gt.rb b/lib/wag/instructions/f32/gt.rb index c5f02d8..5b5ea03 100644 --- a/lib/wag/instructions/f32/gt.rb +++ b/lib/wag/instructions/f32/gt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Gt < Base.instruction(0x5e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/le.rb b/lib/wag/instructions/f32/le.rb index 9d12590..9f96d38 100644 --- a/lib/wag/instructions/f32/le.rb +++ b/lib/wag/instructions/f32/le.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Le < Base.instruction(0x5f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/load.rb b/lib/wag/instructions/f32/load.rb index a6502d5..b48f35b 100644 --- a/lib/wag/instructions/f32/load.rb +++ b/lib/wag/instructions/f32/load.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Load < Base.instruction(0x2a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/lt.rb b/lib/wag/instructions/f32/lt.rb index 9dfe049..507bf2c 100644 --- a/lib/wag/instructions/f32/lt.rb +++ b/lib/wag/instructions/f32/lt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Lt < Base.instruction(0x5d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/max.rb b/lib/wag/instructions/f32/max.rb index 2460612..2c9af78 100644 --- a/lib/wag/instructions/f32/max.rb +++ b/lib/wag/instructions/f32/max.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Max < Base.instruction(0x97) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/min.rb b/lib/wag/instructions/f32/min.rb index 1fb6572..15ebedd 100644 --- a/lib/wag/instructions/f32/min.rb +++ b/lib/wag/instructions/f32/min.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Min < Base.instruction(0x96) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/mul.rb b/lib/wag/instructions/f32/mul.rb index 7c0cb37..5e810a3 100644 --- a/lib/wag/instructions/f32/mul.rb +++ b/lib/wag/instructions/f32/mul.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Mul < Base.instruction(0x94) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/ne.rb b/lib/wag/instructions/f32/ne.rb index 1acf411..acb7942 100644 --- a/lib/wag/instructions/f32/ne.rb +++ b/lib/wag/instructions/f32/ne.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Ne < Base.instruction(0x5c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/nearest.rb b/lib/wag/instructions/f32/nearest.rb index 6d98858..5593c40 100644 --- a/lib/wag/instructions/f32/nearest.rb +++ b/lib/wag/instructions/f32/nearest.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Nearest < Base.instruction(0x90) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/neg.rb b/lib/wag/instructions/f32/neg.rb index d193b88..92949aa 100644 --- a/lib/wag/instructions/f32/neg.rb +++ b/lib/wag/instructions/f32/neg.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Neg < Base.instruction(0x8c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/reinterpret_i32.rb b/lib/wag/instructions/f32/reinterpret_i32.rb index e10df4c..015540f 100644 --- a/lib/wag/instructions/f32/reinterpret_i32.rb +++ b/lib/wag/instructions/f32/reinterpret_i32.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class ReinterpretI32 < Base.instruction(0xbe) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/sqrt.rb b/lib/wag/instructions/f32/sqrt.rb index e1b1149..3f79af9 100644 --- a/lib/wag/instructions/f32/sqrt.rb +++ b/lib/wag/instructions/f32/sqrt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Sqrt < Base.instruction(0x91) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/store.rb b/lib/wag/instructions/f32/store.rb index bf9c93f..46f13e0 100644 --- a/lib/wag/instructions/f32/store.rb +++ b/lib/wag/instructions/f32/store.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Store < Base.instruction(0x38) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/sub.rb b/lib/wag/instructions/f32/sub.rb index e378c3c..6631f07 100644 --- a/lib/wag/instructions/f32/sub.rb +++ b/lib/wag/instructions/f32/sub.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Sub < Base.instruction(0x93) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f32/trunc.rb b/lib/wag/instructions/f32/trunc.rb index 40abb8d..7b116fc 100644 --- a/lib/wag/instructions/f32/trunc.rb +++ b/lib/wag/instructions/f32/trunc.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F32 class Trunc < Base.instruction(0x8f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/abs.rb b/lib/wag/instructions/f64/abs.rb index 12fee2e..4c3940f 100644 --- a/lib/wag/instructions/f64/abs.rb +++ b/lib/wag/instructions/f64/abs.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Abs < Base.instruction(0x99) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/add.rb b/lib/wag/instructions/f64/add.rb index e62fc36..c2f5a9e 100644 --- a/lib/wag/instructions/f64/add.rb +++ b/lib/wag/instructions/f64/add.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Add < Base.instruction(0xa0) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/ceil.rb b/lib/wag/instructions/f64/ceil.rb index 75c4419..89c949f 100644 --- a/lib/wag/instructions/f64/ceil.rb +++ b/lib/wag/instructions/f64/ceil.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Ceil < Base.instruction(0x9b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/const.rb b/lib/wag/instructions/f64/const.rb index a31193e..6868173 100644 --- a/lib/wag/instructions/f64/const.rb +++ b/lib/wag/instructions/f64/const.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Const < Base.instruction(0x44) + prepend WAG::Instructable attr_reader :literal def initialize(literal) diff --git a/lib/wag/instructions/f64/convert_i32_s.rb b/lib/wag/instructions/f64/convert_i32_s.rb index 274700b..0b0550d 100644 --- a/lib/wag/instructions/f64/convert_i32_s.rb +++ b/lib/wag/instructions/f64/convert_i32_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class ConvertI32S < Base.instruction(0xb7) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/convert_i32_u.rb b/lib/wag/instructions/f64/convert_i32_u.rb index 6f22cba..fd2d94c 100644 --- a/lib/wag/instructions/f64/convert_i32_u.rb +++ b/lib/wag/instructions/f64/convert_i32_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class ConvertI32U < Base.instruction(0xb8) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/convert_i64_s.rb b/lib/wag/instructions/f64/convert_i64_s.rb index 184c37f..643c80a 100644 --- a/lib/wag/instructions/f64/convert_i64_s.rb +++ b/lib/wag/instructions/f64/convert_i64_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class ConvertI64S < Base.instruction(0xb9) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/convert_i64_u.rb b/lib/wag/instructions/f64/convert_i64_u.rb index 87b33c6..edccc69 100644 --- a/lib/wag/instructions/f64/convert_i64_u.rb +++ b/lib/wag/instructions/f64/convert_i64_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class ConvertI64U < Base.instruction(0xba) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/copysign.rb b/lib/wag/instructions/f64/copysign.rb index b759d86..be1dd19 100644 --- a/lib/wag/instructions/f64/copysign.rb +++ b/lib/wag/instructions/f64/copysign.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Copysign < Base.instruction(0xa6) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/div.rb b/lib/wag/instructions/f64/div.rb index 3480fd7..c04c045 100644 --- a/lib/wag/instructions/f64/div.rb +++ b/lib/wag/instructions/f64/div.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Div < Base.instruction(0xa3) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/eq.rb b/lib/wag/instructions/f64/eq.rb index 030848a..33aeb7a 100644 --- a/lib/wag/instructions/f64/eq.rb +++ b/lib/wag/instructions/f64/eq.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Eq < Base.instruction(0x61) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/floor.rb b/lib/wag/instructions/f64/floor.rb index 7b52d74..bad6e4c 100644 --- a/lib/wag/instructions/f64/floor.rb +++ b/lib/wag/instructions/f64/floor.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Floor < Base.instruction(0x9c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/ge.rb b/lib/wag/instructions/f64/ge.rb index e8b54af..54b4cfe 100644 --- a/lib/wag/instructions/f64/ge.rb +++ b/lib/wag/instructions/f64/ge.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Ge < Base.instruction(0x66) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/gt.rb b/lib/wag/instructions/f64/gt.rb index cff9d2f..27386b6 100644 --- a/lib/wag/instructions/f64/gt.rb +++ b/lib/wag/instructions/f64/gt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Gt < Base.instruction(0x64) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/le.rb b/lib/wag/instructions/f64/le.rb index 5c1fd3d..903852f 100644 --- a/lib/wag/instructions/f64/le.rb +++ b/lib/wag/instructions/f64/le.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Le < Base.instruction(0x65) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/load.rb b/lib/wag/instructions/f64/load.rb index df76088..bc9234e 100644 --- a/lib/wag/instructions/f64/load.rb +++ b/lib/wag/instructions/f64/load.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Load < Base.instruction(0x2b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/lt.rb b/lib/wag/instructions/f64/lt.rb index fc465d2..10896d6 100644 --- a/lib/wag/instructions/f64/lt.rb +++ b/lib/wag/instructions/f64/lt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Lt < Base.instruction(0x63) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/max.rb b/lib/wag/instructions/f64/max.rb index ef00864..e276b14 100644 --- a/lib/wag/instructions/f64/max.rb +++ b/lib/wag/instructions/f64/max.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Max < Base.instruction(0xa5) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/min.rb b/lib/wag/instructions/f64/min.rb index 81f311b..2a8f647 100644 --- a/lib/wag/instructions/f64/min.rb +++ b/lib/wag/instructions/f64/min.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Min < Base.instruction(0xa4) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/mul.rb b/lib/wag/instructions/f64/mul.rb index aedc311..f29a1c7 100644 --- a/lib/wag/instructions/f64/mul.rb +++ b/lib/wag/instructions/f64/mul.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Mul < Base.instruction(0xa2) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/ne.rb b/lib/wag/instructions/f64/ne.rb index c4d738c..64958de 100644 --- a/lib/wag/instructions/f64/ne.rb +++ b/lib/wag/instructions/f64/ne.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Ne < Base.instruction(0x62) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/nearest.rb b/lib/wag/instructions/f64/nearest.rb index d5b2e16..ab6d550 100644 --- a/lib/wag/instructions/f64/nearest.rb +++ b/lib/wag/instructions/f64/nearest.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Nearest < Base.instruction(0x9e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/neg.rb b/lib/wag/instructions/f64/neg.rb index 43477ee..393d7f3 100644 --- a/lib/wag/instructions/f64/neg.rb +++ b/lib/wag/instructions/f64/neg.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Neg < Base.instruction(0x9a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/promote_f32.rb b/lib/wag/instructions/f64/promote_f32.rb index 9189d0e..67bafd9 100644 --- a/lib/wag/instructions/f64/promote_f32.rb +++ b/lib/wag/instructions/f64/promote_f32.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class PromoteF32 < Base.instruction(0xbb) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/reinterpret_i64.rb b/lib/wag/instructions/f64/reinterpret_i64.rb index ae86225..c2377ff 100644 --- a/lib/wag/instructions/f64/reinterpret_i64.rb +++ b/lib/wag/instructions/f64/reinterpret_i64.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class ReinterpretI64 < Base.instruction(0xbf) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/sqrt.rb b/lib/wag/instructions/f64/sqrt.rb index 9826ebb..440bf8a 100644 --- a/lib/wag/instructions/f64/sqrt.rb +++ b/lib/wag/instructions/f64/sqrt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Sqrt < Base.instruction(0x9f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/store.rb b/lib/wag/instructions/f64/store.rb index 22c3c68..6a7b2da 100644 --- a/lib/wag/instructions/f64/store.rb +++ b/lib/wag/instructions/f64/store.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Store < Base.instruction(0x39) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/sub.rb b/lib/wag/instructions/f64/sub.rb index 248ed2d..6cd433b 100644 --- a/lib/wag/instructions/f64/sub.rb +++ b/lib/wag/instructions/f64/sub.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Sub < Base.instruction(0xa1) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/f64/trunc.rb b/lib/wag/instructions/f64/trunc.rb index 3d0356b..a140891 100644 --- a/lib/wag/instructions/f64/trunc.rb +++ b/lib/wag/instructions/f64/trunc.rb @@ -4,6 +4,7 @@ module WAG module Instruction module F64 class Trunc < Base.instruction(0x9d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/global/get.rb b/lib/wag/instructions/global/get.rb index c35b936..9c0844e 100644 --- a/lib/wag/instructions/global/get.rb +++ b/lib/wag/instructions/global/get.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Global class Get < Base.instruction(0x23) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/global/set.rb b/lib/wag/instructions/global/set.rb index f98bfa3..8aa868c 100644 --- a/lib/wag/instructions/global/set.rb +++ b/lib/wag/instructions/global/set.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Global class Set < Base.instruction(0x24) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/i32/add.rb b/lib/wag/instructions/i32/add.rb index 546d65b..4e86121 100644 --- a/lib/wag/instructions/i32/add.rb +++ b/lib/wag/instructions/i32/add.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Add < Base.instruction(0x6a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/and.rb b/lib/wag/instructions/i32/and.rb index 50772c9..c6b674c 100644 --- a/lib/wag/instructions/i32/and.rb +++ b/lib/wag/instructions/i32/and.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class And < Base.instruction(0x71) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/clz.rb b/lib/wag/instructions/i32/clz.rb index 270eb42..330e9a3 100644 --- a/lib/wag/instructions/i32/clz.rb +++ b/lib/wag/instructions/i32/clz.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Clz < Base.instruction(0x67) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/const.rb b/lib/wag/instructions/i32/const.rb index 6ca9f22..5ae6c47 100644 --- a/lib/wag/instructions/i32/const.rb +++ b/lib/wag/instructions/i32/const.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Const < Base.instruction(0x41) + prepend WAG::Instructable attr_reader :literal def initialize(literal) diff --git a/lib/wag/instructions/i32/ctz.rb b/lib/wag/instructions/i32/ctz.rb index 871c786..fb91c13 100644 --- a/lib/wag/instructions/i32/ctz.rb +++ b/lib/wag/instructions/i32/ctz.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Ctz < Base.instruction(0x68) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/div_s.rb b/lib/wag/instructions/i32/div_s.rb index 5c84b33..483f29f 100644 --- a/lib/wag/instructions/i32/div_s.rb +++ b/lib/wag/instructions/i32/div_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class DivS < Base.instruction(0x6d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/div_u.rb b/lib/wag/instructions/i32/div_u.rb index a48e62a..94ba576 100644 --- a/lib/wag/instructions/i32/div_u.rb +++ b/lib/wag/instructions/i32/div_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class DivU < Base.instruction(0x6e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/eq.rb b/lib/wag/instructions/i32/eq.rb index 02676d1..de87829 100644 --- a/lib/wag/instructions/i32/eq.rb +++ b/lib/wag/instructions/i32/eq.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Eq < Base.instruction(0x46) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/eqz.rb b/lib/wag/instructions/i32/eqz.rb index e75c801..dfada39 100644 --- a/lib/wag/instructions/i32/eqz.rb +++ b/lib/wag/instructions/i32/eqz.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Eqz < Base.instruction(0x45) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/ge_s.rb b/lib/wag/instructions/i32/ge_s.rb index 0fe3b31..917f4a1 100644 --- a/lib/wag/instructions/i32/ge_s.rb +++ b/lib/wag/instructions/i32/ge_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class GeS < Base.instruction(0x4e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/ge_u.rb b/lib/wag/instructions/i32/ge_u.rb index 9860aef..5ef6ee1 100644 --- a/lib/wag/instructions/i32/ge_u.rb +++ b/lib/wag/instructions/i32/ge_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class GeU < Base.instruction(0x4f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/gt_s.rb b/lib/wag/instructions/i32/gt_s.rb index 1b216ce..6172902 100644 --- a/lib/wag/instructions/i32/gt_s.rb +++ b/lib/wag/instructions/i32/gt_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class GtS < Base.instruction(0x4a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/gt_u.rb b/lib/wag/instructions/i32/gt_u.rb index 3e6e9d7..278e186 100644 --- a/lib/wag/instructions/i32/gt_u.rb +++ b/lib/wag/instructions/i32/gt_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class GtU < Base.instruction(0x4b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/le_s.rb b/lib/wag/instructions/i32/le_s.rb index 708ce8a..0e3f9ea 100644 --- a/lib/wag/instructions/i32/le_s.rb +++ b/lib/wag/instructions/i32/le_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class LeS < Base.instruction(0x4c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/le_u.rb b/lib/wag/instructions/i32/le_u.rb index c6c463a..7c17773 100644 --- a/lib/wag/instructions/i32/le_u.rb +++ b/lib/wag/instructions/i32/le_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class LeU < Base.instruction(0x4d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/load.rb b/lib/wag/instructions/i32/load.rb index 2de8957..adf6272 100644 --- a/lib/wag/instructions/i32/load.rb +++ b/lib/wag/instructions/i32/load.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Load < Base.instruction(0x28) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/load16_s.rb b/lib/wag/instructions/i32/load16_s.rb index 2622534..209ebf1 100644 --- a/lib/wag/instructions/i32/load16_s.rb +++ b/lib/wag/instructions/i32/load16_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Load16S < Base.instruction(0x2e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/load16_u.rb b/lib/wag/instructions/i32/load16_u.rb index a5d5487..54d5ce4 100644 --- a/lib/wag/instructions/i32/load16_u.rb +++ b/lib/wag/instructions/i32/load16_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Load16U < Base.instruction(0x2f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/load8_s.rb b/lib/wag/instructions/i32/load8_s.rb index 41022d7..fb6c08b 100644 --- a/lib/wag/instructions/i32/load8_s.rb +++ b/lib/wag/instructions/i32/load8_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Load8S < Base.instruction(0x2c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/load8_u.rb b/lib/wag/instructions/i32/load8_u.rb index dd62574..14aaf4b 100644 --- a/lib/wag/instructions/i32/load8_u.rb +++ b/lib/wag/instructions/i32/load8_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Load8U < Base.instruction(0x2d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/lt_s.rb b/lib/wag/instructions/i32/lt_s.rb index aa7a9db..36e4726 100644 --- a/lib/wag/instructions/i32/lt_s.rb +++ b/lib/wag/instructions/i32/lt_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class LtS < Base.instruction(0x48) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/lt_u.rb b/lib/wag/instructions/i32/lt_u.rb index 6e80a69..f3b330e 100644 --- a/lib/wag/instructions/i32/lt_u.rb +++ b/lib/wag/instructions/i32/lt_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class LtU < Base.instruction(0x49) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/mul.rb b/lib/wag/instructions/i32/mul.rb index 10310b7..69ecd70 100644 --- a/lib/wag/instructions/i32/mul.rb +++ b/lib/wag/instructions/i32/mul.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Mul < Base.instruction(0x6c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/ne.rb b/lib/wag/instructions/i32/ne.rb index b1032b9..b12cd41 100644 --- a/lib/wag/instructions/i32/ne.rb +++ b/lib/wag/instructions/i32/ne.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Ne < Base.instruction(0x47) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/or.rb b/lib/wag/instructions/i32/or.rb index afc9f1a..4ad639b 100644 --- a/lib/wag/instructions/i32/or.rb +++ b/lib/wag/instructions/i32/or.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Or < Base.instruction(0x72) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/popcnt.rb b/lib/wag/instructions/i32/popcnt.rb index 7e760fa..26d234a 100644 --- a/lib/wag/instructions/i32/popcnt.rb +++ b/lib/wag/instructions/i32/popcnt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Popcnt < Base.instruction(0x69) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/reinterpret_f32.rb b/lib/wag/instructions/i32/reinterpret_f32.rb index 8448324..4cb8d47 100644 --- a/lib/wag/instructions/i32/reinterpret_f32.rb +++ b/lib/wag/instructions/i32/reinterpret_f32.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class ReinterpretF32 < Base.instruction(0xbc) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/rem_s.rb b/lib/wag/instructions/i32/rem_s.rb index 4f32dc0..336057e 100644 --- a/lib/wag/instructions/i32/rem_s.rb +++ b/lib/wag/instructions/i32/rem_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class RemS < Base.instruction(0x6f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/rem_u.rb b/lib/wag/instructions/i32/rem_u.rb index 84382e3..922cae8 100644 --- a/lib/wag/instructions/i32/rem_u.rb +++ b/lib/wag/instructions/i32/rem_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class RemU < Base.instruction(0x70) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/rotl.rb b/lib/wag/instructions/i32/rotl.rb index 1197ed3..43905f4 100644 --- a/lib/wag/instructions/i32/rotl.rb +++ b/lib/wag/instructions/i32/rotl.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Rotl < Base.instruction(0x77) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/rotr.rb b/lib/wag/instructions/i32/rotr.rb index 4f6c155..41047a5 100644 --- a/lib/wag/instructions/i32/rotr.rb +++ b/lib/wag/instructions/i32/rotr.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Rotr < Base.instruction(0x78) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/shl.rb b/lib/wag/instructions/i32/shl.rb index 2321b37..7fb6651 100644 --- a/lib/wag/instructions/i32/shl.rb +++ b/lib/wag/instructions/i32/shl.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Shl < Base.instruction(0x74) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/shr_s.rb b/lib/wag/instructions/i32/shr_s.rb index af0f2d7..33f6d3e 100644 --- a/lib/wag/instructions/i32/shr_s.rb +++ b/lib/wag/instructions/i32/shr_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class ShrS < Base.instruction(0x75) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/shr_u.rb b/lib/wag/instructions/i32/shr_u.rb index 60ebccd..44f52c3 100644 --- a/lib/wag/instructions/i32/shr_u.rb +++ b/lib/wag/instructions/i32/shr_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class ShrU < Base.instruction(0x76) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/store.rb b/lib/wag/instructions/i32/store.rb index 38cb11e..5a9473e 100644 --- a/lib/wag/instructions/i32/store.rb +++ b/lib/wag/instructions/i32/store.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Store < Base.instruction(0x36) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/store16.rb b/lib/wag/instructions/i32/store16.rb index f3405c6..b04f986 100644 --- a/lib/wag/instructions/i32/store16.rb +++ b/lib/wag/instructions/i32/store16.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Store16 < Base.instruction(0x3b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/store8.rb b/lib/wag/instructions/i32/store8.rb index 6e06757..ebb6a06 100644 --- a/lib/wag/instructions/i32/store8.rb +++ b/lib/wag/instructions/i32/store8.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Store8 < Base.instruction(0x3a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/sub.rb b/lib/wag/instructions/i32/sub.rb index 959112a..5d352d3 100644 --- a/lib/wag/instructions/i32/sub.rb +++ b/lib/wag/instructions/i32/sub.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Sub < Base.instruction(0x6b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/trunc_f32_s.rb b/lib/wag/instructions/i32/trunc_f32_s.rb index f9f344d..6ce6775 100644 --- a/lib/wag/instructions/i32/trunc_f32_s.rb +++ b/lib/wag/instructions/i32/trunc_f32_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class TruncF32S < Base.instruction(0xa8) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/trunc_f32_u.rb b/lib/wag/instructions/i32/trunc_f32_u.rb index 4ebce80..f5c3492 100644 --- a/lib/wag/instructions/i32/trunc_f32_u.rb +++ b/lib/wag/instructions/i32/trunc_f32_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class TruncF32U < Base.instruction(0xa9) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/trunc_f64_s.rb b/lib/wag/instructions/i32/trunc_f64_s.rb index 9b72f3e..f96bb4f 100644 --- a/lib/wag/instructions/i32/trunc_f64_s.rb +++ b/lib/wag/instructions/i32/trunc_f64_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class TruncF64S < Base.instruction(0xaa) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/trunc_f64_u.rb b/lib/wag/instructions/i32/trunc_f64_u.rb index c8ccbde..ba66386 100644 --- a/lib/wag/instructions/i32/trunc_f64_u.rb +++ b/lib/wag/instructions/i32/trunc_f64_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class TruncF64U < Base.instruction(0xab) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/wrap_i64.rb b/lib/wag/instructions/i32/wrap_i64.rb index 87fd787..4c5899b 100644 --- a/lib/wag/instructions/i32/wrap_i64.rb +++ b/lib/wag/instructions/i32/wrap_i64.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class WrapI64 < Base.instruction(0xa7) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i32/xor.rb b/lib/wag/instructions/i32/xor.rb index da7f34e..5ed9ece 100644 --- a/lib/wag/instructions/i32/xor.rb +++ b/lib/wag/instructions/i32/xor.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I32 class Xor < Base.instruction(0x73) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/add.rb b/lib/wag/instructions/i64/add.rb index c9fc279..ad006c3 100644 --- a/lib/wag/instructions/i64/add.rb +++ b/lib/wag/instructions/i64/add.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Add < Base.instruction(0x7c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/and.rb b/lib/wag/instructions/i64/and.rb index 263c1df..7b6b7dd 100644 --- a/lib/wag/instructions/i64/and.rb +++ b/lib/wag/instructions/i64/and.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class And < Base.instruction(0x83) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/clz.rb b/lib/wag/instructions/i64/clz.rb index 5c24d8c..24954bd 100644 --- a/lib/wag/instructions/i64/clz.rb +++ b/lib/wag/instructions/i64/clz.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Clz < Base.instruction(0x79) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/const.rb b/lib/wag/instructions/i64/const.rb index 7b0fe2a..5b061e4 100644 --- a/lib/wag/instructions/i64/const.rb +++ b/lib/wag/instructions/i64/const.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Const < Base.instruction(0x42) + prepend WAG::Instructable attr_reader :literal def initialize(literal) diff --git a/lib/wag/instructions/i64/ctz.rb b/lib/wag/instructions/i64/ctz.rb index 45b2d05..dbc5795 100644 --- a/lib/wag/instructions/i64/ctz.rb +++ b/lib/wag/instructions/i64/ctz.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Ctz < Base.instruction(0x7a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/div_s.rb b/lib/wag/instructions/i64/div_s.rb index a8c37a7..65b80d7 100644 --- a/lib/wag/instructions/i64/div_s.rb +++ b/lib/wag/instructions/i64/div_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class DivS < Base.instruction(0x7f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/div_u.rb b/lib/wag/instructions/i64/div_u.rb index 77c1bec..9f8c9a4 100644 --- a/lib/wag/instructions/i64/div_u.rb +++ b/lib/wag/instructions/i64/div_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class DivU < Base.instruction(0x80) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/eq.rb b/lib/wag/instructions/i64/eq.rb index 2a6c093..1c8533f 100644 --- a/lib/wag/instructions/i64/eq.rb +++ b/lib/wag/instructions/i64/eq.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Eq < Base.instruction(0x51) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/eqz.rb b/lib/wag/instructions/i64/eqz.rb index 9dd461e..c0dad31 100644 --- a/lib/wag/instructions/i64/eqz.rb +++ b/lib/wag/instructions/i64/eqz.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Eqz < Base.instruction(0x50) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/extend_i32_s.rb b/lib/wag/instructions/i64/extend_i32_s.rb index 3282a67..fae001d 100644 --- a/lib/wag/instructions/i64/extend_i32_s.rb +++ b/lib/wag/instructions/i64/extend_i32_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class ExtendI32S < Base.instruction(0xac) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/extend_i32_u.rb b/lib/wag/instructions/i64/extend_i32_u.rb index 5117f17..33d2e76 100644 --- a/lib/wag/instructions/i64/extend_i32_u.rb +++ b/lib/wag/instructions/i64/extend_i32_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class ExtendI32U < Base.instruction(0xad) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/ge_s.rb b/lib/wag/instructions/i64/ge_s.rb index 6d3687e..cab8042 100644 --- a/lib/wag/instructions/i64/ge_s.rb +++ b/lib/wag/instructions/i64/ge_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class GeS < Base.instruction(0x59) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/ge_u.rb b/lib/wag/instructions/i64/ge_u.rb index ef568a4..58e05a0 100644 --- a/lib/wag/instructions/i64/ge_u.rb +++ b/lib/wag/instructions/i64/ge_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class GeU < Base.instruction(0x5a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/gt_s.rb b/lib/wag/instructions/i64/gt_s.rb index 594c094..6eefc1d 100644 --- a/lib/wag/instructions/i64/gt_s.rb +++ b/lib/wag/instructions/i64/gt_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class GtS < Base.instruction(0x55) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/gt_u.rb b/lib/wag/instructions/i64/gt_u.rb index 70165b4..ffe56f3 100644 --- a/lib/wag/instructions/i64/gt_u.rb +++ b/lib/wag/instructions/i64/gt_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class GtU < Base.instruction(0x56) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/le_s.rb b/lib/wag/instructions/i64/le_s.rb index 9316a96..8105554 100644 --- a/lib/wag/instructions/i64/le_s.rb +++ b/lib/wag/instructions/i64/le_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class LeS < Base.instruction(0x57) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/le_u.rb b/lib/wag/instructions/i64/le_u.rb index e806a6e..afaa203 100644 --- a/lib/wag/instructions/i64/le_u.rb +++ b/lib/wag/instructions/i64/le_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class LeU < Base.instruction(0x58) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load.rb b/lib/wag/instructions/i64/load.rb index c678016..8dc4dd5 100644 --- a/lib/wag/instructions/i64/load.rb +++ b/lib/wag/instructions/i64/load.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load < Base.instruction(0x29) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load16_s.rb b/lib/wag/instructions/i64/load16_s.rb index ce0ae4f..8ff33d6 100644 --- a/lib/wag/instructions/i64/load16_s.rb +++ b/lib/wag/instructions/i64/load16_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load16S < Base.instruction(0x32) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load16_u.rb b/lib/wag/instructions/i64/load16_u.rb index 2918e8a..56a86d9 100644 --- a/lib/wag/instructions/i64/load16_u.rb +++ b/lib/wag/instructions/i64/load16_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load16U < Base.instruction(0x33) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load32_s.rb b/lib/wag/instructions/i64/load32_s.rb index ec1d96b..cb51152 100644 --- a/lib/wag/instructions/i64/load32_s.rb +++ b/lib/wag/instructions/i64/load32_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load32S < Base.instruction(0x34) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load32_u.rb b/lib/wag/instructions/i64/load32_u.rb index d674952..7032398 100644 --- a/lib/wag/instructions/i64/load32_u.rb +++ b/lib/wag/instructions/i64/load32_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load32U < Base.instruction(0x35) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load8_s.rb b/lib/wag/instructions/i64/load8_s.rb index 8755585..5732012 100644 --- a/lib/wag/instructions/i64/load8_s.rb +++ b/lib/wag/instructions/i64/load8_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load8S < Base.instruction(0x30) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/load8_u.rb b/lib/wag/instructions/i64/load8_u.rb index 1aa847d..9169c94 100644 --- a/lib/wag/instructions/i64/load8_u.rb +++ b/lib/wag/instructions/i64/load8_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Load8U < Base.instruction(0x31) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/lt_s.rb b/lib/wag/instructions/i64/lt_s.rb index 85c5c22..e72526a 100644 --- a/lib/wag/instructions/i64/lt_s.rb +++ b/lib/wag/instructions/i64/lt_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class LtS < Base.instruction(0x53) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/lt_u.rb b/lib/wag/instructions/i64/lt_u.rb index 56dc70b..a1436a9 100644 --- a/lib/wag/instructions/i64/lt_u.rb +++ b/lib/wag/instructions/i64/lt_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class LtU < Base.instruction(0x54) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/mul.rb b/lib/wag/instructions/i64/mul.rb index 507c6c4..95a335f 100644 --- a/lib/wag/instructions/i64/mul.rb +++ b/lib/wag/instructions/i64/mul.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Mul < Base.instruction(0x7e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/ne.rb b/lib/wag/instructions/i64/ne.rb index 233fda0..ceb12a0 100644 --- a/lib/wag/instructions/i64/ne.rb +++ b/lib/wag/instructions/i64/ne.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Ne < Base.instruction(0x52) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/or.rb b/lib/wag/instructions/i64/or.rb index 8ef6ef4..d6f92d6 100644 --- a/lib/wag/instructions/i64/or.rb +++ b/lib/wag/instructions/i64/or.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Or < Base.instruction(0x84) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/popcnt.rb b/lib/wag/instructions/i64/popcnt.rb index 2ae50ef..967f58b 100644 --- a/lib/wag/instructions/i64/popcnt.rb +++ b/lib/wag/instructions/i64/popcnt.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Popcnt < Base.instruction(0x7b) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/reinterpret_f64.rb b/lib/wag/instructions/i64/reinterpret_f64.rb index 2d3958e..e1f782c 100644 --- a/lib/wag/instructions/i64/reinterpret_f64.rb +++ b/lib/wag/instructions/i64/reinterpret_f64.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class ReinterpretF64 < Base.instruction(0xbd) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/rem_s.rb b/lib/wag/instructions/i64/rem_s.rb index 1116b61..a97b716 100644 --- a/lib/wag/instructions/i64/rem_s.rb +++ b/lib/wag/instructions/i64/rem_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class RemS < Base.instruction(0x81) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/rem_u.rb b/lib/wag/instructions/i64/rem_u.rb index af6a374..368a440 100644 --- a/lib/wag/instructions/i64/rem_u.rb +++ b/lib/wag/instructions/i64/rem_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class RemU < Base.instruction(0x82) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/rotl.rb b/lib/wag/instructions/i64/rotl.rb index afc8b0f..b6b6d3b 100644 --- a/lib/wag/instructions/i64/rotl.rb +++ b/lib/wag/instructions/i64/rotl.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Rotl < Base.instruction(0x89) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/rotr.rb b/lib/wag/instructions/i64/rotr.rb index e167317..1de0174 100644 --- a/lib/wag/instructions/i64/rotr.rb +++ b/lib/wag/instructions/i64/rotr.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Rotr < Base.instruction(0x8a) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/shl.rb b/lib/wag/instructions/i64/shl.rb index a678f5a..a2c503d 100644 --- a/lib/wag/instructions/i64/shl.rb +++ b/lib/wag/instructions/i64/shl.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Shl < Base.instruction(0x86) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/shr_s.rb b/lib/wag/instructions/i64/shr_s.rb index e99969c..9eb3942 100644 --- a/lib/wag/instructions/i64/shr_s.rb +++ b/lib/wag/instructions/i64/shr_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class ShrS < Base.instruction(0x87) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/shr_u.rb b/lib/wag/instructions/i64/shr_u.rb index 7ddd391..816f3a8 100644 --- a/lib/wag/instructions/i64/shr_u.rb +++ b/lib/wag/instructions/i64/shr_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class ShrU < Base.instruction(0x88) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/store.rb b/lib/wag/instructions/i64/store.rb index 4c477fb..08f578a 100644 --- a/lib/wag/instructions/i64/store.rb +++ b/lib/wag/instructions/i64/store.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Store < Base.instruction(0x37) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/store16.rb b/lib/wag/instructions/i64/store16.rb index 8500718..a0fcafd 100644 --- a/lib/wag/instructions/i64/store16.rb +++ b/lib/wag/instructions/i64/store16.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Store16 < Base.instruction(0x3d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/store32.rb b/lib/wag/instructions/i64/store32.rb index f7a106e..302c868 100644 --- a/lib/wag/instructions/i64/store32.rb +++ b/lib/wag/instructions/i64/store32.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Store32 < Base.instruction(0x3e) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/store8.rb b/lib/wag/instructions/i64/store8.rb index 3dd67b9..1b34f1f 100644 --- a/lib/wag/instructions/i64/store8.rb +++ b/lib/wag/instructions/i64/store8.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Store8 < Base.instruction(0x3c) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/sub.rb b/lib/wag/instructions/i64/sub.rb index 8f9b511..f7b5ab6 100644 --- a/lib/wag/instructions/i64/sub.rb +++ b/lib/wag/instructions/i64/sub.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Sub < Base.instruction(0x7d) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/trunc_f32_s.rb b/lib/wag/instructions/i64/trunc_f32_s.rb index eeda544..11e462e 100644 --- a/lib/wag/instructions/i64/trunc_f32_s.rb +++ b/lib/wag/instructions/i64/trunc_f32_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class TruncF32S < Base.instruction(0xae) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/trunc_f32_u.rb b/lib/wag/instructions/i64/trunc_f32_u.rb index 91dac2c..5e3fe59 100644 --- a/lib/wag/instructions/i64/trunc_f32_u.rb +++ b/lib/wag/instructions/i64/trunc_f32_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class TruncF32U < Base.instruction(0xaf) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/trunc_f64_s.rb b/lib/wag/instructions/i64/trunc_f64_s.rb index cf0c654..a716860 100644 --- a/lib/wag/instructions/i64/trunc_f64_s.rb +++ b/lib/wag/instructions/i64/trunc_f64_s.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class TruncF64S < Base.instruction(0xb0) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/trunc_f64_u.rb b/lib/wag/instructions/i64/trunc_f64_u.rb index 4f464fe..64fd4d6 100644 --- a/lib/wag/instructions/i64/trunc_f64_u.rb +++ b/lib/wag/instructions/i64/trunc_f64_u.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class TruncF64U < Base.instruction(0xb1) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/i64/xor.rb b/lib/wag/instructions/i64/xor.rb index b12aec7..fb4fdc7 100644 --- a/lib/wag/instructions/i64/xor.rb +++ b/lib/wag/instructions/i64/xor.rb @@ -4,6 +4,7 @@ module WAG module Instruction module I64 class Xor < Base.instruction(0x85) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/if.rb b/lib/wag/instructions/if.rb index 9509da9..071ac6d 100644 --- a/lib/wag/instructions/if.rb +++ b/lib/wag/instructions/if.rb @@ -3,6 +3,24 @@ module WAG module Instruction class If < Base.instruction(0x04) + prepend WAG::Instructable + def result(*types) + @result = WAG::Result.new(*types) + end + + def then(&block) + instruction = WAG::Then.new + instructions << instruction + instruction.instance_exec(&block) if block + instruction + end + alias then_ then + + def to_sexpr + return [name, @result.to_sexpr] if @result + + super() + end end end end diff --git a/lib/wag/instructions/local/get.rb b/lib/wag/instructions/local/get.rb index 30dc922..e7deeaa 100644 --- a/lib/wag/instructions/local/get.rb +++ b/lib/wag/instructions/local/get.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Local class Get < Base.instruction(0x20) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/local/set.rb b/lib/wag/instructions/local/set.rb index 4e9d0c7..895d5f4 100644 --- a/lib/wag/instructions/local/set.rb +++ b/lib/wag/instructions/local/set.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Local class Set < Base.instruction(0x21) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/local/tee.rb b/lib/wag/instructions/local/tee.rb index d2ede8d..48f99e2 100644 --- a/lib/wag/instructions/local/tee.rb +++ b/lib/wag/instructions/local/tee.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Local class Tee < Base.instruction(0x22) + prepend WAG::Instructable attr_reader :label def initialize(label) diff --git a/lib/wag/instructions/loop.rb b/lib/wag/instructions/loop.rb index 3ad000e..0a80204 100644 --- a/lib/wag/instructions/loop.rb +++ b/lib/wag/instructions/loop.rb @@ -3,6 +3,7 @@ module WAG module Instruction class Loop < Base.instruction(0x03) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/memory/grow.rb b/lib/wag/instructions/memory/grow.rb index 45beb0a..7ecc301 100644 --- a/lib/wag/instructions/memory/grow.rb +++ b/lib/wag/instructions/memory/grow.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Memory class Grow < Base.instruction(0x40) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/memory/size.rb b/lib/wag/instructions/memory/size.rb index ca09b76..441c61e 100644 --- a/lib/wag/instructions/memory/size.rb +++ b/lib/wag/instructions/memory/size.rb @@ -4,6 +4,7 @@ module WAG module Instruction module Memory class Size < Base.instruction(0x3f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/return.rb b/lib/wag/instructions/return.rb index 7c43a2a..ff501be 100644 --- a/lib/wag/instructions/return.rb +++ b/lib/wag/instructions/return.rb @@ -3,6 +3,7 @@ module WAG module Instruction class Return < Base.instruction(0x0f) + prepend WAG::Instructable end end end diff --git a/lib/wag/instructions/select.rb b/lib/wag/instructions/select.rb index 0010d80..855d338 100644 --- a/lib/wag/instructions/select.rb +++ b/lib/wag/instructions/select.rb @@ -3,6 +3,7 @@ module WAG module Instruction class Select < Base.instruction(0x1b) + prepend WAG::Instructable end end end diff --git a/lib/wag/label.rb b/lib/wag/label.rb index 6381b7b..655a4ce 100644 --- a/lib/wag/label.rb +++ b/lib/wag/label.rb @@ -2,17 +2,25 @@ module WAG class Label - include WAG::WAT + include WAG::Encodable attr_reader :value def initialize(value) - @value = value.to_s - @value = @value[1..-1] if @value.start_with?('$') + if value.is_a?(Integer) + @value = @value.to_i + else + value = value.to_s + @value = if value.start_with?('$') + value.to_sym + else + "$#{value}".to_sym + end + end end def to_sexpr - "$#{value}".to_sym + value end def self.from(value) diff --git a/lib/wag/local.rb b/lib/wag/local.rb new file mode 100644 index 0000000..7261037 --- /dev/null +++ b/lib/wag/local.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module WAG + # Local is not an instruction, but a nested keyword. + class Local + include WAG::Encodable + + attr_reader :label, :type + + def initialize(label, type) + @label = WAG::Label.from(label) + @type = WAG::Type.from(type) + end + + def to_sexpr + [:local, label.to_sexpr, type.to_sexpr] + end + end +end diff --git a/lib/wag/memory.rb b/lib/wag/memory.rb index fac32f8..de6f9b9 100644 --- a/lib/wag/memory.rb +++ b/lib/wag/memory.rb @@ -2,18 +2,20 @@ module WAG class Memory - include WAG::WAT + include WAG::Encodable - attr_reader :number, :min, :max + attr_reader :label, :number, :min, :max - def initialize(number, min = nil, max = nil) - @number = number - @min = min - @max = max + def initialize(*args) + @label = WAG::Label.from(args.shift) if args.first.is_a?(Symbol) + + (@number, @min, @max) = args end def to_sexpr - [:memory, number].tap do |expr| + [:memory].tap do |expr| + expr.push(label.to_sexpr) if label + expr.push(number) if min expr.push(min) expr.push(max) if max diff --git a/lib/wag/module.rb b/lib/wag/module.rb index 1f04758..335d127 100644 --- a/lib/wag/module.rb +++ b/lib/wag/module.rb @@ -2,7 +2,7 @@ module WAG class Module - include WAG::WAT + include WAG::Encodable def initialize @data = [] @@ -12,6 +12,7 @@ module WAG @globals = [] @imports = [] @memories = [] + @tables = [] @types = [] end @@ -70,13 +71,21 @@ module WAG func end - def to_sexpr # rubocop:disable Metrics/AbcSize + def table(elements, type = :anyfunc, &block) + table = Table.new(elements, type) + @tables << table + table.instance_exec(&block) if block + table + end + + def to_sexpr # rubocop:disable Metrics/AbcSize, Metrics/MethodLength mod = [:module] mod.concat(@imports.map(&:to_sexpr)) mod.concat(@exports.map(&:to_sexpr)) mod.concat(@memories.map(&:to_sexpr)) mod.concat(@globals.map(&:to_sexpr)) mod.concat(@types.map(&:to_sexpr)) + mod.concat(@tables.map(&:to_sexpr)) mod.concat(@elements.map(&:to_sexpr)) mod.concat(@data.map(&:to_sexpr)) mod.concat(@functions.map(&:to_sexpr)) diff --git a/lib/wag/param.rb b/lib/wag/param.rb index fab6ef9..995a1fc 100644 --- a/lib/wag/param.rb +++ b/lib/wag/param.rb @@ -2,7 +2,7 @@ module WAG class Param - include WAG::WAT + include WAG::Encodable attr_reader :type, :label diff --git a/lib/wag/result.rb b/lib/wag/result.rb index 1ebad96..042a61a 100644 --- a/lib/wag/result.rb +++ b/lib/wag/result.rb @@ -2,7 +2,7 @@ module WAG class Result - include WAG::WAT + include WAG::Encodable attr_reader :types diff --git a/lib/wag/table.rb b/lib/wag/table.rb index b39c287..9105dad 100644 --- a/lib/wag/table.rb +++ b/lib/wag/table.rb @@ -2,10 +2,10 @@ module WAG class Table - include WAG::WAT + include WAG::Encodable attr_reader :elements, :type - def initialize(elements, type = :funcref) + def initialize(elements, type = :anyfunc) @elements = elements @type = type end diff --git a/lib/wag/then.rb b/lib/wag/then.rb new file mode 100644 index 0000000..3f1760c --- /dev/null +++ b/lib/wag/then.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module WAG + # Then is not an instruction, but a nested keyword. + class Then + include WAG::Encodable + prepend WAG::Instructable + + def to_sexpr + :then + end + end +end diff --git a/lib/wag/wabt.rb b/lib/wag/wabt.rb new file mode 100644 index 0000000..e5a0f47 --- /dev/null +++ b/lib/wag/wabt.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module WAG + # This class wraps the [WebAssembly Binary Toolkit][1] utilities to make it easier to + # work with from within WAG. + + # 1: https://github.com/WebAssembly/wabt + class WABT + def initialize + throw 'Unable to find `wat2wasm` in path. Please install WABT.' unless find_util('wat2wasm') + end + + def wat2wasm(wat_source) + Dir.mktmpdir('wat2wasm') do |dir| + wat_path = File.join(dir, 'source.wat') + wasm_path = File.join(dir, 'target.wasm') + File.write(wat_path, wat_source) + system(find_util('wat2wasm'), '-o', wasm_path, wat_path, exception: true) + File.unlink(wat_path) + File.read(wasm_path) + end + end + + def wasm_validate(wasm_source) + Dir.mktmpdir('wasm-validate') do |dir| + wasm_path = File.join(dir, 'validate.wasm') + File.write(wasm_path, wasm_source) + if system(find_util('wasm-validate'), wasm_path) + true + else + false + end + end + end + + private + + def find_util(util_name) + path = `which #{util_name}`.strip + return nil if path.empty? + + path + end + end +end diff --git a/lib/wag/wasm.rb b/lib/wag/wasm.rb new file mode 100644 index 0000000..0d16285 --- /dev/null +++ b/lib/wag/wasm.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module WAG + # A container for the WebAssembly binary format. + class WASM + def initialize(code) + @code = code + end + + def valid? + WAG::WABT.new.wasm_validate(@code) + end + + def save(path) + File.write(path, @code) + end + + def to_s + @code + end + end +end diff --git a/lib/wag/wat.rb b/lib/wag/wat.rb index 3f35cbc..eda3797 100644 --- a/lib/wag/wat.rb +++ b/lib/wag/wat.rb @@ -1,19 +1,18 @@ # frozen_string_literal: true module WAG - # A simple mixin which formats s-expressions as WAT. - module WAT - def to_wat - wat_encode(to_sexpr) + # A container for the WebAssembly text format. + class WAT + def initialize(source) + @source = source end - private + def to_wasm + WAG::WASM.new(WAG::WABT.new.wat2wasm(@source)) + end - def wat_encode(data) - return "(#{data.map { |e| wat_encode(e) }.join(' ')})" if data.is_a?(Enumerable) - return data.inspect if data.is_a?(String) - - data.to_s + def to_s + @source end end end diff --git a/spec/acceptance/code_validates_spec.rb b/spec/acceptance/code_validates_spec.rb new file mode 100644 index 0000000..2d991a2 --- /dev/null +++ b/spec/acceptance/code_validates_spec.rb @@ -0,0 +1,485 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# Simple examples taken from: https://blog.scottlogic.com/2018/04/26/webassembly-by-hand.html + +RSpec.describe 'WAT code generation' do + let(:mod) { WAG::Module.new } + subject { mod } + + context 'Basic example' do + let(:mod) do + super().tap do |mod| + mod.func do + result(:i32) + i32.const(42) + end + mod.export('helloWorld') do + func(0) + end + end + end + + describe '#to_wat' do + subject { mod.to_wat.to_s } + it { is_expected.to eq '(module (export "helloWorld" (func 0)) (func (result i32) (i32.const 42)))' } + end + + describe '#to_wasm' do + subject { mod.to_wasm } + + it { is_expected.to be_valid } + end + end + + context 'Game of life example' do + let(:mod) do + super().tap do |mod| + mod.import('console', 'log') do + func(:log) do + param(:i32) + param(:i32) + end + end + + mod.memory(:mem, 1) + + mod.table(16, :anyfunc) + + mod.elem(0, :dead, :dead, :dead, :alive, :dead, :dead, :dead, :dead, + :dead, :dead, :dead, :alive, :alive, :dead, :dead, :dead, + :dead, :dead) + + mod.func(:alive) do + result(:i32) + i32.const(1) + end + + mod.func(:dead) do + result(:i32) + i32.const(0) + end + + mod.func(:offsetFromCoordinate) do + param(:x, :i32) + param(:y, :i32) + result(:i32) + + i32.add do + i32.mul do + i32.const(200) + local.get(:y) + end + i32.mul do + i32.const(4) + local.get(:x) + end + end + end + + mod.func(:setCell) do + param(:x, :i32) + param(:y, :i32) + param(:value, :i32) + + i32.store do + call(:offsetFromCoordinate) do + local.get(:x) + local.get(:y) + end + local.get(:value) + end + end + + mod.func(:getCell) do + param(:x, :i32) + param(:y, :i32) + result(:i32) + + if_ do + result(:i32) + block do + result(:i32) + i32.and do + call(:inRange) do + i32.const(0) + i32.const(50) + local.get(:x) + end + call(:inRange) do + i32.const(0) + i32.const(50) + local.get(:y) + end + end + end + then_ do + i32.load8_u do + call(:offsetFromCoordinate) do + local.get(:x) + local.get(:y) + end + end + end + else_ do + i32.const(0) + end + end + end + + mod.func(:liveNeighbourCount) do + param(:x, :i32) + param(:y, :i32) + result(:i32) + + i32.const(0) + + # add the cell value from x + 1, y + call(:isCellAlive) do + i32.add do + local.get(:x) + i32.const(1) + end + local.get(:y) + end + i32.add + + # add the cell value from x - 1, y + call(:isCellAlive) do + i32.add do + local.get(:x) + i32.const(-1) + end + local.get(:y) + end + i32.add + + # add the cell value from x, y - 1 + call(:isCellAlive) do + local.get(:x) + i32.add do + local.get(:y) + i32.const(-1) + end + end + i32.add + + # add the cell value from x - 1, y - 1 + call(:isCellAlive) do + i32.add do + local.get(:x) + i32.const(-1) + end + i32.add do + local.get(:y) + i32.const(-1) + end + end + i32.add + + # add the cell value from x + 1, y - 1 + call(:isCellAlive) do + i32.add do + local.get(:x) + i32.const(1) + end + i32.add do + local.get(:y) + i32.const(-1) + end + end + i32.add + + # add the cell value from x, y + 1 + call(:isCellAlive) do + local.get(:x) + i32.add do + local.get(:y) + i32.const(1) + end + end + i32.add + + # add the cell value from x - 1, y + 1 + call(:isCellAlive) do + i32.add do + local.get(:x) + i32.const(-1) + end + i32.add do + local.get(:y) + i32.const(1) + end + end + i32.add + + # add the cell value from x + 1, y + 1 + call(:isCellAlive) do + i32.add do + local.get(:x) + i32.const(1) + end + i32.add do + local.get(:y) + i32.const(1) + end + end + i32.add + end + + mod.func(:inRange) do + param(:low, :i32) + param(:high, :i32) + param(:value, :i32) + result(:i32) + + i32.and do + i32.ge_s do + local.get(:value) + local.get(:low) + end + i32.lt_s do + local.get(:value) + local.get(:high) + end + end + end + + mod.func(:isCellAlive) do + param(:x, :i32) + param(:y, :i32) + result(:i32) + + i32.and do + call(:getCell) do + local.get(:x) + local.get(:y) + end + i32.const(1) + end + end + + mod.func(:setCellStateForNextGeneration) do + param(:x, :i32) + param(:y, :i32) + param(:value, :i32) + + call(:setCell) do + local.get(:x) + local.get(:y) + i32.or do + call(:isCellAlive) do + local.get(:x) + local.get(:y) + end + i32.shl do + local.get(:value) + i32.const(1) + end + end + end + end + + mod.func(:evolveCellToNextGeneration) do + param(:x, :i32) + param(:y, :i32) + + call(:setCellStateForNextGeneration) do + local.get(:x) + local.get(:y) + call_indirect do + result(:i32) + i32.or do + i32.mul do + i32.const(9) + call(:isCellAlive) do + local.get(:x) + local.get(:y) + end + end + call(:liveNeighbourCount) do + local.get(:x) + local.get(:y) + end + end + end + end + end + + mod.func(:increment) do + param(:value, :i32) + result(:i32) + + i32.add do + local.get(:value) + i32.const(1) + end + end + + mod.func(:evolveAllCells) do + local(:x, :i32) + local(:y, :i32) + + local.set(:x) do + i32.const(0) + end + local.set(:y) do + i32.const(0) + end + + block do + loop_ do + local.set(:x) do + i32.const(0) + end + + block do + loop_ do + call(:evolveCellToNextGeneration) do + local.get(:x) + local.get(:y) + end + local.set(:x) do + call(:increment) do + local.get(:x) + end + end + br_if(1) do + i32.eq do + local.get(:x) + i32.const(50) + end + end + br(0) + end + end + + local.set(:y) do + call(:increment) do + local.get(:y) + end + end + br_if(1) do + i32.eq do + local.get(:y) + i32.const(50) + end + end + br(0) + end + end + end + + mod.func(:promoteNextGeneration) do + local(:x, :i32) + local(:y, :i32) + + local.set(:x) do + i32.const(0) + end + local.set(:y) do + i32.const(0) + end + + block do + loop_ do + local.set(:x) do + i32.const(0) + end + + block do + loop_ do + call(:setCell) do + local.get(:x) + local.get(:y) + i32.shr_u do + call(:getCell) do + local.get(:x) + local.get(:y) + end + i32.const(1) + end + end + + local.set(:x) do + call(:increment) do + local.get(:x) + end + end + br_if(1) do + i32.eq do + local.get(:x) + i32.const(50) + end + end + br(0) + end + end + + local.set(:y) do + call(:increment) do + local.get(:y) + end + end + br_if(1) do + i32.eq do + local.get(:y) + i32.const(50) + end + end + br(0) + end + end + end + + mod.func(:tick) do + call(:evolveAllCells) + call(:promoteNextGeneration) + end + + mod.export('tick') do + func(:tick) + end + mod.export('promoteNextGeneration') do + func(:promoteNextGeneration) + end + mod.export('evolveAllCells') do + func(:evolveAllCells) + end + mod.export('evolveCellToNextGeneration') do + func(:evolveCellToNextGeneration) + end + mod.export('setCellStateForNextGeneration') do + func(:setCellStateForNextGeneration) + end + mod.export('isCellAlive') do + func(:isCellAlive) + end + mod.export('inRange') do + func(:inRange) + end + mod.export('offsetFromCoordinate') do + func(:offsetFromCoordinate) + end + mod.export('liveNeighbourCount') do + func(:liveNeighbourCount) + end + mod.export('getCell') do + func(:getCell) + end + mod.export('setCell') do + func(:setCell) + end + mod.export('memory') do + memory(:mem) + end + end + end + + describe '#to_wasm' do + subject { mod.to_wasm } + it { is_expected.to be_valid } + end + end +end diff --git a/spec/wag/export_spec.rb b/spec/wag/export_spec.rb index 7cc4728..457886b 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, :funcref) + export.table(1, :anyfunc) end describe '#to_sexpr' do subject { super().to_sexpr } - it { is_expected.to eq [:export, 'marty', [:table, 1, :funcref]] } + it { is_expected.to eq [:export, 'marty', [:table, 1, :anyfunc]] } end end diff --git a/spec/wag/function_spec.rb b/spec/wag/function_spec.rb index 1308022..59b5f44 100644 --- a/spec/wag/function_spec.rb +++ b/spec/wag/function_spec.rb @@ -11,7 +11,7 @@ RSpec.describe WAG::Function do let(:label) { Faker::Name.first_name } it 'correctly sets the label' do - expect(subject.label.value).to eq label + expect(subject.label.value).to eq "$#{label}".to_sym end end @@ -29,7 +29,7 @@ RSpec.describe WAG::Function do it 'correctly sets the param' do subject expect(function.params.first).to be_a(WAG::Param) - expect(function.params.first.label.value).to eq(label) + expect(function.params.first.label.value).to eq("$#{label}".to_sym) expect(function.params.first.type).to be_a(WAG::Type::I32) end end diff --git a/spec/wag/global_instructions_spec.rb b/spec/wag/global_instructions_spec.rb index 7a9aac8..2572c33 100644 --- a/spec/wag/global_instructions_spec.rb +++ b/spec/wag/global_instructions_spec.rb @@ -24,7 +24,7 @@ RSpec.describe WAG::GlobalInstructions do it 'sets the label correctly' do subject expect(instructions.first.label.value) - .to eq(label) + .to eq("$#{label}".to_sym) end end end diff --git a/spec/wag/import_spec.rb b/spec/wag/import_spec.rb index 8508015..e2145cb 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, :funcref) + import.table(1, :anyfunc) end describe '#to_sexpr' do subject { super().to_sexpr } - it { is_expected.to eq [:import, 'marty', 'mcfly', [:table, 1, :funcref]] } + it { is_expected.to eq [:import, 'marty', 'mcfly', [:table, 1, :anyfunc]] } end end diff --git a/spec/wag/instructable_spec.rb b/spec/wag/instructable_spec.rb index 5e419f3..1f5453f 100644 --- a/spec/wag/instructable_spec.rb +++ b/spec/wag/instructable_spec.rb @@ -39,7 +39,7 @@ RSpec.describe WAG::Instructable do it { is_expected.to be_a(WAG::MemoryInstructions) } end - %i[unreachable nop block loop if else end br_table return call + %i[unreachable nop block loop if else end br_table return call_indirect drop select].each do |instruction_name| describe "##{instruction_name}" do subject { super().public_send(instruction_name) } @@ -48,7 +48,7 @@ RSpec.describe WAG::Instructable do end end - %i[br br_if].each do |instruction_name| + %i[br br_if call].each do |instruction_name| describe "##{instruction_name}" do let(:label) { Faker::Name.first_name } subject { super().public_send(instruction_name, label) } diff --git a/spec/wag/instructions_spec.rb b/spec/wag/instructions_spec.rb index f18efcd..e82c9b6 100644 --- a/spec/wag/instructions_spec.rb +++ b/spec/wag/instructions_spec.rb @@ -178,6 +178,7 @@ INSTRUCTIONS = { unreachable: 0x00, REQUIRED_ARGS = { br: [:label], br_if: [:label], + call: [:label], "local.get": [:label], "local.set": [:label], "local.tee": [:label], diff --git a/spec/wag/label_spec.rb b/spec/wag/label_spec.rb index 6f02d98..10608bd 100644 --- a/spec/wag/label_spec.rb +++ b/spec/wag/label_spec.rb @@ -19,7 +19,7 @@ RSpec.describe WAG::Label do context 'When the value is a string' do describe '#value' do subject { super().value } - it { is_expected.to eq value } + it { is_expected.to eq "$#{value}".to_sym } end end diff --git a/spec/wag/local_instructions_spec.rb b/spec/wag/local_instructions_spec.rb index 82cacbf..527a078 100644 --- a/spec/wag/local_instructions_spec.rb +++ b/spec/wag/local_instructions_spec.rb @@ -24,7 +24,7 @@ RSpec.describe WAG::LocalInstructions do it 'sets the label correctly' do subject expect(instructions.first.label.value) - .to eq(label) + .to eq("$#{label}".to_sym) end end end diff --git a/spec/wag/module_spec.rb b/spec/wag/module_spec.rb index af0dd5c..c06d172 100644 --- a/spec/wag/module_spec.rb +++ b/spec/wag/module_spec.rb @@ -11,11 +11,6 @@ RSpec.describe WAG::Module do subject { super().to_sexpr } it { is_expected.to eq [:module] } end - - describe '#to_wat' do - subject { super().to_wat } - it { is_expected.to eq '(module)' } - end end describe 'When the module imports a memory' do @@ -112,4 +107,15 @@ RSpec.describe WAG::Module do it { is_expected.to eq [:module, [:func, :$add, %i[param i32], %i[param i32], %i[result i32]]] } end end + + describe 'When the module declares a table' do + before do + mod.table(16) + end + + describe '#to_sexpr' do + subject { super().to_sexpr } + it { is_expected.to eq [:module, [:table, 16, :anyfunc]] } + end + end end diff --git a/spec/wag/table_spec.rb b/spec/wag/table_spec.rb index 4c2eb49..bcbd8df 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, :funcref] } + it { is_expected.to eq [:table, elements, :anyfunc] } end end