Compiler: Using Command-line Interface
Help Command
coco help [command]
Prints global help or command-specific help.
Version Command
coco version
Prints the current Coco version.
Optional Flags
flag | description | supported values |
---|---|---|
-s, --suppress-banner | suppress the cocolang figlet banner | n/a |
Nut Command
coco nut init <module_name>
coco nut run <script-name>
The nut
command manages coco.nut
file, the manifest file for a module of .coco
source file(s).
-
init
creates a coco.nut manifest in the current folder. -
run
executes a named script defined in coco.nut.
Nut Init Subcommand
coco nut init <module_name>
creates a file with the following contents:
[coco]
version = "0.7.0"
[module]
name = "Module"
version = "0.0.1"
license = []
repository = ""
authors = []
[target]
os = "MOI"
arch = "PISA"
[target.moi]
format = "YAML"
output = "module"
[target.pisa]
format = "BIN"
version = "0.5.0"
[lab.render]
big_int_as_hex = true
bytes_as_hex = false
[lab.config.default]
env = "main"
[lab.scripts]
test-toggle = ["engines", "users", "logics"]
[scripts]
compile = "coco compile ."
While all fields in the coco.nut
file are mandatory, the only currently supported target is MOI Manifests (os = “MOI”) for the PISA runtime (arch = “PISA”), so only [target.moi] and [target.pisa] parameter values affect compilation. Allowed values for these parameters are:
[target.moi]
// output format, the output file extension will be
// .yaml, .json or .polo, respectively
format = "YAML", "JSON" or "POLO"
// output file name (with extension) - by default, it's lowercase module name
output = "module.yaml"
[target.pisa]
// format of executable code in PISA manifest
// "ASM" and "HEX" supported from Coco compiler release v0.3.1
format = "BIN", "ASM" or "HEX"
Optional Flags
flag | description | supported values |
---|---|---|
-f, --force | allow overwriting coco.nut file in the current folder, if it exists | n/a |
Nut Run Subcommand
coco nut run <script-name>
run command runs the script script-name
that’s defined in the coco.nut
file. The definition contains shell/terminal commands that can run on Windows/Linux/Mac. The default contains an example of compile
script that rust coco compile
command.
[scripts]
compile = "coco compile ."
Script name can be any string and inside it can be bash script joined with cmd1 && cmd2
.
Compile Command
coco compile [path_to_coco.nut]
The compile
command compiles a .coco
source(s) of a module into a target artifact as defined in the coco.nut
file. When called without specified path to a coco.nut
file, the file in the current folder is used and the target artifact is created in the current folder. When path is specified, the artifact is created in the same folder, as coco.nut
file.
Source .coco
files can have any file names, but only the ones with coco <module_name>
that matches module.name
in the coco.nut
file are used for compilation. Multiple source files for a single module are supported.
Optional Flags
flag | description | supported values |
---|---|---|
--debug | print the opcodes of compiled functions | n/a |
--ast | print the AST as JSON | n/a |
-O, --optimize | optimization level [default: 2] | any valid positive number |
-f, --fileform <MANIFEST_FORMAT_OVERRIDE> | override manifest format | yaml, json, polo |
-c, --codeform <BINARY_FORMAT_OVERRIDE> | override binary format | bin, asm, hex |
Test Command
coco test --debug_pisa <module_name>
The test
command compiles and runs the module without the LogicLab utility. It executes the testcases without looking into the coco.nut
file. When --debug_pisa
flag is passed, the test invokes // <
comments and expects the results from // >
comment. These comments can be placed anywhere and will be executed in order as they are written, they just have to come in pairs // >
followed by // <
. For invoke
commands, module name is always TEST
, regardless of the actual module name.
// < invoke TEST.TstMax(a: 5, b:3)
// > max: 5
// < invoke TEST.TstMax(a: 5, b:7)
// > max: 7
// < invoke TEST.TstMax(a: 3, b:3)
// > max: 3
// TstMax is defined just to test the local "max" function as one can't invoke local functions
endpoint TstMax(a, b U64) -> (max U64):
max = (max) <- max(a:a, b:b)
function max(a, b U64) -> (max U64):
if a >= b:
return (max: a)
max = b
Optional Flags
flag | description | supported values |
---|---|---|
--fuel | fuel set [default: 10000] | any valid positive number |
--debug | print the opcodes of compiled functions | n/a |
--sender | sender address (you can set the sender address yourself else a new one is generated each time the command is run) | any valid address |
--debug_pisa | enable pisa debug mode | n/a |
-O, --optimize | optimization level [default: 2] | any valid positive number |