Skip to content

Commit

Permalink
Use an iterative process for imps
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Jan 24, 2019
1 parent 54b7e51 commit f936cb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def fib(n):
return fib(n - 1) + fib(n - 2)


vm = pywasm.load('./examples/env.wasm', {'env.fib': fib})
vm = pywasm.load('./examples/env.wasm', {'env': {'fib': fib}})
r = vm.exec('get', [10])
print(r) # 55
print(r) # 55
9 changes: 4 additions & 5 deletions pywasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ def __init__(self, module: structure.Module, imps: typing.Dict):
self.store = execution.Store()
externvals = []
for e in self.module.imports:
name = f'{e.module}.{e.name}'
if name not in imps:
raise Exception(f'pywasm: global import {name} not found')
if e.module not in imps or e.name not in imps[e.module]:
raise Exception(f'pywasm: global import {e.module}.{e.name} not found')
if e.kind == convention.extern_func:
a = execution.HostFunc(self.module.types[e.desc], imps[name])
a = execution.HostFunc(self.module.types[e.desc], imps[e.module][e.name])
self.store.funcs.append(a)
externvals.append(execution.ExternValue(e.kind, len(self.store.funcs) - 1))
continue
Expand All @@ -26,7 +25,7 @@ def __init__(self, module: structure.Module, imps: typing.Dict):
if e.kind == convention.extern_mem:
raise NotImplementedError
if e.kind == convention.extern_global:
a = execution.GlobalInstance(execution.Value(e.desc.valtype, imps[name]), e.desc.mut)
a = execution.GlobalInstance(execution.Value(e.desc.valtype, imps[e.module][e.name]), e.desc.mut)
self.store.globals.append(a)
externvals.append(execution.ExternValue(e.kind, len(self.store.globals) - 1))
continue
Expand Down

0 comments on commit f936cb4

Please sign in to comment.