⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 batch-driver.scm

📁 Scheme跨平台编译器
💻 SCM
📖 第 1 页 / 共 2 页
字号:
;;;; batch-driver.scm - Driver procedure for the compiler;; Copyright (c) 2000-2007, Felix L. Winkelmann; Copyright (c) 2008, The Chicken Team; All rights reserved.;; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following; conditions are met:;;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following;     disclaimer. ;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following;     disclaimer in the documentation and/or other materials provided with the distribution. ;   Neither the name of the author nor the names of its contributors may be used to endorse or promote;     products derived from this software without specific prior written permission. ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE; POSSIBILITY OF SUCH DAMAGE.(declare  (unit driver)  (disable-warning var))(private compiler  compiler-arguments process-command-line dump-nodes dump-undefined-globals  default-standard-bindings default-extended-bindings side-effecting-standard-bindings  non-foldable-standard-bindings foldable-standard-bindings non-foldable-extended-bindings foldable-extended-bindings  standard-bindings-that-never-return-false side-effect-free-standard-bindings-that-never-return-false  compiler-cleanup-hook check-global-exports disabled-warnings check-global-imports  file-io-only undefine-shadowed-macros profiled-procedures  unit-name insert-timer-checks used-units inline-max-size  debugging perform-lambda-lifting! disable-stack-overflow-checking  foreign-declarations emit-trace-info block-compilation line-number-database-size  target-heap-size target-stack-size target-heap-growth target-heap-shrinkage  default-default-target-heap-size default-default-target-stack-size verbose-mode original-program-size  target-initial-heap-size postponed-initforms  current-program-size line-number-database-2 foreign-lambda-stubs immutable-constants foreign-variables  rest-parameters-promoted-to-vector inline-table inline-table-used constant-table constants-used mutable-constants  broken-constant-nodes inline-substitutions-enabled compiler-macros-enabled  emit-profile profile-lambda-list profile-lambda-index profile-info-vector-name  direct-call-ids foreign-type-table first-analysis emit-closure-info  initialize-compiler canonicalize-expression expand-foreign-lambda update-line-number-database scan-toplevel-assignments  perform-cps-conversion analyze-expression simplifications perform-high-level-optimizations perform-pre-optimization!  reorganize-recursive-bindings substitution-table simplify-named-call emit-unsafe-marker  perform-closure-conversion prepare-for-code-generation compiler-source-file create-foreign-stub expand-foreign-lambda*  transform-direct-lambdas! source-filename  debugging-chicken bomb check-signature posq stringify symbolify build-lambda-list  string->c-identifier c-ify-string words check-and-open-input-file close-checked-input-file fold-inner constant?  collapsable-literal? immediate? canonicalize-begin-body extract-mutable-constants string->expr get get-all  put! collect! count! get-line get-line-2 find-lambda-container display-analysis-database varnode qnode   build-node-graph build-expression-tree fold-boolean inline-lambda-bindings match-node expression-has-side-effects?  simple-lambda-node? compute-database-statistics print-program-statistics output gen gen-list external-protos-first  pprint-expressions-to-file foreign-type-check estimate-foreign-result-size scan-used-variables scan-free-variables  topological-sort print-version print-usage initialize-analysis-database dump-exported-globals  default-declarations units-used-by-default words-per-flonum default-debugging-declarations  default-profiling-declarations default-optimization-passes  inline-max-size file-requirements use-import-table lookup-exports-file  foreign-string-result-reserve parameter-limit eq-inline-operator optimizable-rest-argument-operators  membership-test-operators membership-unfold-limit valid-compiler-options valid-compiler-options-with-argument  chop-separator chop-extension display-real-name-table display-line-number-database explicit-use-flag  generate-code make-variable-list make-argument-list generate-foreign-stubs foreign-type-declaration  export-list do-lambda-lifting compiler-warning export-file-name  foreign-argument-conversion foreign-result-conversion)(include "tweaks")(define-constant default-profile-name "PROFILE")(define-constant default-inline-max-size 10)(define-constant funny-message-timeout 60000);;; Compile a complete source file:(define (compile-source-file filename . options)  (define (option-arg p)    (if (null? (cdr p))	(quit "missing argument to `-~A' option" (car p))	(let ([arg (cadr p)])	  (if (symbol? arg)	      (quit "invalid argument to `~A' option" arg)	      arg) ) ) )  (initialize-compiler)  (set! explicit-use-flag (memq 'explicit-use options))  (let ([initforms `((##core#declare		      ,@(map (lambda (x) `(quote ,x))			     (append 			      default-declarations			      (if explicit-use-flag				  '()				  `((uses ,@units-used-by-default)) ) ) ) ) ) ]        [verbose (memq 'verbose options)]	[outfile (cond [(memq 'output-file options) 			=> (lambda (node)			     (let ([oname (option-arg node)])			       (if (symbol? oname)				   (symbol->string oname)				   oname) ) ) ]		       [(memq 'to-stdout options) #f]		       [else (make-pathname #f (if filename (pathname-file filename) "out") "c")] ) ]	[ipath (map chop-separator (string-split (or (getenv "CHICKEN_INCLUDE_PATH") "") ";"))]	[opasses default-optimization-passes]	[time0 #f]	[time-breakdown #f]	[forms '()]	[cleanup-forms '(((##sys#implicit-exit-handler)))]	[profile (or (memq 'profile options) (memq 'accumulate-profile options) (memq 'profile-name options))]	[profile-name (or (and-let* ((pn (memq 'profile-name options))) (cadr pn)) default-profile-name)]	[hsize (memq 'heap-size options)]	[hisize (memq 'heap-initial-size options)]	[hgrowth (memq 'heap-growth options)]	[hshrink (memq 'heap-shrinkage options)]	[kwstyle (memq 'keyword-style options)]	[uses-units '()]	[uunit (memq 'unit options)]	[a-only (memq 'analyze-only options)]	[dynamic (memq 'dynamic options)]	[dumpnodes #f]	[quiet (memq 'quiet options)]	[start-time #f]	(upap #f)	[ssize (or (memq 'nursery options) (memq 'stack-size options))] )    (define (cputime) (##sys#fudge 6))    (define (print-header mode dbgmode)      (when verbose (printf "pass: ~a~%~!" mode))      (and (memq dbgmode debugging-chicken)	   (begin	     (printf "[~a]~%" mode)	     #t) ) )    (define (print-node mode dbgmode n)      (when (print-header mode dbgmode)	(if dumpnodes	    (dump-nodes n)	    (pretty-print (build-expression-tree n)) ) ) )    (define (print-db mode dbgmode db pass)      (when (print-header mode dbgmode)	(printf "(iteration ~s)~%" pass)	(display-analysis-database db) ) )    (define (print-expr mode dbgmode xs)      (when (print-header mode dbgmode)	(for-each pretty-print xs) ) )    (define (infohook class data val)      (let ([data2 ((or ##sys#default-read-info-hook (lambda (a b c) b)) class data val)])	(when (and (eq? 'list-info class) (symbol? (car data2)))	  (##sys#hash-table-set!	   ##sys#line-number-database	   (car data2)	   (alist-cons data2 val		       (or (##sys#hash-table-ref ##sys#line-number-database (car data2))			   '() ) ) ) )	data2) )    (define (arg-val str)      (let* ((len (string-length str))	     (len1 (- len 1)) )	(or (if (< len 2)		(string->number str)		(case (string-ref str len1)		  ((#\m #\M) (* (string->number (substring str 0 len1)) (* 1024 1024)))		  ((#\k #\K) (* (string->number (substring str 0 len1)) 1024))		  (else (string->number str)) ) )	    (quit "invalid numeric argument ~S" str) ) ) )    (define (collect-options opt)      (let loop ([opts options])	(cond [(memq opt opts) => (lambda (p) (cons (option-arg p) (loop (cddr p))))]	      [else '()] ) ) )    (define (begin-time)      (when time-breakdown (set! time0 (cputime))) )    (define (end-time pass)      (when time-breakdown	(printf "milliseconds needed for ~a: \t~s~%" pass (- (cputime) time0)) ) )    (define (read-form in)      (##sys#read in infohook) )    (define (analyze pass node . args)      (let-optionals args ((no 0) (contf #t))        (let ((db (analyze-expression node)))	  (when upap	    (upap pass db node		  (cut get db <> <>)		  (cut put! db <> <> <>)		  no contf) )	  db) ) )    (when uunit      (set! unit-name (string->c-identifier (stringify (option-arg uunit)))) )    (set! debugging-chicken       (append-map       (lambda (do)	 (map (lambda (c) (string->symbol (string c)))	      (string->list do) ) )       (collect-options 'debug) ) )    (set! dumpnodes (memq '|D| debugging-chicken))    (when (memq 'lambda-lift options) (set! do-lambda-lifting #t))    (when (memq 'disable-compiler-macros options) (set! compiler-macros-enabled #f))    (when (memq 't debugging-chicken) (##sys#start-timer))    (when (memq 'b debugging-chicken) (set! time-breakdown #t))    (and-let* ((xfile (memq 'emit-exports options)))      (set! export-file-name (cadr xfile)) )    (when (memq 'raw options)      (set! explicit-use-flag #t)      (set! cleanup-forms '())      (set! initforms '()) )    (when (memq 'no-lambda-info options)      (set! emit-closure-info #f) )    (set! use-import-table (memq 'check-imports options))    (let ((imps (collect-options 'import)))      (when (pair? imps)	(set! use-import-table #t)	(for-each lookup-exports-file imps) ) )    (set! disabled-warnings (map string->symbol (collect-options 'disable-warning)))    (when (memq 'no-warnings options)       (when verbose (printf "Warnings are disabled~%~!"))      (set! ##sys#warnings-enabled #f) )    (when (memq 'optimize-leaf-routines options) (set! optimize-leaf-routines #t))    (when (memq 'unsafe options)       (set! unsafe #t)      (##match#set-error-control #:fail) )    (when (and dynamic (memq 'unsafe-libraries options))      (set! emit-unsafe-marker #t) )    (when (memq 'disable-interrupts options) (set! insert-timer-checks #f))    (when (memq 'fixnum-arithmetic options) (set! number-type 'fixnum))    (when (memq 'block options) (set! block-compilation #t))    (when (memq 'emit-external-prototypes-first options) (set! external-protos-first #t))    (when (memq 'inline options) (set! inline-max-size default-inline-max-size))    (and-let* ([inlimit (memq 'inline-limit options)])      (set! inline-max-size 	(let ([arg (option-arg inlimit)])	  (or (string->number arg)	      (quit "invalid argument to `-inline-limit' option: `~A'" arg) ) ) ) )    (when (memq 'case-insensitive options)       (when verbose (printf "Identifiers and symbols are case insensitive~%~!"))      (register-feature! 'case-insensitive)      (case-sensitive #f) )    (when (memq 'compress-literals options)      (compiler-warning 'usage "`the -compress-literals' option is obsolete") )    (when kwstyle      (let ([val (option-arg kwstyle)])	(cond [(string=? "prefix" val) (keyword-style #:prefix)]	      [(string=? "none" val) (keyword-style #:none)]	      [(string=? "suffix" val) (keyword-style #:suffix)]	      [else (quit "invalid argument to `-keyword-style' option")] ) ) )    (set! verbose-mode verbose)    (set! ##sys#read-error-with-line-number #t)    (set! ##sys#include-pathnames      (append (map chop-separator (collect-options 'include-path))	      ##sys#include-pathnames	      ipath) )    (when (and outfile filename (string=? outfile filename))      (quit "source- and output-filename are the same") )    (set! uses-units      (map string->symbol 	   (append-map	    (cut string-split <> ",")	    (collect-options 'uses))))    (when (memq 'keep-shadowed-macros options)      (set! undefine-shadowed-macros #f) )    ;; Handle feature options:    (for-each      register-feature!     (append-map (cut string-split <> ",") (collect-options 'feature)))    ;; Load extensions:    (set! ##sys#features (cons #:compiler-extension ##sys#features))    (let ([extends (collect-options 'extend)])      (when verbose	(printf "Loading compiler extensions...~%~!")	(load-verbose #t) )      (for-each (lambda (f) (load (##sys#resolve-include-filename f #f #t))) extends) )    (set! ##sys#features (delete #:compiler-extension ##sys#features eq?))    (set! ##sys#features (cons '#:compiling ##sys#features))    (set! ##sys#features (cons #:match ##sys#features))    (##sys#provide 'match)     (set! upap (user-post-analysis-pass))    ;; Insert postponed initforms:    (set! initforms (append initforms postponed-initforms))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -