User talk:IanOsgood: Difference between revisions
Content added Content deleted
(→Forth) |
(→Forth) |
||
Line 16: | Line 16: | ||
::Those Javascript language interpreters are simply awesome. Last week, I was reminiscing about a screensaver I once had that showed the execution of cellular automata, and wondered if something like that would be educational. I didn't think to do it in JavaScript, though. --[[User:Short Circuit|Short Circuit]] 12:07, 27 November 2007 (MST) |
::Those Javascript language interpreters are simply awesome. Last week, I was reminiscing about a screensaver I once had that showed the execution of cellular automata, and wondered if something like that would be educational. I didn't think to do it in JavaScript, though. --[[User:Short Circuit|Short Circuit]] 12:07, 27 November 2007 (MST) |
||
: OK, that was easier than I thought. |
: OK, that was easier than I thought.--[[User:IanOsgood|IanOsgood]] 11:46, 27 November 2007 (MST) |
||
\ brainfuck compiler |
|||
''Code moved to [[RCBF (Forth)]].'' |
|||
1024 constant size |
|||
: init ( -- p *p ) here size erase here 0 ; |
|||
: right ( p *p -- p+1 *p ) over c! 1+ dup c@ ; |
|||
: left ( p *p -- p-1 *p ) over c! 1- dup c@ ; \ range check? |
|||
: compile-bf-char ( c -- ) |
|||
case |
|||
[char] [ of postpone begin |
|||
postpone dup |
|||
postpone while endof |
|||
[char] ] of postpone repeat endof |
|||
[char] + of postpone 1+ endof |
|||
[char] - of postpone 1- endof |
|||
[char] > of postpone right endof |
|||
[char] < of postpone left endof |
|||
[char] , of postpone key endof |
|||
[char] . of postpone dup |
|||
postpone emit endof |
|||
\ ignore all other characters |
|||
endcase ; |
|||
: :bf" ( name bfcode" -- ) |
|||
: |
|||
[char] " parse \ " |
|||
postpone init |
|||
bounds do i c@ compile-bf-char loop |
|||
postpone swap |
|||
postpone c! |
|||
postpone ; |
|||
; |
|||
Testing in [[GNU Forth]]: |
|||
:bf" test [,->+<.]" |
|||
see test |
|||
: test |
|||
init |
|||
BEGIN dup |
|||
WHILE key 1- right 1+ left dup emit |
|||
REPEAT |
|||
2drop ; |
|||
: That's pretty cool. Mind if it's copied over to [[RCBF (Forth)]]? I'd still be interested in that Javascript version; Having on-site or at least in-browser environments for languages is something I've been looking into. --[[User:Short Circuit|Short Circuit]] 11:57, 27 November 2007 (MST) |
: That's pretty cool. Mind if it's copied over to [[RCBF (Forth)]]? I'd still be interested in that Javascript version; Having on-site or at least in-browser environments for languages is something I've been looking into. --[[User:Short Circuit|Short Circuit]] 11:57, 27 November 2007 (MST) |
||
:: Sure. It could use some testing, and a word ''':bf-file''' to get the BF source from a file. I'll let you know if I ever get the JavaScript interpreter written. --[[User:IanOsgood|IanOsgood]] 12:25, 27 November 2007 (MST) |
:: Sure. It could use some testing, and a word ''':bf-file''' to get the BF source from a file. I'll let you know if I ever get the JavaScript interpreter written. --[[User:IanOsgood|IanOsgood]] 12:25, 27 November 2007 (MST) |