This is a list of extensions that burlap has.
Enables all extension flags.
Make return;
expand to return none;
and let x;
to let x = none;
Enables using internal burlap functions, see below.
A faster version of range
made for for-loops, burlap automatically uses it. Because of this, it cannot be disabled.
Ranges can be very wastful, as Burlap has to construct a List
and then immediately turn it into a __burlap_iter
, as well as storing every value that will be looped over.
__burlap_range
does better than just producing a __burlap_iter
, it makes a __burlap_rangetype
, which only stores (at, max, step)
and so the range can be a lot bigger and use very little memory.
Can be used to make a typed equality check between two values, for example:
# "true"
print(1 == 1.0);
# "false"
print(__burlap_typed_eq(1, 1.0));
It can also be used to compare internal types, which ==
cannot.
The following code is the pure-sack equivalent:
functi typed_eq(a, b) {
# Check value
if a == b {
# Check type
return type(a) == type(b);
}
return false;
}
Prints the burlap representation of val
. For example:
// Prints 'Str("Test")'
__burlap_print("Test");
Converts err
to a string a uses it as an error
if really_important_function() == false {
// Causes a run time error
__burlap_throw("failed to do important thing!");
}
// Carry on
print("It worked!");
Try to load the library libname
(raises an error on failure) and returns a (__burlap_ptr
) handle to it. Used for FFI with other programming languages. It internally uses dlopen
to load libraries.
Tries to find the symbol called name
in the library with handle libhandle
(raises an error on failure). Internally uses dlsym
to find symbols.
Calls func_ptr
with the C equivalent of args
, returns the return value as ret_type
.
Currently the members of args
and the value of ret_type
can be any of the following:
- Number (
int32_t
) - Decimal (
float
) - Byte (
uint8_t
) - Bool (
_Bool
) - String (
char*
) __burlap_ptr
(void*
)- None or an empty string (
void
, only valid for return types)
ret_type
is intentionally set up so that it can use the return value of type
For example: mylib.c
#include <stdio.h>
int double_num(int n) {
printf("N is: %i\n", n);
return n * 2;
}
and compile with <compiler> -shared -fPIC mylib.c -o mylib.so
Sack:
let handle = __burlap_load_lib("mylib.so");
let print_n = __burlap_load_functi(handle, "double_num");
// Should print "N is: 47"
let mynum = __burlap_ffi_call(print_n, [47], "Number")
// Should print "Doubled num: 94"
print("Doubled num: " + mynum)
The casting function for the __burlap_ptr
type, see below.
These types are internal to burlap, and shouldn't be seen by the average user.
A pointer type, unlike other internal types, __burlap_ptr
is meant to be interacted with. As such, it can be used with equivalence operators, has a cast (__burlap_ptr(x)
), and is returned from (extended) functions.
Used for loops, stores the list and the position.
Used for optimized ranges, stores the position, max value, and step, returned by __burlap_range
.