mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-25 16:37:56 +03:00
174 lines
3.6 KiB
C
Executable File
174 lines
3.6 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;
|
|
}
|
|
|
|
int test_switch(int i)
|
|
{
|
|
switch (i) {
|
|
case 0: return 0;
|
|
case 1: return 1;
|
|
case 2: return 2;
|
|
}
|
|
return 100;
|
|
}
|
|
|
|
int test_switch_default(int i)
|
|
{
|
|
switch (i) {
|
|
case 0: return 0;
|
|
case 1: return 1;
|
|
case 2: return 2;
|
|
default: return 100;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int test_string_switch(string s)
|
|
{
|
|
switch (s) {
|
|
case "a": return 0;
|
|
case "b": return 1;
|
|
case "c": return 2;
|
|
}
|
|
return 100;
|
|
}
|
|
|
|
int test_string_switch_default(string s)
|
|
{
|
|
switch (s) {
|
|
case "a": return 0;
|
|
case "b": return 1;
|
|
case "c": return 2;
|
|
default: return 100;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
ref int gi;
|
|
|
|
void set_page_ref(int v)
|
|
{
|
|
gi <- v;
|
|
}
|
|
|
|
void test_ref_compare(void)
|
|
{
|
|
int i;
|
|
int j;
|
|
ref int rn;
|
|
ref int ri = i;
|
|
ref int rj = j;
|
|
|
|
test_bool("NULL === NULL", rn === NULL, true);
|
|
test_bool("NULL !== NULL", rn !== NULL, false);
|
|
test_bool("ri === NULL", ri === NULL, false);
|
|
test_bool("ri !== NULL", ri !== NULL, true);
|
|
test_bool("ri === ri", ri === ri, true);
|
|
test_bool("ri !== ri", ri !== ri, false);
|
|
test_bool("ri === rj", ri === rj, false);
|
|
test_bool("ri !== rj", ri !== rj, true);
|
|
}
|
|
|
|
void func_stack2(void)
|
|
{
|
|
func_stack1();
|
|
}
|
|
|
|
void func_stack1(void)
|
|
{
|
|
func_stack0();
|
|
}
|
|
|
|
void func_stack0(void)
|
|
{
|
|
test_string("system.GetFuncStackName(0)", system.GetFuncStackName(0), "func_stack0");
|
|
test_string("system.GetFuncStackName(0)", system.GetFuncStackName(1), "func_stack1");
|
|
test_string("system.GetFuncStackName(0)", system.GetFuncStackName(2), "func_stack2");
|
|
}
|
|
|
|
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);
|
|
test_equal("switch", test_switch(2), 2);
|
|
test_equal("switch (no default)", test_switch(3), 100);
|
|
test_equal("switch (default)", test_switch_default(3), 100);
|
|
test_equal("string switch", test_string_switch("b"), 1);
|
|
test_equal("string switch (no default)", test_string_switch("d"), 100);
|
|
test_equal("string switch (default)", test_string_switch_default("d"), 100);
|
|
test_equal("local ref escape", (set_page_ref(42), gi), 42);
|
|
func_stack2();
|
|
'message1';
|
|
'message2';
|
|
test_ref_compare();
|
|
}
|
|
|
|
int msg_count = 0;
|
|
|
|
void message(int msg_nr, int nr_messages, string msg)
|
|
{
|
|
if (msg_count == 0)
|
|
test_string("message1", msg, "message1");
|
|
else if (msg_count == 1)
|
|
test_string("message2", msg, "message2");
|
|
msg_count++;
|
|
}
|