creme

所属分类:驱动编程
开发工具:OCaml
文件大小:0KB
下载次数:0
上传日期:2013-02-21 07:50:51
上 传 者sh-1993
说明:  内核编程语言的一个子集。,
(A small subset of the Kernel programming language.,)

文件列表:
Makefile (175, 2013-02-20)
OCamlMakefile (35397, 2013-02-20)
boot/ (0, 2013-02-20)
boot/base.crm (10461, 2013-02-20)
src/ (0, 2013-02-20)
src/creme.ml (3514, 2013-02-20)
src/eval.ml (10235, 2013-02-20)
src/gencar.ml (870, 2013-02-20)
src/lexer.mll (3674, 2013-02-20)
src/main.ml (1340, 2013-02-20)
src/reader.ml (3943, 2013-02-20)
tests/ (0, 2013-02-20)
tests/ackermann.crm (828, 2013-02-20)
tests/cpstak.crm (638, 2013-02-20)
tests/fact.crm (372, 2013-02-20)
tests/fib-tail.crm (256, 2013-02-20)
tests/fib.crm (324, 2013-02-20)
tests/gcd.crm (337, 2013-02-20)
tests/tak.crm (197, 2013-02-20)

# Creme Creme is an implementation of a subset of the Kernel programming language in OCaml. ## Requirements * OCaml 4.00+ ## Examples You can, of course, use Creme in a manner similar to you would with Scheme: ``` ($define! map ($lambda (f ls) ($if (null? ls) ls (cons (f (car ls)) (map f (cdr ls)))))) ``` Which defines an applicative combiner `map`. An applicative combiner will have its arguments evaluated before being passed to it. The power of Kernel, however, comes from the `$vau` operative. An operative does not get its arguments evaluated. Instead, we combine `$vau` with the `eval` operative, which allows explicity evaluation of forms. This allows us to define syntax like `$cond` or `$let`: ``` ($define! $cond ($vau clauses env ($define! aux ($lambda ((test . body) . clauses) ($if (eval test env) (apply (wrap $sequence) body env) (apply (wrap $cond) clauses env)))) ($if (null? clauses) #inert (apply aux clauses)))) ``` This means that unlike in Scheme, where macros aren't first-class, we get something similar to macros as first-class citizens. Neat. ## Optimizations While most of Kernel's features can be bootstrapped from a few primitives, it can lead to performance issues. The biggest performance gain was gotten by rewriting the `$sequence` operative in OCaml. Further performance gains were gotten by doing the same for `$vau` and `$lambda`. ``` % time ./creme-no-opt tests/tak.crm > /dev/null ./creme-no-opt tests/tak.crm > /dev/null 19.39s user 0.02s system 99% cpu 19.418 total % time ./creme-opt-seq tests/tak.crm > /dev/null ./creme-opt-seq tests/tak.crm > /dev/null 5.13s user 0.01s system 99% cpu 5.142 total % time ./creme-opt-seq-vau tests/tak.crm > /dev/null ./creme-opt-seq-vau tests/tak.crm > /dev/null 4.18s user 0.01s system 99% cpu 4.190 total % time ./creme-opt-seq-vau-lambda tests/tak.crm > /dev/null ./creme-opt-seq-vau-lambda tests/tak.crm > /dev/null 2.39s user 0.01s system 99% cpu 2.394 total ``` ## Todo * Add #o, #b, #x, #e, #i numerical prefixes * Add rational numbers to numerical tower * Improve environment support * Add to test cases

近期下载者

相关文件


收藏者