int main (int argc, char *argv[]) { SyxOop instance; SyxOop context; SyxOop process; SyxOop result; /* initialize Syx */ syx_init (argc, argv, NULL); /* load the default image */ syx_memory_load_image (NULL); /* now file in class and method declarations from our ST file */ syx_cold_file_in ("add.st"); /* create a Sum instance */ instance = syx_object_new (syx_globals_at ("Sum")); /* create a Process */ process = syx_process_new (); /* create a MethodContext which sends the #with:and: message */ context = syx_send_message (process, syx_nil, // the parent context instance, // the receiver "with:and:", // the selector 2, // the number of arguments syx_small_integer_new (41), // first argument syx_small_integer_new (22)); /* execute the process in blocking mode */ syx_process_execute_blocking (process); /* fetch the last returned object (an instance variable of Process) */ result = SYX_PROCESS_RETURNED_OBJECT (process); printf ("The result is %d\n", SYX_SMALL_INTEGER (result)); /* cleanup Syx */ syx_quit (); return 0; }
int SYX_CDECL main (int argc, char *argv[]) { SyxOop process, context; SyxOop arguments; SyxOop structTestClass; SyxOop structTest; syx_init (0, NULL, ".."); syx_memory_load_image ("test.sim"); syx_scheduler_init (); puts ("- Initializing test classes"); syx_cold_file_in ("stsupport/TestCStruct.st"); structTestClass = syx_globals_at ("TestCStruct"); syx_object_initialize (structTestClass); structTest = syx_object_new (structTestClass); puts ("- Test fields alignment 1"); arguments = syx_array_new_size (6); SYX_OBJECT_DATA(arguments)[0] = syx_small_integer_new ((syx_nint)&test1.f1 - (syx_nint)&test1); SYX_OBJECT_DATA(arguments)[1] = syx_small_integer_new ((syx_nint)&test1.f2 - (syx_nint)&test1); SYX_OBJECT_DATA(arguments)[2] = syx_small_integer_new ((syx_nint)&test1.f3 - (syx_nint)&test1); SYX_OBJECT_DATA(arguments)[3] = syx_small_integer_new ((syx_nint)&test1.f4 - (syx_nint)&test1); SYX_OBJECT_DATA(arguments)[4] = syx_small_integer_new ((syx_nint)&test1.f5 - (syx_nint)&test1); SYX_OBJECT_DATA(arguments)[5] = syx_small_integer_new ((syx_nint)&test1.f6 - (syx_nint)&test1); process = syx_process_new (); context = syx_send_message (structTest, "testOffsets:from:", 2, arguments, syx_symbol_new ("Test1Struct")); syx_interp_enter_context (process, context); syx_process_execute_blocking (process); puts ("- Test fields alignment 2"); arguments = syx_array_new_size (14); SYX_OBJECT_DATA(arguments)[0] = syx_small_integer_new ((syx_nint)&test2.f1 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[1] = syx_small_integer_new ((syx_nint)&test2.f2 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[2] = syx_small_integer_new ((syx_nint)&test2.f3 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[3] = syx_small_integer_new ((syx_nint)&test2.f4 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[4] = syx_small_integer_new ((syx_nint)&test2.f5 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[5] = syx_small_integer_new ((syx_nint)&test2.f6 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[6] = syx_small_integer_new ((syx_nint)&test2.f7 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[7] = syx_small_integer_new ((syx_nint)&test2.f8 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[8] = syx_small_integer_new ((syx_nint)&test2.f9 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[9] = syx_small_integer_new ((syx_nint)&test2.f10 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[10] = syx_small_integer_new ((syx_nint)&test2.f11 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[11] = syx_small_integer_new ((syx_nint)&test2.f12 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[12] = syx_small_integer_new ((syx_nint)&test2.f13 - (syx_nint)&test2); SYX_OBJECT_DATA(arguments)[13] = syx_small_integer_new ((syx_nint)&test2.f14 - (syx_nint)&test2); process = syx_process_new (); context = syx_send_message (structTest, "testOffsets:from:", 2, arguments, syx_symbol_new ("Test2Struct")); syx_interp_enter_context (process, context); syx_process_execute_blocking (process); puts ("- Test fields alignment 3"); arguments = syx_array_new_size (6); SYX_OBJECT_DATA(arguments)[0] = syx_small_integer_new ((syx_nint)&test3.f1 - (syx_nint)&test3); SYX_OBJECT_DATA(arguments)[1] = syx_small_integer_new ((syx_nint)&test3.f2 - (syx_nint)&test3); SYX_OBJECT_DATA(arguments)[2] = syx_small_integer_new ((syx_nint)&test3.f3 - (syx_nint)&test3); SYX_OBJECT_DATA(arguments)[3] = syx_small_integer_new ((syx_nint)&test3.f4 - (syx_nint)&test3); SYX_OBJECT_DATA(arguments)[4] = syx_small_integer_new ((syx_nint)&test3.f5 - (syx_nint)&test3); SYX_OBJECT_DATA(arguments)[5] = syx_small_integer_new ((syx_nint)&test3.f6 - (syx_nint)&test3); process = syx_process_new (); context = syx_send_message (structTest, "testOffsets:from:", 2, arguments, syx_symbol_new ("Test3Struct")); syx_interp_enter_context (process, context); syx_process_execute_blocking (process); puts ("- Test reading"); test3.f1 = 240; test3.f2 = 7143; test3.f3 = 'R'; test3.f4 = 199.11822; test3.f5 = 23.5; /* won't read yet */ process = syx_process_new (); context = syx_send_binary_message (structTest, "testRead:", SYX_POINTER_CAST_OOP (&test3)); syx_interp_enter_context (process, context); syx_process_execute_blocking (process); puts ("- Test writing"); process = syx_process_new (); context = syx_send_binary_message (structTest, "testWrite:", SYX_POINTER_CAST_OOP (&test3)); syx_interp_enter_context (process, context); syx_process_execute_blocking (process); assert(test3.f1 == 320); assert(test3.f2 == 10293); assert(test3.f3 == ','); assert(test3.f4 == 291.4837); /* Double to float conversion assert(test3.f5 == 76.119); */ /* won't write longs yet */ puts ("- Test unions"); test4.f1 = 'S'; process = syx_process_new (); context = syx_send_binary_message (structTest, "testUnion:", SYX_POINTER_CAST_OOP (&test4)); syx_interp_enter_context (process, context); syx_process_execute_blocking (process); assert(test4.f1 == 'T'); syx_quit (); return 0; }