1(import (chicken irregex)
2 (chicken process-context)
3 srfi-1)
4
5(include "parser.scm")
6(include "interpreter.scm")
7
8(define (die msg)
9 (let ((port (current-error-port)))
10 (display msg port)
11 (newline port)
12 (exit 1)))
13
14(define (dump-variable var)
15 (display (car var)) (display ": ")
16 (display (cdr var)) (newline))
17
18(define (string->variable str)
19 (let ((kv (irregex-split (irregex "=") str)))
20 (if (= (length kv) 2)
21 (cons (first kv) (string->number (second kv)))
22 (die (string-append "invalid assignment: " str)))))
23
24(define (initial-variables)
25 (let ((args (argv)))
26 (if (> (length args) 1)
27 (map string->variable (cdr args))
28 '())))
29
30(define (main)
31 (let ((prog (parse-loop-prog (current-input-port))))
32 (if prog
33 (let ((vars (eval-loop-prog (initial-variables) prog)))
34 (for-each dump-variable vars))
35 (die "input program is invalid"))))
36
37(cond-expand
38 ((or chicken-script compiling) (main))
39 (else #t))