2020-04-14 07:40:30 +00:00
|
|
|
@pragma entry main
|
|
|
|
|
2020-04-14 11:45:52 +00:00
|
|
|
|
2020-04-14 07:40:30 +00:00
|
|
|
function ensure (a, b, desc)
|
|
|
|
{
|
|
|
|
if (a != b)
|
|
|
|
{
|
2020-04-14 11:45:52 +00:00
|
|
|
print "FAILURE in", desc;
|
2020-04-14 07:40:30 +00:00
|
|
|
exit (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function call_by_ref_1(&a, b, &c)
|
|
|
|
{
|
|
|
|
c = "hello, world";
|
|
|
|
return b * a;
|
|
|
|
}
|
|
|
|
|
|
|
|
function call_by_ref_2(a, &b)
|
|
|
|
{
|
|
|
|
b[1] = b[1] * a;
|
2020-04-14 11:45:52 +00:00
|
|
|
b[2] = "perfect";
|
2020-04-14 07:40:30 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2020-04-25 18:35:04 +00:00
|
|
|
function call_by_ref_3(&x)
|
|
|
|
{
|
|
|
|
x = "hello world";
|
|
|
|
}
|
|
|
|
|
2020-04-14 07:40:30 +00:00
|
|
|
function main()
|
|
|
|
{
|
|
|
|
x = 20;
|
|
|
|
y = 90;
|
|
|
|
r = call_by_ref_1(x, y, z);
|
2020-04-14 11:45:52 +00:00
|
|
|
ensure (r, 1800, SCRIPTNAME);
|
2020-04-14 07:40:30 +00:00
|
|
|
ensure (x, 20);
|
|
|
|
ensure (y, 90);
|
|
|
|
ensure (z, "hello, world");
|
|
|
|
|
|
|
|
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
|
2020-04-14 11:45:52 +00:00
|
|
|
## SCRIPTNAME doesn't tell the main file.
|
2020-04-14 07:40:30 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
@local b;
|
|
|
|
call_by_ref_2(99, b);
|
|
|
|
ensure (b[1], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
@local b;
|
|
|
|
b[1] = 1;
|
|
|
|
r = call_by_ref_2(99, b);
|
|
|
|
ensure (r, 99);
|
|
|
|
ensure (b[1], 99);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
@local b;
|
|
|
|
b[1] = 1;
|
|
|
|
r = hawk::call("call_by_ref_2", 99, b);
|
|
|
|
ensure (r, 99);
|
2020-04-14 11:45:52 +00:00
|
|
|
ensure (length(b), 2, SCRIPTNAME);
|
|
|
|
ensure (b[1], 99, SCRIPTNAME);
|
|
|
|
ensure (b[2], "perfect", SCRIPTNAME);
|
2020-04-14 07:40:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 17:27:56 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
@local a;
|
|
|
|
a[1] = hawk::array();
|
|
|
|
a[1][2]=20;
|
|
|
|
ensure (a[1][2], 20, SCRIPTNAME);
|
|
|
|
a[1][2]++;
|
|
|
|
ensure (a[1][2], 21, SCRIPTNAME);
|
|
|
|
--a[1][2];
|
|
|
|
ensure (a[1][2], 20, SCRIPTNAME);
|
|
|
|
}
|
|
|
|
|
2020-04-25 18:35:04 +00:00
|
|
|
{
|
|
|
|
@local a;
|
|
|
|
a = hawk::array();
|
|
|
|
a[10] = "good";
|
|
|
|
call_by_ref_3(a[9]);
|
|
|
|
ensure (a[10], "good", SCRIPTNAME);
|
|
|
|
ensure (a[9], "hello world", SCRIPTNAME);
|
|
|
|
call_by_ref_3(a[10]);
|
|
|
|
ensure (a[10], "hello world", SCRIPTNAME);
|
|
|
|
ensure (a[9], "hello world", SCRIPTNAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-14 07:40:30 +00:00
|
|
|
print "SUCCESS"
|
|
|
|
}
|