How to use the wasmer.Instance function in wasmer

To help you get started, we’ve selected a few wasmer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wasmerio / python-ext-wasm / tests / instance.py View on Github external
def test_is_a_class(self):
        self.assertTrue(inspect.isclass(Instance))
github wasmerio / python-ext-wasm / tests / memory_view.py View on Github external
def test_bytes_per_element(self):
        self.assertEqual(Instance(TEST_BYTES).uint8_memory_view().bytes_per_element, 1)
        self.assertEqual(Instance(TEST_BYTES).int8_memory_view().bytes_per_element, 1)
        self.assertEqual(Instance(TEST_BYTES).uint16_memory_view().bytes_per_element, 2)
        self.assertEqual(Instance(TEST_BYTES).int16_memory_view().bytes_per_element, 2)
        self.assertEqual(Instance(TEST_BYTES).uint32_memory_view().bytes_per_element, 4)
        self.assertEqual(Instance(TEST_BYTES).int32_memory_view().bytes_per_element, 4)
github wasmerio / python-ext-wasm / tests / instance.py View on Github external
def test_call_i32_i64_f32_f64_f64(self):
        self.assertEqual(
            round(Instance(TEST_BYTES).exports['i32_i64_f32_f64_f64'](1, 2, 3.4, 5.6), 6),
            1 + 2 + 3.4 + 5.6
        )
github wasmerio / python-ext-wasm / tests / test_memory.py View on Github external
def test_set_bytearray():
    memory = Instance(TEST_BYTES).memory.uint8_view()

    memory[7:12] = bytearray(b'abcde')
    assert memory[7:12] == [97, 98, 99, 100, 101]
github wasmerio / python-ext-wasm / tests / test_memory.py View on Github external
def test_set_single_value():
    memory = Instance(TEST_BYTES).memory.uint8_view()

    assert memory[7] == 0
    memory[7] = 42
    assert memory[7] == 42
github wasmerio / python-ext-wasm / tests / memory_view.py View on Github external
def test_hello_world(self):
        instance = Instance(TEST_BYTES)
        pointer = instance.exports['string']()
        memory = instance.uint8_memory_view(pointer)
        nth = 0
        string = ''

        while (0 != memory[nth]):
            string += chr(memory[nth])
            nth += 1

        self.assertEqual(string, 'Hello, World!')
github wasmerio / python-ext-wasm / tests / test_memory.py View on Github external
def test_hello_world():
    instance = Instance(TEST_BYTES)
    pointer = instance.exports.string()
    memory = instance.memory.uint8_view(pointer)
    nth = 0
    string = ''

    while (0 != memory[nth]):
        string += chr(memory[nth])
        nth += 1

    assert string, 'Hello, World!'
github Mec-iS / rust-wasm-python-101 / pywasm / run_wasm_with_python.py View on Github external
def run_test():
    with open(path, 'rb') as bytecode:
        wasm_bytes = bytecode.read()
        instance = Instance(wasm_bytes)

        # print exported functions
        print("Modules exported from Rust: ")
        print(instance.exports)

        # assign functions
        simple_add = instance.exports.simple_add
        fibo = instance.exports.fibo
        loop_str = instance.exports.loop_str
        rust_geo_convex_hull = instance.exports.rust_geo_convex_hull
        reverse_string = instance.exports.reverse_string

        # try a simple addition
        result = simple_add(12, 12)
        print("call simple_add(12, 12): ")
        print(result)
github Mec-iS / rust-wasm-python-101 / pywasm / run_timing_collection.py View on Github external
def run_timing():
    with open(path, 'rb') as bytecode:
        wasm_bytes = bytecode.read()
        instance = Instance(wasm_bytes)
        # assign functions
        simple_add = instance.exports.simple_add
        fibo = instance.exports.fibo
        rust_geo_convex_hull = instance.exports.rust_geo_convex_hull

        # print exported functions
        print("Modules exported from Rust: ")
        print(instance.exports)

        # define metadata in results
        from collections import OrderedDict
        results = OrderedDict()
        results['timestap'] = str(datetime.now())
        results['python_wasmer_v'] = f'{wasmer.__version__}|{wasmer.__core_version__}'

        import subprocess