Reserved keywords
FunC reserves the following symbols and words. These cannot be used as identifiers.Symbols
+ - * /
% ? : ,
; ( ) [
] { } =
_ < > &
| ^ ~ ==
!= <= >= <=>
<< >> ~>> ^>>
~/ ^/ ~% ^%
/% += -= *=
/= ~/= ^/= %=
~%= ^%= <<= >>=
~>>= ^>>= &= |=
^= ->
Words
return var repeat do
while until try catch
if ifnot then else
elseif elseifnot int cell
slice builder cont tuple
type forall extern global
asm impure inline inline_ref
auto_apply method_id operator infix
infixl infixr const #pragma
#include
Built-ins
This section covers extra language constructs that are not part of the core but are still important for functionality. Although they could be implemented in stdlib.fc, keeping them as built-in features allows the FunC optimizer to work more efficiently. In addition, FunC does not allow the built-in names in this section to be used as identifiers. However, there is an exception: built-ins with non-symbolic names can be used as identifiers for local variables.Built-ins with symbolic names
_+_ _-_ -_ _*_
_/_ _~/_ _^/_ _%_
_~%_ _^%_ _/%_ _<<_
_>>_ _~>>_ _^>>_ _&_
_|_ _^_ ~_ ^_+=_
^_-=_ ^_*=_ ^_/=_ ^_~/=_
^_^/=_ ^_%=_ ^_~%=_ ^_^%=_
^_<<=_ ^_>>=_ ^_~>>=_ ^_^>>=_
^_&=_ ^_|=_ ^_^=_ _==_
_!=_ _<_ _>_ _<=_
_>=_ _<=>_
Each one of the above names is a function wrapping the corresponding operator.
For example, _+_ can be understood as wrapping the + operator:
apply receives as argument a function f of type (int, int) -> int
and applies it on the arguments 2 and 3:
apply by passing _+_:
+ directly does not compile:
Built-ins with non-symbolic names
divmod ~divmod moddiv ~moddiv
muldiv muldivr muldivc muldivmod
true false nil Nil
null? throw throw_if throw_unless
throw_arg throw_arg_if throw_arg_unless load_int
load_uint preload_int preload_uint store_int
store_uint ~store_int ~store_uint load_bits
preload_bits int_at cell_at slice_at
tuple_at at touch ~touch
touch2 ~touch2 ~dump ~strdump
run_method0 run_method1 run_method2 run_method3
divmod
divmod takes two integers as input and returns the quotient and remainder of their division dividend / divisor.
~divmod
Same as divmod, but allows using modifying notation.
Example:
moddiv
moddiv takes two integers as input and returns the remainder and quotient of their division dividend / divisor.
~moddiv
Same as moddiv, but allows using modifying notation.
Example:
muldiv
muldiv performs a multiply-then-divide operation (factor1 * factor2) / divisor, where / is the division operator.
It uses a 513-bit intermediate result to prevent overflow if the final result fits within 257 bits.
muldivr
muldivr performs a multiply-then-divide operation (factor1 * factor2) ~/ divisor, where ~/ is the rounding division operator.
It uses a 513-bit intermediate result to prevent overflow if the final result fits within 257 bits.
muldivc
muldivc performs a multiply-then-divide operation (factor1 * factor2) ^/ divisor, where ^/ is the ceiling division operator.
It uses a 513-bit intermediate result to prevent overflow if the final result fits within 257 bits.
muldivmod
muldivmod performs a multiply-then-divide operation (factor1 * factor2) / divisor, where / is the division operator,
and returns the quotient and remainder of such division. It uses a 513-bit intermediate result to prevent overflow if the final result fits within 257 bits.
true
true is an alias for -1.
false
false is an alias for 0.
nil
nil is an alias for the null value.
Nil
Nil is an alias for the empty tuple [].
null?
null? checks if the given argument is null. Returns 0 if the argument is not null, and -1 otherwise.
For more info, see null values.
throw
throw takes only one argument, the error code. See TVM error codes for details about error codes.
throw_if
-1.
It receives two arguments: the error code, which defines the exception type, and the condition.
See TVM error codes for details about error codes.
throw_unless
0.
It receives two arguments: the error code, which defines the exception type, and the condition.
See TVM error codes for details about error codes.
throw_arg
try..catch statements.
Refer to the try..catch statement page for an example on how to use the first argument.
The second argument is the error code. See TVM error codes for details about error codes.
throw_arg_if
-1.
Similarly to throw_arg, the first argument can be of any type, and it is used to pass extra information about the error. This extra information can be
processed in try..catch statements, in the same way as with throw_arg.
The second argument is the error code. See TVM error codes for details about error codes.
The third argument is the condition to check.
throw_arg_unless
0.
Similarly to throw_arg, the first argument can be of any type, and it is used to pass extra information about the error. This extra information can be
processed in try..catch statements, in the same way as with throw_arg.
The second argument is the error code. See TVM error codes for details about error codes.
The third argument is the condition to check.
load_int
len-bit integer from slice s. Returns the modified slice and the obtained integer.
load_uint
len-bit integer from slice s. Returns the modified slice and the obtained unsigned integer.
preload_int
len-bit integer from slice s. Returns the obtained integer. This method does not modify slice s.
preload_uint
len-bit integer from slice s. Returns the obtained unsigned integer. This method does not modify slice s.
store_int
len-bit integer x in builder b. Returns the modified builder.
store_uint
len-bit integer x in builder b. Returns the modified builder.
~store_int
store_int, but adapted to use modifying notation.
~store_uint
store_uint, but adapted to use modifying notation.
load_bits
len bits from slice s. It returns the modified slice and a slice containing the loaded bits.
preload_bits
len bits from slice s. It returns a slice containing the loaded bits. This method does not modify slice s.
int_at
index in tuple t, casted as an integer.
It is responsibility of the programmer to check that the returned element is actually an integer.
cell_at
index in tuple t, casted as a cell.
It is responsibility of the programmer to check that the returned element is actually a cell.
slice_at
index in tuple t, casted as a slice.
It is responsibility of the programmer to check that the returned element is actually a slice.
tuple_at
index in tuple t, casted as a tuple.
It is responsibility of the programmer to check that the returned element is actually a tuple.
at
index in tuple t. The returned element can be of any type.
touch
v to the top of the stack. It returns the argument v.
~touch
~touch is identical to touch, but adapted to use modifying notation.
touch2
t to the top of the stack; first component with type X and then component with type Y. It returns the argument tensor t.
~touch2
~touch2 is identical to touch2, but adapted to use modifying notation.
~dump
value to the debug log. It returns the argument value and the unit value ().
Modifying notation can be used on this function.
In case value is a slice containing ASCII characters, it is preferable to use ~strdump if the intention is
to print the ASCII string in the debug log. Otherwise, ~dump will print the slice’s contents as bits.
~strdump
s. It returns the argument s and the unit value ().
Modifying notation can be used on this function.
If the argument s is not a slice containing ASCII characters, the debug log will show an error.