From 8e40505015831f7d820f7ac79d7a5cbb2de391c1 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 24 Feb 2015 12:54:05 -0500 Subject: [PATCH] Added cmd line option to autogen blocks of code --- cgen.scm | 27 ++++++++++++++++----------- cyclone.scm | 2 ++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cgen.scm b/cgen.scm index b93993db..2cf38d76 100644 --- a/cgen.scm +++ b/cgen.scm @@ -1048,10 +1048,11 @@ (emit "}") (emit *c-main-function*))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Automatically generate blocks of code for the compiler -;; TODO: need a compiler option to call this from cmd line -(define (autogen) - (let ((fp (open-output-file "tmp.txt"))) +(define (autogen filename) + (let ((fp (open-output-file filename))) (autogen:defprimitives fp) (autogen:primitive-procedures fp) (close-output-port fp))) @@ -1071,13 +1072,17 @@ ;; List of primitive procedures (define (autogen:primitive-procedures fp) - (pp ;; CHICKEN pretty-print - (cons - 'list - (map - (lambda (p) - `(list (quote ,p) ,p)) - *primitives*)) - fp)) + (let ((code + (cons + 'list + (map + (lambda (p) + `(list (quote ,p) ,p)) + *primitives*)))) + (cond-expand + (chicken + (pp code fp)) ;; CHICKEN pretty-print + (else + (write code fp))))) diff --git a/cyclone.scm b/cyclone.scm index cc7f007c..bb25d058 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -158,6 +158,8 @@ (newline)) ((member "-v" args) (display *version-banner*)) + ((member "--autogen" args) + (autogen "autogen.out")) ((member "-d" args) (run-compiler args #f)) ;; Debug, do not run GCC (else