@@ -37,6 +37,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3737var myVisualizer = null ; // singleton ExecutionVisualizer instance
3838
3939
40+ function NOP ( ) { } ;
41+
42+
4043$ ( document ) . ready ( function ( ) {
4144 var queryStrOptions = getQueryStringOptions ( ) ;
4245
@@ -49,16 +52,9 @@ $(document).ready(function() {
4952 var showOnlyOutputsBool = ( queryStrOptions . showOnlyOutputs == 'true' ) ;
5053 var cumModeBool = ( queryStrOptions . cumulativeState == 'true' ) ;
5154
52- // set up all options in a JS object
53- var options = { cumulative_mode : cumModeBool ,
54- heap_primitives : heapPrimitivesBool ,
55- show_only_outputs : showOnlyOutputsBool ,
56- py_crazy_mode : ( pyState == '2crazy' ) } ;
57-
58-
59- var preseededCurInstr = queryStrOptions . preseededCurInstr ;
60- if ( ! preseededCurInstr ) {
61- preseededCurInstr = 0 ;
55+ var startingInstruction = queryStrOptions . preseededCurInstr ;
56+ if ( ! startingInstruction ) {
57+ startingInstruction = 0 ;
6258 }
6359
6460 var backend_script = null ;
@@ -68,10 +64,8 @@ $(document).ready(function() {
6864 else if ( pyState == '3' ) {
6965 backend_script = python3_backend_script ;
7066 }
71-
72- if ( ! backend_script ) {
73- alert ( 'Error: This server is not configured to run Python ' + $ ( '#pythonVersionSelector' ) . val ( ) ) ;
74- return ;
67+ else if ( pyState == '2crazy' ) {
68+ backend_script = python2crazy_backend_script ;
7569 }
7670
7771
@@ -98,92 +92,48 @@ $(document).ready(function() {
9892 }
9993
10094
101- function executeCode ( forceStartingInstr ) {
102- $ . get ( backend_script ,
103- { user_script : preseededCode ,
104- raw_input_json : rawInputLst . length > 0 ? JSON . stringify ( rawInputLst ) : '' ,
105- options_json : JSON . stringify ( options ) } ,
106- function ( dataFromBackend ) {
107- var trace = dataFromBackend . trace ;
108-
109- // don't enter visualize mode if there are killer errors:
110- if ( ! trace ||
111- ( trace . length == 0 ) ||
112- ( trace [ trace . length - 1 ] . event == 'uncaught_exception' ) ) {
113-
114- if ( trace . length == 1 ) {
115- alert ( trace [ 0 ] . exception_msg ) ;
116- }
117- else if ( trace [ trace . length - 1 ] . exception_msg ) {
118- alert ( trace [ trace . length - 1 ] . exception_msg ) ;
119- }
120- else {
121- alert ( "Whoa, unknown error! Reload to try again, or report a bug to philip@pgbovine.net" ) ;
122- }
123- }
124- else {
125- var startingInstruction = 0 ;
126-
127- // only do this at most ONCE, and then clear out preseededCurInstr
128- if ( preseededCurInstr && preseededCurInstr < trace . length ) { // NOP anyways if preseededCurInstr is 0
129- startingInstruction = preseededCurInstr ;
130- }
131-
132- // forceStartingInstr overrides everything else
133- if ( forceStartingInstr !== undefined ) {
134- startingInstruction = forceStartingInstr ;
135- }
95+ // set up all options in a JS object
96+ var backendOptionsObj = { cumulative_mode : cumModeBool ,
97+ heap_primitives : heapPrimitivesBool ,
98+ show_only_outputs : showOnlyOutputsBool ,
99+ py_crazy_mode : ( pyState == '2crazy' ) } ;
100+
101+ var frontendOptionsObj = { startingInstruction : startingInstruction ,
102+ embeddedMode : true ,
103+ verticalStack : verticalStackBool ,
104+ disableHeapNesting : heapPrimitivesBool ,
105+ drawParentPointers : drawParentPointerBool ,
106+ textualMemoryLabels : textRefsBool ,
107+ showOnlyOutputs : showOnlyOutputsBool ,
108+ executeCodeWithRawInputFunc : executeCodeWithRawInput ,
109+ updateOutputCallback : ( resizeContainer ? resizeContainerNow : null )
110+
111+ // undocumented experimental modes:
112+ pyCrazyMode : ( pyState == '2crazy' ) ,
113+ highlightLines : typeof $ . bbq . getState ( "highlightLines" ) !== "undefined" ,
114+ }
136115
137- myVisualizer = new ExecutionVisualizer ( 'vizDiv' ,
138- dataFromBackend ,
139- { startingInstruction : preseededCurInstr ,
140- embeddedMode : true ,
141- verticalStack : verticalStackBool ,
142- disableHeapNesting : heapPrimitivesBool ,
143- drawParentPointers : drawParentPointerBool ,
144- textualMemoryLabels : textRefsBool ,
145- showOnlyOutputs : showOnlyOutputsBool ,
146- highlightLines : typeof $ . bbq . getState ( "highlightLines" ) !== "undefined" ,
147- executeCodeWithRawInputFunc : executeCodeWithRawInput ,
148- pyCrazyMode : ( pyState == '2crazy' ) ,
149- updateOutputCallback : ( resizeContainer ? resizeContainerNow : null )
150- } ) ;
151-
152- // set keyboard bindings
153- // VERY IMPORTANT to clear and reset this every time or
154- // else the handlers might be bound multiple times
155- $ ( document ) . unbind ( 'keydown' ) ;
156- $ ( document ) . keydown ( function ( k ) {
157- if ( k . keyCode == 37 ) { // left arrow
158- if ( myVisualizer . stepBack ( ) ) {
159- k . preventDefault ( ) ; // don't horizontally scroll the display
160- }
161- }
162- else if ( k . keyCode == 39 ) { // right arrow
163- if ( myVisualizer . stepForward ( ) ) {
164- k . preventDefault ( ) ; // don't horizontally scroll the display
165- }
166- }
167- } ) ;
168- }
169- } ,
170- "json" ) ;
116+ function executeCode ( forceStartingInstr ) {
117+ if ( forceStartingInstr ) {
118+ frontendOptionsObj . startingInstruction = forceStartingInstr ;
119+ }
120+ executePythonCode ( preseededCode ,
121+ backend_script , backendOptionsObj ,
122+ frontendOptionsObj ,
123+ 'vizDiv' ,
124+ NOP , NOP ) ;
171125 }
172126
173127
174128 function executeCodeFromScratch ( ) {
175129 // reset these globals
176130 rawInputLst = [ ] ;
177-
178131 executeCode ( ) ;
179132 }
180133
181134 function executeCodeWithRawInput ( rawInputStr , curInstr ) {
182- enterDisplayNoFrillsMode ( ) ;
183-
184135 // set some globals
185136 rawInputLst . push ( rawInputStr ) ;
186-
187137 executeCode ( curInstr ) ;
188138 }
189139
0 commit comments