summaryrefslogtreecommitdiff
path: root/src/gscc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gscc')
-rwxr-xr-xsrc/gscc57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/gscc b/src/gscc
index c5ddbd3..87449ee 100755
--- a/src/gscc
+++ b/src/gscc
@@ -4,8 +4,9 @@
(use-modules (ice-9 getopt-long)
- (modules lexer lexer)
- (modules parser parser))
+ (modules lexer lexer)
+ (modules parser parser)
+ (modules generator generator))
(define version "v0.1")
@@ -14,13 +15,13 @@
(define (error message)
(display (string-concatenate `(,message "
Usage:
- gscc [OPTIONS] file
+ gscc [OPTIONS] file
Options:
- --version, -v: print version information
- --debug, -d: turn on verbose output
- --lex, -l: run the lexer, but stop before assembly generation
- --parse, -p: run the lexer and parser, but stop before assembly generation
- --codegen, -c: perform lexing, parsing, and assembly generation, but stop before code emission")))
+ --version, -v: print version information
+ --debug, -d: turn on verbose output
+ --lex, -l: run the lexer, but stop before assembly generation
+ --parse, -p: run the lexer and parser, but stop before assembly generation
+ --codegen, -c: perform lexing, parsing, and assembly generation, but stop before code emission")))
(exit #f))
(define (preprocess file)
@@ -35,11 +36,13 @@ file on a success."
(define (process file parse? assemble?)
"Driver for lexing, parsing, and assembly generation."
(let* ((port (open-input-file file))
- (tokens (begin (set-current-input-port port)
- (read-tokens))))
+ (tokens (begin (set-current-input-port port)
+ (read-tokens))))
+ (close-input-port port)
(when parse?
- (p-program tokens))
- (close-input-port port)))
+ (let ((ast (p-program tokens)))
+ (when assemble?
+ (display (generate ast)))))))
(define (postprocess file dest)
"Assembles and links file, producing an executable.
@@ -48,28 +51,28 @@ Returns #f on a failure, #t on a success."
(define (main args)
(let* ((option-spec
- '((version (single-char #\v) (value #f))
- (debug (single-char #\d) (value #f))
- (lex (single-char #\l) (value #f))
- (parse (single-char #\p) (value #f))
- (codegen (single-char #\c) (value #f))))
- (options (getopt-long args option-spec))
- (rest (option-ref options '() #f))
- (file (if (null? rest) #f (car rest))))
+ '((version (single-char #\v) (value #f))
+ (debug (single-char #\d) (value #f))
+ (lex (single-char #\l) (value #f))
+ (parse (single-char #\p) (value #f))
+ (codegen (single-char #\c) (value #f))))
+ (options (getopt-long args option-spec))
+ (rest (option-ref options '() #f))
+ (file (if (null? rest) #f (car rest))))
(cond
((option-ref options 'version #f)
(display (string-concatenate `("gscc (the 'Guile Scheme C Compiler', " ,version ")\n"))))
((not (equal? 1 (length rest))) (error "Wrong number of arguments."))
((or (not file)
- (not (access? file R_OK))
- (not (equal? 'regular (stat:type (stat file))))) (error "The file could not be read."))
+ (not (access? file R_OK))
+ (not (equal? 'regular (stat:type (stat file))))) (error "The file could not be read."))
(#t
(let ((source (preprocess file)))
- (when source
- (display (string-concatenate `("Preprocess reported success (wrote " ,source ").\n")))
- (process source
- (not (option-ref options 'lex #f))
- (not (option-ref options 'parse #f)))))))))
+ (when source
+ (display (string-concatenate `("Preprocess reported success (wrote " ,source ").\n")))
+ (process source
+ (not (option-ref options 'lex #f))
+ (not (option-ref options 'parse #f)))))))))
;; Local Variables: