wag 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.gitlab-ci.yml +15 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +32 -0
  6. data/.travis.yml +6 -0
  7. data/Gemfile +13 -0
  8. data/Gemfile.lock +66 -0
  9. data/LICENSE.txt +40 -0
  10. data/README.md +170 -0
  11. data/Rakefile +8 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/lib/wag.rb +42 -0
  15. data/lib/wag/data.rb +18 -0
  16. data/lib/wag/element.rb +18 -0
  17. data/lib/wag/encodable.rb +23 -0
  18. data/lib/wag/export.rb +39 -0
  19. data/lib/wag/f32_instructions.rb +21 -0
  20. data/lib/wag/f64_instructions.rb +21 -0
  21. data/lib/wag/function.rb +33 -0
  22. data/lib/wag/function_type.rb +16 -0
  23. data/lib/wag/global.rb +18 -0
  24. data/lib/wag/global_instructions.rb +19 -0
  25. data/lib/wag/i32_instructions.rb +22 -0
  26. data/lib/wag/i64_instructions.rb +23 -0
  27. data/lib/wag/import.rb +42 -0
  28. data/lib/wag/indices.rb +14 -0
  29. data/lib/wag/indices/base.rb +16 -0
  30. data/lib/wag/indices/func.rb +8 -0
  31. data/lib/wag/indices/global.rb +8 -0
  32. data/lib/wag/indices/label.rb +8 -0
  33. data/lib/wag/indices/local.rb +8 -0
  34. data/lib/wag/indices/mem.rb +8 -0
  35. data/lib/wag/indices/table.rb +8 -0
  36. data/lib/wag/indices/type.rb +8 -0
  37. data/lib/wag/inflector.rb +13 -0
  38. data/lib/wag/instructable.rb +65 -0
  39. data/lib/wag/instruction.rb +193 -0
  40. data/lib/wag/instructions/base.rb +24 -0
  41. data/lib/wag/instructions/block.rb +21 -0
  42. data/lib/wag/instructions/br.rb +18 -0
  43. data/lib/wag/instructions/br_if.rb +18 -0
  44. data/lib/wag/instructions/br_table.rb +18 -0
  45. data/lib/wag/instructions/call.rb +18 -0
  46. data/lib/wag/instructions/call_indirect.rb +18 -0
  47. data/lib/wag/instructions/drop.rb +8 -0
  48. data/lib/wag/instructions/else.rb +9 -0
  49. data/lib/wag/instructions/end.rb +8 -0
  50. data/lib/wag/instructions/f32/abs.rb +11 -0
  51. data/lib/wag/instructions/f32/add.rb +11 -0
  52. data/lib/wag/instructions/f32/base.rb +13 -0
  53. data/lib/wag/instructions/f32/ceil.rb +11 -0
  54. data/lib/wag/instructions/f32/const.rb +20 -0
  55. data/lib/wag/instructions/f32/convert_i32_s.rb +11 -0
  56. data/lib/wag/instructions/f32/convert_i32_u.rb +11 -0
  57. data/lib/wag/instructions/f32/convert_i64_s.rb +11 -0
  58. data/lib/wag/instructions/f32/convert_i64_u.rb +11 -0
  59. data/lib/wag/instructions/f32/copysign.rb +11 -0
  60. data/lib/wag/instructions/f32/demote_f64.rb +11 -0
  61. data/lib/wag/instructions/f32/div.rb +11 -0
  62. data/lib/wag/instructions/f32/eq.rb +11 -0
  63. data/lib/wag/instructions/f32/floor.rb +11 -0
  64. data/lib/wag/instructions/f32/ge.rb +11 -0
  65. data/lib/wag/instructions/f32/gt.rb +11 -0
  66. data/lib/wag/instructions/f32/le.rb +11 -0
  67. data/lib/wag/instructions/f32/load.rb +11 -0
  68. data/lib/wag/instructions/f32/lt.rb +11 -0
  69. data/lib/wag/instructions/f32/max.rb +11 -0
  70. data/lib/wag/instructions/f32/min.rb +11 -0
  71. data/lib/wag/instructions/f32/mul.rb +11 -0
  72. data/lib/wag/instructions/f32/ne.rb +11 -0
  73. data/lib/wag/instructions/f32/nearest.rb +11 -0
  74. data/lib/wag/instructions/f32/neg.rb +11 -0
  75. data/lib/wag/instructions/f32/reinterpret_i32.rb +11 -0
  76. data/lib/wag/instructions/f32/sqrt.rb +11 -0
  77. data/lib/wag/instructions/f32/store.rb +11 -0
  78. data/lib/wag/instructions/f32/sub.rb +11 -0
  79. data/lib/wag/instructions/f32/trunc.rb +11 -0
  80. data/lib/wag/instructions/f64/abs.rb +11 -0
  81. data/lib/wag/instructions/f64/add.rb +11 -0
  82. data/lib/wag/instructions/f64/base.rb +13 -0
  83. data/lib/wag/instructions/f64/ceil.rb +11 -0
  84. data/lib/wag/instructions/f64/const.rb +20 -0
  85. data/lib/wag/instructions/f64/convert_i32_s.rb +11 -0
  86. data/lib/wag/instructions/f64/convert_i32_u.rb +11 -0
  87. data/lib/wag/instructions/f64/convert_i64_s.rb +11 -0
  88. data/lib/wag/instructions/f64/convert_i64_u.rb +11 -0
  89. data/lib/wag/instructions/f64/copysign.rb +11 -0
  90. data/lib/wag/instructions/f64/div.rb +11 -0
  91. data/lib/wag/instructions/f64/eq.rb +11 -0
  92. data/lib/wag/instructions/f64/floor.rb +11 -0
  93. data/lib/wag/instructions/f64/ge.rb +11 -0
  94. data/lib/wag/instructions/f64/gt.rb +11 -0
  95. data/lib/wag/instructions/f64/le.rb +11 -0
  96. data/lib/wag/instructions/f64/load.rb +11 -0
  97. data/lib/wag/instructions/f64/lt.rb +11 -0
  98. data/lib/wag/instructions/f64/max.rb +11 -0
  99. data/lib/wag/instructions/f64/min.rb +11 -0
  100. data/lib/wag/instructions/f64/mul.rb +11 -0
  101. data/lib/wag/instructions/f64/ne.rb +11 -0
  102. data/lib/wag/instructions/f64/nearest.rb +11 -0
  103. data/lib/wag/instructions/f64/neg.rb +11 -0
  104. data/lib/wag/instructions/f64/promote_f32.rb +11 -0
  105. data/lib/wag/instructions/f64/reinterpret_i64.rb +11 -0
  106. data/lib/wag/instructions/f64/sqrt.rb +11 -0
  107. data/lib/wag/instructions/f64/store.rb +11 -0
  108. data/lib/wag/instructions/f64/sub.rb +11 -0
  109. data/lib/wag/instructions/f64/trunc.rb +11 -0
  110. data/lib/wag/instructions/global/base.rb +13 -0
  111. data/lib/wag/instructions/global/get.rb +20 -0
  112. data/lib/wag/instructions/global/set.rb +20 -0
  113. data/lib/wag/instructions/i32/add.rb +11 -0
  114. data/lib/wag/instructions/i32/and.rb +11 -0
  115. data/lib/wag/instructions/i32/base.rb +13 -0
  116. data/lib/wag/instructions/i32/clz.rb +11 -0
  117. data/lib/wag/instructions/i32/const.rb +20 -0
  118. data/lib/wag/instructions/i32/ctz.rb +11 -0
  119. data/lib/wag/instructions/i32/div_s.rb +11 -0
  120. data/lib/wag/instructions/i32/div_u.rb +11 -0
  121. data/lib/wag/instructions/i32/eq.rb +11 -0
  122. data/lib/wag/instructions/i32/eqz.rb +11 -0
  123. data/lib/wag/instructions/i32/ge_s.rb +11 -0
  124. data/lib/wag/instructions/i32/ge_u.rb +11 -0
  125. data/lib/wag/instructions/i32/gt_s.rb +11 -0
  126. data/lib/wag/instructions/i32/gt_u.rb +11 -0
  127. data/lib/wag/instructions/i32/le_s.rb +11 -0
  128. data/lib/wag/instructions/i32/le_u.rb +11 -0
  129. data/lib/wag/instructions/i32/load.rb +11 -0
  130. data/lib/wag/instructions/i32/load16_s.rb +11 -0
  131. data/lib/wag/instructions/i32/load16_u.rb +11 -0
  132. data/lib/wag/instructions/i32/load8_s.rb +11 -0
  133. data/lib/wag/instructions/i32/load8_u.rb +11 -0
  134. data/lib/wag/instructions/i32/lt_s.rb +11 -0
  135. data/lib/wag/instructions/i32/lt_u.rb +11 -0
  136. data/lib/wag/instructions/i32/mul.rb +11 -0
  137. data/lib/wag/instructions/i32/ne.rb +11 -0
  138. data/lib/wag/instructions/i32/or.rb +11 -0
  139. data/lib/wag/instructions/i32/popcnt.rb +11 -0
  140. data/lib/wag/instructions/i32/reinterpret_f32.rb +11 -0
  141. data/lib/wag/instructions/i32/rem_s.rb +11 -0
  142. data/lib/wag/instructions/i32/rem_u.rb +11 -0
  143. data/lib/wag/instructions/i32/rotl.rb +11 -0
  144. data/lib/wag/instructions/i32/rotr.rb +11 -0
  145. data/lib/wag/instructions/i32/shl.rb +11 -0
  146. data/lib/wag/instructions/i32/shr_s.rb +11 -0
  147. data/lib/wag/instructions/i32/shr_u.rb +11 -0
  148. data/lib/wag/instructions/i32/store.rb +11 -0
  149. data/lib/wag/instructions/i32/store16.rb +11 -0
  150. data/lib/wag/instructions/i32/store8.rb +11 -0
  151. data/lib/wag/instructions/i32/sub.rb +11 -0
  152. data/lib/wag/instructions/i32/trunc_f32_s.rb +11 -0
  153. data/lib/wag/instructions/i32/trunc_f32_u.rb +11 -0
  154. data/lib/wag/instructions/i32/trunc_f64_s.rb +11 -0
  155. data/lib/wag/instructions/i32/trunc_f64_u.rb +11 -0
  156. data/lib/wag/instructions/i32/wrap_i64.rb +11 -0
  157. data/lib/wag/instructions/i32/xor.rb +11 -0
  158. data/lib/wag/instructions/i64/add.rb +11 -0
  159. data/lib/wag/instructions/i64/and.rb +11 -0
  160. data/lib/wag/instructions/i64/base.rb +13 -0
  161. data/lib/wag/instructions/i64/clz.rb +11 -0
  162. data/lib/wag/instructions/i64/const.rb +20 -0
  163. data/lib/wag/instructions/i64/ctz.rb +11 -0
  164. data/lib/wag/instructions/i64/div_s.rb +11 -0
  165. data/lib/wag/instructions/i64/div_u.rb +11 -0
  166. data/lib/wag/instructions/i64/eq.rb +11 -0
  167. data/lib/wag/instructions/i64/eqz.rb +11 -0
  168. data/lib/wag/instructions/i64/extend_i32_s.rb +11 -0
  169. data/lib/wag/instructions/i64/extend_i32_u.rb +11 -0
  170. data/lib/wag/instructions/i64/ge_s.rb +11 -0
  171. data/lib/wag/instructions/i64/ge_u.rb +11 -0
  172. data/lib/wag/instructions/i64/gt_s.rb +11 -0
  173. data/lib/wag/instructions/i64/gt_u.rb +11 -0
  174. data/lib/wag/instructions/i64/le_s.rb +11 -0
  175. data/lib/wag/instructions/i64/le_u.rb +11 -0
  176. data/lib/wag/instructions/i64/load.rb +11 -0
  177. data/lib/wag/instructions/i64/load16_s.rb +11 -0
  178. data/lib/wag/instructions/i64/load16_u.rb +11 -0
  179. data/lib/wag/instructions/i64/load32_s.rb +11 -0
  180. data/lib/wag/instructions/i64/load32_u.rb +11 -0
  181. data/lib/wag/instructions/i64/load8_s.rb +11 -0
  182. data/lib/wag/instructions/i64/load8_u.rb +11 -0
  183. data/lib/wag/instructions/i64/lt_s.rb +11 -0
  184. data/lib/wag/instructions/i64/lt_u.rb +11 -0
  185. data/lib/wag/instructions/i64/mul.rb +11 -0
  186. data/lib/wag/instructions/i64/ne.rb +11 -0
  187. data/lib/wag/instructions/i64/or.rb +11 -0
  188. data/lib/wag/instructions/i64/popcnt.rb +11 -0
  189. data/lib/wag/instructions/i64/reinterpret_f64.rb +11 -0
  190. data/lib/wag/instructions/i64/rem_s.rb +11 -0
  191. data/lib/wag/instructions/i64/rem_u.rb +11 -0
  192. data/lib/wag/instructions/i64/rotl.rb +11 -0
  193. data/lib/wag/instructions/i64/rotr.rb +11 -0
  194. data/lib/wag/instructions/i64/shl.rb +11 -0
  195. data/lib/wag/instructions/i64/shr_s.rb +11 -0
  196. data/lib/wag/instructions/i64/shr_u.rb +11 -0
  197. data/lib/wag/instructions/i64/store.rb +11 -0
  198. data/lib/wag/instructions/i64/store16.rb +11 -0
  199. data/lib/wag/instructions/i64/store32.rb +11 -0
  200. data/lib/wag/instructions/i64/store8.rb +11 -0
  201. data/lib/wag/instructions/i64/sub.rb +11 -0
  202. data/lib/wag/instructions/i64/trunc_f32_s.rb +11 -0
  203. data/lib/wag/instructions/i64/trunc_f32_u.rb +11 -0
  204. data/lib/wag/instructions/i64/trunc_f64_s.rb +11 -0
  205. data/lib/wag/instructions/i64/trunc_f64_u.rb +11 -0
  206. data/lib/wag/instructions/i64/xor.rb +11 -0
  207. data/lib/wag/instructions/if.rb +26 -0
  208. data/lib/wag/instructions/local/base.rb +13 -0
  209. data/lib/wag/instructions/local/get.rb +20 -0
  210. data/lib/wag/instructions/local/set.rb +20 -0
  211. data/lib/wag/instructions/local/tee.rb +20 -0
  212. data/lib/wag/instructions/loop.rb +9 -0
  213. data/lib/wag/instructions/memory/base.rb +13 -0
  214. data/lib/wag/instructions/memory/grow.rb +11 -0
  215. data/lib/wag/instructions/memory/size.rb +11 -0
  216. data/lib/wag/instructions/nop.rb +8 -0
  217. data/lib/wag/instructions/return.rb +9 -0
  218. data/lib/wag/instructions/select.rb +9 -0
  219. data/lib/wag/instructions/unreachable.rb +8 -0
  220. data/lib/wag/label.rb +32 -0
  221. data/lib/wag/local.rb +19 -0
  222. data/lib/wag/local_instructions.rb +19 -0
  223. data/lib/wag/memory.rb +26 -0
  224. data/lib/wag/memory_instructions.rb +19 -0
  225. data/lib/wag/module.rb +100 -0
  226. data/lib/wag/param.rb +20 -0
  227. data/lib/wag/result.rb +17 -0
  228. data/lib/wag/table.rb +17 -0
  229. data/lib/wag/then.rb +13 -0
  230. data/lib/wag/type.rb +19 -0
  231. data/lib/wag/types/base.rb +16 -0
  232. data/lib/wag/types/f32.rb +8 -0
  233. data/lib/wag/types/f64.rb +8 -0
  234. data/lib/wag/types/i32.rb +8 -0
  235. data/lib/wag/types/i64.rb +8 -0
  236. data/lib/wag/version.rb +5 -0
  237. data/lib/wag/wabt.rb +45 -0
  238. data/lib/wag/wasm.rb +22 -0
  239. data/lib/wag/wat.rb +18 -0
  240. data/wag.gemspec +35 -0
  241. 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
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,15 @@
1
+ image: ruby:latest
2
+
3
+ before_script:
4
+ - apt-get update && apt-get install wabt && rm -rf /var/cache/apt
5
+ - bundle install
6
+
7
+ test:
8
+ stage: test
9
+ script:
10
+ - bundle exec rspec
11
+
12
+ rubocop:
13
+ stage: test
14
+ script:
15
+ - bundle exec rspec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
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
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
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