As you’ve seen, the entry point of your program is called main
, it returns void
and does not take any arguments.
But, wait, shouldn’t it be a main :: (argc : s32, argv : **u8) -> s32
like in other languages instead ? Well not in Jai! Jai has an intermediate step, where it initialize a few things such as the context, and the command line arguments are cached in the __command_line_arguments
array.
The actual entry point of your program is called __system_entry_point
, and can be found in modules/Runtime_Support.jai
:
#program_export
__jai_runtime_init :: (argc: s32, argv: **u8) -> *Context #c_call {
__command_line_arguments.count = argc;
__command_line_arguments.data = argv;
ts := *first_thread_temporary_storage;
ts.data = first_thread_temporary_storage_data.data;
ts.size = TEMPORARY_STORAGE_SIZE;
ts.original_data = first_thread_temporary_storage_data.data;
ts.original_size = TEMPORARY_STORAGE_SIZE;
first_thread_context.temporary_storage = ts;
return *first_thread_context;
}
#program_export
__jai_runtime_fini :: (_context: *void) #c_call {
// Nothing here for now!
}
#program_export "main"
__system_entry_point :: (argc: s32, argv: **u8) -> s32 #c_call {
__jai_runtime_init(argc, argv);
push_context first_thread_context {
__program_main :: () #runtime_support;
__program_main();
}
return 0;
}
So, you can see that this procedure does take a s32
and a **u8
, and returns a s32
. It is also marked as #c_call
, and is exported as main
so the OS can find it.
This procedure is responsible for initializing the context
, temporary_storage
, and the __command_line_arguments
array by calling __jai_runtime_init
, defined right before. It then calls __program_main
, which is the main
you’ve defined, after pushing the newly created context.