-
Notifications
You must be signed in to change notification settings - Fork 10
/
gofunction.go
49 lines (42 loc) · 1.4 KB
/
gofunction.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
package runtime
type GoFunctionFunc func(*Thread, *GoCont) (Cont, error)
// A GoFunction is a callable value implemented by a native Go function.
type GoFunction struct {
f GoFunctionFunc
safetyFlags ComplianceFlags
name string
nArgs int
hasEtc bool
}
var _ Callable = (*GoFunction)(nil)
// NewGoFunction returns a new GoFunction.
func NewGoFunction(f GoFunctionFunc, name string, nArgs int, hasEtc bool) *GoFunction {
return &GoFunction{
f: f,
name: name,
nArgs: nArgs,
hasEtc: hasEtc,
}
}
// Continuation implements Callable.Continuation.
func (f *GoFunction) Continuation(t *Thread, next Cont) Cont {
return NewGoCont(t, f, next)
}
// SolemnlyDeclareCompliance adds compliance flags to f. See quotas.md for
// details about compliance flags.
func (f *GoFunction) SolemnlyDeclareCompliance(flags ComplianceFlags) {
if flags >= complyflagsLimit {
// User is trying to register a safety flag that is not (yet) defined.
// This is a sign this function is not called solemnly enough!
panic("Invalid safety flags")
}
f.safetyFlags |= flags
}
// SolemnlyDeclareCompliance is a convenience function that adds the same set of
// compliance flags to a number of functions. See quotas.md for details about
// compliance flags.
func SolemnlyDeclareCompliance(flags ComplianceFlags, fs ...*GoFunction) {
for _, f := range fs {
f.SolemnlyDeclareCompliance(flags)
}
}