|
1 | 1 | # Ruby backend for Online "Python" Tutor |
2 | 2 | # created on 2015-06-29 by Philip Guo |
| 3 | +# first deployed on 2015-07-15 |
3 | 4 | # |
4 | 5 | # WARNING: this script only works on a *hacked version* of Ruby 2.X since |
5 | 6 | # we use the TracePoint API and custom fields such as binding::frame_id. |
|
10 | 11 |
|
11 | 12 | # TODO |
12 | 13 | # |
13 | | -# fix these tests: |
14 | | -# |
15 | | -# in frontend, maybe '=' isn't a valid CSS selector. also escape '?' too |
16 | | -# tests/blocks-iterate.rb |
17 | | -# |
18 | | -# - test syntax errors in the OPT frontend |
19 | 14 | # - display the 'binding' within a proc/lambda object, which represents |
20 | 15 | # https://codequizzes.wordpress.com/2014/04/07/rubys-self-keyword-and-implicit-self/ |
21 | 16 | # its closure. test on tests/proc-return.rb |
22 | | -# - support gets() for user input using the restart hack mechanism |
23 | | -# - user input stored in $_ |
24 | | -# - support 'include'-ing a module and bringing in variables into namespace |
25 | | -# - maybe this already works? |
26 | | -# - cosmetic issues in the OPT frontend for Ruby: |
27 | | -# - relabel "Global frame" as "Globals" or something |
28 | | -# - display None values as 'nil' |
29 | | -# - display booleans as 'true' and 'false' |
30 | | -# - rename 'list' to 'array' - check |
31 | | -# - rename 'dict' to 'hash' - check |
32 | | -# - rename 'instance' to 'object' - check |
33 | | -# - rename 'function' to 'method' - check |
34 | | -# - display private and protected attributes |
| 17 | +# |
| 18 | +# - support gets() for taking user input using the restart hack mechanism |
| 19 | +# that we used for Python. user input stored in $_ |
| 20 | +# |
| 21 | +# - properly display private and protected attributes |
35 | 22 | # |
36 | 23 | # Limitations/quirks: |
37 | | -# - no support for (lexical) environment pointers, since MRI doesn't seem to |
38 | | -# expose them. We can see only the current (dynamic) stack backtrace |
39 | | -# with debug_inspector. |
| 24 | +# - no support yet for (lexical) environment pointers, since MRI doesn't |
| 25 | +# seem to expose them. We can see only the current (dynamic) stack |
| 26 | +# backtrace with debug_inspector. |
40 | 27 | # - NB: is this true? at least we have 'binding' for procs/lambdas |
41 | 28 | # |
42 | | -# - keeps executing for a few more lines after an exception -- dunno if |
| 29 | +# - it keeps executing for a few more lines after an exception -- dunno if |
43 | 30 | # that's standard Ruby behavior or not |
44 | 31 | # |
45 | | -# - method aliases show up as separate Method objects instead of the |
46 | | -# same one |
| 32 | +# - method aliases show up as separate Method objects instead of the same one |
47 | 33 | # |
48 | 34 | # - if you write, say, "require 'date'", it will pull in classes from |
49 | 35 | # the date module into globals, which might make the display HUGE |
@@ -366,7 +352,6 @@ def encode(dat) |
366 | 352 | toplevel_constants = (Module.constants - base_constants_set) # set difference |
367 | 353 | entry['ordered_globals'].concat(toplevel_constants.map { |e| e.to_s }) |
368 | 354 | toplevel_constants.each do |varname| |
369 | | - #val = eval(varname.to_s) # TODO: is there a better way? this seems hacky! # yes, see below |
370 | 355 | val = Module.const_get(varname) |
371 | 356 | globals[varname.to_s] = pg_encoder.encode(val) |
372 | 357 | end |
@@ -527,7 +512,7 @@ def self.iseq_local_variables iseq |
527 | 512 | n_lines_added = 1 |
528 | 513 | else |
529 | 514 | cod << "\nnil" |
530 | | - n_lines_added = 2 |
| 515 | + n_lines_added = 1 # pretty sure this is 1 and not 2 |
531 | 516 | end |
532 | 517 |
|
533 | 518 | eval(cod) # the filename of the user's code is '(eval)' |
|
0 commit comments