Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide type.slots for Ven's walker #549

Open
masak opened this issue Sep 25, 2019 · 2 comments
Open

Provide type.slots for Ven's walker #549

masak opened this issue Sep 25, 2019 · 2 comments

Comments

@masak
Copy link
Owner

masak commented Sep 25, 2019

These 41 LoC:

BEGIN my attrList = [
# simple recursion
[Q.Term.Object, ["propertylist"]],
[Q.Term.Dict, ["propertylist"]],
[Q.Property, ["value"]],
[Q.Trait, ["identifier", "expr"]],
[Q.Term.Func, ["identifier", "traitlist", "block"]],
[Q.Block, ["parameterlist", "statementlist"]],
[Q.Prefix, ["identifier", "operand"]],
[Q.Infix, ["identifier", "lhs", "rhs"]],
[Q.Postfix, ["identifier", "operand"]],
[Q.Postfix.Index, ["index"]],
[Q.Postfix.Call, ["argumentlist"]],
[Q.Postfix.Property, ["property"]],
[Q.Unquote, ["qtype", "expr"]],
[Q.Unquote.Prefix, ["operand"]],
[Q.Unquote.Infix, ["lhs", "rhs"]],
[Q.Term.My, ["identifier"]],
[Q.Term.Quasi, ["qtype", "contents"]],
[Q.Parameter, ["identifier"]],
[Q.Statement.Expr, ["expr"]],
[Q.Statement.If, ["expr", "block", "else"]],
[Q.Statement.Block, ["block"]],
[Q.Statement.For, ["expr", "block"]],
[Q.Statement.While, ["expr", "block"]],
[Q.Statement.Return, ["expr"]],
[Q.Statement.Throw, ["expr"]],
[Q.Statement.Func, ["identifier", "traitlist"]],
[Q.Statement.Macro, ["identifier", "traitlist", "block"]],
[Q.Statement.BEGIN, ["block"]],
[Q.Statement.Class, ["block"]],
[Q.Expr.BlockAdapter, ["block"]],
# array recursion
[Q.TraitList, ["traits"]],
[Q.Term.Array, ["elements"]],
[Q.PropertyList, ["properties"]],
[Q.ArgumentList, ["arguments"]],
[Q.ParameterList, ["parameters"]],
[Q.StatementList, ["statements"]],
];
shouldn't be needed.

If we could just get that information from the individual type objects, that would be much preferable.

Rough sketch: you have a type T, and you call T.slots(). An Array of Slot instances is returned. For our purposes here, it's enough that a slot has a slot.name. Later, we can extend the design of Slot into whatever #490 requires. (Accessors, whatever.) We're sticking to the name "slot" here (instead of "field" or "member" or "attribute") because going forward, we're going to be adhering pretty close to CLOS and Dylan in our object system.

What the walker script does with the attribute name attr is get the attribute by saying root[attr]. This idiom comes from a time in Alma when objects were interchangeable with dicts; they're not any more, but the idiom remains. When we remove it, we'll have to be sure to have some other general way to get an attribute from an object, either by string, or maybe the Slot can provide an actual getter function...? (Great for introspection, but a death knell for "true privacy" of private slots. On the gripping hand, my understanding as an OO language designer is that true privacy never existed in the first place, when you're either high-enough up in the MOP clouds, or low enough in the bytecode gutter. It's more like an "everyday" restriction for when you're in neither of those extremes.)

This issue can be considered fulfilled when a rebased ven-walker runs on top of a PR that provides slots on the types, and it doesn't need its own attrList because it can use the built-in instead.

@vendethiel
Copy link
Collaborator

vendethiel commented Oct 9, 2019

Related from #242 ?

  • There's a pattern that started to show up involving type-chain.reverse.map — finding all the fields, including inherited ones, for example. Find all the uses of this pattern and extract one or more appropriate methods into Type

@masak
Copy link
Owner Author

masak commented Oct 10, 2019

@vendethiel Yes. Looking closer, it happens twice in that branch, at least in that file. Once is for default stringification (recursing over all attributes), and once is for the Q-cloning in the detach method.

Both of these are kind of "internal", in the base source code of 007/Alma itself, and not in user code. On the other hand, such distinctions are kind of moot in the long run, as we attain self-hosting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants