232 lines
7.7 KiB
Plaintext
232 lines
7.7 KiB
Plaintext
expression: up to 256, 3 in, no prefix
|
|
00 sub in in: binary-expr
|
|
|
|
10 (if in1 in2 in3) ; in3 if in1 == #f, in2 otherwise
|
|
|
|
20 (vector-set! in1 in2 in3) ; vector n value, 0 <= n < nelem; ==> in3
|
|
21 (byte-string-set! in1 in2 in3) ; string n value, 0 <= n < nbytes; ==> in3
|
|
22 (struct-set! in1 in2 in3) ; struct n value, 0 <= n < nslots; ==> in3
|
|
|
|
ff (vector-ref-immed in1 msb lsb) ; vector n n; ==> (vector-ref in1 (+ (* msb 256) lsb))
|
|
|
|
binary-expr: up to 256, 2 in, prefix = 00
|
|
00 sub in: unary-expr
|
|
|
|
01 (eq? in1 in2) ; any values; superset of fix=
|
|
02 (cons in1 in2) ; car cdr
|
|
03 (make-vector in1 in2) ; nelem iv, nelem >= 0
|
|
04 (make-byte-string in1 in2) ; nbytes iv, nbytes >= 0
|
|
05 (vector-ref in1 in2) ; vector n, 0 <= n < nelem
|
|
06 (byte-string-ref in1 in2) ; string n, 0 <= n < nbytes
|
|
07 (struct-ref in1 in2) ; struct n, 0 <= n < nslots
|
|
|
|
08 (fix+ in1 in2)
|
|
09 (fix- in1 in2)
|
|
0a (fix* in1 in2)
|
|
0b (fix/ in1 in2)
|
|
0c (fix% in1 in2)
|
|
0d (fix< in1 in2) ; == (fix> in2 in1)
|
|
0e (fix>= in1 in2) ; == (fix<= in2 in1)
|
|
|
|
10 (bit-and in1 in2)
|
|
11 (bit-or in1 in2)
|
|
12 (bit-xor in1 in2)
|
|
|
|
14 (fix<< in1 in2) ; logical/arithmetic left-shift (2*x) w/ overflow into sign
|
|
15 (fix>> in1 in2) ; arithmetic right-shift (x/2)
|
|
16 (fix>>> in1 in2) ; logical right-shift; sign becomes zero (+)
|
|
|
|
18 (float+ in1 in2)
|
|
19 (float- in1 in2)
|
|
1a (float* in1 in2)
|
|
1b (float/ in1 in2)
|
|
1c (float= in1 in2)
|
|
1d (float< in1 in2) ; == (float> in2 in1)
|
|
1e (float>= in1 in2) ; == (float<= in2 in1)
|
|
|
|
20 (atan2 in1 in2) ; float float
|
|
21 (pow in1 in2) ; float float
|
|
22 (ldexp in1 in2) ; float fixnum
|
|
23 (fmod in1 in2) ; float float
|
|
24 (hypot in1 in2) ; float float
|
|
25 (jn in1 in2) ; fixnum float
|
|
26 (yn in1 in2) ; fixnum float
|
|
27 (nextafter in1 in2) ; float float
|
|
28 (remainder in1 in2) ; float float
|
|
29 (scalb in1 in2) ; float float
|
|
|
|
30 (kind-of? in1 in2) ; value struct-type ==> boolean
|
|
31 (byte-string= in1 in2)
|
|
32 (byte-string< in1 in2) ; == (byte-string> in2 in1)
|
|
33 (byte-string>= in1 in2) ; == (byte-string<= in2 in1)
|
|
|
|
50 (set-box! in1 in2) ; box value ==> in2
|
|
51 (set-car! in1 in2) ; pair value ==> in2
|
|
52 (set-cdr! in1 in2) ; pair value ==> in2
|
|
|
|
70 (tail-call-if in1 in2) ; flag byte-string, perform tail call (in2) if in1 != #f
|
|
|
|
ff (fatal-error-if in1 in2) ; signal fatal error (annotated with 'in2') if in1 != #f
|
|
|
|
unary-expr: up to 256, 1 in, prefix = 00 00
|
|
01 (unbox in)
|
|
02 (weak-unbox in)
|
|
03 (car in)
|
|
04 (cdr in)
|
|
|
|
08 (boolean? in) ; value ==> bool
|
|
09 (fixnum? in) ; value ==> bool
|
|
0a (box? in) ; value ==> bool
|
|
0b (pair? in) ; value ==> bool
|
|
0c (vector? in) ; value ==> bool
|
|
0d (byte-string? in) ; value ==> bool
|
|
0e (struct? in) ; value ==> bool
|
|
0f (float? in) ; value ==> bool
|
|
10 (builtin? in) ; value ==> bool
|
|
11 (weak-box? in) ; value ==> bool
|
|
|
|
18 (make-box in) ; value ==> box
|
|
19 (make-struct in) ; metastruct ==> struct
|
|
1a (make-float in) ; fixnum ==> float
|
|
1b (make-lambda in) ; template-or-lambda ==> lambda
|
|
1c (make-weak-box in) ; value ==> weak-box
|
|
|
|
20 (not in) ; if in == #f then #t else #f
|
|
21 (bit-not in) ; one's complement / bitwise negation
|
|
22 (fix- in) ; two's complement / arithmetic negation
|
|
23 (float- in) ; floating-point negation
|
|
|
|
28 (vector-size in)
|
|
29 (byte-string-size in)
|
|
2a (struct-nslots in)
|
|
2b (struct-type in)
|
|
2c (object-id in)
|
|
|
|
; ISO C floating-point
|
|
30 (acos in)
|
|
31 (asin in)
|
|
32 (atan in)
|
|
33 (cos in)
|
|
34 (sin in)
|
|
35 (tan in)
|
|
36 (cosh in)
|
|
37 (sinh in)
|
|
38 (tanh in)
|
|
39 (exp in)
|
|
3a (frexp in) ; float ==> (float . fixnum)
|
|
3b (log in) ; base e
|
|
3c (log10 in)
|
|
3d (modf in) ; float ==> (float . float)
|
|
3e (sqrt in)
|
|
3f (ceil in)
|
|
40 (fabs in)
|
|
41 (floor in)
|
|
|
|
; SVID & X/Open
|
|
50 (erf in)
|
|
51 (erfc in)
|
|
; (gamma in) ; obsolete
|
|
52 (j0 in)
|
|
53 (j1 in)
|
|
54 (lgamma in) ; float ==> (float . fixnum), actually lgamma_r
|
|
55 (y0 in)
|
|
56 (y1 in)
|
|
|
|
; SVID & XPG 4.2/5
|
|
57 (asinh in)
|
|
58 (acosh in)
|
|
59 (atanh in)
|
|
5a (cbrt in)
|
|
5b (logb in)
|
|
|
|
; XPG 4.2/5
|
|
5c (expm1 in)
|
|
5d (ilogb in)
|
|
5e (log1p in)
|
|
; (rint in) ; implies changing rounding mode; use floor or ceil
|
|
|
|
; C99
|
|
70 (normal? in)
|
|
71 (finite? in)
|
|
72 (subnormal? in)
|
|
73 (infinite? in)
|
|
74 (nan? in)
|
|
|
|
in:
|
|
tN 00-7f [transient, 0 <= N < 128, one for each prior expression]
|
|
gN 80-bf [global, 0 <= N < 64]
|
|
iN c0-ef [instance, 0 <= N < 48]
|
|
#f f0 [constant]
|
|
nil f1 [constant]
|
|
undef f2 [constant]
|
|
-- f3-f7 [reserved, 3 <= x < 8]
|
|
self f8 [current lambda]
|
|
globals f9 [current global value vector]
|
|
inst fa [current instance value vector]
|
|
argv fb [argument list]
|
|
kw-args fc [keyword arguments] (sorted)
|
|
kw-vals fd [keyword values] (match kw-args)
|
|
ctx fe [dynamic context]
|
|
k ff [continuation]
|
|
|
|
lambda:[
|
|
global: vector of immutable values (g0..gN); shared between instances (lambdas)
|
|
instance: vector of immutable values (i0..iN); shared between calls
|
|
code: byte-string containing sequence of 4-byte instruction words
|
|
tail-call: byte-string of in-refs: (target argv kw-args kw-vals ctx k)
|
|
]
|
|
|
|
template:[
|
|
global: linked
|
|
instance: byte-string of in-refs. to parent instance/transient slots
|
|
code: linked
|
|
tail-call: linked
|
|
]
|
|
|
|
Protocol:
|
|
|
|
Normal function calls (return to caller, or caller's continuation if tail-call):
|
|
Call: Tail-call function with valid 'k' and original 'ctx'.
|
|
Return: Tail-call 'k' with #f continuation and context (ignored).
|
|
|
|
Coroutines (cooperating, interleaved tail-call chains in CPS):
|
|
Call: Tail-call function with valid 'k' and original 'ctx'.
|
|
Return: Tail-call 'k' with valid 'k' and original 'ctx'.
|
|
|
|
call-with-current-continuation:
|
|
Look up abort handler by prompt tag in incoming 'ctx'.
|
|
call provided lambda with lambda parameter as follows:
|
|
Tail-call abort handler with same parameters and 'k' & 'ctx' from call/cc.
|
|
|
|
call-with-composable-continuation:
|
|
(define (call-with-composable-continuation proc [prompt-tag (current-prompt-tag)])
|
|
(let [(meta-continuation (prompt-tag-meta-continuation prompt-tag))]
|
|
(call-with-current-continuation
|
|
(lambda (k)
|
|
(let [(result (let [(var (lambda values
|
|
(call-with-continuation-prompt
|
|
(lambda () (apply k values))
|
|
prompt-tag)))]
|
|
(proc var)))]
|
|
((meta-continuation) result))))]))
|
|
|
|
call-with-continuation-prompt:
|
|
(define (call-with-continuation-prompt body-thunk
|
|
[prompt-tag (current-prompt-tag)]
|
|
[abort-proc (lambda (fn . args)
|
|
(apply fn args))])
|
|
(let [(meta-continuation (prompt-tag-meta-continuation prompt-tag))
|
|
(abort-handler (prompt-tag-abort-handler prompt-tag))]
|
|
(call-with-current-continuation
|
|
(lambda (k)
|
|
(parameterize [(meta-continuation k)
|
|
(abort-handler abort-proc)]
|
|
(let [(result (body-thunk))]
|
|
((meta-continuation) result))))))]))
|
|
|
|
parameterize:
|
|
Call thunk with 'k' and updated context. (No change to original context.)
|
|
New context includes (parameter ==> value) association.
|
|
|
|
# vim:set sw=2 expandtab tw=0:
|