Execute Brain****/J: Difference between revisions

no edit summary
(Created page with '<lang J>require'misc' NB. operations inc=: 1 0 +/@,: ] dec=: _1 0 +/@,: ] INC=: ] +/@,: -@>:@ptr {. 1: DEC=: ] +/@,: -@>:@ptr {. _1: OUT=: ][ ptr output@{ extend ACC=: ] input`…')
 
No edit summary
Line 117:
The buffered I/O implementation here prompts the user for a line of code whenever a character is needed and none has been provided. The prompt will be a blank line. Output is flushed before prompting the user and when completing a program. If a program terminates prematurely (because of an interrupt or a bug), unflushed output will appear in the variable OBUF.
 
Note this implementation encodes branch targets into the compiled code, and that <code>compile</code> assumes that <code>[</code> and <code>]</code> are balanced. Unbalanced brackets are not supported (and will cause the first instruction of the program to be replaced with an unspecified branch instruction).
 
You can also use <code>trace</code>, instead of <code>run</code>. <code>trace</code> takes the same arguments as run, but will return every state the tape went through, instead of the final state. This is mostly interested for understanding the behavior of small programs.
6,951

edits