wag 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8db1e828d1c55e0c59b0a6539f5dcad050122978b58aaa58c50c81df127d7ba5
|
4
|
+
data.tar.gz: a607dc324fbb937d62d805ebb3ca78ca1e1ace3f2e76f5d2be5f3f91286414aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1126a636ca4025172739c045f2db368570fd81d0a9f74d871a9804f605afe194e3a9183ac1f508dd9a69b5583cb8aa3a122c0164657d3e18aa9b8ada316132a
|
7
|
+
data.tar.gz: 453b4607afe93437cdbacb39156bcb9915e0fba5d40f4bce6337d2974af211efcf79c478e1f292f4cd853aeb7a023a831941c81b561973f5acf2b9b78d031b6a
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
2
|
+
# configuration file. It makes it possible to enable/disable
|
3
|
+
# certain cops (checks) and to alter their behavior if they accept
|
4
|
+
# any parameters. The file can be placed either in your home
|
5
|
+
# directory or in some project directory.
|
6
|
+
#
|
7
|
+
# RuboCop will start looking for the configuration file in the directory
|
8
|
+
# where the inspected file is and continue its way up to the root directory.
|
9
|
+
#
|
10
|
+
# See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Style/HashEachMethods:
|
16
|
+
Enabled: true
|
17
|
+
|
18
|
+
Style/HashTransformKeys:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Style/HashTransformValues:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Exclude:
|
26
|
+
- spec/**/*_spec.rb
|
27
|
+
|
28
|
+
Style/Documentation:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/OptionalArguments:
|
32
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in wag.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'pry', '~> 0.13.0'
|
9
|
+
gem 'rake', '~> 12.0'
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
gem 'rubocop', '~> 0.80.1'
|
12
|
+
|
13
|
+
gem 'faker', '~> 2.11'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wag (0.1.0)
|
5
|
+
dry-inflector (~> 0.2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
coderay (1.1.2)
|
12
|
+
concurrent-ruby (1.1.6)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
dry-inflector (0.2.0)
|
15
|
+
faker (2.11.0)
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
i18n (1.8.2)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
jaro_winkler (1.5.4)
|
20
|
+
method_source (1.0.0)
|
21
|
+
parallel (1.19.1)
|
22
|
+
parser (2.7.0.5)
|
23
|
+
ast (~> 2.4.0)
|
24
|
+
pry (0.13.0)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (12.3.3)
|
29
|
+
rexml (3.2.4)
|
30
|
+
rspec (3.9.0)
|
31
|
+
rspec-core (~> 3.9.0)
|
32
|
+
rspec-expectations (~> 3.9.0)
|
33
|
+
rspec-mocks (~> 3.9.0)
|
34
|
+
rspec-core (3.9.1)
|
35
|
+
rspec-support (~> 3.9.1)
|
36
|
+
rspec-expectations (3.9.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-mocks (3.9.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-support (3.9.2)
|
43
|
+
rubocop (0.80.1)
|
44
|
+
jaro_winkler (~> 1.5.1)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 2.7.0.1)
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
48
|
+
rexml
|
49
|
+
ruby-progressbar (~> 1.7)
|
50
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
51
|
+
ruby-progressbar (1.10.1)
|
52
|
+
unicode-display_width (1.6.1)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
faker (~> 2.11)
|
59
|
+
pry (~> 0.13.0)
|
60
|
+
rake (~> 12.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
rubocop (~> 0.80.1)
|
63
|
+
wag!
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Copyright 2020 James Harton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
* The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
* No Harm: The software may not be used by anyone for systems or activities that
|
14
|
+
actively and knowingly endanger, harm, or otherwise threaten the physical,
|
15
|
+
mental, economic, or general well-being of other individuals or groups, in
|
16
|
+
violation of the United Nations Universal Declaration of Human Rights
|
17
|
+
(https://www.un.org/en/universal-declaration-human-rights/).
|
18
|
+
|
19
|
+
* Services: If the Software is used to provide a service to others, the licensee
|
20
|
+
shall, as a condition of use, require those others not to use the service in any
|
21
|
+
way that violates the No Harm clause above.
|
22
|
+
|
23
|
+
* Enforceability: If any portion or provision of this License shall to any
|
24
|
+
extent be declared illegal or unenforceable by a court of competent
|
25
|
+
jurisdiction, then the remainder of this License, or the application of such
|
26
|
+
portion or provision in circumstances other than those as to which it is so
|
27
|
+
declared illegal or unenforceable, shall not be affected thereby, and each
|
28
|
+
portion and provision of this Agreement shall be valid and enforceable to the
|
29
|
+
fullest extent permitted by law.
|
30
|
+
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
33
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
34
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
35
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
36
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
37
|
+
|
38
|
+
This Hippocratic License is an Ethical Source license
|
39
|
+
(https://ethicalsource.dev) derived from the MIT License, amended to limit the
|
40
|
+
impact of the unethical use of open source software.
|
data/README.md
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# WAG - The WebAssembly Code Generator
|
2
|
+
|
3
|
+
This Ruby gem allows you to generate WebAssembly programs programmatically using
|
4
|
+
a DSL.
|
5
|
+
|
6
|
+
It is closely modeled after WAT, the WebAssembly text format, and at this stage
|
7
|
+
generates WAT and compiles and validates it using [the WebAssembly Binary Toolkit][1].
|
8
|
+
|
9
|
+
Due to the flexibility of WAT this library is very flexible in what structures
|
10
|
+
it allows you to create. Be aware that you can build modules which are not
|
11
|
+
valid WASM. Always validate your modules by using `#to_wasm.valid?`.
|
12
|
+
|
13
|
+
## Keyword conflict
|
14
|
+
|
15
|
+
Any WASM instructions whose name conflicts with a Ruby keyword (eg `loop`,
|
16
|
+
`return`, etc) are also aliased with a underscore suffix for use in the DSL. The
|
17
|
+
methods defining the original names are also there, so can be used by the likes
|
18
|
+
of `public_send`, etc.
|
19
|
+
|
20
|
+
## Folding
|
21
|
+
|
22
|
+
WAG supports generating both the "folded" and "unfolded" variants of the WAT
|
23
|
+
language. As an example here are two implementations of Euclid's Greatest
|
24
|
+
Common Divisor algorithm:
|
25
|
+
|
26
|
+
### Example of unfolded generation
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
unfolded = WAG::Module.new.build do
|
30
|
+
func(:gcd) do
|
31
|
+
param(:a, :i32)
|
32
|
+
param(:b, :i32)
|
33
|
+
result(:i32)
|
34
|
+
local(:r, :i32)
|
35
|
+
|
36
|
+
block
|
37
|
+
loop_
|
38
|
+
|
39
|
+
# let r = a % b
|
40
|
+
local.get(:a)
|
41
|
+
local.get(:b)
|
42
|
+
i32.rem_s
|
43
|
+
local.set(:r)
|
44
|
+
|
45
|
+
# let a = b and b = R
|
46
|
+
local.get(:b)
|
47
|
+
local.set(:a)
|
48
|
+
local.get(:r)
|
49
|
+
local.set(:b)
|
50
|
+
|
51
|
+
|
52
|
+
# if a % b == 0, return b
|
53
|
+
local.get(:a)
|
54
|
+
local.get(:b)
|
55
|
+
i32.rem_s
|
56
|
+
i32.eqz
|
57
|
+
br_if 1
|
58
|
+
|
59
|
+
br 0
|
60
|
+
end_
|
61
|
+
end_
|
62
|
+
|
63
|
+
local.get(:b)
|
64
|
+
return_
|
65
|
+
end
|
66
|
+
export("gcd").func(:gcd)
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
### Example of folded generation
|
71
|
+
```ruby
|
72
|
+
folded = WAG::Module.new.build do
|
73
|
+
func(:gcd) do
|
74
|
+
param(:a, :i32)
|
75
|
+
param(:b, :i32)
|
76
|
+
result(:i32)
|
77
|
+
|
78
|
+
local(:r, :i32)
|
79
|
+
|
80
|
+
block do
|
81
|
+
loop_ do
|
82
|
+
# let r = a % b
|
83
|
+
local.set(:r) do
|
84
|
+
i32.rem_s do
|
85
|
+
local.get(:a)
|
86
|
+
local.get(:b)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# let a = b and b = R
|
91
|
+
local.set(:a) do
|
92
|
+
local.get(:b)
|
93
|
+
end
|
94
|
+
local.set(:b) do
|
95
|
+
local.get(:r)
|
96
|
+
end
|
97
|
+
|
98
|
+
# if a % b == 0, return b
|
99
|
+
br_if(1) do
|
100
|
+
i32.eqz do
|
101
|
+
i32.rem_s do
|
102
|
+
local.get(:a)
|
103
|
+
local.get(:b)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
br 0
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
return_ do
|
113
|
+
local.get(:b)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
export("gcd") do
|
117
|
+
func(:gcd)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
Both modules emit identical WASM bytecode and produce the same answers:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
folded.to_wasm.save("folded.wasm")
|
126
|
+
unfolded.to_wasm.save("unfolded.wasm")
|
127
|
+
```
|
128
|
+
|
129
|
+
```bash
|
130
|
+
$ sha256sum folded.wasm unfolded.wasm
|
131
|
+
0023ef97eba001226401e432912f2e644a6cbef107ba183546c51177eee46e2c folded.wasm
|
132
|
+
0023ef97eba001226401e432912f2e644a6cbef107ba183546c51177eee46e2c unfolded.wasm
|
133
|
+
$ wasmtime folded.wasm --invoke gcd 270 192
|
134
|
+
6
|
135
|
+
$ wasmtime unfolded.wasm --invoke gcd 270 192
|
136
|
+
6
|
137
|
+
```
|
138
|
+
|
139
|
+
1: https://github.com/WebAssembly/wabt
|
140
|
+
|
141
|
+
## Installation
|
142
|
+
|
143
|
+
Add this line to your application's `Gemfile`:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
gem 'wag'
|
147
|
+
```
|
148
|
+
|
149
|
+
And then execute:
|
150
|
+
|
151
|
+
$ bundle install
|
152
|
+
|
153
|
+
Or install it yourself as:
|
154
|
+
|
155
|
+
$ gem install wag
|
156
|
+
|
157
|
+
|
158
|
+
## Development
|
159
|
+
|
160
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
161
|
+
|
162
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
163
|
+
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/jimsy/wag.
|
167
|
+
|
168
|
+
## License
|
169
|
+
|
170
|
+
The gem is available as open source under the terms of the [Hippocratic License](https://firstdonoharm.dev/version/2/1/license.html).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'wag'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/wag.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'wag/version'
|
4
|
+
|
5
|
+
module WAG
|
6
|
+
class Error < StandardError; end
|
7
|
+
# Your code goes here...
|
8
|
+
|
9
|
+
require 'wag/encodable'
|
10
|
+
require 'wag/inflector'
|
11
|
+
require 'wag/instructable'
|
12
|
+
|
13
|
+
require 'wag/data'
|
14
|
+
require 'wag/element'
|
15
|
+
require 'wag/export'
|
16
|
+
require 'wag/f32_instructions'
|
17
|
+
require 'wag/f64_instructions'
|
18
|
+
require 'wag/function'
|
19
|
+
require 'wag/function_type'
|
20
|
+
require 'wag/global_instructions'
|
21
|
+
require 'wag/global'
|
22
|
+
require 'wag/i32_instructions'
|
23
|
+
require 'wag/i64_instructions'
|
24
|
+
require 'wag/import'
|
25
|
+
require 'wag/indices'
|
26
|
+
require 'wag/instruction'
|
27
|
+
require 'wag/label'
|
28
|
+
require 'wag/local_instructions'
|
29
|
+
require 'wag/local'
|
30
|
+
require 'wag/memory_instructions'
|
31
|
+
require 'wag/memory'
|
32
|
+
require 'wag/module'
|
33
|
+
require 'wag/param'
|
34
|
+
require 'wag/result'
|
35
|
+
require 'wag/table'
|
36
|
+
require 'wag/then'
|
37
|
+
require 'wag/type'
|
38
|
+
|
39
|
+
require 'wag/wabt'
|
40
|
+
require 'wag/wasm'
|
41
|
+
require 'wag/wat'
|
42
|
+
end
|