Commit Graph

2357 Commits

Author SHA1 Message Date
Neil Brown
49d6e2aaaf Reworked how the stack sizes are recorded and merged together
The previous method, using the C preprocessor was both nasty, and crazily resource-intensive.  The new method stores stack size information in files that are read in and processed by the compiler when it comes time to link.
2009-04-07 16:03:52 +00:00
Neil Brown
0a67b804bb Added more intrinsically-defined operators to the list 2009-04-07 16:01:44 +00:00
Neil Brown
a8c9802f5d Changed the occam type checker to handle checking user defined operators better
They are now recursed into with no type context, then afterwards the type is deduced.  This seems to be how they were meant to work, and is also much faster than what I was doing.
2009-04-07 15:52:06 +00:00
Neil Brown
7031ab7fb8 Changed the lexer to make it lex the new (user-defineable) operators 2009-04-07 15:51:34 +00:00
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
7bd4e3d309 Added functions to the list of things that need stack sizes, even if they are external
I think this is not quite right, but for now it fixes stack sizes not being generated for any non-inlined standard operators.
2009-04-07 15:42:37 +00:00
Neil Brown
6e4e9c1808 Implemented much more of the support functions, and renamed some of the uglier types 2009-04-06 13:24:26 +00:00
Neil Brown
c4f625b1ba Overhauled the support headers to add most of the missing occam operators as inline functions 2009-04-06 00:56:06 +00:00
Neil Brown
9260048da2 Quickly fixed the Rain frontend to compile with the operator changes 2009-04-05 23:08:12 +00:00
Neil Brown
6d6d26d5d6 Fixed the backends to work with the new system (mainly removing unnecessary code) 2009-04-05 23:06:47 +00:00
Neil Brown
e1c18cc082 Changed inferTypes to resolve operators to the right definition
This patch follows on from the previous change to the parser.  When it spots a function-call, it looks for operators and treats them differently.

It keeps a stack of operators in scope (csOperators in CompState), and when an operator is used, it searches the stack (with all old definitions masked out) for operator definitions to resolve to.

The way it chooses which operator to use in the presence of overloadings (e.g. + on INT vs + on INT32) is simply to try them all.  If one matches, it uses that.  If none, or more than one match, it gives an error.  This makes the code simple and seems logical, but I'm not totally confident if this is the required behaviour for resolving overloaded operators.
2009-04-05 23:01:26 +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
cd0dd96939 Added some code to the Intrinsics module to list all (currently only some) of the occam standard operators with the types they can operate on 2009-04-05 22:48:23 +00:00
Neil Brown
238abc5070 Removed all the stuff from the ShowCode module that used to deal with operators 2009-04-05 22:38:00 +00:00
Neil Brown
7b4a6c812c Removed monadic and dyadic operators from the AST
This is the first part of a change, suggested in #64, to remove operators in favour of functions (which will also allow user-defined operators).

The ticket suggested removed operators after the parser, but the way it's working out, it is fine to just never represent as anything other than function calls.

All the knock-on changes will be recorded in later patches.
2009-04-05 22:31:26 +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
f8103c1d2d Added a library path to the set of Tock directories 2009-04-04 15:57:50 +00:00
Neil Brown
8400de520b Fixed the regular expression on #INCLUDE and #USE to allow any white-space at the end 2009-04-04 15:34:43 +00:00
Neil Brown
c2174743e7 Made the unknown preprocessor directive warning show what the unknown directive was 2009-04-04 15:34:17 +00:00
Neil Brown
172e331a9c Made sure that constants pulled up into sizes arrays are resolved into integers, rather than still referring to named constants 2009-04-04 15:23:40 +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
df21bf23ae Added a command-line option to print the include path
I'm not totally clear yet if the include path is or should be different to the module path, but I think it will become clear as I get KRoC compiling.
2009-04-04 13:45:22 +00:00
Neil Brown
923b9700d8 Stopped fixed-sizes being added for TOCKEXTERNAL PROCs 2009-04-04 13:44:56 +00:00
Neil Brown
11cc8c92a7 Corrected a small warning in PrettyShow 2009-04-04 12:49:01 +00:00
Neil Brown
03bfe593cb Fixed a bug in determining the sizes for RETYPES 2009-04-04 12:31:25 +00:00
Neil Brown
c361a36e41 Added a message so that when we fail to find a file, we say exactly where we looked 2009-04-04 12:31:06 +00:00
Neil Brown
d595b73f28 Added a command-line option to print out the module directory 2009-04-04 12:30:09 +00:00
Neil Brown
cfcf50297f Added the new tock include directory to the standard search path 2009-04-04 12:29:53 +00:00
Neil Brown
0466a50dfa Changed the build process to support a directory to put modules and includes in, and added a dummy lib (occamutl) 2009-04-04 12:28:47 +00:00
Neil Brown
18f37a0d96 Made it easier to print out a plain String after processing the command-line options 2009-04-04 12:27:56 +00:00
Neil Brown
c9f9eb8587 Added a couple of filter calls to the usage checking to speed it up
It now removes empty sets of (relevant) background knowledge to avoid needlessly creating lots of problems (thousands!) when it only needs one, and also stopped it checking array usage when there's at most one written-to/read-from index.

Fixes #90
2009-04-04 08:52:41 +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
45db9cdd27 Realised that my bits and bytes per word were somewhat mixed up 2009-04-03 20:19:48 +00:00
Neil Brown
c0ead7b5a8 Added some of the standard occam defines, such as TARGET.BITS.PER.WORD
For the moment, TARGET.HAS.FPU is left out, because a lot of occam libraries seem to do ASM if it's defined, and we can't handle ASM
2009-04-03 17:55:12 +00:00
Neil Brown
8170d9569d Added some code to Tock to be able to handle unlexable ASM blocks in source files 2009-04-03 17:54:13 +00:00
Neil Brown
9fbbe87fd4 Fixed the reading of floating point literals to work for negative numbers 2009-04-03 17:53:10 +00:00
Neil Brown
5f124636fb Fixed the name munged to be stable for #USE directives, but use the old name counter for #INCLUDE directives
This is necessary because occam files often #INCLUDE something multiple times (e.g. cgtests) and want different names, but this is not the case for #USE.
2009-04-03 16:52:40 +00:00
Neil Brown
38ffed2bda Stopped the .o file being removed after compilation when the -c flag was given 2009-04-03 16:52:16 +00:00
Neil Brown
081e4f79d4 Added more recognised suffixes to knock off in #USE directives 2009-04-03 16:52:00 +00:00
Neil Brown
427938039c Implemented a search path for Tock (for #INCLUDE and #USE directives) 2009-04-03 16:51:00 +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
b9cbcf0902 Added the intrinsic CAUSEERROR 2009-04-03 15:14:24 +00:00
Neil Brown
471c3a1ef5 Allowed #INCLUDE and #USE directives to have comments after the quoted part
I couldn't decide whether to fix this in the parser or the preprocessing code.  I went for the latter, as it was the simplest option.
2009-04-03 14:37:10 +00:00
Neil Brown
b803b1ec91 Reworked how stack sizes are calculated, and changed how we use them in the build process
Now that we support separate compilation, some of the stack sizes for PROCs depend on the stack sizes of other PROCs that were compiled in different files.  We can't just assume the default 512 bytes for these "foreign" PROCs, because that often won't be enough.  So instead, we must make the stack sizes for the current PROCs depend on (i.e. use in the calculation) the stack sizes of the foreign PROCs.

This dependence adds some issues though.  We cannot declare in one C file a const int that depends on the value of an extern const int from another C file (not valid C, it seems).  So instead, we move all the stack size declarations to header files, and use #includes and the preprocessor to make sure that the stack sizes are statically determined.

This in turn simplifies the build process in some ways.  These headers only need to be compiled by the .occ file that has the main process, by including them all into a C file and compiling that as before.  It means that each .occ file only has one .o file resulting (plus two C headers*, and a .inc file) so linking is a bit less confusing.

* I am keeping the two C headers for now, rather than appending the sizes one to the normal header, because I'm not entirely sure whether having one header that the C file depends on may trigger a recompilation that we don't want in some build systems.  I can always merge them later if that's not a valid worry.
2009-04-03 12:24:53 +00:00
Neil Brown
9bf32e339d Made sure that the names printed in TOCKEXTERNAL pragmas are fully munged (and thus equivalent to the exact C function name) 2009-04-03 12:22:19 +00:00
Neil Brown
d6ad0ba202 Made the name of record-copying PROCs different for each file that generates them, to avoid clashes at link time 2009-04-03 10:25:55 +00:00