The general approach seems to be correct, but I think I found an error in the decompilation of literal variables such as Array. I sent Compiler-ct.425 to the inbox which should fix this issue.
Hi all,
I'm currently trying to implement #parseNodeWith: on SyntaxMorph, in order to embed SyntaxMorphs into regular tiles. (Did this ever work in past?)
I'm afraid the attempt in the commit below does not work yet; you can create a script editor, but parsing is erroneous, so you cannot execute the script.
To reproduce:
Compile the following:
MyPlayer >> examplePlayerCode
self forward: 6 * 7.
self turn: (11 raisedTo: 13 modulo: 97)
and evaluate:
| e p |p := Morph new openInWorld assuredPlayer.e := (MyPlayer >> #examplePlayerCode) decompile asScriptEditorFor: p.e openInHand.
In Player>>#acceptScript:for:, #generate: is called on node, and
when I decompile the result, I get a strange result:
examplePlayerCodeTest
self forward: 6 * 7.
self
forward: (#forward: forward: #forward:).
I don't know how to use #generate: exactly, but other senders usually appear to recompile a method before passing it to #generate:.
For comparison:
[ (Collection >> #asArray) decompile generate: CompiledMethodTrailer empty ] fails, but
[ m := (Collection >> #asArray) decompile.
Why is that recompilation required but decompilation is insufficient? Is this some bug, or is it expected behavior?
However, in the case of SyntaxMorph, I don't know how to recompile the node before, as a SyntaxMorph should be able to represent a node of an arbitrary type that must not be constrained to a MessageNode. So how could I solve the problem to generate code from SyntaxMorphs?
tl;dr: What is the full story of #generate: and how can it be made to work in this example?
Many thanks in advance! :-)
Best,
Christoph