Files
nunuhara_xsystem4/test/Source/lang.jaf
T
Nunuhara Cabbage 470c051124 Implement full suite of array instructions
All array instructions supported by the SDK compiler, anyway. There are
a few instructions that were added in later versions, like A_FIND and
A_REVERSE.
2019-10-28 20:31:50 -07:00

68 lines
1.4 KiB
C
Executable File

// -*-mode: C; coding: sjis; -*-
int g;
void assign(ref int i, int v)
{
i = v;
}
void string_set_local(string s)
{
s = "oops";
}
void string_assign(ref string dst, string src)
{
dst = src;
}
struct lang_struct_inner {
int a;
};
struct lang_struct {
int a;
lang_struct_inner in;
};
void struct_set_a(lang_struct s, int i)
{
s.a = i;
}
void struct_set_inner(lang_struct s, int i)
{
s.in.a = i;
}
void array_set_local (array@int@2 ar, int i, int j, int v)
{
ar[i][j] = v;
}
functype int arithmetic(int, int);
int arithmetic_sub(int a, int b)
{
return a - b;
}
void test_lang(void)
{
int i;
string s;
lang_struct ls;
arithmetic f;
array@int@2 ar[2][2];
test_equal("global assignment", (g = 16, g), 16);
test_equal("ref assignment", (i = 0, assign(i, 32), i), 32);
test_string("string pass-by-value", (s = "test", string_set_local(s), s), "test");
test_string("string pass-by-ref", (s = "foo", string_assign(s, "bar"), s), "bar");
test_equal("struct pass-by-value", (ls.a = 42, struct_set_a(ls, 2), ls.a), 42);
test_equal("nested struct pass-by-value", (ls.in.a = 42, struct_set_inner(ls, 2), ls.in.a), 42);
test_equal("array pass-by-value", (ar[1][1] = 2, array_set_local(ar, 1, 1, 42), ar[1][1]), 2);
test_equal("conditional", (i = 1, i ? 42 : 0), 42);
test_equal("functype", (f = &arithmetic_sub, f(7, 2)), 5);
}