-
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
08 Static typing #15
08 Static typing #15
Conversation
TestingResult:
The debug message doesn't look too pretty, but we are getting the expected The resolver does not actually interpret/execute any code (besides DECLARE statements), so it only raises |
Name declarationTo carry out type checking, the resolver will have to handle name declarations: And that means There is definitely overlap with the interpreter here. I suspect this responsibility will eventually be transferred from interpreter to resolver. |
Resolving expressionsOur resolver does not need to interpret and execute statements. Besides resolving frames, we also want it to do some type checking. For a statically typed language like 9608 pseudocode, we should technically know the data type that each expression In the meantime, let's have |
Name and type checkinghttps://github.com/nyjc-computing/pseudo/blob/26713911a341ded30c666a3abf92925510cd8f05/resolver.py#L32-L36 https://github.com/nyjc-computing/pseudo/blob/26713911a341ded30c666a3abf92925510cd8f05/resolver.py#L7-L12 |
Resolving expressionshttps://github.com/nyjc-computing/pseudo/blob/3739cf576e6093e46bde38b947260e6ccfbfb128/resolver.py#L19-L32 |
TestingTook out the [739469c] Result:
|
Bug
Now we can't declare names: they get caught by our name check. We should carry out the name check only for |
We now have the infrastructure in place for checking names before they are retrieved from the frame, and checking value types before they are assigned to names. All this, done before the interpreter carries out any interpreting. |
Static typing
9608 pseudocode is a statically typed language. Notice that when declaring variables, we declare their type as well. And the pseudocode operators and functions expect specific types in most cases:
Static typing implies that the value and variable types should be known at compile time. This means that before we step into
interpret()
, the interpreter should already know what it is dealing with, and be reasonably sure it can execute statements safely in most cases.In other words, we shouldn't be seeing much type-checking code like
It is telling that this is a
LogicError
: it could have been checked before we attemptedinterpret()
ing.It sure seems like this is a job our resolver should take on while it is inserting
frame
s intoget
s; it feels right, too, that as it inserts frames it also checks types.