;;;; Core Scheme Definition -*- mode: scheme -*- ;;; This is the language accepted by the compiler and interpreter. ;;; ;;; Unlike MzScheme's "Primitive Syntax", Minor's core language ;;; doesn't deal with macros or modules; those should all be expanded ;;; away before code is presented for interpretation or compilation. ;;; All the scoping and phase separation junk has nothing to do with ;;; the compiler's job --- generating code for a particular ;;; expression. ;;; ;;; There are some things the compiler does need to know, that module ;;; systems and the like do impinge upon: ;;; ;;; - The extent of global bindings' visibility. If a compiler can ;;; find all the assignments to and uses of a given variable, and ;;; prove that no new assignments or uses will be added in the ;;; future, it can use that knowledge to generate better code. ;;; ;;; - Even if the compiler can't find all uses of a variable, finding ;;; all the assignments to it, and being able to prove that no more ;;; will be added, can still be helpful. ;;; ;;; To convey this information, the module system needs to expand into ;;; core forms that have the given properties. For example, if a ;;; module has unexported bindings for x, y, and z, and exported, ;;; read-only bindings a, b, and c, it might expand into something ;;; like this: ;;; ;;; (begin ;;; (define x #f) ;;; (define y #f) ;;; (define z #f) ;;; (letrec ((a ...) (b ...) (c ...) ;;; (x1 ...) (y1 ...) (z1 ...)) ;;; ... module body here ... ;;; (set! x x1) ;;; (set! y y1) ;;; (set! z z1))) ;;; ;;; Given this core expression, it is easy for the compiler to see ;;; that the bindings for a, b, and c are invisible outside the macro ;;; body, and that while the values of x, y, and z do escape to the ;;; outside world, their values as seen within the module will never ;;; change. ;;; The possible shapes of a core scheme expression are defined by ;;; top-level-form: (define-shapes (top-level-form definition expression ;; We need to include this as a core form to give ;; macro expansions at the top level a way to expand ;; to multiple definitions. ('begin top-level-form ...)) (definition ('define identifier expression)) (expression identifier (expression expression ...) ('if expression expression expression) ('lambda formals form ...1) ('set! identifier expression) ('letrec ((identifier expression) ...) form ...1) ('quote literal)) (formals (identifier ...) (identifier ... . identifier)))