aboutsummaryrefslogtreecommitdiffstats
path: root/csc/main.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-08-01 19:35:19 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-08-01 19:35:19 -0700
commitacc561366f3fe6ec0377103f52ef0f7e923711c9 (patch)
treed7a19cfbad78a69ebea71b27302e708c0655863d /csc/main.csc
parentRename the compiler in bytecode.rs. (diff)
downloadchromatopelma-acc561366f3fe6ec0377103f52ef0f7e923711c9.tar.zst
Modify the project structure.
Now the lib directory contains what will eventually end up on the user's /usr/lib/csc. When I write make install, it will copy all of the .csc files from lib into the destination lib directory. This means I can start working on the standard library in lib/scheme.
Diffstat (limited to 'csc/main.csc')
-rw-r--r--csc/main.csc76
1 files changed, 0 insertions, 76 deletions
diff --git a/csc/main.csc b/csc/main.csc
deleted file mode 100644
index 9dae75f..0000000
--- a/csc/main.csc
+++ /dev/null
@@ -1,76 +0,0 @@
-(import (scheme base)
- (only (scheme file)
- open-binary-output-file)
- (only (scheme read)
- read)
- (only (csc compiler)
- *library-search-dirs*
- compile)
- (only (csc flag)
- *args*
- bool-flag
- define-flag
- parse-error-flag
- parse-error-msg
- parse-error?
- parse-flags)
- (only (csc format)
- printf)
- (only (csc loop)
- loop)
- (only (csc match)
- match))
-
-
-(define-flag *include* "include" (lambda (s) (cons s *include*)) '())
-(define-flag *output* "output" string-copy "")
-(define-flag *help* "help" bool-flag #f)
-(define-flag *h* "h" bool-flag #f)
-
-
-(define *help-msg*
- "Usage: csc [OPTION]... [FILE]
-
- --include DIRECTORY Search in the given directory for libraries.
- This flag can be passed more than once.
- --output FILE Write output to the given file. The default is
- to immediately execute.
-
- --help,-h Print the usage message.
-")
-
-
-(define (read-file f)
- (call-with-input-file f
- (lambda (p)
- (loop for expr = (read p)
- until (eof-object? expr)
- collect expr))))
-
-
-(define (write-file f bytes)
- (call-with-port (open-binary-output-file f)
- (lambda (p)
- (write-bytevector bytes p))))
-
-
-(define (main)
- (guard (e ((parse-error? e)
- (printf "Error: could not parse flag {}: {}\n{}" (parse-error-flag e) (parse-error-msg e) *help-msg*)
- (exit 2)))
- (parse-flags))
- (when (or *help* *h*)
- (printf "{}" *help-msg*)
- (exit 0))
- (when (string=? "" *output*)
- (printf "For now, the option --output is required. In the future, we will be able to execute code directly.\n")
- (exit 2))
- (define input-file (match *args*
- ((file) file)
- (_ (printf "Error: must pass exactly one file to csc.\n{}" *help-msg*)
- (exit 2))))
- (set! *library-search-dirs* *include*)
- (write-file *output* (compile (read-file input-file))))
-
-
-(main)