sai-language
Version:
An object-oriented language designed to afford code comprehension and maintenance. Transpiles in-place to Javascript.
88 lines (47 loc) • 2.4 kB
Markdown
## Command line programs
### SAI script runner: sai-run
`sai-run` can be executed on the command line with a path to a SAI object.
sai-run [path/objectname]
The object will be created and instantiated immediately.
For example:
// HelloWorld.sai
object HelloWorld main 1.0.0
Instantiate task
debug 'Hello world!'
Then compiling and executing:
$ sai-run HelloWorld
Hello world!
Code for the builder is located in the `runner.sai` script.
### SAI script compiler: sai-build
This doc is a little out of date, execute sai-build to see current notes.
`sai-build` can be executed on the command line with a path to a SAI object.
sai-build [path/objectname]
A full prototype for that object will be written to STDOUT. If your project has multiple objects, you will need to compile each object independently and save it to its own `.js` file.
Example:
$ sai-build sample/Impossible/Impossible >impossible.js
$ node impossible.js
Mathemetician's "Impossible" puzzle solver.
Initial candidate count: 2304
Phase 2 candidate count: 145
Phase 3 candidate count: 86
Results candidate count: 1
Solution 1: X=4, Y=13; sum=17, product=52
The prototype will require the `sai-library` package.
Code for the builder is located in the `builder.sai` script.
#### Pre-compiled stand-alone projects
If you wish to omit the use of `sai-language` in your project, you must compile everything before-hand.
The run-time library will not use the dynamic **create** loader, instead expecting all objects to be precompiled and available by the run-time loader which uses the native `require`.
#### Compiled SAI as main()
To mark an object for immediate instantiation when `require`d (e.g. when run on the command line), add **main** to the object definition as follows:
object [objectname] main [objectversion]
When the resulting Javascript file is executed, a single version of the object will be instantiated, thus invoking the **Instantiate** task.
For example:
// HelloWorld.sai
object HelloWorld main 1.0.0
Instantiate task
debug 'Hello world!'
Then compiling and executing:
$ sai-build HelloWorld >helloworld.js
$ node helloworld.js
Hello world!
When using `sai-run` the **main** clause is not necessary, but still best practice.