DEV Community

flisk
flisk

Posted on

Goose Hello World: print, Then Run It

Part 1 of Goose, then any language on Flisk. Language source: Goose, by example. The Flisk half is part 4, and it does not care which language this file is.

Install the compiler, not the agent

Download a release from aardappel/goose and put that directory on PATH. The compiler finds its standard library beside itself. Prebuilt compilers exist for Windows x64, Linux x64, and macOS Apple silicon and Intel. Linux wants glibc 2.35 or newer. macOS wants 13.3 or newer.

On macOS, clear quarantine on the unpacked directory or the binary will not start:

xattr -dr com.apple.quarantine /path/to/unpacked-goose
Enter fullscreen mode Exit fullscreen mode

which goose must be this compiler. If goose --help talks about LLM providers, that is a different program. Rename it off PATH before you continue.

In-process run needs libc headers: libc6-dev or glibc-devel on Linux, Xcode command line tools on macOS. goose build also needs gcc or clang.

The program

mkdir -p ~/src/goose-flisk && cd ~/src/goose-flisk
Enter fullscreen mode Exit fullscreen mode

hello.goose:

fn main() {
    print("hello, goose");
}
Enter fullscreen mode Exit fullscreen mode

Every program starts at fn main. print takes any number of arguments, renders each, and writes one line. There is no format string.

goose hello.goose
Enter fullscreen mode Exit fullscreen mode

Expected:

hello, goose
Enter fullscreen mode Exit fullscreen mode

No verb, and goose run, both compile into the compiler's own process with TinyCC. That is the loop while you are reading. goose check hello.goose only typechecks.

A second print, still one line each:

fn main() {
    print("hello, goose");
    print("answer=", 42, " ratio=", 0.75, " yes=", 3 > 2);
}
Enter fullscreen mode Exit fullscreen mode

42 is an integer. 0.75 is a float. 3 > 2 is a bool. print renders all of them. Arrays print as [1, 2, 3]. You will use that in part 3.

A real binary

goose build hello.goose && ./hello
Enter fullscreen mode Exit fullscreen mode

goose build writes an executable beside the source. goose -o hello.c hello.goose writes the C if you want to compile it yourself. goose build --dry-run hello.goose prints the C command it would run.

Name later programs something other than goose. The compiler is already called that.

Part 2 is how a function is written. main is already one.

Top comments (0)