Commit Graph

106 Commits

Author SHA1 Message Date
Neil Brown
e648a87fd1 Turned REM into \ in the parser, as that was the easiest place to do it 2009-04-07 15:43:56 +00:00
Neil Brown
095e3e1680 Fixed the parsing of associative operators 2009-04-07 15:43:41 +00:00
Neil Brown
f7e114f2fd Overhauled the Types module and ParseOccam to support the new system of operators-as-functions
The idea behind this is to parse unary/binary operators into function calls with 1/2 operands.  So the AST actually has a FunctionCall with the name "+".  Function names may now be quoted operators, and thus you can also have function declarations with names such as "+".  Resolving is *not* done in the parser for these function names, but rather every "+" is left as "+" (no matter what types it operates on, or what is in scope) by the parser (see later patches to InferTypes instead).

When parsing an occam source file, we automatically insert a bunch of PRAGMA TOCKEXTERNAL that define the default occam operators (e.g. + on INT) as external C functions (which they are!).  The naming scheme for these C functions is standardised, and must be used by functions such as mulExprs (which bases the function on the type of its operands) and the new versions mulExprsInt (which are pegged to INT).

The Types module also has some new functions for dealing with operator-functions.
2009-04-05 22:54:05 +00:00
Neil Brown
364bc6f31e Made double-star be resolved into a single star when parsing a string literal
I should probably do all the other escapes too, but for now I haven't.
2009-04-05 22:29:32 +00:00
Neil Brown
e457d82f0c Changed FUNCTIONs and PROCs to have optional bodies, and put all the externals into the AST (without bodies)
This may seem like an odd change, but it simplifies the logic a lot.  I kept having problems with passes not operating on externals (e.g. functions-to-procs, adding array sizes, constant folding in array dimensions) and adding a special case every time to also process the externals was getting silly.

Putting the externals in the AST therefore made sense, but I didn't want to just add dummy bodies as this would cause them to throw up errors (e.g. in the type-checking for functions).  So I turned the bodies into a Maybe type, and that has worked out well.

I also stopped storing the formals in csExternals (since they are now in csNames, and the tree), which streamlined that nicely, and stopped me having to keep them up to date.
2009-04-04 14:56:35 +00:00
Neil Brown
2a321d7910 Added a NameExternal item to NameSource, to stop using NamePredefined for externals 2009-04-04 14:56:00 +00:00
Neil Brown
f755458545 Turned *EXTERNAL pragmas into specifications in the occam parser
There was a bug where things scoped in via pragmas were never scoped out again, which was screwing up the local names stack.  I then realised/decided that pragmas were really specifications, and decided to put them there in the parser.

The rest of this patch is just some rewiring to allow the special name munging involved in pragmas (they have already got a munged version of their name) and to stop the scoped in pragmas appearing in the AST.
2009-04-03 21:06:24 +00:00
Neil Brown
4a36d578c0 Added a check that the names being scoped out match the names that were scoped in, which helps find bugs in the parser 2009-04-03 21:03:19 +00:00
Neil Brown
8220630426 Attempted to fix a problem with parsing pragmas, but I suspect it's still a bit haphazard 2009-04-03 16:50:41 +00:00
Neil Brown
0d63eeb400 Fixed a small parser bug involving variant 2009-04-03 15:34:33 +00:00
Neil Brown
70789661f1 Got pragma-declared FUNCTIONS to be turned into PROCs and handled properly 2009-04-02 18:13:51 +00:00
Neil Brown
460c3e287f Changed names to be uniquified based on their source position, and fixed the source position for things in pragmas
The second part of the patch is essential, given the first.  Otherwise names in different pragmas in the same file can overlap -- this already happened in oak!
2009-04-02 17:45:31 +00:00
Neil Brown
a843d07463 Changed the pragmas to support FUNCTIONs, and to order the names the other way (as Adam wanted) 2009-04-02 16:57:11 +00:00
Neil Brown
9e3e71c70a Added a bit of extra help when a name is not found (suggesting other names) 2009-04-02 15:42:02 +00:00
Neil Brown
51f67f59b4 Reworked the pragma generation again for occam PROCs
One change, based on Adam's suggestion, was to rename the pragma to TOCKEXTERNAL.

Another, also based on Adam's suggestion, was to generate both the munged name and the original name, which allows (along with a previous patch) different files to declare the same PROC, and will remove the need for the occam_ prefix in the backend.

I also stopped using specific states in the lexer, in favour of just using the normal lexing function (which has had its type generalised slightly).
2009-04-02 15:33:32 +00:00
Neil Brown
ca818d423c Made the munging of the names include the file name, to help with separate compilation
This will allow (along with a few patches in a minute) different occam files to declare the same PROC, and have it resolved correctly based on the order of their declaration, just like if it was all in one file.
2009-04-02 15:31:50 +00:00
Neil Brown
c79fd70959 Made sure that warnings are shown along with errors in the parser
The solution is a bit hacky, but this was an important problem.  If your PRAGMA failed to parse, that was worthy of a warning.  But if that then caused the parse to fail, all you would get is the parser error (could not find name), and you would never see the warnings about the pragmas not being recognised.  So now the pragmas are shoved into the error (using a basic encoding) and pulled out and issued if the parser dies.
2009-04-02 15:07:39 +00:00
Neil Brown
7e7a437a3b Switched to using a different kind of pragma for occam externals, and munged the names to avoid collisions
The separately compiled occam PROCs now use #PRAGMA OCCAMEXTERNAL, which also discards the "= number" thing at the end.  These PROCs then need to be processed differently when adding on the sizes (C externals have one size per dimension, occam externals have the normal array of sizes).

We also now record which processes were originally at the top-level, and keep their original names (i.e. minus the _u43 suffixes) plus an "occam_" prefix to avoid collisions.
2009-04-01 19:21:40 +00:00
Neil Brown
7b55c96781 Fixed up the parsing of PRAGMAs to make it a bit simple, and match with other changes to the lexer and parser 2009-04-01 17:26:27 +00:00
Neil Brown
512d05dd36 Removed the redundant warnings from the occam parser (after I put them back into CompState, a long time ago) 2009-04-01 16:56:37 +00:00
Neil Brown
334d22acd8 Corrected a try, so that we don't mistake a CHAN type for a CHAN TYPE type 2009-03-31 11:50:24 +00:00
Neil Brown
dbc3b97343 Changed the lexing and parsing of PRAGMAs again, to allow unknown pragmas
With my previous change to PRAGMAs, unknown pragmas would fatally fail in the lexer, so that an unknown pragma would always stop compilation, which is not good.  I've changed it more towards Adam's suggestion of re-lexing and re-parsing the pragma from the parser, so we now gracefully ignore unknown pragmas again.  The lexer is a bit messy, though.
2009-03-31 11:08:53 +00:00
Neil Brown
c46346ffa2 Changed the occam parser to parse SIZE followed by a variable into the new VariableSizes item 2009-03-30 15:33:36 +00:00
Neil Brown
eb99480484 Finished off the support for external C functions 2009-03-26 22:37:28 +00:00
Neil Brown
5418916245 Added the parsing of channel-array literals in PROC parameters 2009-03-25 16:38:21 +00:00
Neil Brown
7cbe98d200 Modified the lexer and parser to be able to parse PRAGMA EXTERNAL (and added #DEFINE support in the lexer) 2009-03-25 16:36:59 +00:00
Neil Brown
45b22472c3 Changed the rest of tock to reflect the changes to the Is constructor 2009-03-24 23:57:24 +00:00
Neil Brown
030e06f173 Allowed pragmas at the top-level of an occam file 2009-03-24 02:15:23 +00:00
Neil Brown
19e0fb0573 Added an AllocChannelBundle constructor in ExpressionList for assignments that allocate the two ends of a mobile channel bundle 2009-03-23 18:58:50 +00:00
Neil Brown
41805aaacf Changed the ChanEnd constructor to only keep information about its shared-ness, not about the whole channel 2009-03-23 18:40:28 +00:00
Neil Brown
ef4c73aece Added support in the parser for allocating mobile channel bundles, and for shared normal channels 2009-03-23 15:54:49 +00:00
Neil Brown
69d7bc6455 Fixed recursive channel bundle types to work properly 2009-03-23 15:54:24 +00:00
Neil Brown
084861e0be Altered the parser to change CLAIM from being a process into a specification 2009-03-23 15:52:44 +00:00
Neil Brown
5f9d0c6429 Added various keywords, AST elements and parser bits related to channel bundles, claim blocks and shared channels 2009-03-22 22:49:49 +00:00
Neil Brown
8492dc03d4 Introduced a ShareMode in the AST, and used it in the channel attributes (rather than Bool) 2009-03-22 22:29:39 +00:00
Neil Brown
03f1b2d115 Added a few more mobile things (DEFINED keyword, an intrinsic) 2009-03-20 20:53:51 +00:00
Neil Brown
86f0218899 Changed the occam parser to understand the MOBILE and CLONE keywords 2009-03-20 15:17:43 +00:00
Neil Brown
81959bd76b Added quick preliminary support for the PERMITALIASES pragma 2009-02-10 01:01:23 +00:00
Neil Brown
46394b8c34 Fixed the occam and Rain parsers to work with the new system for array literals 2009-02-01 21:54:02 +00:00
Neil Brown
8a28d765e7 Implemented recursive procs
This works fine in the C++ backend, not tested with the C backend yet
2009-01-29 00:43:24 +00:00
Neil Brown
7722e95dfd Added support for recursive functions (not procs, yet)
At the moment, the information is only needed in the parser, which must define recursive names before parsing the body of the function.  But in future, we should keep the information when the function becomes a proc, and then the C/C++ backends may need to use it (for example, when calculating stack space usage)
2009-01-29 00:27:11 +00:00
Neil Brown
6d7f456791 Changed the occam parser to accept STEP in replicators 2009-01-28 23:47:00 +00:00
Neil Brown
49ea4f053e Fixed the occam parser to allow comments after pragmas on the same line
One of the more recent cgtests has a comment after a pragma
2009-01-28 23:40:14 +00:00
Neil Brown
6ff8e3b163 Fixed a bug where records were being recorded with the wrong name type in the occam parser 2009-01-28 22:11:23 +00:00
Neil Brown
4d692c8897 Fixed the occam and Rain parsers to work with the new channel-ends
For now, I have fixed the occam parser so that it allows 1 or more direction specifiers after channel names.  So c?? is valid, and should end up being equivalent to c?, but this may need altering later.
2009-01-20 17:28:57 +00:00
Neil Brown
8a36f6e96f Added support for parsing pragmas, for now just handling the SHARED pragma 2009-01-19 15:11:09 +00:00
Neil Brown
0e7a6c5b98 Added a NameSource field for NameDef that indicates where a name comes from 2008-11-25 17:36:42 +00:00
Neil Brown
0d486f108f Added a value to indicate what type a warning is (to support future configurability) and streamlined the warning functions 2008-11-13 15:36:22 +00:00
Adam Sampson
f102d8e7ef Make "PORT" work for "PORT OF". 2008-06-11 13:18:54 +00:00
Adam Sampson
638a3f3c22 Allow a directed channel array to be sliced.
This lets you write things like "[cs! FOR 5]", which is horrible; I
would prefer "[cs FOR 5]!", since then that doesn't imply that you can
do things like "cs![0] ! 0".

However, Tock now compiles and passes cgtest87 -- the first occam-pi
cgtest we've handled. :)
2008-06-09 21:42:34 +00:00