Running crow programs

In this section, we'll run this "hello world" program using different methods.

main void() info log "Hello, world!"

Run in the browser

Click the button at the bottom of the code block above to run it in the browser.
The code is editable, so you can test things out there while reading the tutorial.
This supports all Crow standard library functions, but it can't do I/O except for printing.

Download and run

Code blocks can be downloaded using the button.
Alternatively, use the 📋 button to copy the code and paste it into a file.

Run with the interpreter

For the next step, you must download and install crow.
Open a terminal and navigate to crow/demo.
Then, run crow hello.crow.
./hello.crow also works (but not on Windows) thanks to the shebang at the top.

The interpreter should be your default option for running code in development, since it quickly starts running code.

Build an executable

Run crow build hello.crow to generate a standalone executable.
The executable will be called hello, or hello.exe on Windows.

"Standalone" means that it can run on a computer that doesn't have crow installed. That makes it a good option for deploying code to a server or distributing to users.

Compile to C

Run crow build hello.crow --out hello.c to "transpile" to a C program.
The C code is pretty ugly, but it can be useful if you want to use a C debugger to debug Crow code.
A comment at the top of the file contains the compile command to use on it.

Compile and run

crow run hello.crow --aot will compile and run native code.
Compared to the interpreter, this takes longer to start but runs faster afterwards. (Even more so with the --optimize flag.) Use this for big jobs.
This uses the same compiler as crow build, but it cleans up the executable after running.

Script arguments

With crow run, arguments are normally for crow, not the script it's running.
But after --, arguments are passed to the script. So for an --aot equivalent to ./hello.crow args here, run:
crow run hello.crow --aot -- args here

To access the arguments, use this alternative signature for main:

main nat(args string[]) info log "arguments are: {" " join args}" 0 # exit code

(There's no way to pass command-line arguments in the browser.)

Just print errors

Run crow check hello.crow to just print compile errors (and warnings) without building or running the code.

Compile errors don't stop the program

crow run hello.crow will usually try to run code even if there were compile errors.
If a compile error is reached, it throws an exception.

Try running the below code (through any method except crow build).
It will run the program normally until it reaches the compile error, then throw an exception.

main void() info log "hello, world" call-a-function-that-does-not-exist info log "goodbye, world" ()