-
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
12b Procedure calls #22
Conversation
Parsing CALL statementsCALLing a procedure is easy, since we don't have to deal with remembering types: Notice that we store BugfixWe should have used [783e918] |
Resolving CALL statementsNow let's resolve the call: A short todo-list for us to keep track of what needs to be checked. This is where the work of implementing procedures is: |
First, we check that the CALL has actually called a valid procedure: We do a preliminary check for number of arguments, so we don't run into iteration problems in the next part: Finally, we match up the args with the defined params:
|
BugCode:
Hmm ... that's because |
RefactoringTo do static type-checking in the resolver (instead of the interpreter), we will have to declare variables and procedures in the resolver: And we take this functionality out from the interpreter: [b52360e] |
Pretty-printingOur frame returns are getting pretty difficult to read. Let's make it easier: [9ff9076] Result:
|
Interpreting CALL statementsLet's implement the interpreter Before this can work, we have to add some missing code to do frame insertion in Quite similar to conditionals and loops, except we have to assign the args to variable names in the frame before we call the statements. |
BugImmediately we run into a bug: Result:
Remember that Well, when we assigned the procedure into the frame, we flouted this rule: |
More refactoringIn the process I ran into another annoying bug: [4c327b3]
And we are done with procedures ... for now. Next steps: to support BYREF and BYVALUE keywords, we need to allow procedures to run with their own frame instead of the global frame, so that we can pass some arguments by value (in a local frame). |
Now we figure out how to call procedures and execute those stored statements.
First, let's rectify an unfortunate choice of term: when defining procedures, we declare parameters not arguments; we will later call the procedure and pass arguments.
[c47a42a]