; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.


; Packages involved in building the initial system.


; Access to values from packages and structures 

(define-structure environments environments-interface
  (open scheme-level-2
	packages packages-internal
	copy-packages
	bindings meta-types 
	fluids cells
	locations	; contents location-assigned?
	exceptions)	; error
  (declare no-state no-macro)
  (files (rts env)))

; EVAL and LOAD

(define-structures ((evaluation evaluation-interface)
		    (load-filenames load-filenames-interface))
  (open scheme-level-2
	packages        	;package-uid package->environment link
	(subset packages-internal (package-expander))
	environments		;package-for-load
	compiler-envs		;bind-source-filename
	reading-forms		;read-forms $note-file-package
	syntax-expand		;expand-forms
	compiler		;compile-forms
	dynamic-linker
	closures		;make-closure
	vm-exposure		;invoke-closure
	features		;current-noise-port force-output
	exceptions fluids cells)
  (declare no-state no-syntax)
  (files (rts eval)))

; Scheme = scheme-level-2 plus EVAL and friends

(define-module (make-scheme environments evaluation)

  (define-structure scheme scheme-interface
    (open scheme-level-2
	  environments
	  evaluation)
    (declare no-state))
  scheme)

; Command processor.

(define-module (make-mini-command scheme) ;copied from debug-packages.scm

  (define-structure mini-command (export command-processor)
    (open scheme
	  ascii byte-vectors os-strings
	  writing methods
	  conditions exceptions handle
	  i/o)                 ;current-error-port
    (files (debug mini-command)
	   (env dispcond))) ; avoid having to include this generally
  mini-command)

; For building systems.

(define-module (make-initial-system scheme command)

  (define-structure initial-system (export start)
    (open scheme
	  util
	  evaluation
	  command
	  interfaces		;make-simple-interface
	  packages		;make-simple-package
	  environments		;with-interaction-environment, etc.
	  load-packages
	  usual-resumer)
    (declare no-state no-syntax)
    (files (env start)))

  initial-system)


; Utility to load packages following dependency links (OPEN and ACCESS)
;Cf. (link-initial-system) and Makefile

(define-structure load-packages load-packages-interface
  (open scheme-level-2
	features		;current-noise-port
	packages		;package-uid package-clients
	packages-internal	;package-visited? package-invoked?
	scan-package		;collect-packages check-structure
	compile-packages	;compile-package
	dynamic-linker
	closures		;make-closure
	vm-exposure		;invoke-closure
	environments		;with-interaction-environment
	(subset compiler-envs (comp-env-next-phase))
	)
  (declare no-state no-syntax)
  (files (env load-package)))

; Things needed by the expression generated by REIFY-STRUCTURES.

(define-structure for-reification for-reification-interface
  (open scheme-level-1
	packages packages-internal
	(subset compile-packages (define-usual-transforms)) ; the entire package may be a bit much
	exceptions
	meta-types			;sexp->type structure-type
	interfaces			;make-simple-interface
	bindings
	locations
	nodes				;get-operator operator? operator-type
	primops				;get-primop primop? primop-type
	usual-macros			;usual-transform
	inline				;inline-transform
	transforms			;make-transform/xxx inline-transform? inline-transform-type
	tables)
  (declare no-state no-syntax)
  (files (bcomp for-reify)))
