brainfuck: enable use from command-line.
parent
faa7fde557
commit
01d244c829
|
@ -1,8 +1,9 @@
|
||||||
! Copyright (C) 2009 John Benediktsson
|
! Copyright (C) 2009 John Benediktsson
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
USING: accessors ascii assocs fry io io.streams.string kernel
|
USING: accessors assocs command-line fry io io.encodings.binary
|
||||||
macros math peg.ebnf prettyprint sequences strings ;
|
io.files io.streams.string kernel macros math namespaces
|
||||||
|
peg.ebnf prettyprint sequences ;
|
||||||
|
|
||||||
IN: brainfuck
|
IN: brainfuck
|
||||||
|
|
||||||
|
@ -70,8 +71,23 @@ code = (loop|ops|unknown)* => [[ compose-all ]]
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
MACRO: run-brainfuck ( code -- )
|
MACRO: run-brainfuck ( code -- )
|
||||||
[ blank? not ] filter parse-brainfuck
|
parse-brainfuck '[ <brainfuck> @ drop flush ] ;
|
||||||
'[ <brainfuck> @ drop flush ] ;
|
|
||||||
|
|
||||||
: get-brainfuck ( code -- result )
|
: get-brainfuck ( code -- result )
|
||||||
[ run-brainfuck ] with-string-writer ; inline
|
[ run-brainfuck ] with-string-writer ; inline
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: (run-brainfuck) ( code -- )
|
||||||
|
[ <brainfuck> ] dip parse-brainfuck call( x -- x ) drop flush ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: brainfuck-main ( -- )
|
||||||
|
command-line get [
|
||||||
|
contents (run-brainfuck)
|
||||||
|
] [
|
||||||
|
[ binary file-contents (run-brainfuck) ] each
|
||||||
|
] if-empty ;
|
||||||
|
|
||||||
|
MAIN: brainfuck-main
|
||||||
|
|
Loading…
Reference in New Issue