From baa2dae345fc37679d8a586e0702eab3b9d10c0c Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Sun, 22 Nov 2009 23:13:34 -0600 Subject: [PATCH] Rearrange example programs based on new modularity feature. --- factorial.rla | 110 -------------------------------- cat.rla => src/examples/cat.rla | 0 src/examples/factorial.rla | 38 +++++++++++ src/lib/math/fact.rla | 74 +++++++++++++++++++++ 4 files changed, 112 insertions(+), 110 deletions(-) delete mode 100755 factorial.rla rename cat.rla => src/examples/cat.rla (100%) create mode 100755 src/examples/factorial.rla create mode 100755 src/lib/math/fact.rla diff --git a/factorial.rla b/factorial.rla deleted file mode 100755 index 569538c..0000000 --- a/factorial.rla +++ /dev/null @@ -1,110 +0,0 @@ -#! /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" - ; (let/cc k - ; (lambda (n) - ; (define (fact n) ...) - ; (k (fact n)))) - #( - #0=#S(#="lambda" - ; (define (fact n) - ; ((if (< n 1) - ; (lambda () 1) - ; (lambda () ... n fact ...)))) - #( - 1 - #S(#="lambda" - ; (lambda _ 1) - #((1) #f) - #() - 0 - "" - 0xfe ; k - 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))))))) - #( - 1 - #S(#="template" - ; (let (n) - ; (let/cc k - ; (lambda (m) - ; (k (* n m))))) - #(#f) - "\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)) - 0x41 ; i1 - 0x80 ; f0 - 0x01 ; g1 - 0x01 ; g1 - ) - #=0 ; fact - ) - "\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)) - 0x03 ; g3 - 0x80 ; f0 - 0x81 ; f1 - 0xff ; ctx - ) - ) - #() - 2 - "\x00\x80\x03\xfd\; (set! f0 (car argv)) - \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 - 0xfe ; k - 0xff ; ctx - ) - ) - "\xfe\xff" ; k ctx - 0 - "" - 0x01 ; g1 - 0xfd ; argv - 0x40 ; i0 - 0x41 ; i1 - ) - #="string->number" ; g2 - ) - #() - 1 - "\x00\x80\x1b\x01"; (set! f0 (lambda g1)) - 0x02 ; g2 - 0xfd ; argv - 0x80 ; f0 - 0xff ; ctx -) -; vim:set syntax= sw=2 expandtab: diff --git a/cat.rla b/src/examples/cat.rla similarity index 100% rename from cat.rla rename to src/examples/cat.rla diff --git a/src/examples/factorial.rla b/src/examples/factorial.rla new file mode 100755 index 0000000..c8c5c2a --- /dev/null +++ b/src/examples/factorial.rla @@ -0,0 +1,38 @@ +#! /home/nybble/src/c/rosella/rosella + +; (lambda (number-string) +; (fact (string->number number-string))) + +#S(#="lambda" + ; (lambda (number-string) + ; (let/cc k + ; (call-with-values + ; (lambda () (string->number number-string)) + ; (lambda (n) (k (fact n)))))) + #( + #S(#="template" + ; (let/cc k + ; (lambda (n) + ; (k (fact n)))) + #( + #i"../lib/math/fact.rla" + ) + "\xfe\xff" ; k ctx + 0 + "" + 0x01 ; g1 + 0xfd ; argv + 0x40 ; i0 + 0x41 ; i1 + ) + #="string->number" ; g2 + ) + #() + 1 + "\x00\x80\x1b\x01"; (set! f0 (lambda g1)) + 0x02 ; g2 + 0xfd ; argv + 0x80 ; f0 + 0xff ; ctx +) +; vim:set syntax= sw=2 expandtab: diff --git a/src/lib/math/fact.rla b/src/lib/math/fact.rla new file mode 100755 index 0000000..3103a87 --- /dev/null +++ b/src/lib/math/fact.rla @@ -0,0 +1,74 @@ +;; Computes n!, n <= 12 (limited to fixnum results) +; (define (fact n) +; (if (< n 1) +; 1 +; (* n (fact (- n 1))))) + +#0=#S(#="lambda" + ; (define (fact n) + ; ((if (< n 1) + ; (lambda () 1) + ; (lambda () ... n fact ...)))) + #( + 1 + #S(#="lambda" + ; (lambda _ 1) + #((1) #f) + #() + 0 + "" + 0xfe ; k + 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))))))) + #( + 1 + #S(#="template" + ; (let (n) + ; (let/cc k + ; (lambda (m) + ; (k (* n m))))) + #(#f) + "\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)) + 0x41 ; i1 + 0x80 ; f0 + 0x01 ; g1 + 0x01 ; g1 + ) + #=0 ; fact + ) + "\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)) + 0x03 ; g3 + 0x80 ; f0 + 0x81 ; f1 + 0xff ; ctx + ) + ) + #() + 2 + "\x00\x80\x03\xfd\; (set! f0 (car argv)) + \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 + 0xfe ; k + 0xff ; ctx +) +; vim:set syntax= sw=2 expandtab: