Commit Graph

34 Commits

Author SHA1 Message Date
Adam Sampson
3da2ad1385 Provide combinators for generic traversals.
The types get hairier, but the code is much simpler!

I've left {check,apply}DepthM{,2} there for now, but reimplemented them in
terms of the new combinators.

Fixes #58.
2008-04-08 14:41:25 +00:00
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
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
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
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
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
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
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
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
Adam Sampson
b8b7e04b7c Refactor literal and subscript checks.
For both of these, we already examine all the places they occur for other
reasons, so there's no good reason to do a separate traversal for them.
2008-03-22 23:58:18 +00:00
Adam Sampson
60ca26128c More occam typechecks: input/output items, replicators, choices.
Various infrastructure too to support these.

Doing A.ForEach raised an interesting question: what does it work over?  In
plain occam it'd just be arrays, but it should obviously work for lists too.
This suggests that Size and Subscript should work on lists as well, since
ForEach will be implemented in terms of them. I've therefore introduced the
idea of a "sequence" class of types.
2008-03-22 23:47:29 +00:00
Adam Sampson
6ab4a9923f Implement expression typechecking for occam.
There's obviously some overlap with the Rain typechecker here. I've tried to
cover everything in the AST that could potentially be bound into occam at some
point in the future, even if the occam parser doesn't support it yet (so
this'll do checks for Concat and mobile allocation, for example).
2008-03-22 01:00:42 +00:00