forked from feeley/univ-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.scm
192 lines (145 loc) · 4.53 KB
/
app.scm
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
;;; File: app.scm
;;;----------------------------------------------------------------------------
(declare (standard-bindings) (extended-bindings) (not safe))
#|
(##inline-host-declaration #<<host-code-end
function js_setTimeout(thunk, timeout) { setTimeout(thunk, timeout); }
function js_alert(text) { alert(text); }
function js_load_js(url) {
var scr = document.createElement('script');
scr.setAttribute('type', 'text/javascript');
scr.setAttribute('src', url);
document.getElementsByTagName('head').item(0).appendChild(scr);
}
function XHR_send(callback, retry, url, data) {
var req = false;
function new_req() {
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
req = new XMLHttpRequest();
if (req.overrideMimeType) {
req.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
req = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
req = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {}
}
}
}
function init_req() {
req.onreadystatechange = response_handler;
req.open('POST', url, true);
req.setRequestHeader('Content-type', 'text/plain');
req.setRequestHeader('enctype', 'text/plain');
}
function send_req() {
req.send(data);
}
function response_handler() {
if (req.readyState === 4) {
if (req.status === 200) {
callback(req.responseText);
} else if (retry) {
add('retry','|r='+r+'|');
setTimeout(send_req, 5000);
} else {
callback(null);
}
}
}
new_req();
if (req !== false) {
init_req();
send_req();
}
return req;
}
function port_open(cont, specs) {
XHR_send(cont,
true,
'/port_open',
specs);
}
function port_read(cont, port_id, len) {
XHR_send(cont,
true,
'/port_read?port_id=' + port_id + '&' + 'len=' + len,
null);
}
function port_write(cont, port_id, data) {
XHR_send(cont,
true,
'/port_write?port_id=' + port_id,
data);
}
function port_close(cont, port_id) {
XHR_send(cont,
true,
'/port_close?port_id=' + port_id,
null);
}
function get(id) {
return document.getElementById(id).innerHTML;
}
function set(id, content) {
document.getElementById(id).innerHTML = content;
}
function add(id, content) {
set(id, get(id) + content);
}
function setup() {
function cont2(port_id) {
function cont3(str) {
function cont4(r) {
add('output','|cont4 r='+r+'|');
cont2(port_id);
}
function cont5(r) {
add('output','|cont5 r='+r+'|');
//setup();
}
add('output','|cont3 str='+str+'|');
if (str === '')
port_close(cont5, port_id);
else
cont2(port_id);//port_write(cont4, port_id, str);
}
add('output','|cont2 port_id='+port_id+'|');
port_read(cont3, port_id, 500);
}
add('output','|port_open|');
port_open(cont2,
// '(open-file path: "README" direction: input)'
// '(open-process path: "ls" arguments: ("../../..") direction: input)'
// '(open-directory path: "../../..")'
'(open-tcp-server port-number: 12345)'
);
}
function js_go() {
setTimeout(setup,1000);
}
host-code-end
)
(define setTimeout (##inline-host-expression "gambit_js2scm(js_setTimeout)"))
(define alert (##inline-host-expression "gambit_js2scm(js_alert)"))
(define load-js (##inline-host-expression "gambit_js2scm(js_load_js)"))
(define go (##inline-host-expression "gambit_js2scm(js_go)"))
(go)
|#
(declare (safe))
(println (thread-name (make-thread (lambda () (current-thread)))))
(println (thread-name (make-thread (lambda () (current-thread)) 'allo)))
(println (mutex-name (make-mutex)))
(println (mutex-name (make-mutex 'allo)))
(println (condition-variable-name (make-condition-variable)))
(println (condition-variable-name (make-condition-variable 'allo)))
(##trap
(lambda ()
(eval '(println (quote a)))))
(##trap
(lambda ()
; (println (foo 1 2 3))
(println (eval '(bar 1 2 3)))))