This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl.go
145 lines (112 loc) · 3.44 KB
/
impl.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (c) 2023-present unTill Pro, Ltd.
* @author Michael Saigachenko
*/
package extensions
import (
"reflect"
"runtime"
"unsafe"
)
func Assert(condition bool, msg string) {
if !condition {
Panic("assertion failed: " + msg)
}
}
func Panic(msg string) {
nh := (*reflect.StringHeader)(unsafe.Pointer(&msg))
hostPanic(uint32(nh.Data), uint32(nh.Len))
}
const maxUint = ^uint64(0)
func queryValueImpl(key TKeyBuilder) (bool, TValue) {
id := hostQueryValue(uint64(key))
if id != maxUint {
return true, TValue(id)
} else {
return false, TValue(0)
}
}
func mustGetValueImpl(key TKeyBuilder) TValue {
return TValue(hostGetValue(uint64(key)))
}
func updateValueImpl(key TKeyBuilder, existingValue TValue) TIntent {
return TIntent(hostUpdateValue(uint64(key), uint64(existingValue)))
}
func newValueImpl(key TKeyBuilder) TIntent {
return TIntent(hostNewValue(uint64(key)))
}
func readValuesImpl(key TKeyBuilder, callback func(key TKey, value TValue)) {
currentReadCallback = callback
hostReadValues(uint64(key))
}
var currentReadCallback func(key TKey, value TValue)
//lint:ignore U1000 this is an exported func
//export WasmOnReadValue
func onReadValue(key, value uint64) {
currentReadCallback(TKey(key), TValue(value))
}
//export hostReadValues
func hostReadValues(keyId uint64)
//export hostGetValue
func hostGetValue(keyId uint64) (result uint64)
/*
returns 0 when not exists
*/
//export hostQueryValue
func hostQueryValue(keyId uint64) (result uint64)
//export hostNewValue
func hostNewValue(keyId uint64) uint64
//export hostUpdateValue
func hostUpdateValue(keyId uint64, existingValueId uint64) uint64
//lint:ignore U1000 this is an exported func
//export WasmAbiVersion_0_0_1
func proxyABIVersion() {
}
var ms runtime.MemStats
//lint:ignore U1000 this is an exported func
//export WasmGetHeapInuse
func getHeapInuse() uint64 {
runtime.ReadMemStats(&ms)
return ms.HeapInuse
}
//lint:ignore U1000 this is an exported func
//export WasmGetMallocs
func getMallocs() uint64 {
runtime.ReadMemStats(&ms)
return ms.Mallocs
}
//lint:ignore U1000 this is an exported func
//export WasmGetFrees
func getFrees() uint64 {
runtime.ReadMemStats(&ms)
return ms.Frees
}
//lint:ignore U1000 this is an exported func
//export WasmGetHeapSys
func getHeapSys() uint64 {
runtime.ReadMemStats(&ms)
return ms.HeapSys
}
//lint:ignore U1000 this is an exported func
//export WasmGC
func gc() {
runtime.GC()
}
//export hostPanic
func hostPanic(msgPtr, msgSize uint32)
//export hostRowWriterPutString
func hostRowWriterPutString(id uint64, typ uint32, namePtr, nameSize, valuePtr, valueSize uint32)
//export hostRowWriterPutBytes
func hostRowWriterPutBytes(id uint64, typ uint32, namePtr, nameSize, valuePtr, valueSize uint32)
//export hostRowWriterPutQName
func hostRowWriterPutQName(id uint64, typ uint32, namePtr, nameSize, pkgPtr, pkgSize, entityPtr, entitySize uint32)
//export hostRowWriterPutIntBool
func hostRowWriterPutBool(id uint64, typ uint32, namePtr, nameSize, value uint32)
//export hostRowWriterPutInt32
func hostRowWriterPutInt32(id uint64, typ uint32, namePtr, nameSize, value uint32)
//export hostRowWriterPutInt64
func hostRowWriterPutInt64(id uint64, typ uint32, namePtr, nameSize uint32, value uint64)
//export hostRowWriterPutFloat32
func hostRowWriterPutFloat32(id uint64, typ uint32, namePtr, nameSize uint32, value float32)
//export hostRowWriterPutFloat64
func hostRowWriterPutFloat64(id uint64, typ uint32, namePtr, nameSize uint32, value float64)