Here's how to write your very first fox program in six steps on either Ubuntu 18.04
or Windows 10
. In general, you first write your .fox
source files and compile them to get .s
files, containing assembly instructions. Those go into the assembler, which generates machine code and writes that to .o
(Linux) or .obj
(Windows) files. Then the linker combines these into an executable with no (Linux) or .exe
(Windows) extension. Note that both the assembler and linker step is done in one command on Linux and Windows.
- Verify that you have
gcc
installed. We needgcc
for its assembler and linker. I usegcc 7.5
but other versions may also work just fine. No guarantees though.
$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
-
Download the latest Linux release of the fox compiler
foxy
from the releases page and place it in a folder of your choice. Let's say you picked~/fox-dev
for example. You can also choose to just buildfoxy
yourself by cloning this repository and runningmake
in the/foxy
subdirectory. -
Now we are ready to create the minimal fox program
life
. As the name implies, it's very powerful and returns the number42
. And it does all that in just one single source file calledlife.fox
. Fist we navigate to~/fox-dev
and then we write the source file.
$ cd ~/fox-dev
$ echo "# hello fox" > life.fox
$ echo "var x" >> life.fox
$ echo "x 42" >> life.fox
$ echo "return x" >> life.fox
- Let's compile
life
. We simply supply our platform with-platform linux-gcc
and a list of source files to the compiler.
$ ./foxy -platform linux-gcc life.fox
life.fox
life.fox -> life.s
- Now assemble and link the fox program with a little help from our friend
gcc
.
$ gcc life.s -o life
- Run
life
and print the previous program's return code withecho $?
. Verify that the answer to the ultimate question of life, the universe, and everything, is indeed42
.
$ ./life
$ echo $?
42
-
Install
Visual Studio
if you don't have it yet. We need it for its assembler and linker. I useVisual Studio Community 2019
but 2017 should be compatible as well. -
Grab the latest Windows release of the fox compiler
foxy
from the releases page and extract it to a folder of your choice. Let's use the folderC:\fox-dev
for example. -
Time to create our first fox program. It will be called
life
and consists of just a single source file:life.fox
. It's very complex and returns the number42
. First, you need to open thex64 Native Tools Command Prompt for Visual Studio 2019
. It's easy to find if you open your start menu and begin typing in the first letters. Then enter the following commands in the prompt that pops up to navigate to our folderC:\fox-dev
and write the source filelife.fox
:
> cd c:\fox-dev
> echo # hello fox > life.fox
> echo var x >> life.fox
> echo x 42 >> life.fox
> echo return x >> life.fox
- Now it's time to compile
life
. We simply supply our platform with-platform win-vs
and a list of source files tofoxy
:
> foxy -platform win-vs life.fox
life.fox
life.fox -> life.s
- Next we need to assemble and link the fox program. We will use the
Microsoft Macro Assembler
andMicrosoft Incremental Linker
tools that come withVisual Studio
for this.
> ml64 life.s /link /ENTRY:main
- Let's run
life
and then check that it returned42
by printing%errorlevel%
. Make sure that our program did indeed return the answer to the ultimate question of life, the universe, and everything.
> life
> echo %errorlevel%
42