# Packages
# README
Core
This package contains most the code for the Inox Runtime, the type checking logic is in the symbolic/ package.
Code organization
The code evaluation tests are the same for the bytecode interpreter and the tree walk evaluation, they are located in eval_test.go.
- Tree Walk Evaluation
- Bytecode Interpreter (inspired from https://github.com/d5/tengo.)
- Static Check
- Symbolic Evaluation and Typechecking
- Core Value Types
- Core Pattern Types
- Module
- Context & Security
- Transaction
- Secrets
- Mutation
- Database
- Debugger
- Testing
- Serialization / Deserialization
Module Preparation
Module preparation is implemented in module_preparation.go, it consists of several steps:
- Parsing
- Pre-initialization
- Context Creation
- Global State Creation
- Database Openings
- Retrieval of Project Secrets
- Static Checks
- Symbolic Evaluation (typechecking)
Note that module preparation is not used by module imports.
Parsing
Recursive parsing of the module and its imports.
Pre-initialization
The pre-initialization is the checking and creation of the module's manifest.
- the pre-init block is statically checked (if present).
- the manifest's object literal is statically checked.
- pre-evaluate the env section of the manifest.
- pre-evaluate the preinit-files section of the manifest.
- read & parse the preinit-files using the provided .PreinitFilesystem.
- evaluate & define the global constants (const ....).
- evaluate the preinit block.
- evaluate the manifest's object literal.
- create the manifest.
Context Creation
A context containing all the core pattern types (int, str, ...) is created. The most relevant inputs are:
- the permissions listed in the manifest
- the limits listed in the manifest
- the host definition data specified in the manifest
- the parent context (host definition data and limits are inherited)
Global State Creation
The global state of the module is created and is initialized with the default globals (variables, functions & namespaces).
Database Openings
Databases described in the manifest or created if necessary and opened.
Retrieval of Project Secrets
If a project has been passed its secrets are retrieved and the global project-secrets
is added to the state.
Static Checks
During this phase the code is analyzed in order to find the following issues:
- misplaced statements
- undeclared variables or patterns
- duplicate declarations
(and a few others)
Symbolic Evaluation
The symbolic evaluation of a module is a "virtual" evaluation, it performs checks similar to those of a type checker. Throughout the Inox documentation you may encounter the terms "type checker"/ "type checking", they correspond to the symbolic evaluation phase.
Transactions
Simplified State Diagram
stateDiagram-v2
[*] --> Running
DoingRollback: Doing Rollback
DoingCommit: Doing Commit
Running --> DoingRollback: context is cancelled
Running --> DoingRollback: timeout
Running --> DoingRollback: rollback
Running --> DoingCommit: commit
DoingRollback --> Finished
DoingCommit --> Finished