Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • M mu-spec
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 16
    • Issues 16
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • mumu
  • mu-spec
  • Issues
  • #12
Closed
Open
Issue created Jun 02, 2017 by Isaac Gariano@igariano01Developer

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
}
Assignee
Assign to
Time tracking