2021-01-30 20:27:10 +00:00
|
|
|
module statics
|
|
|
|
|
2021-01-30 23:37:53 +00:00
|
|
|
imports signatures/fostr-sig
|
|
|
|
|
2021-02-13 01:08:55 +00:00
|
|
|
/** md
|
|
|
|
Title: Adding Program Analysis with Statix
|
|
|
|
|
|
|
|
## Development of fostr static analysis
|
|
|
|
|
|
|
|
This section is more documentation of Spoofax in general and Statix
|
|
|
|
in particular than of fostr itself, but is being maintained here in case
|
|
|
|
it could be either helpful to someone getting started with Statix or
|
|
|
|
helpful in understanding how the static characteristics of fostr were designed.
|
|
|
|
|
|
|
|
As mentioned in the [Overview](../README.md), I don't like to program and a
|
|
|
|
corollary of that is never to use a facility unless/until there's a need for
|
|
|
|
it. So the first few rudimentary passes at fostr simply declared every program
|
|
|
|
to be "OK" from the point of view of Statix:
|
|
|
|
```statix
|
|
|
|
{! "\git docs/statix_start:trans/statics.stx" extract:
|
|
|
|
start: programOk
|
|
|
|
stop: (.*TopLevel.*)
|
|
|
|
!}
|
|
|
|
```
|
|
|
|
|
|
|
|
Then I reached the point at which the grammar was basically just
|
|
|
|
```SDF3
|
|
|
|
// Start.TopLevel = <Ex>
|
|
|
|
// Ex.Sequence = sq:Ex+ {layout: align-list sq}
|
|
|
|
// Ex.Terminated = <<Ex>;>
|
|
|
|
{! "\git docs/statix_start:syntax/fostr.sdf3" extract:
|
|
|
|
start: TermEx.Terminate
|
|
|
|
stop: (.*bracket.*)
|
|
|
|
!}
|
|
|
|
```
|
|
|
|
(The first three clauses are in comments because they approximate fostr's
|
|
|
|
grammar; it actually uses a few more sorts for sequences of
|
|
|
|
expressions, to acheive fostr's exact layout rules.)
|
|
|
|
|
|
|
|
This was the first point at which there were two different types that might
|
|
|
|
need to be written to standard output (Int and String), and although of course
|
|
|
|
the dynamically-typed Python and Javascript code generated dealt with both fine,
|
|
|
|
the Haskell code needed to differ depending on the
|
|
|
|
type of the item written (and I hadn't even started OCaml code generation at
|
|
|
|
that point since I knew it would be hopeless without statically typing fostr
|
|
|
|
programs).
|
|
|
|
|
|
|
|
So it was time to bite the bullet and add type checking via Statix to fostr.
|
|
|
|
**/
|
|
|
|
|
|
|
|
// see docs/implementation.md for detail on how to switch to multi-file analysis
|
2021-01-30 20:27:10 +00:00
|
|
|
|
|
|
|
rules // single-file entry point
|
|
|
|
|
2021-02-01 08:29:00 +00:00
|
|
|
programOk : Start
|
2021-01-30 20:27:10 +00:00
|
|
|
|
2021-02-01 08:29:00 +00:00
|
|
|
programOk(TopLevel(_)).
|
2021-01-30 20:27:10 +00:00
|
|
|
|
|
|
|
rules // multi-file entry point
|
|
|
|
|
|
|
|
projectOk : scope
|
|
|
|
|
|
|
|
projectOk(s).
|
|
|
|
|
2021-02-01 08:29:00 +00:00
|
|
|
fileOk : scope * Start
|
2021-01-30 20:27:10 +00:00
|
|
|
|
2021-02-01 08:29:00 +00:00
|
|
|
fileOk(s, TopLevel(_)).
|