wag 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.gitlab-ci.yml +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +40 -0
- data/README.md +170 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/wag.rb +42 -0
- data/lib/wag/data.rb +18 -0
- data/lib/wag/element.rb +18 -0
- data/lib/wag/encodable.rb +23 -0
- data/lib/wag/export.rb +39 -0
- data/lib/wag/f32_instructions.rb +21 -0
- data/lib/wag/f64_instructions.rb +21 -0
- data/lib/wag/function.rb +33 -0
- data/lib/wag/function_type.rb +16 -0
- data/lib/wag/global.rb +18 -0
- data/lib/wag/global_instructions.rb +19 -0
- data/lib/wag/i32_instructions.rb +22 -0
- data/lib/wag/i64_instructions.rb +23 -0
- data/lib/wag/import.rb +42 -0
- data/lib/wag/indices.rb +14 -0
- data/lib/wag/indices/base.rb +16 -0
- data/lib/wag/indices/func.rb +8 -0
- data/lib/wag/indices/global.rb +8 -0
- data/lib/wag/indices/label.rb +8 -0
- data/lib/wag/indices/local.rb +8 -0
- data/lib/wag/indices/mem.rb +8 -0
- data/lib/wag/indices/table.rb +8 -0
- data/lib/wag/indices/type.rb +8 -0
- data/lib/wag/inflector.rb +13 -0
- data/lib/wag/instructable.rb +65 -0
- data/lib/wag/instruction.rb +193 -0
- data/lib/wag/instructions/base.rb +24 -0
- data/lib/wag/instructions/block.rb +21 -0
- data/lib/wag/instructions/br.rb +18 -0
- data/lib/wag/instructions/br_if.rb +18 -0
- data/lib/wag/instructions/br_table.rb +18 -0
- data/lib/wag/instructions/call.rb +18 -0
- data/lib/wag/instructions/call_indirect.rb +18 -0
- data/lib/wag/instructions/drop.rb +8 -0
- data/lib/wag/instructions/else.rb +9 -0
- data/lib/wag/instructions/end.rb +8 -0
- data/lib/wag/instructions/f32/abs.rb +11 -0
- data/lib/wag/instructions/f32/add.rb +11 -0
- data/lib/wag/instructions/f32/base.rb +13 -0
- data/lib/wag/instructions/f32/ceil.rb +11 -0
- data/lib/wag/instructions/f32/const.rb +20 -0
- data/lib/wag/instructions/f32/convert_i32_s.rb +11 -0
- data/lib/wag/instructions/f32/convert_i32_u.rb +11 -0
- data/lib/wag/instructions/f32/convert_i64_s.rb +11 -0
- data/lib/wag/instructions/f32/convert_i64_u.rb +11 -0
- data/lib/wag/instructions/f32/copysign.rb +11 -0
- data/lib/wag/instructions/f32/demote_f64.rb +11 -0
- data/lib/wag/instructions/f32/div.rb +11 -0
- data/lib/wag/instructions/f32/eq.rb +11 -0
- data/lib/wag/instructions/f32/floor.rb +11 -0
- data/lib/wag/instructions/f32/ge.rb +11 -0
- data/lib/wag/instructions/f32/gt.rb +11 -0
- data/lib/wag/instructions/f32/le.rb +11 -0
- data/lib/wag/instructions/f32/load.rb +11 -0
- data/lib/wag/instructions/f32/lt.rb +11 -0
- data/lib/wag/instructions/f32/max.rb +11 -0
- data/lib/wag/instructions/f32/min.rb +11 -0
- data/lib/wag/instructions/f32/mul.rb +11 -0
- data/lib/wag/instructions/f32/ne.rb +11 -0
- data/lib/wag/instructions/f32/nearest.rb +11 -0
- data/lib/wag/instructions/f32/neg.rb +11 -0
- data/lib/wag/instructions/f32/reinterpret_i32.rb +11 -0
- data/lib/wag/instructions/f32/sqrt.rb +11 -0
- data/lib/wag/instructions/f32/store.rb +11 -0
- data/lib/wag/instructions/f32/sub.rb +11 -0
- data/lib/wag/instructions/f32/trunc.rb +11 -0
- data/lib/wag/instructions/f64/abs.rb +11 -0
- data/lib/wag/instructions/f64/add.rb +11 -0
- data/lib/wag/instructions/f64/base.rb +13 -0
- data/lib/wag/instructions/f64/ceil.rb +11 -0
- data/lib/wag/instructions/f64/const.rb +20 -0
- data/lib/wag/instructions/f64/convert_i32_s.rb +11 -0
- data/lib/wag/instructions/f64/convert_i32_u.rb +11 -0
- data/lib/wag/instructions/f64/convert_i64_s.rb +11 -0
- data/lib/wag/instructions/f64/convert_i64_u.rb +11 -0
- data/lib/wag/instructions/f64/copysign.rb +11 -0
- data/lib/wag/instructions/f64/div.rb +11 -0
- data/lib/wag/instructions/f64/eq.rb +11 -0
- data/lib/wag/instructions/f64/floor.rb +11 -0
- data/lib/wag/instructions/f64/ge.rb +11 -0
- data/lib/wag/instructions/f64/gt.rb +11 -0
- data/lib/wag/instructions/f64/le.rb +11 -0
- data/lib/wag/instructions/f64/load.rb +11 -0
- data/lib/wag/instructions/f64/lt.rb +11 -0
- data/lib/wag/instructions/f64/max.rb +11 -0
- data/lib/wag/instructions/f64/min.rb +11 -0
- data/lib/wag/instructions/f64/mul.rb +11 -0
- data/lib/wag/instructions/f64/ne.rb +11 -0
- data/lib/wag/instructions/f64/nearest.rb +11 -0
- data/lib/wag/instructions/f64/neg.rb +11 -0
- data/lib/wag/instructions/f64/promote_f32.rb +11 -0
- data/lib/wag/instructions/f64/reinterpret_i64.rb +11 -0
- data/lib/wag/instructions/f64/sqrt.rb +11 -0
- data/lib/wag/instructions/f64/store.rb +11 -0
- data/lib/wag/instructions/f64/sub.rb +11 -0
- data/lib/wag/instructions/f64/trunc.rb +11 -0
- data/lib/wag/instructions/global/base.rb +13 -0
- data/lib/wag/instructions/global/get.rb +20 -0
- data/lib/wag/instructions/global/set.rb +20 -0
- data/lib/wag/instructions/i32/add.rb +11 -0
- data/lib/wag/instructions/i32/and.rb +11 -0
- data/lib/wag/instructions/i32/base.rb +13 -0
- data/lib/wag/instructions/i32/clz.rb +11 -0
- data/lib/wag/instructions/i32/const.rb +20 -0
- data/lib/wag/instructions/i32/ctz.rb +11 -0
- data/lib/wag/instructions/i32/div_s.rb +11 -0
- data/lib/wag/instructions/i32/div_u.rb +11 -0
- data/lib/wag/instructions/i32/eq.rb +11 -0
- data/lib/wag/instructions/i32/eqz.rb +11 -0
- data/lib/wag/instructions/i32/ge_s.rb +11 -0
- data/lib/wag/instructions/i32/ge_u.rb +11 -0
- data/lib/wag/instructions/i32/gt_s.rb +11 -0
- data/lib/wag/instructions/i32/gt_u.rb +11 -0
- data/lib/wag/instructions/i32/le_s.rb +11 -0
- data/lib/wag/instructions/i32/le_u.rb +11 -0
- data/lib/wag/instructions/i32/load.rb +11 -0
- data/lib/wag/instructions/i32/load16_s.rb +11 -0
- data/lib/wag/instructions/i32/load16_u.rb +11 -0
- data/lib/wag/instructions/i32/load8_s.rb +11 -0
- data/lib/wag/instructions/i32/load8_u.rb +11 -0
- data/lib/wag/instructions/i32/lt_s.rb +11 -0
- data/lib/wag/instructions/i32/lt_u.rb +11 -0
- data/lib/wag/instructions/i32/mul.rb +11 -0
- data/lib/wag/instructions/i32/ne.rb +11 -0
- data/lib/wag/instructions/i32/or.rb +11 -0
- data/lib/wag/instructions/i32/popcnt.rb +11 -0
- data/lib/wag/instructions/i32/reinterpret_f32.rb +11 -0
- data/lib/wag/instructions/i32/rem_s.rb +11 -0
- data/lib/wag/instructions/i32/rem_u.rb +11 -0
- data/lib/wag/instructions/i32/rotl.rb +11 -0
- data/lib/wag/instructions/i32/rotr.rb +11 -0
- data/lib/wag/instructions/i32/shl.rb +11 -0
- data/lib/wag/instructions/i32/shr_s.rb +11 -0
- data/lib/wag/instructions/i32/shr_u.rb +11 -0
- data/lib/wag/instructions/i32/store.rb +11 -0
- data/lib/wag/instructions/i32/store16.rb +11 -0
- data/lib/wag/instructions/i32/store8.rb +11 -0
- data/lib/wag/instructions/i32/sub.rb +11 -0
- data/lib/wag/instructions/i32/trunc_f32_s.rb +11 -0
- data/lib/wag/instructions/i32/trunc_f32_u.rb +11 -0
- data/lib/wag/instructions/i32/trunc_f64_s.rb +11 -0
- data/lib/wag/instructions/i32/trunc_f64_u.rb +11 -0
- data/lib/wag/instructions/i32/wrap_i64.rb +11 -0
- data/lib/wag/instructions/i32/xor.rb +11 -0
- data/lib/wag/instructions/i64/add.rb +11 -0
- data/lib/wag/instructions/i64/and.rb +11 -0
- data/lib/wag/instructions/i64/base.rb +13 -0
- data/lib/wag/instructions/i64/clz.rb +11 -0
- data/lib/wag/instructions/i64/const.rb +20 -0
- data/lib/wag/instructions/i64/ctz.rb +11 -0
- data/lib/wag/instructions/i64/div_s.rb +11 -0
- data/lib/wag/instructions/i64/div_u.rb +11 -0
- data/lib/wag/instructions/i64/eq.rb +11 -0
- data/lib/wag/instructions/i64/eqz.rb +11 -0
- data/lib/wag/instructions/i64/extend_i32_s.rb +11 -0
- data/lib/wag/instructions/i64/extend_i32_u.rb +11 -0
- data/lib/wag/instructions/i64/ge_s.rb +11 -0
- data/lib/wag/instructions/i64/ge_u.rb +11 -0
- data/lib/wag/instructions/i64/gt_s.rb +11 -0
- data/lib/wag/instructions/i64/gt_u.rb +11 -0
- data/lib/wag/instructions/i64/le_s.rb +11 -0
- data/lib/wag/instructions/i64/le_u.rb +11 -0
- data/lib/wag/instructions/i64/load.rb +11 -0
- data/lib/wag/instructions/i64/load16_s.rb +11 -0
- data/lib/wag/instructions/i64/load16_u.rb +11 -0
- data/lib/wag/instructions/i64/load32_s.rb +11 -0
- data/lib/wag/instructions/i64/load32_u.rb +11 -0
- data/lib/wag/instructions/i64/load8_s.rb +11 -0
- data/lib/wag/instructions/i64/load8_u.rb +11 -0
- data/lib/wag/instructions/i64/lt_s.rb +11 -0
- data/lib/wag/instructions/i64/lt_u.rb +11 -0
- data/lib/wag/instructions/i64/mul.rb +11 -0
- data/lib/wag/instructions/i64/ne.rb +11 -0
- data/lib/wag/instructions/i64/or.rb +11 -0
- data/lib/wag/instructions/i64/popcnt.rb +11 -0
- data/lib/wag/instructions/i64/reinterpret_f64.rb +11 -0
- data/lib/wag/instructions/i64/rem_s.rb +11 -0
- data/lib/wag/instructions/i64/rem_u.rb +11 -0
- data/lib/wag/instructions/i64/rotl.rb +11 -0
- data/lib/wag/instructions/i64/rotr.rb +11 -0
- data/lib/wag/instructions/i64/shl.rb +11 -0
- data/lib/wag/instructions/i64/shr_s.rb +11 -0
- data/lib/wag/instructions/i64/shr_u.rb +11 -0
- data/lib/wag/instructions/i64/store.rb +11 -0
- data/lib/wag/instructions/i64/store16.rb +11 -0
- data/lib/wag/instructions/i64/store32.rb +11 -0
- data/lib/wag/instructions/i64/store8.rb +11 -0
- data/lib/wag/instructions/i64/sub.rb +11 -0
- data/lib/wag/instructions/i64/trunc_f32_s.rb +11 -0
- data/lib/wag/instructions/i64/trunc_f32_u.rb +11 -0
- data/lib/wag/instructions/i64/trunc_f64_s.rb +11 -0
- data/lib/wag/instructions/i64/trunc_f64_u.rb +11 -0
- data/lib/wag/instructions/i64/xor.rb +11 -0
- data/lib/wag/instructions/if.rb +26 -0
- data/lib/wag/instructions/local/base.rb +13 -0
- data/lib/wag/instructions/local/get.rb +20 -0
- data/lib/wag/instructions/local/set.rb +20 -0
- data/lib/wag/instructions/local/tee.rb +20 -0
- data/lib/wag/instructions/loop.rb +9 -0
- data/lib/wag/instructions/memory/base.rb +13 -0
- data/lib/wag/instructions/memory/grow.rb +11 -0
- data/lib/wag/instructions/memory/size.rb +11 -0
- data/lib/wag/instructions/nop.rb +8 -0
- data/lib/wag/instructions/return.rb +9 -0
- data/lib/wag/instructions/select.rb +9 -0
- data/lib/wag/instructions/unreachable.rb +8 -0
- data/lib/wag/label.rb +32 -0
- data/lib/wag/local.rb +19 -0
- data/lib/wag/local_instructions.rb +19 -0
- data/lib/wag/memory.rb +26 -0
- data/lib/wag/memory_instructions.rb +19 -0
- data/lib/wag/module.rb +100 -0
- data/lib/wag/param.rb +20 -0
- data/lib/wag/result.rb +17 -0
- data/lib/wag/table.rb +17 -0
- data/lib/wag/then.rb +13 -0
- data/lib/wag/type.rb +19 -0
- data/lib/wag/types/base.rb +16 -0
- data/lib/wag/types/f32.rb +8 -0
- data/lib/wag/types/f64.rb +8 -0
- data/lib/wag/types/i32.rb +8 -0
- data/lib/wag/types/i64.rb +8 -0
- data/lib/wag/version.rb +5 -0
- data/lib/wag/wabt.rb +45 -0
- data/lib/wag/wasm.rb +22 -0
- data/lib/wag/wat.rb +18 -0
- data/wag.gemspec +35 -0
- metadata +299 -0
    
        data/lib/wag/label.rb
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class Label
         | 
| 5 | 
            +
                include WAG::Encodable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_reader :value
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(value)
         | 
| 10 | 
            +
                  if value.is_a?(Integer)
         | 
| 11 | 
            +
                    @value = value.to_i
         | 
| 12 | 
            +
                  else
         | 
| 13 | 
            +
                    value = value.to_s
         | 
| 14 | 
            +
                    @value = if value.start_with?('$')
         | 
| 15 | 
            +
                               value.to_sym
         | 
| 16 | 
            +
                             else
         | 
| 17 | 
            +
                               "$#{value}".to_sym
         | 
| 18 | 
            +
                             end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def to_sexpr
         | 
| 23 | 
            +
                  value
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def self.from(value)
         | 
| 27 | 
            +
                  return value if value.is_a?(WAG::Label)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  WAG::Label.new(value)
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
    
        data/lib/wag/local.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              # Local is not an instruction, but a nested keyword.
         | 
| 5 | 
            +
              class Local
         | 
| 6 | 
            +
                include WAG::Encodable
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                attr_reader :label, :type
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def initialize(label, type)
         | 
| 11 | 
            +
                  @label = WAG::Label.from(label)
         | 
| 12 | 
            +
                  @type = WAG::Type.from(type)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def to_sexpr
         | 
| 16 | 
            +
                  [:local, label.to_sexpr, type.to_sexpr]
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class LocalInstructions
         | 
| 5 | 
            +
                def initialize(instructions)
         | 
| 6 | 
            +
                  @instructions = instructions
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                %i[get set tee].each do |instruction_name|
         | 
| 10 | 
            +
                  camelised_name = "Local::#{WAG::Inflector.inflector.camelize(instruction_name)}"
         | 
| 11 | 
            +
                  define_method(instruction_name) do |*args, &block|
         | 
| 12 | 
            +
                    instruction = WAG::Instruction.const_get(camelised_name).new(*args)
         | 
| 13 | 
            +
                    @instructions << instruction
         | 
| 14 | 
            +
                    instruction.instance_exec(&block) if block
         | 
| 15 | 
            +
                    instruction
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/wag/memory.rb
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class Memory
         | 
| 5 | 
            +
                include WAG::Encodable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_reader :label, :number, :min, :max
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(*args)
         | 
| 10 | 
            +
                  @label = WAG::Label.from(args.shift) if args.first.is_a?(Symbol)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  (@number, @min, @max) = args
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def to_sexpr
         | 
| 16 | 
            +
                  [:memory].tap do |expr|
         | 
| 17 | 
            +
                    expr.push(label.to_sexpr) if label
         | 
| 18 | 
            +
                    expr.push(number)
         | 
| 19 | 
            +
                    if min
         | 
| 20 | 
            +
                      expr.push(min)
         | 
| 21 | 
            +
                      expr.push(max) if max
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class MemoryInstructions
         | 
| 5 | 
            +
                def initialize(instructions)
         | 
| 6 | 
            +
                  @instructions = instructions
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                %i[size grow].each do |instruction_name|
         | 
| 10 | 
            +
                  camelised_name = "Memory::#{WAG::Inflector.inflector.camelize(instruction_name)}"
         | 
| 11 | 
            +
                  define_method(instruction_name) do |*args, &block|
         | 
| 12 | 
            +
                    instruction = WAG::Instruction.const_get(camelised_name).new(*args)
         | 
| 13 | 
            +
                    @instructions << instruction
         | 
| 14 | 
            +
                    instruction.instance_exec(&block) if block
         | 
| 15 | 
            +
                    instruction
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/wag/module.rb
    ADDED
    
    | @@ -0,0 +1,100 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class Module
         | 
| 5 | 
            +
                include WAG::Encodable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize
         | 
| 8 | 
            +
                  @data = []
         | 
| 9 | 
            +
                  @elements = []
         | 
| 10 | 
            +
                  @exports = []
         | 
| 11 | 
            +
                  @functions = []
         | 
| 12 | 
            +
                  @globals = []
         | 
| 13 | 
            +
                  @imports = []
         | 
| 14 | 
            +
                  @memories = []
         | 
| 15 | 
            +
                  @tables = []
         | 
| 16 | 
            +
                  @types = []
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def build(&block)
         | 
| 20 | 
            +
                  instance_exec(&block)
         | 
| 21 | 
            +
                  self
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def import(module_name, name, &block)
         | 
| 25 | 
            +
                  import = Import.new(module_name, name)
         | 
| 26 | 
            +
                  @imports << import
         | 
| 27 | 
            +
                  import.instance_exec(&block) if block
         | 
| 28 | 
            +
                  import
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def export(name, &block)
         | 
| 32 | 
            +
                  export = Export.new(name)
         | 
| 33 | 
            +
                  @exports << export
         | 
| 34 | 
            +
                  export.instance_exec(&block) if block
         | 
| 35 | 
            +
                  export
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def memory(number, min = nil, max = nil, &block)
         | 
| 39 | 
            +
                  mem = Memory.new(number, min, max)
         | 
| 40 | 
            +
                  @memories << mem
         | 
| 41 | 
            +
                  mem.instance_exec(&block) if block
         | 
| 42 | 
            +
                  mem
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                def global(label, type, &block)
         | 
| 46 | 
            +
                  global = Global.new(label, type)
         | 
| 47 | 
            +
                  @globals << global
         | 
| 48 | 
            +
                  global.instance_exec(&block) if block
         | 
| 49 | 
            +
                  global
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def type(label, &block)
         | 
| 53 | 
            +
                  type = FunctionType.new(label)
         | 
| 54 | 
            +
                  @types << type
         | 
| 55 | 
            +
                  type.instance_exec(&block) if block
         | 
| 56 | 
            +
                  type
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def elem(table_id, *labels, &block)
         | 
| 60 | 
            +
                  elem = Element.new(table_id, *labels)
         | 
| 61 | 
            +
                  @elements << elem
         | 
| 62 | 
            +
                  elem.instance_exec(&block) if block
         | 
| 63 | 
            +
                  elem
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def data(offset, value)
         | 
| 67 | 
            +
                  data = Data.new(offset, value)
         | 
| 68 | 
            +
                  @data << data
         | 
| 69 | 
            +
                  data
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                def func(label = nil, &block)
         | 
| 73 | 
            +
                  func = Function.new(label)
         | 
| 74 | 
            +
                  @functions << func
         | 
| 75 | 
            +
                  func.instance_exec(&block) if block
         | 
| 76 | 
            +
                  func
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                def table(elements, type = :anyfunc, &block)
         | 
| 80 | 
            +
                  table = Table.new(elements, type)
         | 
| 81 | 
            +
                  @tables << table
         | 
| 82 | 
            +
                  table.instance_exec(&block) if block
         | 
| 83 | 
            +
                  table
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                def to_sexpr # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
         | 
| 87 | 
            +
                  mod = [:module]
         | 
| 88 | 
            +
                  mod.concat(@imports.map(&:to_sexpr))
         | 
| 89 | 
            +
                  mod.concat(@exports.map(&:to_sexpr))
         | 
| 90 | 
            +
                  mod.concat(@memories.map(&:to_sexpr))
         | 
| 91 | 
            +
                  mod.concat(@globals.map(&:to_sexpr))
         | 
| 92 | 
            +
                  mod.concat(@types.map(&:to_sexpr))
         | 
| 93 | 
            +
                  mod.concat(@tables.map(&:to_sexpr))
         | 
| 94 | 
            +
                  mod.concat(@elements.map(&:to_sexpr))
         | 
| 95 | 
            +
                  mod.concat(@data.map(&:to_sexpr))
         | 
| 96 | 
            +
                  mod.concat(@functions.map(&:to_sexpr))
         | 
| 97 | 
            +
                  mod
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
            end
         | 
    
        data/lib/wag/param.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class Param
         | 
| 5 | 
            +
                include WAG::Encodable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_reader :type, :label
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(type, label = nil)
         | 
| 10 | 
            +
                  @type = WAG::Type.from(type)
         | 
| 11 | 
            +
                  @label = WAG::Label.from(label) if label
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def to_sexpr
         | 
| 15 | 
            +
                  return [:param, label.to_sexpr, type.to_sexpr] if label
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  [:param, type.to_sexpr]
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
    
        data/lib/wag/result.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class Result
         | 
| 5 | 
            +
                include WAG::Encodable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_reader :types
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(*types)
         | 
| 10 | 
            +
                  @types = types.map { |t| WAG::Type.from(t) }
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def to_sexpr
         | 
| 14 | 
            +
                  [:result].concat(types.map(&:to_sexpr))
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        data/lib/wag/table.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              class Table
         | 
| 5 | 
            +
                include WAG::Encodable
         | 
| 6 | 
            +
                attr_reader :elements, :type
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(elements, type = :anyfunc)
         | 
| 9 | 
            +
                  @elements = elements
         | 
| 10 | 
            +
                  @type = type
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def to_sexpr
         | 
| 14 | 
            +
                  [:table, elements, type]
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
    
        data/lib/wag/then.rb
    ADDED
    
    
    
        data/lib/wag/type.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              module Type
         | 
| 5 | 
            +
                require 'wag/types/base'
         | 
| 6 | 
            +
                require 'wag/types/f32'
         | 
| 7 | 
            +
                require 'wag/types/f64'
         | 
| 8 | 
            +
                require 'wag/types/i32'
         | 
| 9 | 
            +
                require 'wag/types/i64'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                module_function
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def from(type)
         | 
| 14 | 
            +
                  return type if type.is_a?(WAG::Type::Base)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  const_get(WAG::Inflector.inflector.camelize(type.to_s)).new
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module WAG
         | 
| 4 | 
            +
              module Type
         | 
| 5 | 
            +
                class Base
         | 
| 6 | 
            +
                  def to_sexpr
         | 
| 7 | 
            +
                    name = WAG::Inflector.inflector.demodulize(self.class.name.to_s)
         | 
| 8 | 
            +
                    WAG::Inflector.inflector.underscore(name).to_sym
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def value?
         | 
| 12 | 
            +
                    true
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         |