You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement a direct translation of JuvixCore to VampIR.
It can be assumed that we're translating a single main function of type Int -> ... -> Int -> Int which has the form \x1 ... \xn -> b where the body b can contain only:
the variables x1,...,xn,
integer constants,
fully applied arithmetic operations and comparisons (OpInt* and OpEq from BuiltinOp in Core),
if-then-else, i.e., case expressions on booleans,
boolean constructors (with tags TagTrue and TagFalse),
fully applied failure nodes (OpFail),
let bindings of type Int at the top only (these should be translated to VampIR local definitions; see also Let hoisting #2033).
In particular, b doesn't contain lambdas, identifiers or inductive types other than booleans.
Ultimately, we should support arbitrary finite first-order data types in the type of the main function, with some fixed encoding to tuples of integers/field elements. It is easy to support Bool in addition to Int.
A quick and generally incorrect way of translating the failure nodes is to replace them with 0. The resulting VampIR programs will compile because Int is the only type. They will work correctly as long as the recursion limit is not reached. Perhaps this should be done at first. A proper way is to encode them with pairs (see B.7 in the Juvix-to-VampIR pipeline report).
Implementing booleans in VampIR is explained in the VampIR book (section Boolean logic). If-then-else with both branches integers can be implemented as:
def if b x y = b * x + (1 - b) * y;
Equality checking can be implemented as:
def isZero x = {
def xi = fresh (1 | x);
x * (1 - xi * x) = 0;
1 - xi * x
};
def equal x y = isZero (x - y);
I'm not sure how we should implement less-than, but we can ignore it for now.
Thanks! For natural numbers I guess just checking a \ b = 0 would be better. Ultimately, I think the field should be exposed directly as a separate type Field with its own operations, and integers should be a different type Int (or Int32) with less-than comparisons based on bitwise decomposition.
Implement a direct translation of JuvixCore to VampIR.
It can be assumed that we're translating a single main function of type
Int -> ... -> Int -> Int
which has the form\x1 ... \xn -> b
where the bodyb
can contain only:x1
,...,xn
,OpInt*
andOpEq
fromBuiltinOp
in Core),TagTrue
andTagFalse
),OpFail
),let
bindings of typeInt
at the top only (these should be translated to VampIR local definitions; see also Let hoisting #2033).In particular,
b
doesn't contain lambdas, identifiers or inductive types other than booleans.Ultimately, we should support arbitrary finite first-order data types in the type of the main function, with some fixed encoding to tuples of integers/field elements. It is easy to support
Bool
in addition toInt
.A quick and generally incorrect way of translating the failure nodes is to replace them with 0. The resulting VampIR programs will compile because Int is the only type. They will work correctly as long as the recursion limit is not reached. Perhaps this should be done at first. A proper way is to encode them with pairs (see B.7 in the Juvix-to-VampIR pipeline report).
Implementing booleans in VampIR is explained in the VampIR book (section Boolean logic). If-then-else with both branches integers can be implemented as:
Equality checking can be implemented as:
I'm not sure how we should implement less-than, but we can ignore it for now.
References
The text was updated successfully, but these errors were encountered: