A
On 28 April 2018 at 20:21, Peter Uhnák <[email protected]> wrote:
> What would entail actually extending the syntax and adding the set literal?
>
> From my brief observations (when I was discussing this with OP on discord):
>
> * adding a new AST node
> * extend RBParser
> * extend IRMethod/IRTranslator... maybe generating bytecode for `{ ... }
> asSet` instead would be enough? (not sure how debugger would react to this)
>
> anything else? Would VM changes be required?
>
> I added
>
'{' binarySelector expr '.' ... '.' expr ['.'] '}'
to my compiler because I was sick of other people being
able to write stuff more elegantly in Python than I could
in Smalltalk. Here the binarySelector controls what kind
of set:
= Set
== IdentitySet
?= CaseInsensitiveSet
< SortedSet (splay trees)
> SortedSet (with comparison reversed)
<> TernarySet (ternary search string for strings).
I'm not happy with the syntax, but it's the least ugly I've
been able to find. Having syntax only for Set would be so
limiting there'd be no real point.
So. No change to the scanner.
No change to the abstract syntax trees.
{== x. y}
generates the same syntax tree that
((IdentitySet new: 2) add: x; add: y; yourself)
would have done.
And therefore no change to the back end code
generator.
The *only* change was the parsing routine that
responds to '{'.
The fundamental issue is WHY you want an extension
to the syntax. In my case, the {binarySelector exprs}
syntax for sets and corresponding #{binarySelector maplets}
syntax for dictionaries were to let me approximate the
brevity of Python and Javascript. I didn't need new
*semantics*.
In contrast, the ##(expr) syntax in Dolphin, Smalltalk/X,
and whatever others does NOT offer brevity at all but
DOES offer new semantics. To the limited, not to say
derisory, extent to which I understand the Dolphin compiler,
it does have a special StOptimizedNode type of AST node
for ##(...) forms. I don't *think* any VM changes are
needed, unless of course you want to be able to decompile
the byte-code and recover the ##(expr) source. I don't
have a Windows box any more, so I can't run Dolphin,
sorry, just admire it. I can say that it takes care not
to put literals inside a ##(expr) form in the literal
table.