-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironment.go
More file actions
78 lines (70 loc) · 1.99 KB
/
Copy pathEnvironment.go
File metadata and controls
78 lines (70 loc) · 1.99 KB
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
77
78
package arbor
import (
"fmt"
"io/ioutil"
"os"
"path"
)
// LoadFile loads our file to run. It returns the content as a byte array, bool if it is pre-compiled, and an error if anything is broken
func LoadFile(fileName string, isWasm bool) ([]byte, bool, error) {
if isWasm {
content, _, err := loadFileNoCache(fileName)
return content, true, err
}
return maybeLoadCacheFile(fileName)
}
// loadFileNoCache just loads a straight file with out checking the cache first
func loadFileNoCache(fileName string) ([]byte, bool, error) {
pwd, err := os.Getwd()
if err != nil {
return nil, false, err
}
fileLoc := path.Join(pwd, fileName)
data, err := ioutil.ReadFile(fileLoc)
if err != nil {
return nil, false, err
}
return data, false, nil
}
// maybeLoadCacheFile loads the cached file first
func maybeLoadCacheFile(fileName string) ([]byte, bool, error) {
pwd, err := os.Getwd()
if err != nil {
return nil, false, err
}
fileLoc := path.Join(pwd, fileName)
fileInfo, err := os.Stat(fileLoc)
if err != nil {
return nil, false, err
}
cacheName := path.Join(".ab_cache", fmt.Sprintf("%s.abc", fileName))
cacheLoc := path.Join(pwd, cacheName)
cacheInfo, err := os.Stat(cacheLoc)
if !os.IsNotExist(err) && fileInfo.ModTime().After(cacheInfo.ModTime()) {
content, _, err := loadFileNoCache(fileName)
return content, true, err
}
return loadFileNoCache(fileName)
}
// RunWasm runs a Wasm file
func RunWasm(wasmCode []byte, entrypoint string, extensions ...string) (int64, error) {
vm, err := NewVirtualMachine(wasmCode, entrypoint, extensions...)
if err != nil {
return int64(-1), err
}
ret, err := vm.Run()
if err != nil {
vm.PrintStackTrace()
return int64(-1), err
}
return ret, nil
// return int64(-1), fmt.Errorf("not implemented")
}
// RunWat runs a Wat file
func RunWat() (int64, error) {
return int64(-1), fmt.Errorf("not implemented")
}
//RunArbor runs an arbor file
func RunArbor(wasmCode []byte, entrypoint string) (int64, error) {
return int64(-1), fmt.Errorf("not implemented")
}