Class: WASI

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

Defined Under Namespace

Classes: CIOVec, IOVec

Constant Summary collapse

STDIN_FD =
0
STDOUT_FD =
1
STDERR_FD =
2
@@argv_buf_size =
0
@@environc =
0
@@environ_buf_size =
0

Class Method Summary collapse

Class Method Details

.args_get(argv, argv_buf) ⇒ Object



89
# File 'lib/rlang/lib/wasi.rb', line 89

def self.args_get(argv, argv_buf); end

.args_sizes_get(argc, args_size) ⇒ Object



86
# File 'lib/rlang/lib/wasi.rb', line 86

def self.args_sizes_get(argc, args_size); end

.argv_initObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rlang/lib/wasi.rb', line 106

def self.argv_init
  local argv: :Array32, environ: :Array32

  # Get number of arguments and their total size
  errno = WASI.args_sizes_get(ARGC.addr, @@argv_buf_size.addr)
  raise "Errno args_sizes_get" if errno != 0

  # Allocate memory areas to receive the argument pointers
  # (argv) and the argument strings (argv_buf)
  #
  # Setup an extra slot in argv array to simplify the
  # loop below
  argv = Array32.new(ARGC+1) # Assuming I32 for pointers
  argv_buf = Malloc.malloc(@@argv_buf_size)
  errno = WASI.args_get(argv.ptr, argv_buf)

  raise "Errno args_get" if errno != 0
  argv[ARGC] = argv[0] + @@argv_buf_size

  # Workaround to avoid dynamic constant assignment error
  Memory.store32(ARGV.addr, Array32.new(ARGC))

  # Now scan through arguments and turn them into a Rlang
  # Array of Strings (like ARGV in Ruby)
  i = 0
  while i < ARGC
    length = argv[i+1] - argv[i] - 1 # -1 because of null terminated
    ARGV[i] = String.new(argv[i], length)
    # Nullify argv[i] so that String is not freed
    argv[i] = 0
    i += 1
  end
  argv.free
  return errno
end

.environ_get(environ, environ_buf) ⇒ Object



92
# File 'lib/rlang/lib/wasi.rb', line 92

def self.environ_get(environ, environ_buf); end

.environ_initObject

Initialize WASI environment and related Rlang objects (ARGC, ARGV,…)



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rlang/lib/wasi.rb', line 144

def self.environ_init
  local environ: :Array32

  # Get environ variable count and buf size
  errno = WASI.environ_sizes_get(@@environc.addr, @@environ_buf_size.addr)
  raise "Errno environ_sizes_get" if errno != 0

  # Allocate memory areas to receive the env var pointers
  # (env) and the env var strings (env_buf)
  environ = Array32.new(@@environc+1) # Assuming I32 for pointers
  environ_buf = Malloc.malloc(@@environ_buf_size)
  errno = WASI.environ_get(environ.ptr, environ_buf)

  raise "Errno environ_get" if errno != 0
  environ[@@environc] = environ[0] + @@environ_buf_size

  # Workaround to avoid dynamic constant assignment error
  Memory.store32(ENV.addr, Array32.new(@@environc))

  # Now scan through arguments and turn them into a Rlang
  # Array of Strings (like ARGV in Ruby)
  i = 0
  while i < @@environc
    length = environ[i+1] - environ[i] - 1 # -1 because of null terminated
    ENV[i] = String.new(environ[i], length)
    # Nullify environ[i] so that String is not freed
    #environ[i] = 0
    i += 1
  end
  #environ.free

  return errno
end

.environ_sizes_get(environc, environ_buf_size) ⇒ Object



95
# File 'lib/rlang/lib/wasi.rb', line 95

def self.environ_sizes_get(environc, environ_buf_size); end

.fd_read(fd, iovs, iovs_count, nread_ptr) ⇒ Object



101
# File 'lib/rlang/lib/wasi.rb', line 101

def self.fd_read(fd, iovs, iovs_count, nread_ptr); end

.fd_write(fd, iovs, iovs_count, nwritten_ptr) ⇒ Object



98
# File 'lib/rlang/lib/wasi.rb', line 98

def self.fd_write(fd, iovs, iovs_count, nwritten_ptr); end

.initObject



178
179
180
181
# File 'lib/rlang/lib/wasi.rb', line 178

def self.init
  self.argv_init
  self.environ_init
end

.proc_exit(exitcode) ⇒ Object



104
# File 'lib/rlang/lib/wasi.rb', line 104

def self.proc_exit(exitcode); result :none; end