From 136548ad2ebc5fb36444ffecad1bcdc9e3311aa1 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Tue, 4 Dec 2018 10:28:34 +0100 Subject: [PATCH] , works with dummy input (2) --- #gui.rkt#1# | 1182 ----------------------------------------------- gui.rkt | 22 +- interpreter.rkt | 47 +- 3 files changed, 34 insertions(+), 1217 deletions(-) delete mode 100644 #gui.rkt#1# diff --git a/#gui.rkt#1# b/#gui.rkt#1# deleted file mode 100644 index bfb605e..0000000 --- a/#gui.rkt#1# +++ /dev/null @@ -1,1182 +0,0 @@ -#reader(lib"read.ss""wxme")WXME0108 ## -#| - This file uses the GRacket editor format. - Open this file in DrRacket version 7.0 or later to read it. - - Most likely, it was created by saving a program in DrRacket, - and it probably contains a program with non-text elements - (such as images or comment boxes). - - http://racket-lang.org/ -|# - 33 7 #"wxtext\0" -3 1 6 #"wxtab\0" -1 1 8 #"wximage\0" -2 0 8 #"wxmedia\0" -4 1 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0" -1 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0" -1 0 68 -( - #"((lib \"image-core.ss\" \"mrlib\") (lib \"image-core-wxme.rkt\" \"mr" - #"lib\"))\0" -) 1 0 16 #"drscheme:number\0" -3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0" -1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0" -1 0 93 -( - #"((lib \"collapsed-snipclass.ss\" \"framework\") (lib \"collapsed-sni" - #"pclass-wxme.ss\" \"framework\"))\0" -) 0 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0" -0 0 19 #"drscheme:sexp-snip\0" -0 0 29 #"drscheme:bindings-snipclass%\0" -1 0 101 -( - #"((lib \"ellipsis-snip.rkt\" \"drracket\" \"private\") (lib \"ellipsi" - #"s-snip-wxme.rkt\" \"drracket\" \"private\"))\0" -) 2 0 88 -( - #"((lib \"pict-snip.rkt\" \"drracket\" \"private\") (lib \"pict-snip.r" - #"kt\" \"drracket\" \"private\"))\0" -) 0 0 55 -#"((lib \"snip.rkt\" \"pict\") (lib \"snip-wxme.rkt\" \"pict\"))\0" -1 0 34 #"(lib \"bullet-snip.rkt\" \"browser\")\0" -0 0 25 #"(lib \"matrix.ss\" \"htdp\")\0" -1 0 22 #"drscheme:lambda-snip%\0" -1 0 29 #"drclickable-string-snipclass\0" -0 0 26 #"drracket:spacer-snipclass\0" -0 0 57 -#"(lib \"hrule-snip.rkt\" \"macro-debugger\" \"syntax-browser\")\0" -1 0 26 #"drscheme:pict-value-snip%\0" -0 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0" -1 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0" -2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0" -1 0 18 #"drscheme:xml-snip\0" -1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0" -1 0 21 #"drscheme:scheme-snip\0" -2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0" -1 0 10 #"text-box%\0" -1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0" -1 0 1 6 #"wxloc\0" - 0 0 56 0 1 #"\0" -0 75 1 #"\0" -0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9 -#"Standard\0" -0 75 30 #"Source Code Pro for Powerline\0" -0 13 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24 -#"framework:default-color\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15 -#"text:ports out\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1 --1 2 15 #"text:ports err\0" -0 -1 1 #"\0" -1 0 -1 -1 93 -1 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17 -#"text:ports value\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1 --1 2 27 #"Matching Parenthesis Style\0" -0 -1 1 #"\0" -1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1 --1 2 1 #"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37 -#"framework:syntax-color:scheme:symbol\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38 -#"framework:syntax-color:scheme:keyword\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 -38 #"framework:syntax-color:scheme:comment\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 194 158 31 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37 -#"framework:syntax-color:scheme:string\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 211 72 255 0 0 0 -1 -1 2 -35 #"framework:syntax-color:scheme:text\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39 -#"framework:syntax-color:scheme:constant\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 211 72 255 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 49 -#"framework:syntax-color:scheme:hash-colon-keyword\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42 -#"framework:syntax-color:scheme:parenthesis\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 150 255 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36 -#"framework:syntax-color:scheme:error\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36 -#"framework:syntax-color:scheme:other\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 16 -#"Misspelled Text\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 -38 #"drracket:check-syntax:lexically-bound\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 28 -#"drracket:check-syntax:set!d\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 37 -#"drracket:check-syntax:unused-require\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36 -#"drracket:check-syntax:free-variable\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31 -#"drracket:check-syntax:imported\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 47 -#"drracket:check-syntax:my-obligation-style-pref\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 116 0 0 0 0 -1 -1 2 50 -#"drracket:check-syntax:their-obligation-style-pref\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 116 0 0 0 0 -1 -1 2 48 -#"drracket:check-syntax:unk-obligation-style-pref\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 139 142 28 0 0 0 -1 -1 2 -49 #"drracket:check-syntax:both-obligation-style-pref\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 139 142 28 0 0 0 -1 -1 2 -26 #"plt:htdp:test-coverage-on\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 -#"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 2 27 -#"plt:htdp:test-coverage-off\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1 -#"\0" -0 70 1 #"\0" -1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 --1 -1 4 4 #"XML\0" -0 70 1 #"\0" -1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 --1 -1 2 37 #"plt:module-language:test-coverage-on\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 38 -#"plt:module-language:test-coverage-off\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1 -#"\0" -0 71 1 #"\0" -1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 --1 -1 4 1 #"\0" -0 -1 1 #"\0" -1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1 --1 4 1 #"\0" -0 71 1 #"\0" -1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1 --1 4 1 #"\0" -0 71 1 #"\0" -1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1 --1 2 1 #"\0" -0 -1 1 #"\0" -1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1 - 0 945 0 28 3 16 #"#lang racket/gui" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 7 #"require" -0 0 24 3 1 #" " -0 0 19 3 17 #"\"interpreter.rkt\"" -0 0 24 29 1 #"\n" -0 0 24 3 9 #" " -0 0 14 3 9 #"framework" -0 0 24 29 1 #"\n" -0 0 24 3 9 #" " -0 0 14 3 10 #"racket/set" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 28 #"; The editor width in pixels" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 12 #"EDITOR-WIDTH" -0 0 24 3 1 #" " -0 0 21 3 3 #"600" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 13 #"EDITOR-HEIGHT" -0 0 24 3 1 #" " -0 0 21 3 3 #"600" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 49 #"; The frame racket/gui base object for the editor" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 6 #"frame%" -0 0 24 29 1 #"\n" -0 0 24 3 16 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 13 #"\"DrBrainf*ck\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 16 #" [" -0 0 14 3 5 #"width" -0 0 24 3 1 #" " -0 0 14 3 12 #"EDITOR-WIDTH" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 16 #" [" -0 0 14 3 6 #"height" -0 0 24 3 1 #" " -0 0 14 3 13 #"EDITOR-HEIGHT" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 52 #"; execute-content: ((ProgState) -> Any) -> ProgState" -0 0 24 29 1 #"\n" -0 0 17 3 78 -( - #"; Given a callback, calls the callback with the last state of execut" - #"ion of the" -) 0 0 24 29 1 #"\n" -0 0 17 3 9 #"; program" -0 0 17 3 1 #" " -0 0 17 3 6 #"loaded" -0 0 17 3 1 #" " -0 0 17 3 2 #"in" -0 0 17 3 1 #" " -0 0 17 3 3 #"the" -0 0 17 3 7 #" editor" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 2 #" (" -0 0 14 3 15 #"execute-content" -0 0 24 3 1 #" " -0 0 14 3 4 #"done" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 14 3 7 #"execute" -0 0 24 29 1 #"\n" -0 0 24 3 4 #" (" -0 0 14 3 19 #"program->prog-state" -0 0 24 29 1 #"\n" -0 0 24 3 5 #" (" -0 0 14 3 15 #"string->program" -0 0 24 29 1 #"\n" -0 0 24 3 6 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #" " -0 0 14 3 18 #"get-flattened-text" -0 0 24 3 4 #"))) " -0 0 14 3 4 #"done" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 45 #"; run-program: Button ControlEvent -> Nothing" -0 0 24 29 1 #"\n" -0 0 17 3 79 -( - #"; Given a button and an event, runs the program currently loaded in " - #"the editor." -) 0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 2 #" (" -0 0 14 3 11 #"run-program" -0 0 24 3 1 #" " -0 0 14 3 6 #"button" -0 0 24 3 1 #" " -0 0 14 3 5 #"event" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 2 #" " -0 0 17 3 44 #"; empty output text and set color to running" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 10 #"run-output" -0 0 24 3 1 #" " -0 0 14 3 9 #"set-value" -0 0 24 3 1 #" " -0 0 19 3 2 #"\"\"" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 10 #"run-output" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-field-background" -0 0 24 3 1 #" " -0 0 14 3 7 #"run-col" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 24 3 2 #" " -0 0 17 3 17 #"; run the program" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 14 3 15 #"execute-content" -0 0 24 29 1 #"\n" -0 0 24 3 4 #" (" -0 0 15 3 6 #"lambda" -0 0 24 3 2 #" (" -0 0 14 3 2 #"ps" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 6 #" (" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 3 #"out" -0 0 24 3 2 #" (" -0 0 14 3 17 #"prog-state-output" -0 0 24 3 1 #" " -0 0 14 3 2 #"ps" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 3 5 #" " -0 0 24 29 1 #"\n" -0 0 24 3 5 #" " -0 0 17 3 38 #"; set output and change color to ended" -0 0 24 29 1 #"\n" -0 0 24 3 6 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 10 #"run-output" -0 0 24 3 1 #" " -0 0 14 3 9 #"set-value" -0 0 24 3 1 #" " -0 0 14 3 3 #"out" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 6 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 10 #"run-output" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-field-background" -0 0 24 3 1 #" " -0 0 14 3 7 #"end-col" -0 0 24 3 4 #"))))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 37 #"; Definition of the run button widget" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 7 #"run-btn" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 7 #"button%" -0 0 24 3 2 #" [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 22 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 5 #"\"Run\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 21 #" " -0 0 17 3 40 #"; Callback procedure for a button click:" -0 0 24 29 1 #"\n" -0 0 24 3 22 #" [" -0 0 14 3 8 #"callback" -0 0 24 3 1 #" " -0 0 14 3 11 #"run-program" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 33 #"; Definition of the editor canves" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 1 #"c" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 14 #"editor-canvas%" -0 0 24 3 2 #" [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 36 #"; Definition of editor text object. " -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 9 #"text-pro%" -0 0 24 3 2 #" (" -0 0 14 3 23 #"text:line-numbers-mixin" -0 0 24 29 1 #"\n" -0 0 24 3 20 #" (" -0 0 14 3 32 #"editor:standard-style-list-mixin" -0 0 24 29 1 #"\n" -0 0 24 3 21 #" (" -0 0 14 3 16 #"color:text-mixin" -0 0 24 29 1 #"\n" -0 0 24 3 22 #" (" -0 0 14 3 16 #"text:basic-mixin" -0 0 24 29 1 #"\n" -0 0 24 3 23 #" (" -0 0 14 3 18 #"editor:basic-mixin" -0 0 24 3 1 #" " -0 0 14 3 5 #"text%" -0 0 24 3 6 #"))))))" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 9 #"text-pro%" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 29 #"; Show line numbers in editor" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #" " -0 0 14 3 18 #"show-line-numbers!" -0 0 24 3 1 #" " -0 0 21 3 2 #"#t" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 22 #"; A BFToken is one of:" -0 0 24 29 1 #"\n" -0 0 17 3 12 #"; - 'comment" -0 0 24 29 1 #"\n" -0 0 17 3 16 #"; - 'instruction" -0 0 24 29 1 #"\n" -0 0 17 3 10 #"; - 'shift" -0 0 24 29 1 #"\n" -0 0 17 3 9 #"; - 'loop" -0 0 24 29 1 #"\n" -0 0 17 3 40 #"; Interp: category of a bf program token" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 22 #"; A BFStyle is one of:" -0 0 24 29 1 #"\n" -0 0 17 3 13 #"; - \"Comment\"" -0 0 24 29 1 #"\n" -0 0 17 3 17 #"; - \"Instruction\"" -0 0 24 29 1 #"\n" -0 0 17 3 11 #"; - \"Shift\"" -0 0 24 29 1 #"\n" -0 0 17 3 10 #"; - \"Loop\"" -0 0 24 29 1 #"\n" -0 0 17 3 50 #"; Interp: name of the style for a bf program token" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 40 #"; bf-token->bf-style: BFToken -> BFStyle" -0 0 24 29 1 #"\n" -0 0 17 3 53 #"; Given a BFToken, returns the corresponding BFStyle." -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 2 #" (" -0 0 14 3 18 #"bf-token->bf-style" -0 0 24 3 1 #" " -0 0 14 3 5 #"token" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 9 #" (" -0 0 15 3 4 #"cond" -0 0 24 3 3 #" [(" -0 0 14 3 8 #"symbol=?" -0 0 24 3 1 #" " -0 0 14 3 5 #"token" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 7 #"comment" -0 0 24 3 2 #") " -0 0 19 3 9 #"\"Comment\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 16 #" [(" -0 0 14 3 8 #"symbol=?" -0 0 24 3 1 #" " -0 0 14 3 5 #"token" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 4 #"loop" -0 0 24 3 2 #") " -0 0 19 3 6 #"\"Loop\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 16 #" [(" -0 0 14 3 8 #"symbol=?" -0 0 24 3 1 #" " -0 0 14 3 5 #"token" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 5 #"shift" -0 0 24 3 2 #") " -0 0 19 3 7 #"\"Shift\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 16 #" [(" -0 0 14 3 8 #"symbol=?" -0 0 24 3 1 #" " -0 0 14 3 5 #"token" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 11 #"instruction" -0 0 24 3 2 #") " -0 0 19 3 13 #"\"Instruction\"" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 77 -( - #"; bf-lexer: InputPort -> (values 1String BFToken #f Option Opti" - #"on) " -) 0 0 24 29 1 #"\n" -0 0 17 3 76 -( - #"; Given an input port, returns the BFToken of the instruction pointe" - #"d by the" -) 0 0 24 29 1 #"\n" -0 0 17 3 7 #"; port." -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 2 #" (" -0 0 14 3 8 #"bf-lexer" -0 0 24 3 1 #" " -0 0 14 3 4 #"port" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 15 3 13 #"define-values" -0 0 24 3 2 #" (" -0 0 14 3 1 #"_" -0 0 24 3 1 #" " -0 0 14 3 2 #"__" -0 0 24 3 1 #" " -0 0 14 3 3 #"pos" -0 0 24 3 3 #") (" -0 0 14 3 18 #"port-next-location" -0 0 24 3 1 #" " -0 0 14 3 4 #"port" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 1 #"c" -0 0 24 3 2 #" (" -0 0 14 3 9 #"read-char" -0 0 24 3 1 #" " -0 0 14 3 4 #"port" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 15 3 4 #"cond" -0 0 24 3 3 #" [(" -0 0 14 3 11 #"eof-object?" -0 0 24 3 1 #" " -0 0 14 3 1 #"c" -0 0 24 3 3 #") (" -0 0 14 3 6 #"values" -0 0 24 3 1 #" " -0 0 14 3 1 #"c" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 3 #"eof" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 2 #")]" -0 0 24 29 1 #"\n" -0 0 24 3 9 #" [" -0 0 14 3 4 #"else" -0 0 24 29 1 #"\n" -0 0 24 3 10 #" (" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 4 #"1str" -0 0 24 3 2 #" (" -0 0 14 3 6 #"string" -0 0 24 3 1 #" " -0 0 14 3 1 #"c" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 3 10 #" (" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 8 #"bf-token" -0 0 24 29 1 #"\n" -0 0 24 3 12 #" (" -0 0 15 3 4 #"cond" -0 0 24 3 3 #" [(" -0 0 14 3 11 #"set-member?" -0 0 24 3 2 #" (" -0 0 14 3 3 #"set" -0 0 24 3 1 #" " -0 0 19 3 3 #"\"+\"" -0 0 24 3 1 #" " -0 0 19 3 3 #"\"-\"" -0 0 24 3 1 #" " -0 0 19 3 3 #"\",\"" -0 0 24 3 1 #" " -0 0 19 3 3 #"\".\"" -0 0 24 3 2 #") " -0 0 14 3 4 #"1str" -0 0 24 3 2 #") " -0 0 21 3 1 #"'" -0 0 14 3 11 #"instruction" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 19 #" [(" -0 0 14 3 11 #"set-member?" -0 0 24 3 2 #" (" -0 0 14 3 3 #"set" -0 0 24 3 1 #" " -0 0 19 3 3 #"\"<\"" -0 0 24 3 1 #" " -0 0 19 3 3 #"\">\"" -0 0 24 3 2 #") " -0 0 14 3 4 #"1str" -0 0 24 3 2 #") " -0 0 21 3 1 #"'" -0 0 14 3 5 #"shift" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 19 #" [(" -0 0 14 3 11 #"set-member?" -0 0 24 3 2 #" (" -0 0 14 3 3 #"set" -0 0 24 3 1 #" " -0 0 19 3 3 #"\"[\"" -0 0 24 3 1 #" " -0 0 19 3 3 #"\"]\"" -0 0 24 3 2 #") " -0 0 14 3 4 #"1str" -0 0 24 3 2 #") " -0 0 21 3 1 #"'" -0 0 14 3 4 #"loop" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 18 #" [" -0 0 14 3 4 #"else" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 7 #"comment" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 3 10 #" (" -0 0 14 3 6 #"values" -0 0 24 3 1 #" " -0 0 14 3 4 #"1str" -0 0 24 3 1 #" " -0 0 14 3 8 #"bf-token" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 2 #" (" -0 0 14 3 1 #"+" -0 0 24 3 1 #" " -0 0 14 3 3 #"pos" -0 0 24 3 3 #") (" -0 0 14 3 1 #"+" -0 0 24 3 1 #" " -0 0 14 3 3 #"pos" -0 0 24 3 1 #" " -0 0 21 3 1 #"1" -0 0 24 3 5 #"))]))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 35 #"; Syntax highlighting for brainf*ck" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #" " -0 0 14 3 13 #"start-colorer" -0 0 24 3 1 #" " -0 0 14 3 18 #"bf-token->bf-style" -0 0 24 3 1 #" " -0 0 14 3 8 #"bf-lexer" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 24 3 3 #"())" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 47 #"; Define basic style for instructions (+ - , .)" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 2 #" (" -0 0 15 3 11 #"make-object" -0 0 24 3 1 #" " -0 0 14 3 12 #"style-delta%" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-delta-foreground" -0 0 24 3 1 #" " -0 0 19 3 6 #"\"blue\"" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 36 #"editor:set-standard-style-list-delta" -0 0 24 3 1 #" " -0 0 19 3 13 #"\"Instruction\"" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 44 #"; Define style for shifting operations (< >)" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-delta-foreground" -0 0 24 3 1 #" " -0 0 19 3 5 #"\"red\"" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 36 #"editor:set-standard-style-list-delta" -0 0 24 3 1 #" " -0 0 19 3 7 #"\"Shift\"" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 51 #"; Define basic style for looping instructions ([ ])" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-delta-foreground" -0 0 24 3 1 #" " -0 0 19 3 13 #"\"forestgreen\"" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 36 #"editor:set-standard-style-list-delta" -0 0 24 3 1 #" " -0 0 19 3 6 #"\"Loop\"" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 26 #"; Define style of comments" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-delta-foreground" -0 0 24 3 1 #" " -0 0 19 3 8 #"\"orange\"" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 36 #"editor:set-standard-style-list-delta" -0 0 24 3 1 #" " -0 0 19 3 9 #"\"Comment\"" -0 0 24 3 1 #" " -0 0 14 3 5 #"delta" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 22 #"; Running output color" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 7 #"run-col" -0 0 24 3 2 #" (" -0 0 15 3 11 #"make-object" -0 0 24 3 1 #" " -0 0 14 3 6 #"color%" -0 0 24 3 1 #" " -0 0 21 3 3 #"250" -0 0 24 3 1 #" " -0 0 21 3 3 #"250" -0 0 24 3 1 #" " -0 0 21 3 3 #"200" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 24 #"; Output completed color" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 7 #"end-col" -0 0 24 3 2 #" (" -0 0 15 3 11 #"make-object" -0 0 24 3 1 #" " -0 0 14 3 6 #"color%" -0 0 24 3 1 #" " -0 0 21 3 3 #"200" -0 0 24 3 1 #" " -0 0 21 3 3 #"250" -0 0 24 3 1 #" " -0 0 21 3 3 #"200" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 2 #"mb" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 9 #"menu-bar%" -0 0 24 3 2 #" [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 6 #"m-file" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 5 #"menu%" -0 0 24 3 2 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 6 #"\"File\"" -0 0 24 3 3 #"] [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 2 #"mb" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 6 #"m-edit" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 5 #"menu%" -0 0 24 3 2 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 6 #"\"Edit\"" -0 0 24 3 3 #"] [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 2 #"mb" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 29 1 #"\n" -0 0 17 3 28 #"; The run output text object" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 10 #"run-output" -0 0 24 3 2 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 11 #"text-field%" -0 0 24 29 1 #"\n" -0 0 24 3 25 #" [" -0 0 14 3 5 #"style" -0 0 24 3 2 #" (" -0 0 14 3 4 #"list" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 8 #"multiple" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 14 #"vertical-label" -0 0 24 3 2 #")]" -0 0 24 29 1 #"\n" -0 0 24 3 25 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 19 #"\"Execution output:\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 25 #" [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 3 #"]))" -0 0 24 29 1 #"\n" -0 0 24 3 2 #" " -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 7 #"mi-open" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 10 #"menu-item%" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 6 #"\"Open\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 6 #"m-file" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 8 #"callback" -0 0 24 29 1 #"\n" -0 0 24 3 9 #" (" -0 0 15 3 6 #"lambda" -0 0 24 3 2 #" (" -0 0 14 3 1 #"i" -0 0 24 3 1 #" " -0 0 14 3 1 #"e" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 11 #" (" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 4 #"path" -0 0 24 3 2 #" (" -0 0 14 3 8 #"get-file" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 2 #"))" -0 0 24 29 1 #"\n" -0 0 24 3 11 #" (" -0 0 15 3 4 #"when" -0 0 24 3 1 #" " -0 0 14 3 4 #"path" -0 0 24 29 1 #"\n" -0 0 24 3 13 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #" " -0 0 14 3 9 #"load-file" -0 0 24 3 1 #" " -0 0 14 3 4 #"path" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 4 #"text" -0 0 24 3 4 #")))]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 8 #"shortcut" -0 0 24 3 1 #" " -0 0 21 3 3 #"#\\o" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 15 #"shortcut-prefix" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 24 3 1 #"(" -0 0 14 3 3 #"ctl" -0 0 24 3 4 #")]))" -0 0 24 29 1 #"\n" -0 0 24 3 2 #" " -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 15 3 6 #"define" -0 0 24 3 1 #" " -0 0 14 3 7 #"mi-save" -0 0 24 29 1 #"\n" -0 0 24 3 3 #" (" -0 0 14 3 3 #"new" -0 0 24 3 1 #" " -0 0 14 3 10 #"menu-item%" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 5 #"label" -0 0 24 3 1 #" " -0 0 19 3 6 #"\"Save\"" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 6 #"parent" -0 0 24 3 1 #" " -0 0 14 3 6 #"m-file" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 8 #"callback" -0 0 24 29 1 #"\n" -0 0 24 3 9 #" (" -0 0 15 3 6 #"lambda" -0 0 24 3 2 #" (" -0 0 14 3 1 #"i" -0 0 24 3 1 #" " -0 0 14 3 1 #"e" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 11 #" (" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #" " -0 0 14 3 9 #"save-file" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 14 3 4 #"text" -0 0 24 3 3 #"))]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 8 #"shortcut" -0 0 24 3 1 #" " -0 0 21 3 3 #"#\\s" -0 0 24 3 1 #"]" -0 0 24 29 1 #"\n" -0 0 24 3 8 #" [" -0 0 14 3 15 #"shortcut-prefix" -0 0 24 3 1 #" " -0 0 21 3 1 #"'" -0 0 24 3 1 #"(" -0 0 14 3 3 #"ctl" -0 0 24 3 4 #")]))" -0 0 24 29 1 #"\n" -0 0 24 3 2 #" " -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 34 #"append-editor-operation-menu-items" -0 0 24 3 1 #" " -0 0 14 3 6 #"m-edit" -0 0 24 3 1 #" " -0 0 21 3 2 #"#f" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #" " -0 0 14 3 20 #"set-max-undo-history" -0 0 24 3 1 #" " -0 0 21 3 3 #"100" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 1 #"c" -0 0 24 3 1 #" " -0 0 14 3 10 #"set-editor" -0 0 24 3 1 #" " -0 0 14 3 6 #"editor" -0 0 24 3 1 #")" -0 0 24 29 1 #"\n" -0 0 24 3 1 #"(" -0 0 14 3 4 #"send" -0 0 24 3 1 #" " -0 0 14 3 1 #"f" -0 0 24 3 1 #" " -0 0 14 3 4 #"show" -0 0 24 3 1 #" " -0 0 21 3 2 #"#t" -0 0 24 3 1 #")" -0 0 diff --git a/gui.rkt b/gui.rkt index a4176a3..7bb6565 100644 --- a/gui.rkt +++ b/gui.rkt @@ -14,13 +14,15 @@ [width EDITOR-WIDTH] [height EDITOR-HEIGHT])) -; execute-content: () -> ProgState -; Returns the last state of execution of the program loaded in the editor -(define (execute-content) +; execute-content: ((ProgState) -> Any) -> ProgState +; Given a callback, calls the callback with the last state of execution of the +; program loaded in the editor +(define (execute-content done) (execute (program->prog-state (string->program - (send editor get-flattened-text))))) + (send editor get-flattened-text))) + done (lambda (callback) (callback 50)))) ; run-program: Button ControlEvent -> Nothing ; Given a button and an event, runs the program currently loaded in the editor. @@ -30,11 +32,13 @@ (send run-output set-field-background run-col) ; run the program - (define out (prog-state-output (execute-content))) - - ; set output and change color to ended - (send run-output set-value out) - (send run-output set-field-background end-col)) + (execute-content + (lambda (ps) + (define out (prog-state-output ps)) + + ; set output and change color to ended + (send run-output set-value out) + (send run-output set-field-background end-col)))) ; Definition of the run button widget (define run-btn (new button% [parent f] diff --git a/interpreter.rkt b/interpreter.rkt index ec9e5c6..d405fd9 100644 --- a/interpreter.rkt +++ b/interpreter.rkt @@ -222,16 +222,6 @@ (check-expect (exec-out (prog-state (list 65) 0 1 "" ".[->+<]" 0)) (prog-state (list 65) 0 1 "A" ".[->+<]" 1)) -; char-at: String Nat -> 1String -; Given a string and an index, returns the 1String at the position pointed by -; index -(define (char-at s i) - (substring s i (add1 i))) - -; Tests for char-at -(check-expect (char-at "malusa" 2) "l") -(check-error (char-at "another string" 300)) - ; WalkingDirection can be one of: ; - 'forward ; - 'backward @@ -317,6 +307,11 @@ (prog-state '(1) 0 1 "" "[++--]++--+-[]" 5)) (prog-state '(1) 0 1 "" "[++--]++--+-[]" 1)) +; insert-in-tape: DataTape Byte Nat -> DataTape +(define (insert-in-tape dt val n) + (cond [(zero? n) (cons val (rest dt))] + [else (cons (first dt) (insert-in-tape (rest dt) val (sub1 n)))])) + ; exec-in: ProgState ((Byte -> _) -> _) (ProgState -> _) -> _ ; Given a ProgState, a function that takes a callback function requiring a Byte ; and a function which takes the new ProgState, calls done with the input @@ -325,7 +320,7 @@ (define (exec-in w get-input done) (define (got-input byte) (done (prog-state - (insert-in-tape byte (prog-state-dp w)) + (insert-in-tape (prog-state-tape w) byte (prog-state-dp w)) (prog-state-dp w) (prog-state-tape-len w) (prog-state-output w) @@ -333,23 +328,23 @@ (add1 (prog-state-ip w))))) (get-input got-input)) -; execute: ProgState ((ProgState) -> _) -> ProgState +; execute: ProgState ((ProgState) -> _) ((Byte -> _) -> _) -> ProgState ; Given an initial ProgState state, calls done when the final ProgState is ready ; to execute the program. -(define (execute w done) - (local [(define program-len (string-length (prog-state-program w)))] - (cond [(>= (prog-state-ip w) program-len) (done w)] - [else - (define inst (char-at (prog-state-program w) (prog-state-ip w))) - (cond [(string=? inst ",") (exec-in w (lambd] - [else - (execute (cond [(string=? inst "+") (exec-add1 w)] - [(string=? inst "-") (exec-sub1 w)] - [(string=? inst "<") (exec-tape-left w)] - [(string=? inst ">") (exec-tape-right w)] - [(string=? inst "[") (exec-loop-start w)] - [(string=? inst "]") (exec-loop-end w)] - [(string=? inst ".") (exec-out w)]) done)])]))) +(define (execute w done get-input) + (define program-len (string-length (prog-state-program w))) + (cond [(>= (prog-state-ip w) program-len) (done w)] + [else + (define inst (string-ref (prog-state-program w) (prog-state-ip w))) + (cond [(char=? inst #\,) + (exec-in w get-input (lambda (ps) (execute ps done get-input)))] + [else (execute (cond [(char=? inst #\+) (exec-add1 w)] + [(char=? inst #\-) (exec-sub1 w)] + [(char=? inst #\<) (exec-tape-left w)] + [(char=? inst #\>) (exec-tape-right w)] + [(char=? inst #\[) (exec-loop-start w)] + [(char=? inst #\]) (exec-loop-end w)] + [(char=? inst #\.) (exec-out w)]) done get-input)])])) ; Tests for execute (check-expect (execute (prog-state (list 0) 0 3 "" "" 0))