Skip to content
Browse files

Shuffle, shuffle, shuffle.

  • Loading branch information...
1 parent 78449db commit 13f06e54703663f3b72b265e602bfb2087789f43 @damelang committed Dec 15, 2011
Showing with 24 additions and 23 deletions.
  1. +11 −0 compilers/maru/misc.l
  2. +13 −23 compilers/maru/nile-compiler.l
View
11 compilers/maru/misc.l
@@ -0,0 +1,11 @@
+(define-function concat-files (files)
+ (foldr (lambda (file string)
+ (let ((contents (input-stream-up-to (input-stream (open file) file) *end*)))
+ (concat-string contents string)))
+ "" files))
+
+(define-function invoke-parser (parser-class rule stream)
+ (let ((pstream (parser-stream stream))
+ (p (parser parser-class pstream)))
+ (rule p)
+ (<parser>-result p)))
View
36 compilers/maru/nile-compiler.l
@@ -1,6 +1,8 @@
-(define nile-TYPE-UNKNOWN)
+(load "misc.l")
+(define nile-TYPE-UNKNOWN)
(load "nile-ast.l")
+(define nile-TYPE-UNKNOWN (nile-typedef "UNKNOWN" ()))
(define peg-make-definition peg-make-definition-with-memo)
;(define peg-make-definition peg-make-definition-with-recursion)
@@ -133,12 +135,10 @@
# Top level
definition = typedef | opdef | processdef ;
error = -> (error "error in Nile program near: "(parser-stream-context self.source)) ;
- program = (EOL* definition)*:defs EOL* (!. | error) -> defs ;
+ start = (EOL* definition)*:defs EOL* (!. | error) -> defs ;
}
-(define nile-TYPE-UNKNOWN (nile-typedef "UNKNOWN" ()))
-
-(define nile-prelude (list
+(define nile-prelude-ast (list
(nile-typedef "Real" ())
(nile-opdef (nile-opsig "-" (list (nile-typedvar "a" "Real")) "Real") () ())
(nile-opdef (nile-opsig "<" (list (nile-typedvar "a" "Real") (nile-typedvar "b" "Real")) "Real") () ())
@@ -147,26 +147,16 @@
(nile-processdef (nile-processsig "Passthrough" () nile-TYPE-UNKNOWN) () () ())
(nile-processdef (nile-processsig "SortBy" (list (nile-typedvar "e" "Real")) nile-TYPE-UNKNOWN) () () ())))
-(define-function nile-compile (program)
- (let ((defs (concat-list nile-prelude program))
+(define-function nile-compile-ast (ast)
+ (let ((defs (concat-list nile-prelude-ast ast))
(globals (map (lambda (def) (cons (name def) def)) defs))
(_ (list-do def defs (resolve-refs def globals)))
)
- defs))
-
-(define-function concat-files (files)
- (foldr (lambda (file string)
- (let ((contents (input-stream-up-to (input-stream (open file) file) *end*)))
- (concat-string contents string)))
- "" files))
-
-(define nile-program
- (let ((pstream (parser-stream (string-stream (concat-files *arguments*))))
- (nparser (parser <nile-parser> pstream)))
- (set *arguments* ())
- ($program nparser)
- (<parser>-result nparser)))
+ defs))
-(define nile-compiled-program (nile-compile nile-program))
+(let ((stream (string-stream (concat-files *arguments*)))
+ (ast (invoke-parser <nile-parser> $start stream))
+ (result (nile-compile-ast ast)))
+ (map-with print-structure result 0))
-(map-with print-structure nile-compiled-program 0)
+(set *arguments* ())

0 comments on commit 13f06e5

Please sign in to comment.
Something went wrong with that request. Please try again.