Alucard
The easiest way to install Alucard at the moment is through ros.
ros install sbcl-bin
ros install asdf
git clone https://github.com/anoma/juvix-circuits.git
cd juvix-circuits
ros install "nobody-famous/alive-lsp"
make install
make all
will install it in ./build/
as well.The last command will add it to ~/.local/bin/
, so make sure that is on your path!
Now we can run alucard!
There are basically 2 ways to run alucard programs.
The interactive mode is via a REPL in Emacs/VSCode. To run the interactive mode,
If you are using a SLIME (VS-Code uses SLIME), replace the -y
with -s
.
Then use your client (e.g. Slime or Sly) to connect to localhost with port 4005 (or whatever port is shown in the terminal). You can set the port with the -p
option.
If you are using vscode it might spit you out in the cl-user package. to check your prompt should say ALUSER>
in vs-code or emacs. If that is the case then run the following
one can quit out of the repl by typing (quit)
.
Batch mode lets you provide input from files to the alu.image
executable with the -i
flag and specify the output file with the -o
flag.
If the -o
flag is not given, you will go into interactive mode.
To specify the function that will act as the entry point to one's circuit, you can write
(entry-point function-name)
in the file, otherwise no code will be generated.
If you are running sly, M-x sly-connect
to localhost with the port number shown in your terminal earlier.
If one is using ccl
instead of SBCL
you might want to run:
You can also (ql:quickload :alu)
if one has the asd
file on the path or have loaded into one's environemnt, and have the same functionality!
Please check the readme
You know you are ready to get going when typing *package*
in your REPL returns
or your REPL prompt says ALUSER>
.
Let's define a simple circuit, which represents the equation, .
In the above code, the keyword defcircuit
is used to denote that we are defining a polynomial circuit, named add-three
. The circuit takes as input the integer x
, which is a public
input, and the output is true
if the equation is satisfied, and false if not.
To get the VAMP-IR code corresponding to any circuit defined below, call the function
vampir
on it.
For example, the VAMP-IR code for add-three
is shown below.
Note that since the compiler pipeline is currently incomplete, it is not yet possible to run VAMP-IR and generate output.
Currently it's good to run vampir
on various circuits created, as the type checker currently only runs when trying to extract.
Let's look at some more examples.
The follow circuit represents the equation .
We can also define a circuit to calculate the square root of an input in the following manner.
The def
plays a role similar to let
in Rust. The with-constraint
macro can be used in any situation where we want a variable to be subject to certain constraints.
Alucard also allows us to define custom datatypes.
Let us define the type point
which defines a point on the Cartesian plane.
Let's write a function to calculate the distance of this point from the origin. We'll make use of the square-root
function we wrote earlier.
Let us now mark this function as the entry point to the file
(entry-point distance)
We can also invoke the same functionality from the repl as well
Some of this formula is repetitive, namely the (exp (lookup pt) 2)
we can use the common lisp integration to remove such repetitive looking code.
Namely we can use flet
, which defines a local function to be our square function.
If we find this function general enough we can move it to the top level with defun
.
A lot more can be abstracted, we have the entire toolkit of the common lisp programming language to help abstract away alucard code!
A lot more information on this can be found in the reference manual
Let us say we try to make a type error.
In this code, we are saying the expected output of square should be of (int 32)
, however the type should really just be int
. We can move this check
to any part of the expression in the square
function and the error would be the same.
Here we get the type error message saying that (int 32)
and int
are not compatable, and further the stack trace to the point.
It is saying that the expression (EXP CORD 2)
caused the error as we stated that the type must be of (int 32)
right before!
The stack trace just give the expression dump until the current point where the error occurs.
If the system errors with a very baroque error message like
And spits you into a repl, please file an issue or message mariari
directly. These are internal errors and they might show up!