-
Notifications
You must be signed in to change notification settings - Fork 0
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
24b Improvements: Decoupling #64
Conversation
We should define interfaces like this for any class that gets inherited. Let's look at Expr: pseudo-9608/pseudocode/lang.py Lines 358 to 377 in ab0133c
Not having an Immediate implications: looks like we'll have to decouple Literal from TypedValue and give it its own pseudo-9608/pseudocode/lang.py Lines 381 to 392 in 7251472
And it now implements its own |
Looking at our expectations of what an Expr is and does: pseudo-9608/pseudocode/lang.py Lines 358 to 369 in 7c2d2a7
It seems like Name should no longer be considered an Expr: it does not resolve to a Type, and doesn't evaluate to a Value as well (note that names are not one of pseudo's types). So we take out its inheritance from Expr: pseudo-9608/pseudocode/lang.py Lines 396 to 407 in 7c2d2a7
It would, however, still be useful to retain the token associated with the name, so we'll keep that. |
The Now, many chapters later, this did not come to pass; for the most part each Expr will use a specific part of itself as the associated token. For example, Declare Exprs are always associated with their name token: pseudo-9608/pseudocode/parser.py Lines 348 to 353 in 7c2d2a7
It no longer makes sense to be passing tokens to Expr at init time then. Let's update Declare: [425544d], [a678a47] pseudo-9608/pseudocode/lang.py Lines 411 to 425 in a678a47
Note that we no longer need to call |
Similar changes for Unary and Binary: [7eec403], [5983f87] They also lose the superclass init. Unfortunately, their operators are passed as functions: we generally want to avoid Exprs knowing about how tokens work; we can pass tokens around but try not to extract information from them manually. This means we will have to instantiate Unary and Binary with a |
And finally, our most complex Exprs. Call no longer needs to hold on to a token: [9682e6e] pseudo-9608/pseudocode/lang.py Lines 484 to 496 in 9682e6e
pseudo-9608/pseudocode/lang.py Lines 500 to 511 in 9682e6e
|
A few fixes in the way we use Name: [06b3e87] This is mighty confusing. I'm going to redo this part when I figure out a way to pass names and tokens around more cleanly.
And then remove it: [622be6d] |
More fixes:
|
Next, typing fixes for various statement types: |
Then some renaming for better readability: [98383cd] Instead of Value, we now use PseudoValue to refer to pseudo's special value types (Callable, File, Array, Object, ...) Value, on the other hand, refers to any value which can be represented in a TypedValue. So this includes PsuedoValues, bool, int, float, str. |
What follows is a lot of mole-whacking for typing inconsistencies, which are ... too numerous to detail here. I simply aimed to have working code for now, and next chapter we will go about organising things in a clearer fashion that will make it easier for us to reason about the code. On the plate are:
|
pseudocode/interpreter.py:323: error: "Stmt" has no attribute "rule"
Let's start with this:
pseudo-9608/pseudocode/lang.py
Lines 496 to 497 in d59a6b0
This tells Python that the
Stmt
class has arule
class attribute, and any class that inherits this should override therule
attribute (or risk getting aNotImplemented
value when trying to access it`.And now that message goes away when we run
mypy
again.