1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-05-02 01:33:22 -07:00

update notes

This commit is contained in:
Connor Olding 2016-11-27 21:49:46 -08:00
parent 63ddf558df
commit 635621de0d

View File

@ -184,14 +184,13 @@ that Dumper can later understand.
the `:check` method the `:check` method
asserts that a token exists and is of a given type (`tt`). asserts that a token exists and is of a given type (`tt`).
it will defer to the `:lookup` method if the token type mismatches,
which isn't guaranteed to help.
preprocessing is split into three passes: preprocessing is split into two passes:
### pass 1 ### pass 1
resolves variables by substitution, parses expressions, resolves variables by substitution,
parses and evaluates expressions,
and collects relative labels. and collects relative labels.
this pass starts by creating a new, empty table of statements to fill. this pass starts by creating a new, empty table of statements to fill.
@ -200,11 +199,11 @@ statements are passed through, possibly modified, or read and left-out.
the reason for the copying is that taking indexes into an array (statements) the reason for the copying is that taking indexes into an array (statements)
that you're removing elements from is A Bad Idea. that you're removing elements from is A Bad Idea.
variable-declaring statements (`!VAR`) are read to a dictionary table, all expression tokens are evaluated,
for future replacement of their keys with values by the `:lookup` method. and all variable tokens are substituted.
note that the variable-parsing code itself calls `:lookup` through `:check`, variable-declaring statements (`!VAR`) are read to a dictionary table
so new variables can simply copy the values of previous variables. for future substitution of their keys with values.
labels (`!LABEL`) are checked for RELLABEL tokens to collect labels (`!LABEL`) are checked for RELLABEL tokens to collect
for later replacement in pass 2. for later replacement in pass 2.
@ -213,35 +212,18 @@ appended and prepended respectively.
the collection tables are arrays of tables containing the keys the collection tables are arrays of tables containing the keys
`index` and `name`. `index` and `name`.
every statement that isn't eaten has its tokens looked-up by the
`:lookup` method. at this state, it just handles variable substitution.
### pass 2 ### pass 2
resolves relative labels by substitution. resolves relative labels by substitution.
this code enables `self.do_labels` which tells `:lookup` to start
handling relative labels as well, now that they've all been collected.
`:lookup` is run on every token of every statement.
the appending/prepending done in pass 1 ensures the appending/prepending done in pass 1 ensures
that the appropriate relative labels are found in the proper order. that the appropriate relative labels are found in the proper order.
### pass 3
attempts to parse and evaluate constant expressions.
### room for improvment ### room for improvment
pass 3 (expressions) should be an attempt to evaluate constants,
and parsing should be moved to be part of pass 1.
looking back, the `new_statements` ordeal looking back, the `new_statements` ordeal
only seems necessary for the (poor) error handling it provides. only seems necessary for the (poor) error handling it provides.
the handling of statement tables could be made better.
## Expander ## Expander
expands pseudo-instructions, including the inferrence of implied registers. expands pseudo-instructions, including the inferrence of implied registers.