Re-write factorial.rla to be closer to what a compiler should generate.
This commit is contained in:
parent
5e36910eab
commit
601aa9db67
|
|
@ -1,54 +1,87 @@
|
|||
#! /home/nybble/src/c/rosella/rosella
|
||||
|
||||
; (lambda (number-string)
|
||||
; (define (fact n)
|
||||
; (if (< n 1)
|
||||
; 1
|
||||
; (* n (fact (- n 1)))))
|
||||
; (fact (string->number number-string)))
|
||||
|
||||
#S(#="lambda"
|
||||
; (lambda (number-string)
|
||||
; (define (fact n) ...)
|
||||
; (let/cc k
|
||||
; (call-with-values
|
||||
; (lambda () (string->number number-string))
|
||||
; (lambda (n) (k (fact n))))))
|
||||
#(
|
||||
#S(#="template" ; g1
|
||||
#S(#="template"
|
||||
; (let/cc k
|
||||
; (lambda (n)
|
||||
; (define (fact n) ...)
|
||||
; (k (fact n))))
|
||||
#(
|
||||
#0=#S(#="lambda" ; g1
|
||||
#0=#S(#="lambda"
|
||||
; (define (fact n)
|
||||
; ((if (< n 1)
|
||||
; (lambda () 1)
|
||||
; (lambda () ... n fact ...))))
|
||||
#(
|
||||
#S(#="lambda" ; g1
|
||||
#(1 #f) ; g1 g2
|
||||
#1=#()
|
||||
1 ; f0
|
||||
"\x02\x80\x01\x00"; (set! f0 (cons g1 nil))
|
||||
1
|
||||
#S(#="lambda"
|
||||
; (lambda _ 1)
|
||||
#((1) #f)
|
||||
#()
|
||||
0
|
||||
""
|
||||
0xfe ; k
|
||||
0x80 ; f0
|
||||
0x02 ; g2 (#f)
|
||||
0xff ; ctx
|
||||
0x01 ; g1
|
||||
0x02 ; g2
|
||||
0x02 ; g2
|
||||
)
|
||||
#S(#="template"
|
||||
; (let [n]
|
||||
; (lambda _
|
||||
; (let/cc k
|
||||
; (call-with-values
|
||||
; (lambda () (fact (- n 1)))
|
||||
; (lambda (m) (k (* n m)))))))
|
||||
#(
|
||||
#=0 ; g1
|
||||
#S(#="template" ; g2
|
||||
1
|
||||
#S(#="template"
|
||||
; (let (n)
|
||||
; (let/cc k
|
||||
; (lambda (m)
|
||||
; (k (* n m)))))
|
||||
#(#f)
|
||||
"\x40\xff\xfe" ; i0 ctx k
|
||||
"\x40\xfe" ; i0 k
|
||||
1
|
||||
"\x00\x80\x03\xfd\; (set! f0 (car argv))
|
||||
\x0a\x80\x40\x80\; (set! f0 (fix* i0 f0))
|
||||
\x02\x80\x80\x00"; (set! f0 (cons f0 nil))
|
||||
0x42 ; i2
|
||||
0x41 ; i1
|
||||
0x80 ; f0
|
||||
0x01 ; g1
|
||||
0x41 ; i1
|
||||
0x01 ; g1
|
||||
)
|
||||
1 ; g3
|
||||
#=0 ; fact
|
||||
)
|
||||
"\x80" ; f0
|
||||
2 ; f0-f1
|
||||
"\x09\x80\x40\x03\; (set! f0 (fix- i0 g3))
|
||||
"\x80"
|
||||
2
|
||||
"\x09\x80\x40\x01\; (set! f0 (fix- i0 g1))
|
||||
\x02\x80\x80\x00\; (set! f0 (cons f0 nil))
|
||||
\x00\x81\x1b\x02"; (set! f1 (lambda g2))
|
||||
0x01 ; g1
|
||||
0x03 ; g3
|
||||
0x80 ; f0
|
||||
0x81 ; f1
|
||||
0xff ; ctx
|
||||
)
|
||||
1 ; g3
|
||||
)
|
||||
#=1 ; #()
|
||||
#()
|
||||
2
|
||||
"\x00\x80\x03\xfd\; (set! f0 (car argv))
|
||||
\x0d\x81\x80\x03\; (set! f1 (fix< f0 g3))
|
||||
\x81\x81\x01\x02\; (set! f1 (if f1 g1 g2))
|
||||
\x0d\x81\x80\x01\; (set! f1 (fix< f0 g1))
|
||||
\x81\x81\x02\x03\; (set! f1 (if f1 g2 g3))
|
||||
\x00\x81\x1b\x81"; (set! f1 (lambda f1))
|
||||
0x81 ; f1
|
||||
0x00 ; nil
|
||||
|
|
@ -59,15 +92,15 @@
|
|||
"\xfe\xff" ; k ctx
|
||||
0
|
||||
""
|
||||
0x01 ; f1
|
||||
0x01 ; g1
|
||||
0xfd ; argv
|
||||
0x40 ; i0
|
||||
0x41 ; i1
|
||||
)
|
||||
#="string->number" ; g2
|
||||
)
|
||||
#=1 ; #()
|
||||
1 ; f0
|
||||
#()
|
||||
1
|
||||
"\x00\x80\x1b\x01"; (set! f0 (lambda g1))
|
||||
0x02 ; g2
|
||||
0xfd ; argv
|
||||
|
|
|
|||
2
interp.c
2
interp.c
|
|
@ -90,6 +90,8 @@ value_t run_interpreter(value_t lambda, value_t argv)
|
|||
#if 0
|
||||
fprint_value(stderr, state.lambda.value); fputc('\n', stderr);
|
||||
fprint_value(stderr, state.argv.value); fputc('\n', stderr);
|
||||
fprint_value(stderr, state.k.value); fputc('\n', stderr);
|
||||
fprint_value(stderr, state.ctx.value); fputc('\n', stderr);
|
||||
fputc('\n', stderr);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue