This is similar (but not identical) to the change Adam was doing at the same type for occam.
I think the main difference is that rather than returning () from parsing a reserved word,
I return Meta so that you can easily write rules like:
do { m <- sSemiColon ; return $ A.Skip m}
The tests have also been updated to use the new parser, and fail on either a lexing or a
parsing error.
This is the code that expands array and record assignments out into multiple
assignments. Having it done as a pass means it can do a better job -- this
fixes some problems with cgtest56 where the old version of the code couldn't
handle record assignments from literals.
This is the first pass that's had to add a replicator to the tree, so this also
introduces a helper function for generating new replicator counters.
CompState now contains Sets and Maps, which aren't instances of Data and thus
break pshow. This could be fixed in the future by providing instance
definitions, assuming the GHC library maintainers don't beat us to it.
This means that field names end up as "foo_u123" rather than "foo" in the
generated source -- which is a good thing, because some of the cgtests use
field names like "bool" and "int".
This fixes a bug that cgtest56 exposed, where an array of a user-defined type
that was itself an array wound up being an array of arrays rather than a single
array.
As part of this, makeArrayType is now called addDimensions, and takes a list of
dimensions to add rather than just one.
isValidLiteralType was a bit too simplistic before; it needs to look at array
types one dimension at a time rather than trying to do the whole lot at once.
The types have been added to the AST. Beyond the obvious trivial changes (extra cases in functions, etc), the only
significant change was that isSafeConversion needed to be changed. I took the opportunity to totally rewrite the
function into a graph-like mechanism rather than just using a list. To demonstrate its correctness I also wrote an
exhaustive test for it.
This also makes sure that every function gets a stack size constant.
There are some functions which don't do any stack adjustment -- where GCC's
smart enough to just compile them to a "ret" (because it knows it needs a
function pointer, but also that the function does nothing). CCSP doesn't like
it when you ask for a stack size of 0; I haven't yet investigated why, but this is likely to change anyway once Carl's changes go into CCSP trunk.
This is another one for the list of occam oddities: there are situations where
both a hex literal and a preprocessor directive are legal, so the two can't be
ambiguous -- no #FACE or #ADA in the future!
The occam parser is now a GenParser Token OccState, rather than a GenParser
Char OccState, and a lot of now-redundant code has been removed. The parser is
also somewhat faster, which wasn't intended but is nice anyway.
I've also modified the Rain parser to not rely on the old preprocessing code;
it wasn't appropriate for Rain's syntax anyway, so I assume Neil will be
replacing it eventually.
This is because the structure pass needs to be able to tell where new lines
start, and if the line number changes in the middle of a token then it'll get
confused.
This looks more complicated than it is because it meant adding state to the
lexer -- it's now quite a neat little three-state machine.
This also renames DecimalLiteral to IntLiteral to match the rest of the code.
The parser now gets a stream of tokens, rather than needing to worry about
loading files itself.
This also reworks the lexer's idea of what constitutes a Token -- it's now a
pair (Meta, TokenType), so it's always easy to pull out/rewrite the metadata --
and adds proper support for lexing preprocessor directives, rather than just
treating them as reserved words.