#line 663 "/home/travis/build/felix-lang/felix/src/packages/program.fdoc"
  
  class System
  {
    const argc:int = "PTF argc" requires property "needs_ptf";
    const _argv:&&char= "PTF argv" requires property "needs_ptf";
  
    fun argv:int -> string = '::std::string($1<0||$1>=PTF argc??"":PTF argv[$1])'
      requires property "needs_ptf";
    fun argv_dflt (x:int) (y:string) => match argv x with | "" => y | a => a;
  
    fun args () => List::map (argv) (List::range argc);
  
    proc setargs : + (+char) * size = "PTF argc=$2; PTF argv=$1;" requires property "needs_ptf";
    proc setargs[N] (a:string^N)
    {
      gen myget(i:size)=>a.i.cstr;
      var x = varray[+char] (a.len,a.len,myget);
      setargs (x.stl_begin,x.len);
    }
  
    gen system (cmd:string) : int => Shell::system(cmd);
    gen exit: int -> any = '::std::exit($1)' requires Cxx_headers::cstdlib;
    gen abort: 1 -> any = "::std::abort($1)" requires Cxx_headers::cstdlib;
    _gc_pointer type ptf_t = "thread_frame_t*";
    const ptf:ptf_t = "ptf" requires property "needs_ptf";
  
    pexit examines the return code from a system call.
    If the code is 0 it exists with 0.
    On Windows:
       if the code is -1, it exits with errno.
       otherwise code 3
    On Unix:
      if the code is non-zero then
        if the callout aborted, return its abort code.
        if the callout died due to a signal, exit with code 2
        otherwise exit with code 3
    In both these cases a non-zero return causes a message
    to be printed on stderr.
  
    if PLAT_WIN32 do
      proc pexit(e:int)
      {
        if e != 0 do
          if e == -1 do
            err :=  errno;
            eprintln$ "Error "+err.str+" in flx: " + strerror err;
            System::exit err.int;
          else
            eprintln$ "Unknown error in shell " + str e;
            System::exit 3;
          done
        done
        System::exit e;
      }
    else
      proc pexit(e:int)
      {
        if e != 0 do
          if PosixProcess::WIFEXITED e.PosixProcess::process_status_t do
            err :=  PosixProcess::WEXITSTATUS e.PosixProcess::process_status_t;
            eprintln$ "Error "+err.str+" in flx: " + strerror err.errno_t;
            System::exit err;
          elif PosixProcess::WIFSIGNALED e.PosixProcess::process_status_t do
            sig := Process::WTERMSIG e.PosixProcess::process_status_t;
            eprintln$ "Shell terminated by signal " + str sig;
            System::exit 2;
          else
            eprintln$ "Unknown error in shell " + str e;
            System::exit 3;
          done
        done
        System::exit e;
      }
    done
  
    gen get_stdout(x:string) : int * string => Shell::get_stdout x;
  
  }