core.ops
Parrot's core library of ops.
These are the fundamental operations.
These operations allow interaction between the Parrot program and the system environment.
BE AFRAID! THIS IS *EEEEEEEVIL* pure and simple. (From the 8th dimension, no less)
If for some reason the line's longer than 64K you get only 64K
These operations load registers from constants or other registers.
$1[$2] = $3[$4];
These operations perform a conditional relative branch. If the condition is met, the branch happens, otherwise control falls to the next operation.
Return address is popped off the call stack if no address is supplied.
Return address is popped off the call stack if no address is supplied.
These operations store the results of arithmetic on other registers and constants into their destination register, $1.
... the remainder when x is divided by y, and thus is zero
when y divides x exactly.
...
The direction of truncation for / and the sign of the result
for % are machine-dependent for negative operands, as is the
action taken on overflow or underflow.
-- [1], page 41
Also:
... if the second operand is 0, the result is undefined.
Otherwise, it is always true that (a/b)*b + a%b is equal to z. If
both operands are non-negative, then the remainder is non-
negative and smaller than the divisor; if not, it is guaranteed
only that the absolute value of the remainder is smaller than
the absolute value of the divisor.
-- [1], page 205
This op is provided for those who need it (such as speed-sensitive
applications with heavy use of mod, but using it only with positive
arguments), but a more mathematically useful mod based on ** floor(x/y)
and defined with y == 0 is provided by the mod_i op.
[1] Brian W. Kernighan and Dennis M. Ritchie, *The C Programming
Language*, Second Edition. Prentice Hall, 1988.
TODO: Doesn't the Parrot interpreter need to catch the exception?
fmod() function, which computes
... the remainder of dividing x by y. The return value is
x - n * y, where n is the quotient of x / y, rounded towards
zero to an integer.
-- fmod() manpage on RedHat Linux 7.0
In addition, fmod() returns
the remainder, unless y is zero, when the function fails and
errno is set.
According to page 251 of [1], the result when y is zero is implementation- defined.
This op is provided for those who need it, but a more mathematically
useful numeric mod based on floor(x/y) instead of truncate(x/y) and
defined with y == 0 is provided by the mod_n op.
[1] Brian W. Kernighan and Dennis M. Ritchie, *The C Programming
Language*, Second Edition. Prentice Hall, 1988.
TODO: Doesn't the Parrot interpreter need to catch the exception?
x mod y = x - y * floor(x / y)
For more information on this definition of mod, see section 3.4 of [2], pages 81-85.
References:
[1] Donald E. Knuth, *MMIXware: A RISC Computer for the Third
Millennium* Springer, 1999.
[2] Ronald L. Graham, Donald E. Knuth and Oren Patashnik, *Concrete
Mathematics*, Second Edition. Addison-Wesley, 1994.
x mod y = x - y * floor(x / y)
For more information on this definition of mod, see section 3.4 of [1], pages 81-85.
References:
[1] Ronald L. Graham, Donald E. Knuth and Oren Patashnik, *Concrete
Mathematics*, Second Edition. Addison-Wesley, 1994.
These operations operate on STRINGs.
TODO: Create a three-argument version of this? Don't force in-place modification.'
The three argument version appends the string $3 to $2 and places the result into $1.
These operations perform various transcendental operations such as logarithmics and trigonometrics.
The three-argument versions set $1 to the arc tangent (in radians) of $2 / $3, taking account of the signs of the arguments in determining the quadrant of the result.
These operations apply bitwise logical functions to their arguments.
These operations modify the internal interpreter flags, affecting its subsequent operation.
These operations effect entire sets of registers.
INTVAL ('i') and FLOATVAL ('n') registers clear to zero.
PMC ('p') and STRING ('s') registers clear to NULL.
These operations effect individual registers.
The control flow opcodes check conditions and manage program flow.
TODO: Implement this, or delete the entry.
Ops to manipulate the symbol table
Opcodes which need to be sorted into better categories.
new P0, PerlScalar
Optionally a size may be passed to the constructor which may or may not be used by the particular class. For example:
new P0, PerlStruct, 64
To turn on multiple categories, OR the category numbers together.
Copyright (C) 2001 Yet Another Society. All rights reserved.
This program is free software. It is subject to the same license as the Parrot interpreter itself.