beetlebug▾
/

ztcl::wasm::host instantiate

Instantiates a module with the import families of a grant, and gives an instance handle.

ztcl::wasm::host instantiate MODULE ?-grant DICT? ?OPTION VALUE ...?

Description

Calls ztcl::wasm instantiate with the imports of each family of -grant and the other options. A family is the wasm module name of its imports, and a module name of -imports that is a family of the grant is an error. A failed instantiation frees what the grant made.

Arguments

ArgumentTypeDefaultDescription
MODULEhandlerequiredA module handle from ztcl::wasm new or load.

Options

OptionTypeDefaultDescription
-grantdictnoneGives the module the families of the dict: each name with a dict of its options.

-grant DICT

Gives the module the families of the dict: each name with a dict of its options.

The family vm needs the capability vm. Its options: -options LIST, the options of ztcl::vm create that the module can give (by default -image -cpus -memory -cmdline -entropy -balloon -warm); -fixed LIST, the options that the host gives to each guest; -guests N, the most guests at one time (4); -timeout MS, the time limit of exec with no output (30,000); -snapshots DIR, the folder of snapshot and restore (none); and -max-bytes N, the most bytes of an input (67,108,864).

% set g [ztcl::wasm::host instantiate $m -grant {vm {-guests 1 -timeout 5000}}]
> ztcl::wasm call $g start 1
-2
% ztcl::wasm::host instantiate $m -grant {vm {-bogus 1}}
bad option "-bogus" of the family vm: must be -fixed, -guests, -max-bytes, -options, -snapshots, or -timeout
-errorcode ZTCL WASM GRANT vm

% ztcl::wasm::host instantiate $m -grant {vm {-guests 0}}
the value of -guests must be an integer above 0: "0"
-errorcode ZTCL WASM GRANT vm

% ztcl::wasm::host instantiate $m -grant {vm {}} -imports {vm {}}
the module name "vm" is in -imports and in -grant
-errorcode ZTCL WASM GRANT vm

Returns

An instance handle.

Examples

Each example of this page runs after package require ztcl::wasm::host # (import "vm" "last_error" (func (param i32 i32) (result i32))), (import "vm" "start" (func (param i32) (result i32))), (memory (export "memory") 1), and an export of each import set m [ztcl::wasm new [binary decode hex 0061736d01000000010c0260027f7f017f60017f017f021c0202766d0a6c6173745f6572726f72000002766d05737461727400010503010001071f03066d656d6f727902000a6c6173745f6572726f7200000573746172740001]] .

% set w [ztcl::wasm::host instantiate $m -grant {vm {}}]
> ztcl::wasm call $w start 9
-2

% ztcl::wasm call $w last_error 0 100
> ztcl::wasm memory $w string 0 26
no guest with the handle 9

Errors

% ztcl::wasm::host instantiate $m
missing import "vm" "last_error"
-errorcode ZTCL WASM LINK

% ztcl::wasm::host instantiate $m -grant {tk {}}
no import family "tk": must be vm, info, location, motion, audio
-errorcode ZTCL WASM GRANT tk

% ztcl::wasm::host instantiate
wrong # args: should be "ztcl::wasm::host instantiate module ?-grant dict? ?option value ...?"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.4

See also