picrin/contrib/70.main/main.scm

57 lines
1.5 KiB
Scheme
Raw Normal View History

2014-08-30 11:36:20 -04:00
(define-library (picrin main)
(import (scheme base)
(scheme read)
(scheme write)
(scheme process-context)
(scheme load)
(scheme eval)
2015-06-19 13:35:13 -04:00
(picrin base)
2014-08-30 11:36:20 -04:00
(picrin repl))
(define (print-help)
(display "picrin scheme\n")
(display "\n")
(display "Usage: picrin [options] [file]\n")
(display "\n")
(display "Options:\n")
(display " -e [program] run one liner script\n")
2014-09-01 09:51:04 -04:00
(display " -l [file] load the file then enter repl\n")
2014-08-30 11:36:20 -04:00
(display " -h or --help show this help\n"))
(define (getopt)
(let ((args (cdr (command-line))))
(if (null? args)
(values 'repl #f)
(case (string->symbol (car args))
((-h --help)
(print-help)
(exit 1))
((-e)
(values 'line (cadr args)))
2014-09-01 09:51:04 -04:00
((-l)
(values 'load (cadr args)))
2014-08-30 11:36:20 -04:00
(else
(values 'file (car args)))))))
(define (exec-file filename)
(load filename))
(define (exec-line str)
(call-with-port (open-input-string str)
(lambda (in)
(let loop ((expr (read in)))
(unless (eof-object? expr)
(eval expr (find-library "picrin.user"))
2014-08-30 11:36:20 -04:00
(loop (read in)))))))
(define (main)
(call-with-values getopt
(lambda (type dat)
(case type
((repl) (repl))
2014-09-01 09:51:04 -04:00
((load) (load dat) (repl))
2014-08-30 11:36:20 -04:00
((line) (exec-line dat))
((file) (exec-file dat))))))
(export main))