]> ocean-lang.org Git - ocean/log
ocean
2 years agooceani: factor out field reference into per-type handler
NeilBrown [Sat, 11 Dec 2021 23:33:39 +0000 (10:33 +1100)]
oceani: factor out field reference into per-type handler

knowledge about how field references for strutures is now in
structure-specific code.  This will allow other types to
behave differently.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: replace some magic numbers with an enum.
NeilBrown [Sat, 11 Dec 2021 22:43:41 +0000 (09:43 +1100)]
oceani: replace some magic numbers with an enum.

I'm growing to dislike magic numbers

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add reference type
NeilBrown [Mon, 6 Dec 2021 05:54:07 +0000 (16:54 +1100)]
oceani: add reference type

 @foo  is a type which is a reference to type 'foo'.
 If var is an @foo, then var@ is the foo.
 @new() returns an appropriate new object
 @free= thing will free thing
 @nil is an invalid reference of any type.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: don't add extra indent for Declare and Assign
NeilBrown [Mon, 6 Dec 2021 06:37:09 +0000 (17:37 +1100)]
oceani: don't add extra indent for Declare and Assign

when printing a declaration or assignment we indent the whole statement,
but NOT the individual parts.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: improve content in some error messages.
NeilBrown [Mon, 6 Dec 2021 06:29:32 +0000 (17:29 +1100)]
oceani: improve content in some error messages.

In particular:
  use new_pos() instead of new() where appropriate
  set where_set where necessary
  set type name properly in anon types

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: introduce 'test' and 'choose' operators
NeilBrown [Sun, 5 Dec 2021 21:04:31 +0000 (08:04 +1100)]
oceani: introduce 'test' and 'choose' operators

If a type supports testing (only Boolean currently),
   ? expr
converts to Boolean, and
   expra ?? exprb

will return expra if it tests as true, and exprb otherwise.
exprb isn't computed if not needed.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: remove the HACK concerning type names starting with space
NeilBrown [Sun, 5 Dec 2021 00:09:57 +0000 (11:09 +1100)]
oceani: remove the HACK concerning type names starting with space

structures returned inline from a function call can be copied.
Other structures - in general - cannot.

This patch introduces a (slightly) better way to tell the difference
than the 'space' hack that was previously used.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: allow types to be used before declaration
NeilBrown [Sat, 4 Dec 2021 23:34:58 +0000 (10:34 +1100)]
oceani: allow types to be used before declaration

As we prepare all types after parsing, we can now use a type before it
is declared.
We need to be careful of mutually recursive structures, and
we need to retry prepare_type if it fails because a needed
member hasn't been prepared yet.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: allow global constants to be used before declared.
NeilBrown [Sat, 4 Dec 2021 22:37:00 +0000 (09:37 +1100)]
oceani: allow global constants to be used before declared.

When an undeclared name is used, it gets allocated a Tnone variable.
If one of these is found in a 'use' statement, it is assumed to be
a label (that will change later).
If it gets declared as a constant, its type gets set appropriately.

When evaluating global constants, if a value cannot be determined, we
continue with other constants, then, retry.  If the failure was because
some constant was not yet declared, this will eventually resolved.
If resolution is not possible, an error is produced.

Currently, non-global variables and functions cannot resolve.
This is tracking in the new Enoconst prop_err flag.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoocean: propagate_types: only set Efail on local err.
NeilBrown [Sat, 4 Dec 2021 22:29:23 +0000 (09:29 +1100)]
ocean: propagate_types: only set Efail on local err.

propagate_types() currently sets Efail if there has been any parse error
at all.  This is wrong.
Instead, keep a count of errors, and only set Efail if that count has increased.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: change the 'ok' flag to 'perr' with well defined bits.
NeilBrown [Sat, 4 Dec 2021 22:13:51 +0000 (09:13 +1100)]
oceani: change the 'ok' flag to 'perr' with well defined bits.

I'll want to extend the information gathered by propagate_types() to
report if a value can be computed immediately.  So generalize
'ok' (which contains a magic value) to a set of flags that can be
reported.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: use more precision when printing numbers
NeilBrown [Fri, 3 Dec 2021 07:58:43 +0000 (18:58 +1100)]
oceani: use more precision when printing numbers

I really want constants to be reproduced accurately when printing a
program.
Maybe I should detect and store the precision used, but for now, just
use a larger precision.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani - delay processing of global constants
NeilBrown [Thu, 2 Dec 2021 02:43:27 +0000 (13:43 +1100)]
oceani - delay processing of global constants

Rather than setting up the value of a constant as it is parsed, collect
the declarations and process them all at the end.

This is a step towards allowing constants to refer to constants that are
declared later.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move prepare_type handling to after the parse.
NeilBrown [Tue, 30 Nov 2021 23:09:34 +0000 (10:09 +1100)]
oceani: move prepare_type handling to after the parse.

This will allow global constants to be used before they are declared.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move struct field processing into ->prepare_type
NeilBrown [Tue, 30 Nov 2021 23:05:27 +0000 (10:05 +1100)]
oceani: move struct field processing into ->prepare_type

This will allow the preparation of the type to be moved later, possibly
after necessary constants and other types have been declared.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move all array size calculation to prepare_type
NeilBrown [Tue, 30 Nov 2021 22:52:47 +0000 (09:52 +1100)]
oceani: move all array size calculation to prepare_type

This makes the code more uniform - array size and alignment is
only set in one place.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: indent grammar more consistently.
NeilBrown [Mon, 29 Nov 2021 08:39:06 +0000 (19:39 +1100)]
oceani: indent grammar more consistently.

- all products are not indented, whether they start with a non-term or a
  '|'.
- Code is indented once - plus internal indents.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: make anon types more formal
NeilBrown [Tue, 23 Nov 2021 22:31:49 +0000 (09:31 +1100)]
oceani: make anon types more formal

As we need anon types - make it explicit and allow a name to be constructed.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: rearrange everything and introduce "Term"
NeilBrown [Tue, 23 Nov 2021 09:52:32 +0000 (20:52 +1100)]
oceani: rearrange everything and introduce "Term"

All non-operator expressions (e.g.  array access, struct access) are now
'Term's.
Also, lots of rearrangement to try to get better ordering.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: change SimpleStatement to be $*exec, not $*binode
NeilBrown [Sat, 20 Nov 2021 05:37:04 +0000 (16:37 +1100)]
oceani: change SimpleStatement to be $*exec, not $*binode

All current SimpleStatements are binode, but future ones may not be.
So change to $*exec.
Declare a binode '*b' in 'reduce' header so the variable is
always available.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: remove "expr precedence" section
NeilBrown [Sat, 20 Nov 2021 03:25:06 +0000 (14:25 +1100)]
oceani: remove "expr precedence" section

Use "declare terminals" for declaring all terminals, whether for
precedence or otherwise.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: support functions returning multiple values.
NeilBrown [Sat, 20 Nov 2021 00:54:49 +0000 (11:54 +1100)]
oceani: support functions returning multiple values.

A function can now return a list of parameters.
These can be assigned to a variable which acts as a struct
containing all those parameters.

There is some HACKy code in here that will need to be sorted later.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: record if a variable declaration was given an explicit type
NeilBrown [Sat, 20 Nov 2021 00:50:55 +0000 (11:50 +1100)]
oceani: record if a variable declaration was given an explicit type

The type may be determined at the same place as the declaration, yet
still not be explicit.  To ensure correct output when printing code,
record what was found.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: pass a file to print_value() and related functions.
NeilBrown [Sat, 20 Nov 2021 00:46:14 +0000 (11:46 +1100)]
oceani: pass a file to print_value() and related functions.

print_type receives a file, and a type can contain values, so
print_value() should take a file too.

Ideally print_exec() would as well, as the value of a function is an
exec.  Maybe another day.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: avoid creating extra line in code blocks.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: improve construction of per-function stack frame
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: pass a destination buffer into interp_exec to receive large result.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: mark structure return from functions as not supported.
NeilBrown [Mon, 15 Nov 2021 21:14:27 +0000 (08:14 +1100)]
oceani: mark structure return from functions as not supported.

Functions can currently only return types that support ->dup.
So disallow anything that doesn't.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: add action tables when needed.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: move EOL handling out of shift()
NeilBrown [Sat, 13 Nov 2021 22:47:21 +0000 (09:47 +1100)]
parsergen: move EOL handling out of shift()

shift() is called in several places, and in only one of those is there a
need to make NEWLINE to EOL.

Move the code out of shift() and instead make a second call to shift()
if shifting NEWLINE failed.  I think this make the code clearer.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: rearrange 'struct state' to reduce wastage.
NeilBrown [Sat, 13 Nov 2021 08:32:42 +0000 (19:32 +1100)]
parsergen: rearrange 'struct state' to reduce wastage.

Having a pointer between two shorts results in a lot of empty space
in the struct.  Remove this wastage.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: store reduction information separate from states.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoboot-strap: update bootstrap code.
NeilBrown [Sat, 13 Nov 2021 08:04:02 +0000 (19:04 +1100)]
boot-strap: update bootstrap code.

Run
  ../md2c ../mdcode.mdc
in boot-strap to get the latest code there.  Just because.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add valgrind testing for 'special' tests
NeilBrown [Sat, 13 Nov 2021 00:40:33 +0000 (11:40 +1100)]
oceani-tests: add valgrind testing for 'special' tests

Make sure we clean up properly, even after a fatal error - just because.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: include failing test in valgrind testing
NeilBrown [Sat, 13 Nov 2021 00:24:23 +0000 (11:24 +1100)]
oceani-tests: include failing test in valgrind testing

We want memory error caught in failing tests too.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: perform coverage test last.
NeilBrown [Fri, 12 Nov 2021 23:14:09 +0000 (10:14 +1100)]
oceani-tests: perform coverage test last.

I want to see valgrind test results even when I don't have full coverage
yet.  So move the coverage test last.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add simple return type
NeilBrown [Fri, 12 Nov 2021 23:10:44 +0000 (10:10 +1100)]
oceani: add simple return type

This allow a simple typed value to be returned from a function using the
'use' statement.
It probably doesn't work for structs - don't try it.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: remove some stray white-space
NeilBrown [Fri, 12 Nov 2021 23:04:16 +0000 (10:04 +1100)]
oceani: remove some stray white-space

Don't want no extra white space.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: Improve Rboolok handling.
NeilBrown [Fri, 12 Nov 2021 23:00:47 +0000 (10:00 +1100)]
oceani: Improve Rboolok handling.

When Rboolok, Tnone is also allowed.
When not Rboolok, and type is not Tnone, it is only the final
statement of a block that *must* return a value.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix parsing for function declaration parameters
NeilBrown [Fri, 12 Nov 2021 22:02:19 +0000 (09:02 +1100)]
oceani: fix parsing for function declaration parameters

Multiple lines of declarations weren't handle properly.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: factor our common code in DeclareFunction
NeilBrown [Fri, 12 Nov 2021 10:29:46 +0000 (21:29 +1100)]
oceani: factor our common code in DeclareFunction

Rather than writing the same thing three times, use a function.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: remove the need for 'then' in function declarations.
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.

This allows the 'then' to be dropped.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: Add functions
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: change variable name in "free global variables"
NeilBrown [Tue, 9 Nov 2021 05:16:31 +0000 (16:16 +1100)]
oceani: change variable name in "free global variables"

I'm using 't' as the name for a pointer to a variable.
Using 'v' makes more sense.  (t was short for 'temp').

Signed-off-by: NeilBrown <neil@brown.name>
2 years agomark-tested: don't fail if coverage is too low
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: improve reporting of variables being freed at end of block.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: guard against code section being empty.
NeilBrown [Tue, 9 Nov 2021 04:52:14 +0000 (15:52 +1100)]
oceani: guard against code section being empty.

If ->code is empty, we want an error message, not a crash.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: Make 'List' separate from Print
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: free variables as soon as they go out of scope.
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

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: CloseParallel must mark anything not Pending as OutScope
NeilBrown [Mon, 8 Nov 2021 09:46:44 +0000 (20:46 +1100)]
oceani: CloseParallel must mark anything not Pending as OutScope

Testing doesn't trip on this yet, but will in a future patch.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add comments to var_block_close() and remove dead code.
NeilBrown [Mon, 8 Nov 2021 09:19:29 +0000 (20:19 +1100)]
oceani: add comments to var_block_close() and remove dead code.

This function is subtle and deserves good documentation for various
cases.
Some of the cases were dead, so remove them.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: update min_depth promptly.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: perform analysis before printing
NeilBrown [Sun, 7 Nov 2021 00:28:04 +0000 (11:28 +1100)]
oceani: perform analysis before printing

This will allow information attached during analysis to
be printed out as comments.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add an 'interp' case for Func
NeilBrown [Sun, 7 Nov 2021 00:04:34 +0000 (11:04 +1100)]
oceani: add an 'interp' case for Func

For Func we jut call interp_exec on b->right.
This ensures that interp_exec() gets called on each exec, so
it can do cleanup (in future patch).

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: create separate scope for do part of while
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: create a separate 'exec' for the while/do part
NeilBrown [Sat, 6 Nov 2021 22:20:05 +0000 (09:20 +1100)]
oceani: create a separate 'exec' for the while/do part

As while/do is a sub-scope within a cond-statement, create a separate
'struct exec' for it (a binode/Loop) so there is an exec for each scope.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move var_block_close() calls to the code sections that close the block
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix up the while/do scope
NeilBrown [Sat, 6 Nov 2021 23:00:29 +0000 (10:00 +1100)]
oceani: fix up the while/do scope

The scope created for while/do does NOT extend into the case/else part.
This is because it is a repeating scope and needs to close and re-open.

We *could* include case/else in the final instance of that scope, but
I'm not at all sure that I want to.  Maybe later.

So close the scope properly and fix up the test code which depends on
the scope being extended.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: change variable.merged to never be NULL
NeilBrown [Sat, 6 Nov 2021 01:17:13 +0000 (12:17 +1100)]
oceani: change variable.merged to never be NULL

variable.merged is now always the primary variable, so it is initialised
to the address of the variable itself.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: simplify loop in var_block_close()
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: simplify test in var_block_close.
NeilBrown [Fri, 5 Nov 2021 23:30:34 +0000 (10:30 +1100)]
oceani: simplify test in var_block_close.

v->depth is never less than v->min_depth, so checking that
both exceed ->scope_depth is pointless, only test ->min_depth.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add lots of UNTESTED markers.
NeilBrown [Wed, 3 Nov 2021 02:08:45 +0000 (13:08 +1100)]
oceani: add lots of UNTESTED markers.

These serve to remind me what needs testing (or marking NOTEST), and
will make it easier to notice when new untested code is added.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: var storage needs to be free last
NeilBrown [Wed, 3 Nov 2021 01:52:08 +0000 (12:52 +1100)]
oceani: var storage needs to be free last

As type may store initializers in storage, but these might not get into
the var list in an error, we need to free that storage last.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: continue to improve test coverage
NeilBrown [Wed, 3 Nov 2021 01:29:34 +0000 (12:29 +1100)]
oceani-tests: continue to improve test coverage

Add a couple of error tests, and mark some code as NOTEST

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add some NOTEST markings.
NeilBrown [Wed, 3 Nov 2021 01:05:51 +0000 (12:05 +1100)]
oceani-tests: add some NOTEST markings.

These lines don't need to be tested.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agomark-untested: improve filter
NeilBrown [Wed, 3 Nov 2021 01:01:17 +0000 (12:01 +1100)]
mark-untested: improve filter

Don't add the mark for any section lines.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add test for duplicate main functions
NeilBrown [Wed, 3 Nov 2021 00:57:01 +0000 (11:57 +1100)]
oceani: add test for duplicate main functions

Add a test so the check for duplicate main functions gets exercised.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: drop "program" in favour of "func"
NeilBrown [Wed, 3 Nov 2021 00:46:54 +0000 (11:46 +1100)]
oceani: drop "program" in favour of "func"

Being to introduce functions.  Currently only the 'main' function which
receives an array of strings.
This array has a variable size.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add test for declaring a CondScope variable
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add test for unknown field name.
NeilBrown [Sat, 30 Oct 2021 04:25:40 +0000 (15:25 +1100)]
oceani-tests: add test for unknown field name.

Test that we get error if unknown field is requested.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: improve test coverage
NeilBrown [Sat, 30 Oct 2021 04:19:39 +0000 (15:19 +1100)]
oceani: improve test coverage

Add a tool 'mark-untest' which adds comments to untested lines.
Then resolve some of them, either adding more tests, or marking
lines as NOTEST

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: make it possible to skip valgrind tests.
NeilBrown [Sat, 30 Oct 2021 04:00:03 +0000 (15:00 +1100)]
oceani-tests: make it possible to skip valgrind tests.

valgrind tests are slow and not always wanted, particilarly when
examining coverage.  So make it easy to skip them.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoocean: change program to receive argc and argv
NeilBrown [Sat, 30 Oct 2021 03:23:46 +0000 (14:23 +1100)]
ocean: change program to receive argc and argv

Rather than a list of strings, a "program" now receives and arg count,
and an array of strings with that size.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move variable values to a stack frame.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix some incorrect section headers.
NeilBrown [Sun, 17 Oct 2021 09:29:16 +0000 (20:29 +1100)]
oceani: fix some incorrect section headers.

section header that just introduce code are 6 deep, not 2.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: clean up interp_prog()
NeilBrown [Sun, 17 Oct 2021 02:45:18 +0000 (13:45 +1100)]
oceani: clean up interp_prog()

In particular, use dup_value() to save the command arguments.
But also re-arrange code to make steps a bit cleaner.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add parse_context arg to all interp functions, and a few others.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: differentiate static-sized arrays from others.
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.

So detect and handle the difference now.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: don't allocate init value for non-initialized fields.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: implement struct field initialisation properly.
NeilBrown [Sat, 16 Oct 2021 05:09:59 +0000 (16:09 +1100)]
oceani: implement struct field initialisation properly.

I wasn't testing default initial values for struct fields, so of course
it didn't work.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move ->prepare_type call (back) into val_alloc()
NeilBrown [Thu, 14 Oct 2021 02:59:34 +0000 (13:59 +1100)]
oceani: move ->prepare_type call (back) into val_alloc()

This ensures it is called for struct fields as well.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: handle variable-sized arrays better.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix a couple of issues
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani - discard anon_typelist
NeilBrown [Sat, 9 Oct 2021 21:14:04 +0000 (08:14 +1100)]
oceani - discard anon_typelist

Don't keep anon types on a separate list, use the same list but given
them an empty name.

This allows us to use add_type() for adding all types.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: drop 'array' field from the 'value' union.
NeilBrown [Sat, 9 Oct 2021 01:05:51 +0000 (12:05 +1100)]
oceani: drop 'array' field from the 'value' union.

This field was never used - we use the generic 'ptr'.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: require all terms to be declared if any are.
NeilBrown [Thu, 7 Oct 2021 00:13:44 +0000 (11:13 +1100)]
parsergen: require all terms to be declared if any are.

The previous implementation only required all terms used for the first
time after a $TERM declaration to be declared.  That isn't really
useful.

So change it to only set the default symbol type of Term after all the
grammar is parsed, and then only if not $TERM declarations were found.

This highlights that various terminals in ocean weren't declared, so
declare them now.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: drop parse_value method for types.
NeilBrown [Sat, 2 Oct 2021 22:57:40 +0000 (09:57 +1100)]
oceani: drop parse_value method for types.

The args to 'program' are now all strings.  The program itself needs to
convert to numbers etc as needed.
So we don't need 'parse_value' any more.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoocean: introduce prefix op for string->number conversion.
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.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: separate types out from values
NeilBrown [Wed, 29 Sep 2021 22:21:15 +0000 (08:21 +1000)]
oceani: separate types out from values

Rather than embed the type in ever value, keep it separate.
This allows arrays without duplicating the member-type information.

Also review and clean up the commentary.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: add missing {}
NeilBrown [Tue, 6 Apr 2021 22:02:20 +0000 (08:02 +1000)]
parsergen: add missing {}

These have ALWAYS been missing, yet the code mostly worked.  Weird.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: doco updates
NeilBrown [Wed, 10 Mar 2021 05:14:20 +0000 (16:14 +1100)]
parsergen: doco updates

Minor revision to descriptive text following all the recent changes.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: don't bother with indent_depth
NeilBrown [Wed, 10 Mar 2021 04:26:59 +0000 (15:26 +1100)]
parsergen: don't bother with indent_depth

We don't need to store the indent_depth if we just shift the bit-stack
up and down.  <<1 pushes a zero, >>1 pops, |=1 changes the zero to one.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agooceani: updates for new approach to parsing indents.
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'.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoUpdate indent_test grammer to align with new approach
NeilBrown [Wed, 10 Mar 2021 01:13:05 +0000 (12:13 +1100)]
Update indent_test grammer to align with new approach

Indents are now now handled very differently.  Update itest
grammar to match.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: add support for EOL token
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.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: implement new handling of IN/OUT and 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.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out heart-of-the-parser code
NeilBrown [Wed, 10 Mar 2021 00:12:50 +0000 (11:12 +1100)]
parsergen: split out heart-of-the-parser code

This finishes the break up of the core parser code.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out the "shift or ignore" section of parsing.
NeilBrown [Wed, 10 Mar 2021 00:00:23 +0000 (11:00 +1100)]
parsergen: split out the "shift or ignore" section of parsing.

This will make it easier to document.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out reduce step of parser
NeilBrown [Tue, 9 Mar 2021 23:56:15 +0000 (10:56 +1100)]
parsergen: split out reduce step of parser

Split out the "reduce" code so it can be more easily documented.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out error handling.
NeilBrown [Tue, 9 Mar 2021 23:51:19 +0000 (10:51 +1100)]
parsergen: split out error handling.

I want to split up the core parsing into the different parts so they can
be documented better.
Firstly: split out error handling.

Signed-off-by: NeilBrown <neil@brown.name>