Class: Dewasm::Pozeiden::WasmModule::Rt::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/dewasm/pozeiden/wasm_module.rb

Constant Summary collapse

PAGE_SIZE =
65536

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min_pages, max_pages) ⇒ Memory

Returns a new instance of Memory.



270
271
272
273
274
275
276
277
278
279
280
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 270

def initialize(min_pages, max_pages)
	@size = min_pages * PAGE_SIZE
	saved = Warning[:experimental]
	begin
		Warning[:experimental] = false
		@buffer = IO::Buffer.new(@size)
	ensure
		Warning[:experimental] = saved
	end
	@max_pages = max_pages && max_pages < 65536 ? max_pages : 65536
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



266
267
268
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 266

def buffer
  @buffer
end

Instance Method Details

#check(addr, len) ⇒ Object



282
283
284
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 282

def check(addr, len)
	Rt.trap("out of bounds memory access") if addr + len > @size
end

#copy(dst, src, len) ⇒ Object



286
287
288
289
290
291
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 286

def copy(dst, src, len)
	check(dst, len)
	check(src, len)
	return if len == 0
	@buffer.copy(@buffer, dst, len, src)
end

#fdl(a) ⇒ Object



293
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 293

def fdl(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.get_value(:f64, a))

#fdla(a, b) ⇒ Object



295
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 295

def fdla(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.get_value(:f64, a))

#fdlo(a, off) ⇒ Object



297
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 297

def fdlo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.get_value(:f64, a))

#fds(a, v) ⇒ Object



299
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 299

def fds(a, v) = (a &= M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.set_value(:f64, a, v))

#fdsa(a, b, v) ⇒ Object



301
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 301

def fdsa(a, b, v) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.set_value(:f64, a, v))

#fdso(a, off, v) ⇒ Object



303
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 303

def fdso(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.set_value(:f64, a, v))

#fill(dst, val, len) ⇒ Object



305
306
307
308
309
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 305

def fill(dst, val, len)
	check(dst, len)
	return if len == 0
	@buffer.clear(val & 0xff, dst, len)
end

#fwl(a) ⇒ Object

Reading :f32 is bit-exact for every non-NaN value. A NaN takes the bit path because the float-to-double conversion quietens it, and wasm's f32.load is bit-preserving.



313
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 313

def fwl(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 4 > @size; r = @buffer.get_value(:f32, a); r.nan? ? Rt.f32_from_bits(@buffer.get_value(:u32, a)) : r)

#fwla(a, b) ⇒ Object

Reading :f32 is bit-exact for every non-NaN value. A NaN takes the bit path because the float-to-double conversion quietens it, and wasm's f32.load is bit-preserving.



317
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 317

def fwla(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 4 > @size; r = @buffer.get_value(:f32, a); r.nan? ? Rt.f32_from_bits(@buffer.get_value(:u32, a)) : r)

#fwlo(a, off) ⇒ Object

Reading :f32 is bit-exact for every non-NaN value. A NaN takes the bit path because the float-to-double conversion quietens it, and wasm's f32.load is bit-preserving.



321
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 321

def fwlo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 4 > @size; r = @buffer.get_value(:f32, a); r.nan? ? Rt.f32_from_bits(@buffer.get_value(:u32, a)) : r)

#fws(a, v) ⇒ Object

Writing :f32 is bit-exact for every non-NaN value. A NaN takes the bit path because the double-to-float conversion quietens it, and wasm's f32.store is bit-preserving.



325
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 325

def fws(a, v) = v.nan? ? iws(a, Rt.f32_bits(v)) : (a &= M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:f32, a, v))

#fwsa(a, b, v) ⇒ Object

Writing :f32 is bit-exact for every non-NaN value. A NaN takes the bit path because the double-to-float conversion quietens it, and wasm's f32.store is bit-preserving.



329
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 329

def fwsa(a, b, v) = v.nan? ? iwsa(a, b, Rt.f32_bits(v)) : (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:f32, a, v))

#fwso(a, off, v) ⇒ Object

Writing :f32 is bit-exact for every non-NaN value. A NaN takes the bit path because the double-to-float conversion quietens it, and wasm's f32.store is bit-preserving.



333
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 333

def fwso(a, off, v) = v.nan? ? iwso(a, off, Rt.f32_bits(v)) : (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:f32, a, v))

#grow(delta) ⇒ Object



335
336
337
338
339
340
341
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 335

def grow(delta)
	old = size
	return M32 if old + delta > @max_pages
	@size += delta * PAGE_SIZE
	@buffer.resize(@size) # zero-fills the new tail
	old
end

#idl(a) ⇒ Object



343
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 343

def idl(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.get_value(:u64, a))

#idla(a, b) ⇒ Object



345
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 345

def idla(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.get_value(:u64, a))

#idlo(a, off) ⇒ Object



347
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 347

def idlo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.get_value(:u64, a))

#ids(a, v) ⇒ Object



349
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 349

def ids(a, v) = (a &= M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.set_value(:u64, a, Rt.m64(v)))

#idsa(a, b, v) ⇒ Object



351
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 351

def idsa(a, b, v) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.set_value(:u64, a, Rt.m64(v)))

#idsba(a, b, v) ⇒ Object



353
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 353

def idsba(a, b, v) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.set_value(:U8, a, v & 0xff))

#idsbo(a, off, v) ⇒ Object



355
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 355

def idsbo(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.set_value(:U8, a, v & 0xff))

#idsho(a, off, v) ⇒ Object



357
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 357

def idsho(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.set_value(:u16, a, v & 0xffff))

#idso(a, off, v) ⇒ Object



359
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 359

def idso(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 8 > @size; @buffer.set_value(:u64, a, Rt.m64(v)))

#idswo(a, off, v) ⇒ Object



361
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 361

def idswo(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:u32, a, v & M32))

#init(dst, data, src, len) ⇒ Object

Also used to initialize active data segments at instantiation time.



364
365
366
367
368
369
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 364

def init(dst, data, src, len)
	Rt.trap("out of bounds memory access") if src + len > data.bytesize
	check(dst, len)
	return if len == 0
	@buffer.set_string(data, dst, len, src)
end

#iwl(a) ⇒ Object



371
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 371

def iwl(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.get_value(:u32, a))

#iwla(a, b) ⇒ Object



373
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 373

def iwla(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.get_value(:u32, a))

#iwlb(a) ⇒ Object



375
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 375

def iwlb(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:S8, a) & M32)

#iwlba(a, b) ⇒ Object



377
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 377

def iwlba(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:S8, a) & M32)

#iwlbo(a, off) ⇒ Object



379
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 379

def iwlbo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:S8, a) & M32)

#iwlo(a, off) ⇒ Object



381
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 381

def iwlo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.get_value(:u32, a))

#iws(a, v) ⇒ Object



383
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 383

def iws(a, v) = (a &= M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:u32, a, v & M32))

#iwsa(a, b, v) ⇒ Object



385
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 385

def iwsa(a, b, v) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:u32, a, v & M32))

#iwsb(a, v) ⇒ Object



387
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 387

def iwsb(a, v) = (a &= M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.set_value(:U8, a, v & 0xff))

#iwsba(a, b, v) ⇒ Object



389
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 389

def iwsba(a, b, v) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.set_value(:U8, a, v & 0xff))

#iwsbo(a, off, v) ⇒ Object



391
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 391

def iwsbo(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.set_value(:U8, a, v & 0xff))

#iwsh(a, v) ⇒ Object



393
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 393

def iwsh(a, v) = (a &= M32; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.set_value(:u16, a, v & 0xffff))

#iwsha(a, b, v) ⇒ Object



395
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 395

def iwsha(a, b, v) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.set_value(:u16, a, v & 0xffff))

#iwsho(a, off, v) ⇒ Object



397
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 397

def iwsho(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.set_value(:u16, a, v & 0xffff))

#iwso(a, off, v) ⇒ Object



399
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 399

def iwso(a, off, v) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.set_value(:u32, a, v & M32))

#read_string(ptr, len) ⇒ Object



401
402
403
404
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 401

def read_string(ptr, len)
	check(ptr, len)
	@buffer.get_string(ptr, len)
end

#sizeObject



406
407
408
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 406

def size
	@size / PAGE_SIZE
end

#udlb(a) ⇒ Object



410
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 410

def udlb(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:U8, a))

#udlba(a, b) ⇒ Object



412
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 412

def udlba(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:U8, a))

#udlbo(a, off) ⇒ Object



414
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 414

def udlbo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:U8, a))

#udlho(a, off) ⇒ Object



416
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 416

def udlho(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.get_value(:u16, a))

#udlw(a) ⇒ Object



418
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 418

def udlw(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.get_value(:u32, a))

#udlwa(a, b) ⇒ Object



420
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 420

def udlwa(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 4 > @size; @buffer.get_value(:u32, a))

#uwlb(a) ⇒ Object



422
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 422

def uwlb(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:U8, a))

#uwlba(a, b) ⇒ Object



424
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 424

def uwlba(a, b) = (a = (a + b) & M32; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:U8, a))

#uwlbo(a, off) ⇒ Object



426
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 426

def uwlbo(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 1 > @size; @buffer.get_value(:U8, a))

#uwlh(a) ⇒ Object



428
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 428

def uwlh(a) = (a &= M32; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.get_value(:u16, a))

#uwlho(a, off) ⇒ Object



430
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 430

def uwlho(a, off) = (a = (a & M32) + off; Rt.trap("out of bounds memory access") if a + 2 > @size; @buffer.get_value(:u16, a))

#wasm_kindObject



268
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 268

def wasm_kind = :memory