Here's a patch which adds the 'missing' opcodes from the earlier email. It also adds the 3 arg variant of concat.
Dan/Simon/Anyone, if it seems ok, I'll commit it, but since it adds 52 op variants, I wasn't sure if it would be ok. Brian Ops follow---- +AUTO_OP add(i, i, ic) { +AUTO_OP add(n, n, nc) { +AUTO_OP cmod(i, i, ic) { +AUTO_OP cmod(i, ic, i) { +AUTO_OP cmod(n, n, nc) { +AUTO_OP cmod(n, nc, n) { +AUTO_OP div(i, i, ic) { +AUTO_OP div(i, ic, i) { +AUTO_OP div(n, n, nc) { +AUTO_OP div(n, nc, n) { +AUTO_OP mod(i, i, ic) { +AUTO_OP mod(i, ic, i) { +AUTO_OP mod(n, n, nc) { +AUTO_OP mod(n, nc, n) { +AUTO_OP mul(i, i, ic) { +AUTO_OP mul(n, n, nc) { +AUTO_OP pow(n, i, ic) { +AUTO_OP pow(n, ic, i) { +AUTO_OP pow(n, i, nc) { +AUTO_OP pow(n, ic, n) { +AUTO_OP pow(n, n, ic) { +AUTO_OP pow(n, nc, i) { +AUTO_OP pow(n, n, nc) { +AUTO_OP pow(n, nc, n) { +AUTO_OP sub(i, i, ic) { +AUTO_OP sub(i, ic, i) { +AUTO_OP sub(n, n, nc) { +AUTO_OP sub(n, nc, n) { +AUTO_OP chopn(s, i) { +AUTO_OP concat(s, sc) { +AUTO_OP concat(s, s, s) { +AUTO_OP concat(s, s, sc) { +AUTO_OP concat(s, sc, s) { +AUTO_OP substr(s, s, i, ic) { +AUTO_OP substr(s, s, ic, i) { +AUTO_OP substr(s, s, ic, ic) { +AUTO_OP substr(s, sc, i, i) { +AUTO_OP substr(s, sc, i, ic) { +AUTO_OP substr(s, sc, ic, i) { +AUTO_OP atan(n, i, ic) { +AUTO_OP atan(n, ic, i) { +AUTO_OP atan(n, i, nc) { +AUTO_OP atan(n, ic, n) { +AUTO_OP atan(n, n, ic) { +AUTO_OP atan(n, nc, i) { +AUTO_OP atan(n, n, nc) { +AUTO_OP atan(n, nc, n) { +AUTO_OP and(i, i, ic) { +AUTO_OP or(i, i, ic) { +AUTO_OP shl(i, i, i) { +AUTO_OP shr(i, i, i) { +AUTO_OP xor(i, i, ic) {
Index: core.ops =================================================================== RCS file: /home/perlcvs/parrot/core.ops,v retrieving revision 1.8 diff -u -r1.8 core.ops --- core.ops 2001/10/16 14:12:41 1.8 +++ core.ops 2001/10/16 15:35:36 @@ -661,8 +661,12 @@ =item B<add>(i, i, i) +=item B<add>(i, i, ic) + =item B<add>(n, n, n) +=item B<add>(n, n, nc) + Set $1 to the sum of $2 and $3. =cut @@ -670,16 +674,28 @@ AUTO_OP add(i, i, i) { $1 = $2 + $3; } + +AUTO_OP add(i, i, ic) { + $1 = $2 + $3; +} AUTO_OP add(n, n, n) { $1 = $2 + $3; } +AUTO_OP add(n, n, nc) { + $1 = $2 + $3; +} + ######################################## =item B<cmod>(i, i, i) +=item B<cmod>(i, i, ic) + +=item B<cmod>(i, ic, i) + NOTE: This "uncorrected mod" algorithm uses the C language's built-in mod operator (x % y), which is @@ -716,11 +732,23 @@ $1 = $2 % $3; } +AUTO_OP cmod(i, i, ic) { + $1 = $2 % $3; +} + +AUTO_OP cmod(i, ic, i) { + $1 = $2 % $3; +} + ######################################## =item B<cmod>(n, n, n) +=item B<cmod>(n, n, nc) + +=item B<cmod>(n, nc, n) + NOTE: This "uncorrected mod" algorithm uses the built-in C math library's fmod() function, which computes @@ -752,7 +780,15 @@ $1 = fmod($2, $3); } +AUTO_OP cmod(n, n, nc) { + $1 = fmod($2, $3); +} +AUTO_OP cmod(n, nc, n) { + $1 = fmod($2, $3); +} + + ######################################## =item B<dec>(i) @@ -795,8 +831,16 @@ =item B<div>(i, i, i) +=item B<div>(i, i, ic) + +=item B<div>(i, ic, i) + =item B<div>(n, n, n) +=item B<div>(n, n, nc) + +=item B<div>(n, nc, n) + Set $1 to the quotient of $2 divided by $3. In the case of INTVAL division, the result is truncated (NOT rounded or floored). @@ -806,11 +850,27 @@ $1 = $2 / $3; } +AUTO_OP div(i, i, ic) { + $1 = $2 / $3; +} + +AUTO_OP div(i, ic, i) { + $1 = $2 / $3; +} + AUTO_OP div(n, n, n) { $1 = $2 / $3; } +AUTO_OP div(n, n, nc) { + $1 = $2 / $3; +} + +AUTO_OP div(n, nc, n) { + $1 = $2 / $3; +} + ######################################## =item B<inc>(i) @@ -853,6 +913,10 @@ =item B<mod>(i, i, i) +=item B<mod>(i, i, ic) + +=item B<mod>(i, ic, i) + NOTE: This "corrected mod" algorithm is based on the C code on page 70 of [1]. Assuming correct behavior of C's built-in mod operator (%) with positive arguments, this algorithm implements a mathematically convenient @@ -899,11 +963,67 @@ $1 = r; } +AUTO_OP mod(i, i, ic) { + INTVAL y = $2; + INTVAL z = $3; + INTVAL s = 0; + INTVAL r; + if (z == 0) { + r = y; + } + else { + if (y < 0) { s += 2; y = -y; } + if (z < 0) { s += 1; z = -z; } + + r = y % z; + + switch (s) { + case 0 + 0: break; + case 0 + 1: r = r - z; break; + case 2 + 0: r = z - r; break; + case 2 + 1: r = -r; break; + } + } + + $1 = r; +} + +AUTO_OP mod(i, ic, i) { + INTVAL y = $2; + INTVAL z = $3; + INTVAL s = 0; + INTVAL r; + + if (z == 0) { + r = y; + } + else { + if (y < 0) { s += 2; y = -y; } + if (z < 0) { s += 1; z = -z; } + + r = y % z; + + switch (s) { + case 0 + 0: break; + case 0 + 1: r = r - z; break; + case 2 + 0: r = z - r; break; + case 2 + 1: r = -r; break; + } + } + + $1 = r; +} + + ######################################## =item B<mod>(n, n, n) +=item B<mod>(n, n, nc) + +=item B<mod>(n, nc, n) + NOTE: This "corrected mod" algorithm is based on the formula of [1]: x mod y = x - y * floor(x / y) @@ -924,13 +1044,29 @@ : $2; } +AUTO_OP mod(n, n, nc) { + $1 = $3 + ? ($2 - $3 * floor($2 / $3)) + : $2; +} + +AUTO_OP mod(n, nc, n) { + $1 = $3 + ? ($2 - $3 * floor($2 / $3)) + : $2; +} + ######################################## =item B<mul>(i, i, i) +=item B<mul>(i, i, ic) + =item B<mul>(n, n, n) +=item B<mul>(n, n, nc) + Set $1 to the product of $2 and $3. =cut @@ -939,21 +1075,45 @@ $1 = $2 * $3; } +AUTO_OP mul(i, i, ic) { + $1 = $2 * $3; +} + AUTO_OP mul(n, n, n) { $1 = $2 * $3; } +AUTO_OP mul(n, n, nc) { + $1 = $2 * $3; +} + ######################################## =item B<pow>(n, i, i) +=item B<pow>(n, i, ic) + +=item B<pow>(n, ic, i) + =item B<pow>(n, i, n) +=item B<pow>(n, i, nc) + +=item B<pow>(n, ic, n) + =item B<pow>(n, n, i) +=item B<pow>(n, n, ic) + +=item B<pow>(n, nc, i) + =item B<pow>(n, n, n) +=item B<pow>(n, n, nc) + +=item B<pow>(n, nc, n) + Set $1 to $2 raised to the power $3. =cut @@ -962,25 +1122,65 @@ $1 = pow((FLOATVAL)$2, (FLOATVAL)$3); } +AUTO_OP pow(n, i, ic) { + $1 = pow((FLOATVAL)$2, (FLOATVAL)$3); +} + +AUTO_OP pow(n, ic, i) { + $1 = pow((FLOATVAL)$2, (FLOATVAL)$3); +} + AUTO_OP pow(n, i, n) { $1 = pow((FLOATVAL)$2, $3); } +AUTO_OP pow(n, i, nc) { + $1 = pow((FLOATVAL)$2, $3); +} + +AUTO_OP pow(n, ic, n) { + $1 = pow((FLOATVAL)$2, $3); +} + AUTO_OP pow(n, n, i) { $1 = pow($2, (FLOATVAL)$3); } +AUTO_OP pow(n, n, ic) { + $1 = pow($2, (FLOATVAL)$3); +} + +AUTO_OP pow(n, nc, i) { + $1 = pow($2, (FLOATVAL)$3); +} + AUTO_OP pow(n, n, n) { $1 = pow($2, $3); } +AUTO_OP pow(n, n, nc) { + $1 = pow($2, $3); +} +AUTO_OP pow(n, nc, n) { + $1 = pow($2, $3); +} + + ######################################## =item B<sub>(i, i, i) +=item B<sub>(i, i, ic) + +=item B<sub>(i, ic, i) + =item B<sub>(n, n, n) +=item B<sub>(n, n, nc) + +=item B<sub>(n, nc, n) + Set $1 to $2 minus $3. =cut @@ -989,11 +1189,27 @@ $1 = $2 - $3; } +AUTO_OP sub(i, i, ic) { + $1 = $2 - $3; +} + +AUTO_OP sub(i, ic, i) { + $1 = $2 - $3; +} + AUTO_OP sub(n, n, n) { $1 = $2 - $3; } +AUTO_OP sub(n, n, nc) { + $1 = $2 - $3; +} + +AUTO_OP sub(n, nc, n) { + $1 = $2 - $3; +} + =back =cut @@ -1012,6 +1228,8 @@ =item B<chopn>(s, ic) +=item B<chopn>(s, i) + Remove $2 characters from the end of the string in $1. TODO: Create a three-argument version of this? Don't force in-place modification. @@ -1022,14 +1240,27 @@ (void)string_chopn($1, $2); } +AUTO_OP chopn(s, i) { + (void)string_chopn($1, $2); +} + ######################################## =item B<concat>(s, s) +=item B<concat>(s,sc) + +=item B<concat>(s, s, s) + +=item B<concat>(s, s, sc) + +=item B<concat>(s, sc, s) + Append the string in $2 to the string in $1. -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. =cut @@ -1038,6 +1269,29 @@ $1 = s; } +AUTO_OP concat(s, sc) { + STRING *s = string_concat($1, $2, 1); + $1 = s; +} + +AUTO_OP concat(s, s, s) { + STRING *s = string_concat($2, $3, 1); + $1 = s; +} + +AUTO_OP concat(s, s, sc) { + STRING *s = string_concat($2, $3, 1); + $1 = s; +} + + +AUTO_OP concat(s, sc, s) { + STRING *s = string_concat($2, $3, 1); + $1 = s; +} + + + ######################################## =item B<length>(i, s) @@ -1055,6 +1309,18 @@ =item B<substr>(s, s, i, i) +=item B<substr>(s, s, i, ic) + +=item B<substr>(s, s, ic, i) + +=item B<substr>(s, s, ic, ic) + +=item B<substr>(s, sc, i, i) + +=item B<substr>(s, sc, i, ic) + +=item B<substr>(s, sc, ic, i) + Set $1 to the portion of $2 starting at (zero-based) character position $3 and having length $4. @@ -1065,7 +1331,37 @@ $1 = s; } +AUTO_OP substr(s, s, i, ic) { + STRING *s = string_substr($2, $3, $4, &$1); + $1 = s; +} + +AUTO_OP substr(s, s, ic, i) { + STRING *s = string_substr($2, $3, $4, &$1); + $1 = s; +} +AUTO_OP substr(s, s, ic, ic) { + STRING *s = string_substr($2, $3, $4, &$1); + $1 = s; +} + +AUTO_OP substr(s, sc, i, i) { + STRING *s = string_substr($2, $3, $4, &$1); + $1 = s; +} + +AUTO_OP substr(s, sc, i, ic) { + STRING *s = string_substr($2, $3, $4, &$1); + $1 = s; +} + +AUTO_OP substr(s, sc, ic, i) { + STRING *s = string_substr($2, $3, $4, &$1); + $1 = s; +} + + =back =cut @@ -1146,14 +1442,30 @@ =item B<atan>(n, i, i) +=item B<atan>(n, i, ic) + +=item B<atan>(n, ic, i) + =item B<atan>(n, i, n) +=item B<atan>(n, i, nc) + +=item B<atan>(n, ic, n) + =item B<atan>(n, n) =item B<atan>(n, n, i) +=item B<atan>(n, n, ic) + +=item B<atan>(n, nc, i) + =item B<atan>(n, n, n) +=item B<atan>(n, n, nc) + +=item B<atan>(n, nc, n) + The two-argument versions set $1 to the arc tangent (in radians) of $2. The three-argument versions set $1 to the arc tangent (in radians) of @@ -1170,10 +1482,26 @@ $1 = atan2((FLOATVAL)$2, (FLOATVAL)$3); } +AUTO_OP atan(n, i, ic) { + $1 = atan2((FLOATVAL)$2, (FLOATVAL)$3); +} + +AUTO_OP atan(n, ic, i) { + $1 = atan2((FLOATVAL)$2, (FLOATVAL)$3); +} + AUTO_OP atan(n, i, n) { $1 = atan2((FLOATVAL)$2, $3); } +AUTO_OP atan(n, i, nc) { + $1 = atan2((FLOATVAL)$2, $3); +} + +AUTO_OP atan(n, ic, n) { + $1 = atan2((FLOATVAL)$2, $3); +} + AUTO_OP atan(n, n) { $1 = atan($2); } @@ -1182,11 +1510,27 @@ $1 = atan2($2, (FLOATVAL)$3); } +AUTO_OP atan(n, n, ic) { + $1 = atan2($2, (FLOATVAL)$3); +} + +AUTO_OP atan(n, nc, i) { + $1 = atan2($2, (FLOATVAL)$3); +} + AUTO_OP atan(n, n, n) { $1 = atan2($2, $3); } +AUTO_OP atan(n, n, nc) { + $1 = atan2($2, $3); +} +AUTO_OP atan(n, nc, n) { + $1 = atan2($2, $3); +} + + ######################################## =item B<cos>(n, i) @@ -1437,6 +1781,8 @@ =item B<and>(i, i, i) +=item B<and>(i, i, ic) + Set the bits of $1 according to the B<and> of the corresponding bits from $2 and $3. =cut @@ -1445,6 +1791,10 @@ $1 = $2 & $3; } +AUTO_OP and(i, i, ic) { + $1 = $2 & $3; +} + ######################################## @@ -1463,6 +1813,8 @@ =item B<or>(i, i, i) +=item B<or>(i, i, ic) + Set the bits of $1 according to the B<or> of the corresponding bits from $2 and $3. =cut @@ -1471,9 +1823,14 @@ $1 = $2 | $3; } +AUTO_OP or(i, i, ic) { + $1 = $2 | $3; +} ######################################## +=item B<shl>(i, i, i) + =item B<shl>(i, i, ic) Set $1 to the value of $2 shifted left by $3 bits. @@ -1484,9 +1841,15 @@ $1 = $2 << $3; } +AUTO_OP shl(i, i, i) { + $1 = $2 << $3; +} + ######################################## +=item B<shr>(i, i, i) + =item B<shr>(i, i, ic) Set $1 to the value of $2 shifted right by $3 bits. @@ -1497,11 +1860,17 @@ $1 = $2 >> $3; } +AUTO_OP shr(i, i, i) { + $1 = $2 >> $3; +} + ######################################## =item B<xor>(i, i, i) +=item B<xor>(i, i, ic) + Set the bits of $1 according to the B<xor> of the corresponding bits from $2 and $3. =cut @@ -1509,6 +1878,11 @@ AUTO_OP xor(i, i, i) { $1 = $2 ^ $3; } + +AUTO_OP xor(i, i, ic) { + $1 = $2 ^ $3; +} + =back