/
engine.go
76 lines (62 loc) · 1.66 KB
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package wasmer
// #include <wasmer.h>
import "C"
import "runtime"
// Engine is used by the Store to drive the compilation and the
// execution of a WebAssembly module.
type Engine struct {
_inner *C.wasm_engine_t
}
func newEngine(engine *C.wasm_engine_t) *Engine {
self := &Engine{
_inner: engine,
}
runtime.SetFinalizer(self, func(self *Engine) {
C.wasm_engine_delete(self.inner())
})
return self
}
// NewEngine instantiates and returns a new Engine with the default configuration.
//
// engine := NewEngine()
//
func NewEngine() *Engine {
return newEngine(C.wasm_engine_new())
}
// NewEngineWithConfig instantiates and returns a new Engine with the given configuration.
//
// config := NewConfig()
// engine := NewEngineWithConfig(config)
//
func NewEngineWithConfig(config *Config) *Engine {
return newEngine(C.wasm_engine_new_with_config(config.inner()))
}
// NewUniversalEngine instantiates and returns a new Universal engine.
//
// engine := NewUniversalEngine()
//
func NewUniversalEngine() *Engine {
config := NewConfig()
config.UseUniversalEngine()
return NewEngineWithConfig(config)
}
// NewDylibEngine instantiates and returns a new Dylib engine.
//
// engine := NewDylibEngine()
//
func NewDylibEngine() *Engine {
config := NewConfig()
config.UseDylibEngine()
return NewEngineWithConfig(config)
}
func (self *Engine) inner() *C.wasm_engine_t {
return self._inner
}
// NewJITEngine is a deprecated function. Please use NewUniversalEngine instead.
func NewJITEngine() *Engine {
return NewUniversalEngine()
}
// NewNativeEngine is a deprecated function. Please use NewDylibEngine instead.
func NewNativeEngine() *Engine {
return NewDylibEngine()
}