Class: Wardite::WasmFunction
- Inherits:
-
Object
- Object
- Wardite::WasmFunction
- Includes:
- ValueHelper
- Defined in:
- lib/wardite.rb
Overview
TODO: common interface btw. WasmFunction and ExternalFunction?
may be _WasmCallable?
Instance Attribute Summary collapse
-
#callsig ⇒ Object
: Array.
-
#code_body ⇒ Object
: CodeSection::CodeBody.
-
#default_locals ⇒ Object
: Array.
-
#findex ⇒ Object
: Integer.
-
#retsig ⇒ Object
: Array.
Instance Method Summary collapse
- #body ⇒ Object
- #clone(override_type: nil) ⇒ Object
- #construct_default_locals ⇒ Object
-
#initialize(callsig, retsig, code_body) ⇒ WasmFunction
constructor
A new instance of WasmFunction.
- #locals_count ⇒ Object
- #locals_type ⇒ Object
Methods included from ValueHelper
Constructor Details
#initialize(callsig, retsig, code_body) ⇒ WasmFunction
Returns a new instance of WasmFunction.
1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'lib/wardite.rb', line 1258 def initialize(callsig, retsig, code_body) @callsig = callsig @retsig = retsig @code_body = code_body @findex = 0 # for debug @default_locals = construct_default_locals end |
Instance Attribute Details
#callsig ⇒ Object
: Array
1244 1245 1246 |
# File 'lib/wardite.rb', line 1244 def callsig @callsig end |
#code_body ⇒ Object
: CodeSection::CodeBody
1248 1249 1250 |
# File 'lib/wardite.rb', line 1248 def code_body @code_body end |
#default_locals ⇒ Object
: Array
1252 1253 1254 |
# File 'lib/wardite.rb', line 1252 def default_locals @default_locals end |
#findex ⇒ Object
: Integer
1250 1251 1252 |
# File 'lib/wardite.rb', line 1250 def findex @findex end |
Instance Method Details
#body ⇒ Object
1268 1269 1270 |
# File 'lib/wardite.rb', line 1268 def body code_body.body end |
#clone(override_type: nil) ⇒ Object
1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/wardite.rb', line 1308 def clone(override_type: nil) if override_type # code_body is assumed to be frozen, so we can copy its ref WasmFunction.new(override_type.callsig, override_type.retsig, code_body) else WasmFunction.new(callsig, retsig, code_body) end end |
#construct_default_locals ⇒ Object
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
# File 'lib/wardite.rb', line 1283 def construct_default_locals locals = [] #: Array[wasmValue] locals_count.each_with_index do |count, i| typ = locals_type[i] count.times do case typ when :i32, :u32 locals.push I32(0) when :i64, :u64 locals.push I64(0) when :f32 locals.push F32(0.0) when :f64 locals.push F64(0.0) else $stderr.puts "warning: unknown type #{typ.inspect}. default to I32" locals.push I32(0) end end end locals end |
#locals_count ⇒ Object
1278 1279 1280 |
# File 'lib/wardite.rb', line 1278 def locals_count code_body.locals_count end |
#locals_type ⇒ Object
1273 1274 1275 |
# File 'lib/wardite.rb', line 1273 def locals_type code_body.locals_type end |