Class: WASI::IOVec

Inherits:
Object show all
Defined in:
lib/rlang/lib/wasi.rb

Overview

An IOVec is an array of (address to buffer, length of buffer) where WASM runtime can read data coming from the WASM module

Constant Summary collapse

IOV_SIZE =
1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ IOVec

Returns a new instance of IOVec.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rlang/lib/wasi.rb', line 60

def initialize(n)
  result :none
  @iovs = Array32.new(2*n)
  @n = n
  i = 0
  while i < n;
    @iovs[i] = Malloc.malloc(IOV_SIZE)
    @iovs[i+1] = IOV_SIZE
    i += 2
  end
end

Instance Attribute Details

#iovsObject (readonly)

Returns the value of attribute iovs.



55
56
57
# File 'lib/rlang/lib/wasi.rb', line 55

def iovs
  @iovs
end

Instance Method Details

#freeObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/rlang/lib/wasi.rb', line 72

def free
  result :none
  i = 0
  while i < @n
    Malloc.free(@iovs[i])
    i += 2
  end
  @iovs.free
  Object.free(self)
end