L1VM - ranges
L1VM - ranges
I did write a new feature for Brackets. Now you can set the legal range of variables by the range
keyword:
(x x_min x_max range)
Here x_min
is the minimum and x_max
the maximum value of x
.
If you assign a value outside this then you will get a runtime error!
The min/max variables must be of const
type.
Here is a full example:
// hello.l1com
// Brackets - Hello world!
//
#include <intr.l1h>
(main func)
(set int64 1 zero 0)
(set int64 1 x 23)
(set int64 1 y 42)
(set const-int64 1 x_min 0)
(set const-int64 1 x_max 10000)
(set double 1 xd 23.0)
(set double 1 yd 42.0)
(set const-double 1 x_mind 0.0)
(set const-double 1 x_maxd 42.0)
(set int64 1 z 43)
(set double 1 zd 43.0)
(set string 13 hello "Hello world!")
(x x_min x_max range)
(xd x_mind x_maxd range)
// print string
print_s (hello)
print_n
{x = (y * z)}
print_i (x)
print_n
{xd = (yd * zd)}
print_d (xd)
print_n
exit (zero)
(funcend)
The program shows this:
$ l1vm prog/hello-ranges -q
Hello world!
1806
ERROR: double variable value in illegal range!
epos: 309
So the double variable xd
would be out of range!