wardite 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/wardite/convert.generated.rb +5 -5
- data/lib/wardite/leb128.rb +5 -4
- data/lib/wardite/load.rb +8 -2
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite.rb +28 -10
- data/scripts/gen_conv.rb +1 -1
- data/sig/generated/wardite/leb128.rbs +3 -2
- data/sig/generated/wardite.rbs +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6335000832a623233f1a9719fe271fa4a000270bc55312fc996fe3f4e72bad9
|
4
|
+
data.tar.gz: d72874301c47400a24fa9992de296d5d490c04d2c6f1dad2b76493f7eed3b464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d3a12027244cac1cc6efeb382a6a164c070946a85886eae1915c90360a6c139766ae2780103511bf1e332418576a6dbdc1fd7ca7266a2974dd228d24155bedb
|
7
|
+
data.tar.gz: 282d5051760ca800a876daaa1962bea603961ce3fc4551560255030c433e445ba0efc945b75b5829112a6742b6492142ad3c2a1d577f30816bcf76f39bd58f2e
|
data/README.md
CHANGED
@@ -7,6 +7,21 @@ A pure-ruby webassembly runtime.
|
|
7
7
|
- [x] Fully typed by RBS (with the aid of [rbs-inline](https://github.com/soutaro/rbs-inline))
|
8
8
|
- [ ] WASI (p1) support
|
9
9
|
|
10
|
+
## Supported Instructions
|
11
|
+
|
12
|
+
ref: https://webassembly.github.io/spec/core/binary/instructions.html
|
13
|
+
|
14
|
+
- [x] Control Instructions
|
15
|
+
- [x] Parametric Instructions
|
16
|
+
- [x] Variable Instructions
|
17
|
+
- [ ] Table Instructions
|
18
|
+
- [x] Memory Instructions (except `data.drop`)
|
19
|
+
- [x] Numeric Instructions (`0x41 ... 0xC4`)
|
20
|
+
- [x] Numeric Instructions (`0xFC` Operations)
|
21
|
+
- [ ] Reference Instructions
|
22
|
+
- [ ] Vector Instructions
|
23
|
+
- [x] end `0x0B`
|
24
|
+
|
10
25
|
## Installation
|
11
26
|
|
12
27
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -58,7 +58,7 @@ module Wardite
|
|
58
58
|
runtime.stack.push(to)
|
59
59
|
|
60
60
|
|
61
|
-
when :
|
61
|
+
when :i32_extend8_s
|
62
62
|
from = runtime.stack.pop
|
63
63
|
raise EvalError, "maybe empty or invalid stack" if !from.is_a?(I32)
|
64
64
|
to = from.extendN_s(to: :i32, from: :i8)
|
@@ -66,7 +66,7 @@ module Wardite
|
|
66
66
|
runtime.stack.push(to)
|
67
67
|
|
68
68
|
|
69
|
-
when :
|
69
|
+
when :i32_extend16_s
|
70
70
|
from = runtime.stack.pop
|
71
71
|
raise EvalError, "maybe empty or invalid stack" if !from.is_a?(I32)
|
72
72
|
to = from.extendN_s(to: :i32, from: :i16)
|
@@ -178,7 +178,7 @@ module Wardite
|
|
178
178
|
runtime.stack.push(to)
|
179
179
|
|
180
180
|
|
181
|
-
when :
|
181
|
+
when :i64_extend8_s
|
182
182
|
from = runtime.stack.pop
|
183
183
|
raise EvalError, "maybe empty or invalid stack" if !from.is_a?(I32)
|
184
184
|
to = from.extendN_s(to: :i64, from: :i8)
|
@@ -186,7 +186,7 @@ module Wardite
|
|
186
186
|
runtime.stack.push(to)
|
187
187
|
|
188
188
|
|
189
|
-
when :
|
189
|
+
when :i64_extend16_s
|
190
190
|
from = runtime.stack.pop
|
191
191
|
raise EvalError, "maybe empty or invalid stack" if !from.is_a?(I32)
|
192
192
|
to = from.extendN_s(to: :i64, from: :i16)
|
@@ -194,7 +194,7 @@ module Wardite
|
|
194
194
|
runtime.stack.push(to)
|
195
195
|
|
196
196
|
|
197
|
-
when :
|
197
|
+
when :i64_extend32_s
|
198
198
|
from = runtime.stack.pop
|
199
199
|
raise EvalError, "maybe empty or invalid stack" if !from.is_a?(I32)
|
200
200
|
to = from.extendN_s(to: :i64, from: :i32)
|
data/lib/wardite/leb128.rb
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
module Wardite
|
3
3
|
module Leb128Helper
|
4
4
|
# @rbs buf: File|StringIO
|
5
|
+
# @rbs max_level: Integer
|
5
6
|
# @rbs return: Integer
|
6
|
-
def fetch_uleb128(buf)
|
7
|
+
def fetch_uleb128(buf, max_level: 8)
|
7
8
|
dest = 0
|
8
9
|
level = 0
|
9
10
|
while b = buf.read(1)
|
@@ -18,7 +19,7 @@ module Wardite
|
|
18
19
|
return dest
|
19
20
|
end
|
20
21
|
|
21
|
-
if level >
|
22
|
+
if level > max_level
|
22
23
|
break
|
23
24
|
end
|
24
25
|
level += 1
|
@@ -29,7 +30,7 @@ module Wardite
|
|
29
30
|
|
30
31
|
# @rbs buf: File|StringIO
|
31
32
|
# @rbs return: Integer
|
32
|
-
def fetch_sleb128(buf)
|
33
|
+
def fetch_sleb128(buf, max_level: 8)
|
33
34
|
dest = 0
|
34
35
|
level = 0
|
35
36
|
while b = buf.read(1)
|
@@ -44,7 +45,7 @@ module Wardite
|
|
44
45
|
break
|
45
46
|
end
|
46
47
|
|
47
|
-
if level >
|
48
|
+
if level > max_level
|
48
49
|
raise "unreachable! debug: dest = #{dest} level = #{level}"
|
49
50
|
end
|
50
51
|
level += 1
|
data/lib/wardite/load.rb
CHANGED
@@ -630,7 +630,7 @@ module Wardite
|
|
630
630
|
when :i32
|
631
631
|
operand << fetch_sleb128(buf)
|
632
632
|
when :i64
|
633
|
-
operand << fetch_sleb128(buf)
|
633
|
+
operand << fetch_sleb128(buf, max_level: 16)
|
634
634
|
when :f32
|
635
635
|
data = buf.read 4
|
636
636
|
if !data || data.size != 4
|
@@ -667,6 +667,12 @@ module Wardite
|
|
667
667
|
end
|
668
668
|
|
669
669
|
dest
|
670
|
+
rescue => e
|
671
|
+
require "pp"
|
672
|
+
$stderr.puts "parsed:::"
|
673
|
+
$stderr.puts "#{dest.pretty_inspect}"
|
674
|
+
$stderr.puts "code = #{code}"
|
675
|
+
raise e
|
670
676
|
end
|
671
677
|
|
672
678
|
# @rbs c: String
|
@@ -845,7 +851,7 @@ module Wardite
|
|
845
851
|
# @rbs return: nil
|
846
852
|
def self.unimplemented_skip_section(code)
|
847
853
|
$stderr.puts "warning: unimplemented section: 0x0#{code}"
|
848
|
-
size = @buf
|
854
|
+
size = fetch_uleb128(@buf)
|
849
855
|
@buf.read(size)
|
850
856
|
nil
|
851
857
|
end
|
data/lib/wardite/version.rb
CHANGED
data/lib/wardite.rb
CHANGED
@@ -310,20 +310,28 @@ module Wardite
|
|
310
310
|
end
|
311
311
|
self.stack = drained_stack(local_start)
|
312
312
|
|
313
|
-
wasm_function.
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
313
|
+
wasm_function.locals_count.each_with_index do |count, i|
|
314
|
+
typ = wasm_function.locals_type[i]
|
315
|
+
count.times do
|
316
|
+
case typ
|
317
|
+
when :i32, :u32
|
318
|
+
locals.push I32(0)
|
319
|
+
when :i64, :u64
|
320
|
+
locals.push I64(0)
|
321
|
+
when :f32
|
322
|
+
locals.push F32(0.0)
|
323
|
+
when :f64
|
324
|
+
locals.push F64(0.0)
|
325
|
+
else
|
326
|
+
$stderr.puts "warning: unknown type #{typ.inspect}. default to I32"
|
327
|
+
locals.push I32(0)
|
328
|
+
end
|
322
329
|
end
|
323
330
|
end
|
324
331
|
|
325
332
|
arity = wasm_function.retsig.size
|
326
333
|
frame = Frame.new(-1, stack.size, wasm_function.body, arity, locals)
|
334
|
+
frame.findex = wasm_function.findex
|
327
335
|
self.call_stack.push(frame)
|
328
336
|
end
|
329
337
|
|
@@ -593,7 +601,8 @@ module Wardite
|
|
593
601
|
end
|
594
602
|
local = frame.locals[idx]
|
595
603
|
if !local
|
596
|
-
|
604
|
+
# require "irb"; binding.irb
|
605
|
+
raise EvalError, "local not found, idx = #{idx}"
|
597
606
|
end
|
598
607
|
stack.push(local)
|
599
608
|
|
@@ -884,6 +893,8 @@ module Wardite
|
|
884
893
|
|
885
894
|
attr_accessor :locals #: Array[wasmValue]
|
886
895
|
|
896
|
+
attr_accessor :findex #: Integer
|
897
|
+
|
887
898
|
# @rbs pc: Integer
|
888
899
|
# @rbs sp: Integer
|
889
900
|
# @rbs body: Array[Op]
|
@@ -897,6 +908,8 @@ module Wardite
|
|
897
908
|
@arity = arity
|
898
909
|
@locals = locals
|
899
910
|
@labels = []
|
911
|
+
|
912
|
+
@findex = 0
|
900
913
|
end
|
901
914
|
end
|
902
915
|
|
@@ -970,6 +983,8 @@ module Wardite
|
|
970
983
|
retsig = type_section.defined_results[sigindex]
|
971
984
|
codes = code_section.func_codes[findex]
|
972
985
|
wasm_function = WasmFunction.new(callsig, retsig, codes)
|
986
|
+
idx = self.funcs.size
|
987
|
+
wasm_function.findex = idx
|
973
988
|
self.funcs << wasm_function
|
974
989
|
end
|
975
990
|
end
|
@@ -1233,6 +1248,8 @@ module Wardite
|
|
1233
1248
|
|
1234
1249
|
attr_accessor :code_body #: CodeSection::CodeBody
|
1235
1250
|
|
1251
|
+
attr_accessor :findex #: Integer
|
1252
|
+
|
1236
1253
|
# @rbs callsig: Array[Symbol]
|
1237
1254
|
# @rbs retsig: Array[Symbol]
|
1238
1255
|
# @rbs code_body: CodeSection::CodeBody
|
@@ -1242,6 +1259,7 @@ module Wardite
|
|
1242
1259
|
@retsig = retsig
|
1243
1260
|
|
1244
1261
|
@code_body = code_body
|
1262
|
+
@findex = 0 # for debug
|
1245
1263
|
end
|
1246
1264
|
|
1247
1265
|
# @rbs return: Array[Op]
|
data/scripts/gen_conv.rb
CHANGED
@@ -46,7 +46,7 @@ module GenConv
|
|
46
46
|
elsif method =~ /^extendN_(u|s)$/
|
47
47
|
suffix = $1
|
48
48
|
from_size = from.to_s.scan(/\d+/).join
|
49
|
-
symbol = "#{to.to_s}
|
49
|
+
symbol = "#{to.to_s}_extend#{from_size}_#{suffix}"
|
50
50
|
extra_kargs = ", from: :#{from.to_s}"
|
51
51
|
elsif method.end_with?("_s") or method.end_with?("_u")
|
52
52
|
core = method.sub(/_(s|u)$/, "")
|
@@ -4,11 +4,12 @@
|
|
4
4
|
module Wardite
|
5
5
|
module Leb128Helper
|
6
6
|
# @rbs buf: File|StringIO
|
7
|
+
# @rbs max_level: Integer
|
7
8
|
# @rbs return: Integer
|
8
|
-
def fetch_uleb128: (File | StringIO buf) -> Integer
|
9
|
+
def fetch_uleb128: (File | StringIO buf, ?max_level: Integer) -> Integer
|
9
10
|
|
10
11
|
# @rbs buf: File|StringIO
|
11
12
|
# @rbs return: Integer
|
12
|
-
def fetch_sleb128: (File | StringIO buf) -> Integer
|
13
|
+
def fetch_sleb128: (File | StringIO buf, ?max_level: untyped) -> Integer
|
13
14
|
end
|
14
15
|
end
|
data/sig/generated/wardite.rbs
CHANGED
@@ -175,6 +175,8 @@ module Wardite
|
|
175
175
|
|
176
176
|
attr_accessor locals: Array[wasmValue]
|
177
177
|
|
178
|
+
attr_accessor findex: Integer
|
179
|
+
|
178
180
|
# @rbs pc: Integer
|
179
181
|
# @rbs sp: Integer
|
180
182
|
# @rbs body: Array[Op]
|
@@ -334,6 +336,8 @@ module Wardite
|
|
334
336
|
|
335
337
|
attr_accessor code_body: CodeSection::CodeBody
|
336
338
|
|
339
|
+
attr_accessor findex: Integer
|
340
|
+
|
337
341
|
# @rbs callsig: Array[Symbol]
|
338
342
|
# @rbs retsig: Array[Symbol]
|
339
343
|
# @rbs code_body: CodeSection::CodeBody
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wardite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio Kondo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A pure-ruby webassembly runtime
|
14
14
|
email:
|