Returning exit status from a Mu program
Currently there does not appear to be a standard way in Mu to return an exit status from a program, or pass arguments to it, e.g. you could do this is c:
int main(int argc, char* argv[])
{
return argc;
}
To implement this in Mu, you have to return an exit status by CCALLing the c 'exit' function, (which is bad as CCALL is implementation specific).
.typedef @int32 = int<32>
.typedef @char = int<8>
.typedef @string = uptr<@char>
.typedef @string_array = uptr<@string>
.funcsig @main_sig = (@int32 @string_array)->()
.funcdecl @my_main <@main_sig>
.funcsig @exit_sig = (@int32) -> ()
.typedef @ufp_exit = ufuncptr<@exit_sig>
.const @const_exit <@ufp_exit> = EXTERN "exit"
.funcdef @my_main VERSION @my_main_v1 <@main_sig>
{
%entry(<@int32>%argc <@string_array>%argv):
CCALL #DEFAULT <@ufp_exit @exit_sig> @const_exit (%argc)
RET
}
I suggest altering the spec to allow the primordial function to have the signature (int<32>, uptr<uptr<char>>)->(int<32>)
and have it behave like the c main function. If there are multiple threads, each with there own 'root' function, I suggest having the first one to return an int i
be equivalent to calling exit(i)
, if you don't wan't the program to die, then you'd use THREADEXIT
instead.
So that above could be rewritten as:
.funcdef @my_main VERSION @my_main_v1 <(@int32 @string_array)->(@int32)>
{
%entry(<@int32>%argc <@string_array>%argv):
RET %argc
}