Commit Graph

1593 Commits

Author SHA1 Message Date
Adam Sampson
9e9459cb4a Clean up EvalLiterals.
In particular, evalSimpleLiteral is now much nicer, and the error
messages should be a bit more comprehensible.

The signed types previously used a different version of fromRead that
passed an extra argument that it then didn't use; I've switched back to
the old version now, since it appears not to need it any more.
2008-04-08 00:29:23 +00:00
Adam Sampson
f1e9ffe230 In the evaluator, handle byte literals of any type. 2008-04-08 00:10:45 +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
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
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
7703eab52f Add applyExplicitM10.
Fortunately all of this will go away once I do the combinator change...
2008-04-07 21:34:34 +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
bfd7b079a7 Make unsubscriptType handle Infer. 2008-04-06 18:42:40 +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
3ab0c30589 When rendering array literals, recompute the dimensions.
This makes sure that literals produced by the constant evaluator will never
contain UnknownDimension. The change looks a lot more complex than it really
is; it already carried the type "downwards", and most of this is just making it
carry it back up to where the A.Literal is being constructured.
2008-04-06 15:40:50 +00:00
Adam Sampson
6fb8780cae Make a pattern match more explicit.
This is looking at array dimensions in literals. By this point unknown
dimensions should have been inferred; if they haven't, I'd rather it blew up
here than caused bizarre behaviour later on.

(This is a good candidate for a property check.)
2008-04-06 15:38:59 +00:00
Adam Sampson
28f329dd07 Don't assume an empty array literal can be a string literal. 2008-04-06 15:33:18 +00:00
Adam Sampson
1640b9ce63 Move applyDimension into Types. 2008-04-06 15:32:35 +00:00
Adam Sampson
3fcf363a31 In AnalyseAsm, ignore labels that contain "." anywhere.
GCC appears to generate labels that look like "constantname.1234" for some
array constants.
2008-04-06 15:31:28 +00:00
Adam Sampson
b65512b64c Make getConstantName descend into definitions.
This means you don't have to have folded constants throughout the tree/state in
order to evaluate them, which makes the early passes less awkward to manage.
2008-04-06 13:46:48 +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
9838cf7b8c Use forall to remove some repeated monad constraints. 2008-04-06 11:19:43 +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
249fd23e75 The type context is now used by passes, not the parser. 2008-04-06 02:59:34 +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
aa3b17b555 Make protocolItems give a more useful error message on failure. 2008-04-06 02:50:46 +00:00
Adam Sampson
e1fca531a0 Rework how OccValue is rendered to an Expression.
The rendering code now takes the type it's aiming for, so it can produce a
value of exactly the same type as the expression that was being folded
originally (rather than trying to work it out for itself).
2008-04-06 02:29:02 +00:00
Adam Sampson
2fdf749be0 Handle Infer in evalSimpleLiteral. 2008-04-06 02:28:43 +00:00
Adam Sampson
71df38813f Make subscriptType and trivialSubscriptType aware of Infer.
Subscripting Infer gives you Infer.

This also makes trivialSubscriptType handle user types in the same way as
subscriptType. (There probably isn't much reason to have both any more, since
subscriptType doesn't do the checks it used to do.)
2008-04-06 02:27:07 +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
e9d95aa0fd Tidy up OccValue a bit. 2008-04-06 00:48:02 +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
37b5735de1 When showing occam code, use CHAN/PORT rather than CHAN OF/PORT OF. 2008-04-05 23:19:12 +00:00
Adam Sampson
9fa45cf406 Make the inferredTypesRecorded property check Infer has been removed. 2008-04-05 22:41:29 +00:00
Adam Sampson
8bbca0f760 Add applyExplicitM9 (as a stopgap). 2008-04-04 12:10:32 +00:00