Commit Graph

221 Commits

Author SHA1 Message Date
Adam Sampson
eb8a855f32 Change most uses of underlyingType to resolveUserType in OccamTypes.
underlyingType recurses, and in at least one case it was going too far.
2008-04-07 23:52:44 +00:00
Adam Sampson
a5bd28bab4 Use a sensible NameType for names converted to unscoped.
This is because the code that finds free names looks at the NameType -- which
it certainly shouldn't.
2008-04-07 23:36:53 +00:00
Adam Sampson
feb0496d71 Handle DATA TYPE FOO IS (some record). 2008-04-07 23:36:30 +00:00
Adam Sampson
201788b478 Fix explicitly-typed array literals -- don't throw away the type. 2008-04-07 22:43:51 +00:00
Adam Sampson
c627214727 Resolve the v[s] ambiguity outside the parser.
This removes the last use of typeOf* from the parser.
2008-04-07 21:36:21 +00:00
Adam Sampson
cc907a1339 Pick the best type available for operators and array literals.
This is rather more expensive than the approach it was using, but it
does the right thing for things like "3 + 4(MYINT)" and "[3, 4(MYINT)]",
and the code's actually simpler.
2008-04-07 20:14:00 +00:00
Adam Sampson
3326c56a54 Always infer left-to-right for dyadic operators (except shifts).
This isn't the right behaviour, although it's closer: what it really needs to
do is to try to infer both sides in the current (or no) context, pick the more
specific type of the two inferred, then use that to redo the other one. Yuck!
2008-04-07 12:04:34 +00:00
Adam Sampson
caa59c6788 Reinstate support for intrinsic Procs and Functions.
This works the same way that it used to. I did experiment with actually
defining them as Procs and Functions in the normal way, but that'd require an
awful lot of special-casing later on, and would preclude support for multiple
types in the future, so I'll keep it this way for now.
2008-04-07 11:55:20 +00:00
Adam Sampson
ea69ebd0ec Assume that string literals have type []BYTE unless otherwise specified.
This means that "" has the correct type, which cgtest07 checks for.
2008-04-07 00:20:42 +00:00
Adam Sampson
d0072fc2ee Infer types in record literals.
This also changes the behaviour for array literals so that the inferred type of
the first item is used as the default for the rest. This satisfies all the
cgtests except for a test in cgtest59 which does "a IS [3, 4 (type)]:", which
I've never seen in a real program, and would require a bit more complication to
handle.
2008-04-07 00:05:15 +00:00
Adam Sampson
6d31c79234 Only apply inferTypes to the AST.
It updates the state itself anyway, and applying it to the AST results in it
doing an awful lot of traversal this early on.
2008-04-06 22:28:58 +00:00
Adam Sampson
3d1d2c4d9c Fix type inference for BytesInExpr. 2008-04-06 19:04:16 +00:00
Adam Sampson
988c5c6fef Add special handling for CHAN ANY.
Fixes #57.
2008-04-06 18:54:32 +00:00
Adam Sampson
71d8c7024b Unsubscript the context (when walking a subscripted expression. 2008-04-06 18:43:34 +00:00
Adam Sampson
2d15eb800c Make pushTypeContext handle Infer as no context. 2008-04-06 18:43:01 +00:00
Adam Sampson
39f78e56ee Relax the type checking on array assignment: [3]INT := []INT is OK.
I'd forgotten to move this rule over from the old checker in the parser.
2008-04-06 18:28:02 +00:00
Adam Sampson
ab6e3d1b3e Infer the types of channel arrays. 2008-04-06 17:59:29 +00:00
Adam Sampson
95e3693efd Die with a sensible error message if the type of an empty array can't be inferred. 2008-04-06 17:59:03 +00:00
Adam Sampson
feefcfd017 Resolve the c ! x ambiguity outside the parser.
Unfortunately there appears to be exactly one place you can do this, and it
turns out to be inside inferTypes (because you need to know the type of c
completely, and you can't type-infer x until you know if it's a tag or a
variable). It's definitely nicer than doing it in the parser, though.

I've also started adding "-- AMBIGUITY" comments in the parser.
2008-04-06 17:47:41 +00:00
Adam Sampson
4b841e1dc1 Show expected tags when none are specified. 2008-04-06 17:47:07 +00:00
Adam Sampson
8cedbed5fc Move makeUniqueName and findUnscopedName into CompState. 2008-04-06 17:42:12 +00:00
Adam Sampson
1640b9ce63 Move applyDimension into Types. 2008-04-06 15:32:35 +00:00
Adam Sampson
1977e7880b Move evalIntExpression into EvalConstants, now that Types doesn't need it.
It now uses the full expression evaluator rather than the literal-only version.
2008-04-06 13:31:37 +00:00
Adam Sampson
8f7c8b9fcb Define variables necessary for some of the constant-folding tests. 2008-04-06 13:12:04 +00:00
Adam Sampson
118a1f3527 Add a resolveAmbiguities pass.
Currently this only handles the FunctionCallList ambiguity.
2008-04-06 11:33:10 +00:00
Adam Sampson
ecab9c1881 foldConstants *after* inferTypes.
On second thoughts, we can't reasonably fold constants until we know what types
they are.
2008-04-06 11:20:34 +00:00
Adam Sampson
8a914cd19a Strip out most of the type awareness from the parser.
Type inference and checking is now handled entirely by the later passes.

There are a few remaining places in the parser that look at the types of things
that have been defined; this is in order to resolve syntax ambiguities (e.g.
c[x], c ! x). This is a temporary measure to minimise cgtest breakage; it can't
work for things that need to be inferred (e.g. "CHAN INT c:" "d IS c:" "d !
x"), so it'll need moving out to a pass in the near future.

There's still quite a bit of work to do on this, but results so far are
encouraging: the code is an awful lot cleaner, and about four hundred lines
shorter.
2008-04-06 02:59:49 +00:00
Adam Sampson
c39503c175 Move occam type inference out to a pass.
This infers the types of literals and abbreviations.

This is not yet complete, but it's mostly there. I was surprised at how complex
it turned out to be, but it's significantly less awkward than having it
threaded through the parser (plus it works correctly, unlike the old code).
There are a few FIXMEs for things I've yet to implement.
2008-04-06 02:56:59 +00:00
Adam Sampson
e6980ba382 Update all specifications when constant folding.
It used to only update IsExprs, but that meant that all the constants inside
types in other things didn't get folded properly, which caused problems.
2008-04-06 02:01:47 +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
Neil Brown
4ef1ff7196 Changed to a state monad for warnings, and added a runPassM function to remove duplicate code for running passes 2008-04-03 12:21:59 +00:00
Neil Brown
20843f70a4 Corrected all the tests to use the new PassM monad 2008-03-10 17:07:48 +00:00
Neil Brown
d66fb79796 Fixed some unused module import warnings, now that PassM is not build of monad transformers 2008-03-10 17:19:45 +00:00
Adam Sampson
7525138c96 Defined types for tree traversals, and moved them to their own file.
We now have three kinds of canned tree traversals, all of which are smart about
which types they're applied to: explicit-descent transformations,
implicit-descent transformations, and implicit-descent checks. I've only
provided depth-first application of the latter two, but we could do
breadth-first in the future if necessary.
2008-04-01 12:01:09 +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
Adam Sampson
b296706bea Update Rain typechecker to match isIntegerType change.
isIntegerType now recognises Time as an integral type, so the rules for Time
operations in the Rain typechecker needed updating.
2008-03-26 14:55:15 +00:00
Adam Sampson
b36068b815 Move retypes check into the SpecType checker, and update the pass list.
This completes the occam typechecker.
2008-03-26 14:39:12 +00:00
Adam Sampson
ef329e3ed0 Check SpecTypes. 2008-03-26 14:20:35 +00:00
Adam Sampson
c9cb7d2bf9 Check Proc calls. 2008-03-26 12:26:04 +00:00
Neil Brown
c37e183879 Added support for a not-equals operator in Rain 2008-03-24 23:44:40 +00:00
Adam Sampson
b672900f46 Check Case, Alt, and all the trivial processes. 2008-03-25 17:27:33 +00:00
Adam Sampson
6861b22da6 Check timer operations. 2008-03-25 16:45:25 +00:00
Adam Sampson
d7e829b4c6 Check assignments. 2008-03-25 16:26:09 +00:00
Adam Sampson
b3e3308b3e Implement channel IO checks, and refactor OccamTypes (again). 2008-03-25 15:56:03 +00:00
Neil Brown
8fe152bf98 Merged the type-checking on time-related statements in Rain into the pass that checks types in communications 2008-03-24 15:15:28 +00:00
Neil Brown
eb50c010b2 Fixed the tests for parsing time-related stuff in Rain to match the recent changes 2008-03-24 14:27:46 +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
74a5cf52a7 Stopped constants being assigned to in the type-checker for Rain 2008-03-23 12:15:00 +00:00
Neil Brown
b316a7d3f4 Added some tests for checking that constants can't be assigned to in Rain 2008-03-23 12:14:34 +00:00