NeilBrown [Sat, 20 Nov 2021 00:37:52 +0000 (11:37 +1100)]
parsergen: avoid creating extra line in code blocks.
When performing coverage analysis, it is important that the line numbers
seen in the .c file are fairly accurate.
Currently we a lines to the end of a code block, and they appear to have
line numbers that correspond to whatever appears after the code block.
This is confusing.
So put all that extra code on the last line (matching the }$).
Also switch back to "gen_reduce" immediately after the code block.
NeilBrown [Fri, 19 Nov 2021 22:10:36 +0000 (09:10 +1100)]
oceani: improve construction of per-function stack frame
The stack-frame management was confused - not properly transitioned from
a single function to multiple functions.
Now we pass in the function to be processed, and it has a known list of
variables that were in-scope in that function.
We track when each variable went into or out-of scope, sort them, and
re-use frame space for variables which have already gone out-of-scope.
NeilBrown [Mon, 15 Nov 2021 21:23:06 +0000 (08:23 +1100)]
oceani: pass a destination buffer into interp_exec to receive large result.
To handle assignment from large objects - particularly a structure
returned by a function - we cannot just pass back a 'struct value'.
Instead we need to pass in a sufficiently large buffer, and have
the value producer copy into it.
This patch passes in a 'dest' and 'dtype' for this purpose. It is not
yet used to full potential.
NeilBrown [Sun, 14 Nov 2021 05:07:15 +0000 (16:07 +1100)]
parsergen: add action tables when needed.
In most cases there is at most one reducible production per state, and
that is all we previously handled.
However occasionally it can be useful to have more than one, triggered
by different look-ahead symbols.
With this patch, we add entries to the go_to table in that case. The
go_to table now has a flag to indicate if the symbol maps to a state (in
which case it can be SHIFTed if a terminal), or to a production (in
which case it triggers a reduction).
If the in-state production has the special value MANY_REDUCIBLE, when
the parser performs a lookup to see which production, if any, should be
reduced.
NeilBrown [Sat, 13 Nov 2021 08:25:23 +0000 (19:25 +1100)]
parsergen: store reduction information separate from states.
There are more states than reductions (aka productions) so storing the
reduction data in the state table results in a lot of duplication - and
wasted space as some states have no reduction.
So create a separate table of reduction information. This will also
make it easier to allow a state to have multiple reductions with LALR
and canonical-LR grammars.
NeilBrown [Wed, 10 Nov 2021 10:27:50 +0000 (21:27 +1100)]
oceani: remove the need for 'then' in function declarations.
Previously an IN had to follow a terminal because it would never for a
reduce.
This made is a problem for
func FuncName
arguments
do
code
as the IN follows FuncName - a non-terminal.
Fix this by allowing an IN to force a reduce if nothing at all can be
shifted.
After "func IDENTIFIER", nothing can be shifted. The IDENTIFIER must be
reduced to FuncName. At that point, the IN is expected, so it won't be
ignored.
NeilBrown [Sun, 7 Nov 2021 21:21:30 +0000 (08:21 +1100)]
oceani: Add functions
As yet, functions cannot return a value, but they can be passed
parameters.
They are declared a bit like consts, but there isn't a common
header for multiple constants.
A pointer to the body of the function is stored in the 'global' area,
like the vale of any other constant.
Functions can be called as a statement - providing they don't return
anything - or as an expression, which will currently be a type error as
they cannot return the correct type.
We allocate a new 'local' frame for each function call, and free it when
the function completes.
NeilBrown [Tue, 9 Nov 2021 05:05:50 +0000 (16:05 +1100)]
mark-tested: don't fail if coverage is too low
As the whole point of mark-tested is to help improve coverage, it is
silly to rail if coverage is too low.
So make it possible to easily skip that test in the Makefile.
NeilBrown [Tue, 9 Nov 2021 04:58:50 +0000 (15:58 +1100)]
oceani: improve reporting of variables being freed at end of block.
1/ if frame_pos hasn't been set, possibly because type propagation hit
an error, don't report the offset.
2/ Don't report G or L for global/local, and this will always be a a
local variable.
NeilBrown [Tue, 9 Nov 2021 02:44:27 +0000 (13:44 +1100)]
oceani: Make 'List' separate from Print
Create a stand-alone ExpressionList which uses the List binode rather
than the Print binode.
The Print statement no longer uses a NULL entry on the end of the list
to denode a trailing comma. Rather ->left is used for a normal print
list and ->right is used for a print list that has a trailing comma.
NeilBrown [Sat, 6 Nov 2021 04:54:52 +0000 (15:54 +1100)]
oceani: free variables as soon as they go out of scope.
Each 'exec' now keeps track of the variables that go out-of-scope when
the exec completes.
CondScope variables need to be re-linked when they get merged.
We now poison a variable when it is freed to ensure it doesn't get used
again by mistake.
The final cleanup now only needs to handle global variables
NeilBrown [Mon, 8 Nov 2021 08:35:25 +0000 (19:35 +1100)]
oceani: update min_depth promptly.
As the loop in var_block_close() continues until min_depth is too low,
we need to set it promptly to stop the same variable being processed
again before it has been merged.
NeilBrown [Sat, 6 Nov 2021 23:59:23 +0000 (10:59 +1100)]
oceani: create separate scope for do part of while
Any variables created in the do part won't be created in the final
iteration, so we want them to be constrained to the do part, not seen as
part of the whole loop body.
This makes while/do match if/then better.
NeilBrown [Sat, 6 Nov 2021 02:04:54 +0000 (13:04 +1100)]
oceani: move var_block_close() calls to the code sections that close the block
Rather than calling var_block_close() from common non-terminals, move
the calls into the body of the parent non-terminal. This places them
after the 'struct exec' which represents the scope has been created.
This is needed to attach the variables to the point where their scope is
closed, so they can be freed.
This change helped me focus on some untested - and broken - code.
NeilBrown [Fri, 5 Nov 2021 23:55:01 +0000 (10:55 +1100)]
oceani: simplify loop in var_block_close()
The 'step' was not in the 'for' header, which makes it harder to follow
how the loop works.
Also add a comment to explain where is happening when ->name->var != v.
NeilBrown [Sat, 30 Oct 2021 04:49:08 +0000 (15:49 +1100)]
oceani-tests: add test for declaring a CondScope variable
If a variable was declared in all branches of a structures command, it
may or may not be declared as something else afterwards.
We need to test both options.
NeilBrown [Sun, 17 Oct 2021 10:03:01 +0000 (21:03 +1100)]
oceani: move variable values to a stack frame.
We have two frames - one for global values (currently always constant)
and one for local variables.
When we get functions, the local variable frame will be managed with a
stack of frames.
NeilBrown [Sun, 17 Oct 2021 02:35:58 +0000 (13:35 +1100)]
oceani: add parse_context arg to all interp functions, and a few others.
When I switch variables to use a stack frame, I'll need the
parse_context available more broadly (as it will hold the stack).
So add it to a selection of functions now.
NeilBrown [Sat, 16 Oct 2021 05:58:42 +0000 (16:58 +1100)]
oceani: differentiate static-sized arrays from others.
Some arrays will always have the same size - a static size.
Others might have a different size each time their scope is entered, if
the size is calculates from a variable.
The latter need to be reallocated whenever scope is entered, the former
do not.
This will matter when we create call frames to be able to handle
recursion.
NeilBrown [Sat, 16 Oct 2021 05:27:41 +0000 (16:27 +1100)]
oceani: don't allocate init value for non-initialized fields.
Struct fields that aren't explicitly initialised must be initialized to
a 'null' value. This can happen at interp-time. There is no need to
allocate a null value when parsing.
NeilBrown [Thu, 14 Oct 2021 02:43:02 +0000 (13:43 +1100)]
oceani: handle variable-sized arrays better.
An array with size set by a constant variable(!) might have a different
size each time the declaration is encountered. So we need to
re-evaluate the size each time.
We currently re-evaluate the size only if it is zero.
So for numerical-constant sized arrays, evaluate size during parsing.
For other arrays, re-evaulate each time using a new prepare_type method.
NeilBrown [Tue, 12 Oct 2021 10:28:47 +0000 (21:28 +1100)]
oceani: fix a couple of issues
1/ when a variable declared in a loop was re-initialized, we didn't free
the old value before allocating a new one.
2/ When assigning to an out-of-bounds array index, created an rval,
but never freed it.
NeilBrown [Sat, 2 Oct 2021 22:36:50 +0000 (09:36 +1100)]
ocean: introduce prefix op for string->number conversion.
Rather than having magic conversion of command line args to numbers as
needed, introduce '$' as a prefix op to to the conversion.
This is a step towards changing 'program' to be a 'main' function.
NeilBrown [Wed, 10 Mar 2021 01:37:46 +0000 (12:37 +1100)]
oceani: updates for new approach to parsing indents.
Now that IN is a valid stand-alone token, it makes sense to change the
grammar for ocean.
We don't need the ':' before an indent if there is some other terminal
there. So:
while
statements
do
statements
doesn't require any ':'.
We use the ':' to separate an expression from following statements,
in 'if' and 'while' and 'case'.
NeilBrown [Wed, 10 Mar 2021 00:49:24 +0000 (11:49 +1100)]
parsergen: add support for EOL token
And EOL token is generated when a NEWLINE is found and an EOL can be
shifted. This allows a product to declare that it must finish at the
end of a line, without consuming the NEWLINE.
NeilBrown [Wed, 10 Mar 2021 00:38:55 +0000 (11:38 +1100)]
parsergen: implement new handling of IN/OUT and NEWLINE
IN/OUT are now expected in the grammar.
In a state where an IN can be shifted, IN symbols are significant to the
grammar. IN symbols appearing anywhere else are ignored (except for how
they affect NEWLINEs).
OUT symbols are ignored precisely when the matching IN was ignored.
NEWLINEs are ignored if the most recent IN was ignored, otherwise they
are significant for the grammar.
NeilBrown [Fri, 5 Mar 2021 10:24:14 +0000 (21:24 +1100)]
parsergen: add support for "special" terminals.
We will want a new terminal "EOL", which is like "NEWLINE", but
different. There is currently no room in the numbering for something
like that, so make some room.
NeilBrown [Fri, 5 Mar 2021 09:31:32 +0000 (20:31 +1100)]
parsergen: remove line_like information.
I'm going to change the 2D nature of the parser over several patches.
First I remove what I don't want, then I add what I do.
During this series, tests won't work!
NeilBrown [Fri, 26 Feb 2021 06:33:43 +0000 (17:33 +1100)]
parsergen: don't use static buffer for result value.
Add the size of the result value to the per-state information, so it can
be allocated before calling do_reduce(), thus removing the need for a
overly large static buffer.
NeilBrown [Fri, 5 Mar 2021 08:20:22 +0000 (19:20 +1100)]
parsergen: change how reserved_words are stored
Rather than a simple array with holes, have a dense array mapping number
to name. This will enable a future change which adds names that don't
have numbers assigned.