All PyFunge modules are contained in funge package. With an exception of front-end modules, all modules are orthogonal to other methods and can be used independently.
This front-end is used by the driver script, pyfunge(1).
This module combines all other modules into the execution environment. If you have to run Funge code you may want to use Program class.
The Funge environment class.
Same to Program, but shows the status of IPs each tick. This is intended to provide the minimum debugger functionality.
The trace will start when any IP hits the cell at stoppos in Funge space. If any fatal exception (mainly because of bugs in PyFunge) is raised it will dump current status as well.
This module implements an efficient vector class(es).
The vector class, which is a subclass of tuple and supports the following operations:
|x + y||Pairwise addition|
|x - y||Pairwise subtraction|
|x * y||Pairwise multiplication by scalar|
|x / y||Pairwise integer division by scalar|
|x // y||Pairwise integer division by scalar|
|x % y||Pairwise remainder by scalar|
|x.between(min, max)||True if every element is between corresponding element of min and max|
|x.pairwise_min(y)||Pairwise minimum element|
|x.pairwise_max(y)||Pairwise maximum element|
|x.replace(_0=a, ...)||Changes particular element|
The vector class uses different class for different number of dimensions internally, so these operations are more efficient than generic class.
This module implements Funge stack and Funge-98 stack stack.
One stack. This class is inherited from Python list so all methods and operations of list can be applied.
The following stack operations are unique to this class. Every push* and pop* methods has its counterpart, rpush* and rpop* methods, only differ that r-prefixed methods treat the stack reversed. For example, push() pushes to the top but rpush() pushes to the bottom. These counterparts are needed mainly for MODE fingerprint.
Pops a value from the top or the bottom of the stack and returns it.
If the stack is empty, it will pop zero.
Pops n values from the top or the bottom of the stack and returns them. Values will be returned in the popped order.
If the stack is empty, it will pop zeroes.
Pops a null-terminated string (“0gnirts”) from the top or the bottom of the stack and returns it.
If the stack is empty, the string ends at the bottom of the stack and it won’t raise any exception.
Pops a list of size n from the top or the bottom of the stack and return it. A vector will be popped in the pushed order (i.e. the reverse popped order), so it is mainly used for pushing position or delta (hence the name).
If the stack is empty, one or more first elements will be zero.
Refers to the top of stack stack and the second-to-top of stack stack. They can be used for stack stack indices or stack argument to every stack stack operations.
They are equal to -1 and -2, respectively. It is recommended that use these symbolic constants than numerical indices.
Funge-98 stack stack. It mainly provides convenience methods for accessing the top of stack stack.
A stack stack itself is organized by Python list, and can be indexed to access individual stack object. For example sstack[TOSS] returns the top of stack stack, and sstack returns the 4th stack from the bottom of stack stack. Also len(sstack) gives the size of stack stack.
For example sstack.push(42, TOSS) is equal to the following code:
if sstack.invertmode: sstack[TOSS].rpush(42) else: sstack[TOSS].push(42)
This module implements Funge spaces.
Writes the value to given position. If value is equal to default value, the cell will be removed from the space.
This module implements Funge instruction pointer, which has independent position, direction and stack stack.
Returns True if invertmode or queuemode is set to the stack stack, or False otherwise.
Setting them affects stack stack methods of current IP. Indeed, these attributes are connected to the stack stack attributes.
Adds commands from the given semantics overlay, e.g. fingerprint object. See add_command() for precise behavior.
It pushes new command to the internal stack for each cell value. This is required by Funge-98 specification: as a consequence, if add_commands() and remove_commands() are not called in the correct order it can execute a command from unloaded fingerprint.
This module defines some package-wide exceptions.
The base of semantics implementation.
This is a decorator for commands. Typical example of semantics classes is like this:
class SomeSemantics(SemanticsBase): @SemanticsBase.register('@') def squiggle(self, ip): self.platform.warn('IP hit a squiggle! Awwwww!!!') raise IPStopped() @SemanticsBase.register('0123456789') def numbers(self, ip): self.platform.warn('You should not use numbers. Pushes the answer instead.') ip.push(42)
commands can be a string or a list of character values. kwargs are stored in the method directory: they can be used as a hint of the instruction. (Note that PyFunge 0.5.0 doesn’t use this hint yet.)
Commands can be inherited and overridden from other classes. If two different methods implement same command the result is undefined.
Implements a core semantics, usable for an argument to Program. It has to implement several methods besides from commands.
This package provides language semantics for Befunge-93 and Funge-98 languages.
This module implements Befunge-93 commands.
Implements an one-dimensional subset of Befunge-93 commands. Such language doesn’t exist but it is used for the base class of Unefunge98.
Implements full Befunge-93 commands.
This module implements core Funge-98 commands. “Core” means no filesystem Funge and no concurrent Funge: see funge.languages.funge98opt module for those.
This module implements additional concurrent and filesystem Funge commands.
This module defines a class for interfacing with external system.
Base class for platform abstraction. The classes should override I/O functions, and optionally file-related functions or system().
This module provides a lookup and base class for Funge-98 fingerprints.
This class manages a list of available fingerprints.
A fingerprint object. It is a SemanticsOverlay with additional methods below.
Fingerprint class, to be added by FingerprintLookup, should have two attributes: API and ID. The former identifies the incompatible revisions of fingerprint API, where current revision is "PyFunge v2". (This is only supported revision for now.) The latter is a fingerprint identifier, like 0x4e554c4c for NULL fingerprint.
This package contains implementations of default fingerprints. The complete list of modules is: