/*
** sys.ops
*/

VERSION = PARROT_VERSION;

=head1 NAME

sys.ops - System Interaction Ops

=head1 DESCRIPTION

Operations that allow the user to interact with the system.

=over 4

=cut

###############################################################################

=item B<err>(out INT)

Store the system error code in $1.

=item B<err>(out STR)

Store the system error message in $1.

=cut

inline op err(out INT) {
  $1 = errno;
  goto NEXT();
}

op err(out STR) {
  char *tmp = strerror(errno);
  $1 = string_make(interpreter, tmp, strlen(tmp), NULL, 0, NULL);
  goto NEXT();
}


########################################

=item B<time>(out INT)

Puts the current system time (represented as a whole number of seconds)
in $1.

=cut

inline op time(out INT) {
  $1 = Parrot_intval_time();
  goto NEXT();
}


########################################

=item B<time>(out NUM)

Puts the current system time (represented as a number of seconds, with
microseconds) in $1.

=cut

inline op time(out NUM) {
  $1 = Parrot_floatval_time();
  goto NEXT();
}

=cut

########################################

=item B<sysinfo>(out STR, in INT)

=item B<sysinfo>(out INT, in INT)

Return system information. The values it returns depends on what you
ask. They are:

=over 4

=item 1 The size of a platform integer

=item 2 The size of a platform float

=item 3 The size of a platform pointer. (Largest possible data pointer)

=item 4 The OS name

This is something like "OS X", "MacOS", "Windows", or "VMS".

=item 5 The OS version string

This is the current (hopefully) OS Version. For OSes that have plain
version numbers it will be the version number. For OSes that name
their versions, it will be the version name.

On HP/UX, this may be something like 11.2, while on Windows it may be
"95", "98", "2000", "NT", "ME", or "XP".

=item 6 The OS version number string

On OSes that don't name themselves, this will be the same as what's
returned in the OS version string. On OSes that I<do> name themselves,
this will be a more specific version number. In all cases it is OS
dependent.

=item 7 The CPU architecture

The name of the CPU family, such as "VAX", "Alpha", "PPC", or "x86".

=item 8 The CPU model

The model name of the current system's CPU. This is something like
"EV68", "Athlon", or "Pentium III".

=back

Note that some of these values may be set at parrot compile time,
rather than at runtime, if the system has no reliable way to fetch the
data dynamically, or if there is no way the value can change. Also,
the value returned may be somewhat misleading--Parrot running under a
VirtualPC window will report "Windows" as its OS and "x86" as its CPU,
even if it's really running on an OS X system.

=cut

inline op sysinfo(out STR, in INT) {
   $1 = sysinfo_s(interpreter, $2);
   goto NEXT();
}

inline op sysinfo(out INT, in INT) {
   $1 = sysinfo_i(interpreter, $2);
   goto NEXT();
}

########################################

=item B<sleep>(in INT)

Sleep for $1 seconds.

=cut

inline op sleep(in INT) {
  if ($1 < 0) {
      internal_exception(NEG_SLEEP, "Cannot go back in time\n");
  }
  Parrot_sleep((UINTVAL)$1);
  goto NEXT();
}

=back

=cut

########################################

=item B<sizeof>(out INT, in INT)

Get the size of native datatype $2 in $1.


inline op sizeof(out INT, in INT) {
    if ($2 < enum_first_type || $2 >= enum_last_type)
        $1 = -1;
    else
        $1 = data_types[$2 - enum_first_type].size;
  goto NEXT();
}

=cut

###############################################################################

=head1 COPYRIGHT

Copyright (C) 2001-2003 The Perl Foundation.  All rights reserved.

=head1 LICENSE

This program is free software. It is subject to the same license
as the Parrot interpreter itself.

=cut
