js-slang icon indicating copy to clipboard operation
js-slang copied to clipboard

Source 3 Concurrent: Functions are not properly represented when passed to display or draw_data

Open jonchan51 opened this issue 4 years ago • 1 comments

display and draw_data expects actual JS functions. As Source 3 Concurrent is a VM, converting the machine's representation of a function to JS for these two functions is not so simple. We ended up passing a fixed string "<Function>" instead. Ideally, it should pass in a javascript function instead.

Relevant function: src/vm/svml-machine.ts's convertToJsFormat

Ideas

  • During compilation, pass the AST for all function definitions to the machine as well as some PC - AST mapping, which can be used by the machine to determine which machine function is which AST. Thereafter, use astring's generate to create the actual function object to be passed to these two displaying functions

jonchan51 avatar Apr 25 '20 04:04 jonchan51

Example test case:

display(x => x);

Expected output: x => x displays in the REPL, and after execution ends, the function is returned as the result of the program, which also gets rendered as x => x. Actual output: "<Function>" displays in the REPL, and the string "all threads terminated" is returned as the result of the program.

thomastanck avatar May 10 '21 05:05 thomastanck