Commit Graph

106 Commits

Author SHA1 Message Date
Neil Brown
41cca68e4e Simplified the Rain parser by reintroducing a RangeLiteral item that will get replaced by an early pass 2009-02-03 12:24:10 +00:00
Neil Brown
957699313f Combined ArrayLiteral and ListLiteral into ArrayListLiteral, and dispensed with ArrayConstr in favour of having array literals as Structured Expression that can contain replicators 2009-02-01 21:50:39 +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
a68c871329 Added an expression to represent a STEP count to the For replicator constructor in the AST 2009-01-28 23:42:31 +00:00
Neil Brown
52459e7557 Turned on usage checking by default
I think the Tock usage checking is now sufficiently advanced (it only rejects one or two parts of the cgtest at the moment) to turn it on by default
2009-01-28 17:34:34 +00:00
Neil Brown
1410e80fb1 Added support for intrinsic functions with multiple return values
Previously, such a function was an IntrinsicFunctionCall inside one expression of an ExpressionList, which the type-checker rejected.  I've had to add a new constructor to ExpressionList, and I've quickly hacked together the line in the C backend to make it work -- but it does seem to work.
2009-01-23 18:58:52 +00:00
Neil Brown
541f7c1421 Turned the Chan type into a Chan type for full channels and a ChanEnd type for the directed ends
This is the first patch in the series of many that implement this change throughout Tock.

Fixes #70.
2009-01-20 17:25:19 +00:00
Neil Brown
f612b99a49 Added a map of name attributes (ready for things like PRAGMA SHARED) to the CompState
This should possibly (and could in future) be combined into NameDef and the main csNames map
2009-01-19 15:10:05 +00:00
Neil Brown
0a98db5295 Changed pshow on CompState (which caused errors) to plain show, by adding a Show instance to CompState 2009-01-15 20:59:37 +00:00
Neil Brown
46a1cc311f Moved a couple of fields related to Rain type checking out of CompState and into a temporary StateT monad for the appropriate pass 2008-12-02 20:59:26 +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
6cbdc0e13b Finally merged the list of warnings into CompState rather than having its own StateT monad 2008-11-20 13:35:44 +00:00
Neil Brown
f88c671cf7 Added a set of enabled warnings to CompState 2008-11-20 13:17:05 +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
Neil Brown
192ccd4e2c Extended the type unification for Rain to support type-checking things that are being poisoned (which could be either end of a channel) 2008-09-12 14:40:04 +00:00
Neil Brown
00a719a451 Added a new InjectPoison process to the AST 2008-09-11 22:16:52 +00:00
Adam Sampson
23e1ba2eec Remove an "in the future" comment that's been done. 2008-06-06 10:15:43 +00:00
Neil Brown
41ff60cb78 Removed the Rep constructor from Structured and instead added a Rep constructor to SpecType
This way, all replicators are declared like other names, and their scope is considered replicated.  This simplifies the code a little.

Fixes #55
2008-06-04 17:00:43 +00:00
Adam Sampson
6ee21f76c9 Initial work on supporting INITIAL and RESULT abbreviations.
This fixes the AST, parser and typechecker, and adds a pass to
transform Result back into Abbrev, but doesn't transform Initial yet.
(It actually works for trivial stuff anyway, but it won't do the right
thing for complex types or PROC parameters.)

It appears (to me) to make sense to support INITIAL/RESULT reshaping
and retyping too, so this does.

Refs #42.
2008-06-02 20:41:37 +00:00
Adam Sampson
cf79f9c284 Get rid of the nasty ghost names hack.
Rather than prefixing the names, there's now a set of ghost names in
CompState.

Fixes #66.
2008-06-02 10:58:26 +00:00
Adam Sampson
36e7353ee7 Take NameType out of NameDef.
NameType is only really needed in the parser, so this takes it out of
NameDef, meaning that later passes defining names no longer need to
set an arbitrary NameType for them. The parser gets slightly more
complicated (because some productions now have to return a SpecType
and a NameType too), but lots of other code gets simpler.

The code that removed free names was the only thing outside the parser
using NameType, and it now makes a more sensible decision based on the
SpecType. Since unscoped names previously didn't have a SpecType at
all, I've added an Unscoped constructor to it and arranged matters
such that unscoped names now get a proper entry in csNames.

Fixes #61.
2008-06-02 10:13:14 +00:00
Adam Sampson
8b3eba594d Add SubscriptCheck field to SubscriptFromFor etc.
This makes it possible to mark a slice as not needing runtime
checking, which is immediately useful for _sizes arrays.

This fixes cgtest03, which was previously failing to compile because
the _sizes array for one of the constants in it contained a runtime
check and thus wasn't itself constant. I've added a testcase file for
the relevant bit of code.
2008-05-26 17:36:26 +00:00
Adam Sampson
b413cf3dc2 Fix some broken Haddock. 2008-05-25 18:49:15 +00:00
Neil Brown
d044b51335 Renamed ndType to ndSpecType, as per Trac ticket #59 2008-05-21 13:38:51 +00:00
Neil Brown
90986ea97b Added a backend that prints out the AST as source (rather than dumping the raw AST) 2008-05-17 22:20:38 +00:00
Neil Brown
ab0301a342 Made the Rain parser actually record an unknown (to-be-inferred) type for numeric literals 2008-05-17 14:24:45 +00:00
Neil Brown
f10cb7d525 Moved the TypeExp type out to its own module, UnifyType 2008-05-17 14:21:57 +00:00
Neil Brown
f8b7e8f8cb Added unifying-related items to CompState, and changed all the uses of ST to IO in the TypeUnification module
As part of this patch I also had to provide a Data instance for TypeExp (to allow CompState to still be an instance of Data).  Using IORefs is easier than STRef RealWorld, and puts everything in terms of IO (which is already in PassM) rather than ST (which would require more lifting).
2008-05-17 12:50:52 +00:00
Neil Brown
e6162877af Changed the AST to fix the different unknown/inferred types
The Infer type (used by the occam frontend) is now separated from the "Unknown" types used in type unification that I'm experimenting with in Rain.
2008-05-17 12:47:31 +00:00
Neil Brown
962c1477b9 Added a special type for marking the type of numeric literals to be inferred later 2008-05-14 11:59:33 +00:00
Neil Brown
3daf82d318 Merged Alternative and AlternativeCond into a single Alternative item that always has a pre-condition 2008-04-03 14:52:37 +00:00
Adam Sampson
710be039cb Have the pregen programs figure out the types using generics.
Previously they had a list of the types they needed to generate
instances for.  This patch adds some helper code that can be used to
list all the AST.* types in the AST automatically. The result is that we
should be able to add new types to the AST without needing to change the
generator code.

This also means that GenOrdAST is now generating *all* the instances of
Ord for the AST; previously the trivial ones were derived by the
compiler.
2008-05-09 14:02:13 +00:00
Adam Sampson
c4f147f5db Rewrite findMeta in terms of listify.
It'll now recurse into the data item you give it, which means it works
on types like Actual where the Meta isn't an immediate child.
2008-04-07 22:31:18 +00:00
Adam Sampson
8cedbed5fc Move makeUniqueName and findUnscopedName into CompState. 2008-04-06 17:42:12 +00:00
Adam Sampson
249fd23e75 The type context is now used by passes, not the parser. 2008-04-06 02:59:34 +00:00
Adam Sampson
475a77404c Handle the RHS type of A.Counted consistently.
Previously the parser set it to the element type, but everything that used it
set it to the type of the whole array. Now it's documented in AST.hs, and the
parser makes it the type of the whole array, since that's almost always what
you really want later on.
2008-04-06 00:09:23 +00:00
Adam Sampson
e52b51b050 Add an Infer type to mark types that should be inferred.
We can then check it's been removed using a property later.
2008-04-04 12:09:33 +00:00
Adam Sampson
3283b7db41 Remove the Type/AbbrevMode information from Actual*.
It's redundant, since you can always compute them from the variable, and it
makes the code that deals with actuals rather cleaner.

On the other hand, it slightly complicates some of the tests, because any names
you use in an Actual need to be defined...
2008-03-26 18:16:09 +00:00
Neil Brown
ceafd77c1e Removed Wait, GetTime and AlternativeWait (the old Rain time items) from the AST 2008-03-24 15:15:54 +00:00
Neil Brown
cbbafffbd2 Changed Rain to use the new timer type rather than things like the GetTime statement 2008-03-24 13:50:14 +00:00
Neil Brown
c68aa42277 Added a sub-type to Timers, to support multiple types 2008-03-23 22:20:16 +00:00
Neil Brown
7f28d3dbe3 Added a warnPC function (like diePC) for use with formatCode 2008-03-22 18:34:40 +00:00
Adam Sampson
7c4275116e Various cleanups to AST.hs.
No code changes; just reformatting.
2008-03-20 22:18:32 +00:00
Neil Brown
bc7e682119 Added a Concat operator for lists, and added support for it (and list assignment) to the backends 2008-03-21 19:20:15 +00:00
Neil Brown
9d0459cb75 Added a ListLiteral item to the AST 2008-03-19 15:58:34 +00:00
Neil Brown
ff9c0549ca Added types to the array constructor items in the AST 2008-03-19 13:21:12 +00:00
Adam Sampson
b1416bb0cf Change A.Dimension to take an Expression, not an Int.
This touches an awful lot of code, but cgtest07/17 (arrays and retyping) pass.

This is useful because there are going to be places in the future where we'll
want to represent dimensions that are known at runtime but not at compile time
-- for example, mobile allocations, or dynamically-sized arrays. It simplifies
the code in a number of places.

However, we do now need to be careful that expressions containing variables do
not leak into the State, since they won't be affected by later passes.

Two caveats (marked as FIXMEs in the source):

- Retypes checking in the occam parser is disabled, since the plan is to move
  it out to a pass anyway.
- There's some (now very obvious) duplication, particularly in the backend, of
  bits of code that construct expressions for the total size of an array
  (either in bytes or elements); this should be moved to a couple of helper
  functions that everything can use.
2008-03-18 16:45:38 +00:00
Adam Sampson
3005dfb506 Add a pass for folding constants in occam.
The existing constant-folding code in the parser is still there, since it needs
to know whether things are constant, and A.Dimension expects an Int.

However, this pass is useful because it does a better job of constant folding
than the parser would on its own: it can fold subexpressions of expressions
that are as a whole not constant.
2008-03-17 15:48:43 +00:00
Neil Brown
5c43172e46 Added an annotation to array subscripts to indicate whether they should have a run-time check added or not 2008-03-09 14:30:19 +00:00
Neil Brown
ba75f5b06c Removed the initialiser expression on the Declaration item in the AST 2008-03-09 00:23:13 +00:00
Adam Sampson
337527a544 Remove obsolete comment -- Structured is parametric now. 2008-03-07 14:42:46 +00:00
Adam Sampson
d2c0fd674e Rework the code for getting errors through the parser.
This used to work by adding a magic prefix to the error message, but it appears
that doesn't work with the GHC 6.6 version of Parsec. It now searches for a
magic substring anywhere in the error message.

It uses // as a delimeter rather than \0 now, since including nulls in Strings
causes problems -- for example, putStr "a\0b" will only print "a".
2008-03-04 12:52:25 +00:00
Adam Sampson
8f2575819b Initial implementation of the occam-pi preprocessor.
This implements #DEFINE, #UNDEF, #IF, #ELSE and #ENDIF, macro expansion with
##, and TRUE, FALSE, AND, OR, NOT and DEFINED within #IF expressions, with the
same semantics as occ21.

The macro COMPILER.TOCK is always defined by default, so you can now say things
like "#IF NOT DEFINED (COMPILER.TOCK) ... #ENDIF".
2008-02-28 20:27:30 +00:00
Neil Brown
eef0ac53e0 Added a flag to the compiler to tell let it to not delete the temporary files it used 2008-02-27 18:23:22 +00:00
Neil Brown
decf249c51 Moved AST, CompState and Metadata out to a new data directory (along with the generated OrdAST and TagAST) 2008-02-26 15:02:13 +00:00