parrotcode: Experimental Operations Contents | Ops

# NAME

experimental.ops - Experimental Operations

# DESCRIPTION

This file contains operations that are in an experimental state. Do not rely upon the existence of the ops in this file when writing production code. No decision has yet been made as to whether they are accepted as regular Parrot ops or not. They are included here for testing purposes only!

## Mathematical operations

Implementations of various mathematical operations

gcd(out INT, in NUM, in NUM)

Greatest Common divisor of \$2 and \$3.

gcd(out INT, out INT, out INT, in INT, in INT)

Given \$4 and \$5, it calculates \$1, \$2 and \$3 so that

\$1 = gcd(\$4, \$5) = \$2 * \$4 + \$3 * \$5 (d = gcd(a,b) = x*a + y*b)

## Misc other ops

new(out PMC, in INT, in KEY)

XXX

splice(in PMC, in PMC, in INT, in INT)

Replace \$4 values at offset \$3 in aggregate \$1 with the PMCs in aggregate \$2. The values are put into the aggregate by a shallow copy. If the values would be reused, they have to be cloned.

slice(out PMC, in PMC, in KEY)

Return a new Iterator PMC \$1 for aggregate \$2 and Slice PMC \$3.

slice(out PMC, in PMC, in KEY, inconst INT)

Return a new list PMC \$1 for aggregate \$2 and Slice PMC \$3.

This is a Python opcode. Range is i <= k < j. \$4 must be 1. May change and move to python.ops.

iter(out PMC, in PMC)

Return a new Iterator PMC \$1 for aggregate \$2.

morph(in PMC, in INT)

Have \$1 turn itself into a PMC of type \$2.

exec(in STR)

Execute the passed-in command. Completely tosses the current process image and replaces it with the command. Doesn't exit (the program ends, after all), though it does throw an exception if something goes wrong.

## Namespace opcodes

These will be moved to var.ops soon.

get_namespace(out PMC)

Get currrent namespace.

get_namespace(out PMC, in PMC)

get_namespace(out PMC, in KEY)

get_namespace(out PMC, in STR)

Get the specified namespace. \$2 is either an array of names or a key. If the namespace doesn't exist, \$1 is set to PMCNULL.

find_global(out PMC, in KEY, in STR)

Find the variable \$3 in \$2.

## More Experimental Ops

`debug_brk`

Break into debugger. Implementation notes:

``` - x86/gcc ... works with gdb
- TODO```
For other architectures, this is a `noop`.

pow(out NUM, in NUM, in INT)

Set \$1 to \$2 raised to the power \$3.

new(out PMC, inconst STR, in PMC)

Create a new PMC of class \$2;

` new P0, "Foo", P1`
The PMC in \$3 is passed to the constructor. It's up to the class what to do with the intializer.

op getclass(out PMC, in INT)

Return the class PMC of the type \$2.