662 Commits

Author SHA1 Message Date
Torin Sandall 58f476b5de Add table and global section encoding support
These sections are required so that we can statically link the policy
and the OPA-WASM library together.

Also, add test case that roundtrips the OPA module for sanity.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-09 14:38:48 -07:00
Torin Sandall 62fe077055 Add support for ir.Loop in compiler
These changes add basic support for ir.Loop in the compiler. To handle
the loop condition, the WASM library has been extended with a function
to set the value of a local boolean. This allows the compiler to
terminate the loop when a match is found.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-09 09:59:05 -07:00
Torin Sandall 90bda056b4 Add C library implementing operations for WASM
These changes add a C library that implements low-level data operations
and JSON parsing for WASM policies. The output of the WASM build process
are checked into the repository so that OPA can easily access the
bytecode for test and other purposes.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-08 17:29:18 -07:00
Torin Sandall 622bcbdf9d Add WASM compiler backend and required types
These changes implement a basic WASM compiler backend for the IR added
in the previous commit. These changes also include a binary-encoding
package that can roundtrip simple WASM modules.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-08 17:29:18 -07:00
Torin Sandall d3fb50ac35 Add basic IR and planner for Rego
The planner package implements a simple planner that takes Rego queries
and emits an intermediate representation (IR) that can be compiled or
evaluated. The planner provides the basis for compiling Rego into WASM.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-08 17:29:18 -07:00
Torin Sandall e04365e6ea Update format package to tolerate nil locations
Previously, the format package would return an error if any of the AST
nodes under the input were missing a location value. When the format
package was first implemented, the main use case was formatting policies
that people had written manually--which means they are provided to OPA
as files/raw strings. As a result, it made sense to treat a missing
location as an error condition because it simplifies the formatting
implementation.

However, when policies are generated (e.g., by partial evaluation) the
AST nodes do not typically carry locations. As a result, these AST nodes
cannot be formatted nicely.

These changes modify the format package to tolerate nil location values.
If a nil location value is encountered, the format package will set the
location value on the AST node to a default location, currently row 1
column 1 with text from the AST node's string representation.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-08-29 18:46:40 -07:00
Torin Sandall ab587d008b Improve formatting of empty ast.Body
Previously, if an empty ast.Body was passed to the formatting package,
it would trigger a panic because the location getter would try to index
into an empty slice.

These changes make the location getter tolerate empty bodies and the
format package tolerate nil locations on empty bodies. The changes also
improve simplify the error message when nil locations are found.

Fixes #909

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-08-29 13:12:16 -07:00
Torin Sandall a400fbab78 Add deps subcommand
These changes add a new subcommand that analyzes policies and prints
base and virtual document dependencies.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-08-21 10:47:46 -07:00
Torin Sandall b3b390098b Add --partial/--unknown flags to eval subcommand
These changes update the eval subcommand to support partial evaluation.
As part of these changes, the pretty formatting of partial evaluation
results has been refactored and moved into the presentation package. The
new version uses the tablewriter like other output values.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-08-17 14:19:57 -07:00
Torin Sandall aaf2ee0323 Fix REPL output for multiple bool exprs
The presentation implementation was trying to print a table with no
expression values or variable bindings. With these changes, the
presentation package will output 'true' if there are no vars and all of
the exprs are of type 'bool'.

Fixes #850

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-07-26 13:31:40 -07:00
Torin Sandall 4cfcd8498d Refactor presentation package interfaces
Previously, output was being printed in the presentation package, REPL,
and eval subcommand. Thes changes refactor the presentation package so
that it can handle all of the output printing required by the REPL and
the eval subcommand.

These changes affect the 'json' output format in the REPL. Previously,
the JSON output format would display either the expression value or
bindings. With these changes, the 'json' output format in the REPL is
the same as the one in the eval subcommand.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-07-26 13:31:40 -07:00
Torin Sandall 4b5a232cd2 Refactor presentation package and docs
Minor changes following eb5e5b243f

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-07-20 17:28:59 -07:00