hawk/hawk/t/h-001.hawk

96 lines
1.5 KiB
Plaintext
Raw Normal View History

@pragma entry main
function ensure (a, b, desc)
{
if (a != b)
{
print "FAILURE in", desc;
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;
b[2] = "perfect";
return a;
}
function call_by_ref_3(&x)
{
x = "hello world";
}
function main()
{
x = 20;
y = 90;
r = call_by_ref_1(x, y, z);
ensure (r, 1800, SCRIPTNAME);
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
## SCRIPTNAME doesn't tell the main file.
{
@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);
ensure (length(b), 2, SCRIPTNAME);
ensure (b[1], 99, SCRIPTNAME);
ensure (b[2], "perfect", SCRIPTNAME);
}
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);
}
{
@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);
}
print "SUCCESS"
}