-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsafe.go
155 lines (133 loc) · 2.94 KB
/
unsafe.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
146
147
148
149
150
151
152
153
154
155
/*
* Droscheme - a Scheme implementation
* Copyright © 2012 Andrew Robbins, Daniel Connelly
*
* This program is free software: it is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. You can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License (LGPLv3): <http://www.gnu.org/licenses/>.
*/
package droscheme
import (
"os"
//"fmt"
"reflect"
"runtime"
"runtime/debug"
//"unsafe"
)
func exit(s Any) {
var status int = 0
if IsInteger(s) {
status = int(ToFixnum(s))
}
os.Exit(status)
}
func TypeEqual(x, y Any) bool {
return x.GetType() == y.GetType()
}
func PointerEqual(x, y Any) bool {
if !TypeEqual(x, y) {
return false
}
//switch x.(type) {
//}
xp := reflect.ValueOf(x).Pointer()
yp := reflect.ValueOf(y).Pointer()
return xp == yp
}
type Cont uintptr
//func GetCC(dummy *byte) Cont
//func SetCC(dummy *byte, cont Cont)
//func GetCC() *Cont {
// var dummy byte
// return getCC(&dummy)
//}
//
//func SetCC(cc *Cont) {
// var dummy byte
// setCC(&dummy, cc)
//}
//func dumpstack(*byte, int32)
//func getstack(*byte, int32) []byte
//func getcontext(*byte) *byte
//func setcontext(*byte, *byte)
//func setcall(g uintptr)
func Dump() {
//var dummy byte
//dumpstack(&dummy, 100)
debug.PrintStack()
}
//func DumpInternals()
func GetFE(pc uintptr) uintptr {
return runtime.FuncForPC(pc).Entry()
}
func GetFL(pc uintptr) (file string, line int) {
return runtime.FuncForPC(pc).FileLine(pc)
}
func GetFN(pc uintptr) string {
return runtime.FuncForPC(pc).Name()
}
func GetPC(fn interface{}) uintptr {
return reflect.ValueOf(fn).Pointer()
}
/*
func OnceCC(cc chan Any, uc chan Any, proc Any) {
fmt.Printf("--- enter OnceCC()\n", uc)
var a Any
select {
case a = <- cc:
fmt.Printf("Got(%v)\n", a)
//if proc != nil {
// r := Dapply(list2(proc, a))
// fmt.Printf("Gives(%v)\n", r)
//}
}
//var pc uintptr = uintptr(unsafe.Pointer(uc))
//fmt.Printf("UseCC()UC=%p\n", uc)
//fmt.Printf("UseCC()PC=0x%X\n", pc)
//pc = GetPC(UseCC)
//fmt.Printf("UseCC()PC=0x%X\n", pc)
//fmt.Printf("UseCC()FN=%s\n", GetFN(pc))
if uc != nil {
SetCC(uc, a)
}
//var dummy byte
//setcontext(&dummy, uc)
fmt.Printf("--- leave OnceCC()\n")
//os.Exit(0)
}
func EverCC(cc chan Any, uc chan Any, proc Any) {
for {
OnceCC(cc, uc, proc)
}
}
func CallCC(proc Any) chan Any {
fmt.Printf("--- enter GetCC()\n")
cc := make(chan Any, 1)
uc := make(chan Any, 1)
if proc != nil {
uc := GetCC(nil)
go UseCC(cc, uc, proc)
return cc
}
defer UseCC(uc, nil, nil)
fmt.Printf("--- leave GetCC()\n")
return cc
}
func ByeCC() {
fmt.Printf("--- enter ByeCC()\n")
cc := make(chan Any, 1)
select {
case _ = <- cc:
panic("unreachable")
}
fmt.Printf("--- leave ByeCC()\n")
}
func SetCC(cc chan Any, a Any) {
fmt.Printf("--- enter SetCC()\n")
cc <- a
ByeCC()
fmt.Printf("--- leave SetCC()\n")
}
*/