boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

07-tailcall.scm (1377B)


      1 ;; Step-7 tail-call smoke test. Exercises every tail-position rewrite
      2 ;; in eval/apply:
      3 ;;   eval_pair  → apply            application
      4 ;;   apply      → eval body        closure body
      5 ;;   eval_if    → eval then/else   if-branch tail
      6 ;;   eval_begin → eval last        begin last-form tail
      7 ;;   eval_sym   → lookup           symbol resolution
      8 ;;   eval_lambda → make_closure    lambda evaluation
      9 ;;   eval_quote → car              quote evaluation
     10 ;;   eval_args  → cons             non-empty arg list
     11 ;;
     12 ;; Four closures are chained by mutual tail-call (a→b→c→d); d's body
     13 ;; combines if + begin + quote + symbol lookup to reach the remaining
     14 ;; tail positions in a single go.
     15 ;;
     16 ;; The LISP.md §"Staged implementation plan" step 7 stress of 10^6
     17 ;; self-calls with flat P1 stack needs an arithmetic primitive to
     18 ;; decrement a bounded counter (or a step counter in the interpreter).
     19 ;; Both are out of scope for step 7: primitives land at step 10, and
     20 ;; the interpreter stays free of per-eval instrumentation. This test
     21 ;; therefore covers correctness, not raw depth — the flat-stack claim
     22 ;; falls out from the TAIL_Nk op semantics proven in demo.M1.
     23 
     24 (define a (lambda (x) (b x)))
     25 (define b (lambda (x) (c x)))
     26 (define c (lambda (x) (d x)))
     27 (define d (lambda (x)
     28             (if x
     29               (begin (quote ignored) x)
     30               0)))
     31 
     32 (a 42)