-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
36 lines (30 loc) · 848 Bytes
/
register.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
// Copyright 2013 Tumblr, Inc.
// Use of this source code is governed by the license for
// The Go Circuit Project, found in the LICENSE file.
//
// Authors:
// 2013 Petar Maymounkov <p@gocircuit.org>
package types
import (
"strconv"
)
var (
ValueTabl *TypeTabl = makeTypeTabl() // Type table for values
FuncTabl *TypeTabl = makeTypeTabl() // Type table for functions
)
// RegisterValue registers the type of x with the type table.
// Types need to be registered before values can be imported.
func RegisterValue(r interface{}) {
ValueTabl.Add(makeType(r))
}
func LookupValue(r interface{}) string {
return ValueTabl.TypeOf(r).Name()
}
// RegisterFunc ...
func RegisterFunc(fn interface{}) {
t := makeType(fn)
if len(t.Func) != 1 {
panic("fn type must have exactly one method: " + strconv.Itoa(len(t.Func)))
}
FuncTabl.Add(t)
}