Specification for the Wierd Programming Language--A MicroFunge First, a Riddle: Q: What do you get when you put three marginally-sane programmers on a mailing list with the Befunge and BrainF*** programming languages? A: You get BeF***, and then they get Wierd. No, it's not really funny unless you already know what we're talking about. So let's get you up to speed. History: The now-defunct Befunge Mailing List once questioned if Befunge was too "top-heavy" a language--that is, if its instruction set was needlessly large. This, as one might expect (especially one reading this specification), quickly degenerated into an argument of "my language is smaller than yours." Ben Olmstead managed to trim down Befunge to a lean seven instructions, dubbing the creation "BeF***". Not to be outdone, it was quickly suggested by John Colagioia that instructions, per se, be eliminated in favor of the "visual programming" aspect of Befunge: The angles made by sequences of instructions. Such a language, of course, would have a single "instruction" from the syntactic standpoint, although it surely cheats by horribly abusing the concept of Euclidean geometry. Chris Pressey then jumped on it, created the angle-to-instruction mapping, and christened the entire mess "Wierd"--a cross between the words "weird" (which the language seemed to be) and "wired" (which would describe the appearance of programs written in the language). The Basics: Wierd, like Befunge, is a two-dimensional language with a rectalinear grid of instructions which manipulate a system stack area. Where Befunge has discrete, textual instructions, however, Wierd has a more implicit instruction set, each instruction denoted, not by a symbol, but by a configuration of symbols relative to the current direction of the instruction pointer: the angle of deviation from "straight ahead" from the IP's perpsective. That is, reading from left to right, the following program contains a single instruction: ****** * * * and the instruction is "read" as a 45-degree angle to the right. The Details: A Wierd source file can be any file, as the language only distinguishes between two symbols: Whitespace and everything else. A chain of non- whitespace symbols makes a Wierd program. Execution begins with the first character of the file (typically considered to be the "upper left" of the program), and the initial direction of the Instruction Pointer is down and to the right. This was chosen to allow the programmer to get away from the corner as efficiently as possible, which reduces the risk of the program becoming trapped. Newlines are defined in a system-dependant manner, though it can be safely assumed on most systems that a carriage return and/or line feed character delineates the end of each line and begins the next. Execution then passes from character to character, in the specified direction until a turn needs to be made. Inertia: Like water, the Wierd IP takes the path of least resistance when confronted with a choice. If the Wierd program branches, the IP will always choose the path which is closest to the direction it is already travelling. Therefore, the following code (assuming the IP starts at the left, and travels to the right, like the above): *********** * * * will stay on the top line, and never travel down the branch shown. Should the IP be faced with two equally-likely choices, the branch chosen by the interpreter is undefined, except for one condition which will be treated later. (Though, as an implementation note, it should be pointed out that the only existing interpreter at this time chooses the left-hand path. Note that Wierd was not intended to be left-handed, specifically; this is just how the coin showed during the design phase--literally). Gap-Jumping: While the above is suitable for a fully-featured programming language, it was quickly realized that programmers could easily (possibly certainly) "paint themselves into a corner," where programs beyond a certain complexity might simply be impossible to write, and would at least be extremely impractical. Therefore, in keeping with the pseudo-electronic motif, the Instruction Pointer was given the ability to launch itself over a limited distance of unused ("empty") programspace to attach to a new program segment. This jumping, to keep it only used in emergency situations, is only usable over a maximum distance of two cells in the program grid. Gap-Jumping follows the same rules as typical movement, regarding Inertia. That is, the IP will choose paths to jump into by how much of a change of direction is required to reach it. Note that jumping a gap into an isolated instruction, like in the following code segment: ***** * is considered an error. The Instructions: The Wierd instruction set is based on that of Befunge, though reduced to a nearly-absurd minimalism, and with a certain amount of "stack abuse," in addition to the abuses already heaped upon the program's geometry. While the People for the Ethical Treatment of Data Structures threatened to protest, they quickly realized that their acronym was not easily pronounced, and retreated to debate the merits of a new name before further business could be discussed. The instructions, listed by angle, are: 0 degrees NO: No operation, continue as normal. 45 degrees P1: Push a data value of 1 onto the stack. 90 degrees IF: Pop the stack. If the value is zero, continue executing as normal. If the value is nonzero, however, reverse direction. 135 degrees GP: Pop the stack. If the value is zero, pops the next two items from the stack, retrieves (gets) the value stored at the coordinates specified by these values (x, then y), and push it onto the stack. If the first value was nonzero, however, takes the value stored below the coordinates on the stack, and stores (puts) it at the coordinates. 180 degrees QU: Jump the gap, if possible. Otherwise, terminate. 225 degrees IO: Pop the stack. If the value is zero, read a character from input, pushing it onto the stack. If the value was nonzero, pop the stack, and print the value to output as a character. 270 degrees IF: See 90 degrees. Included for flexibility. 315 degrees SB: Subtract the top of the stack from the value beneath it, popping both values, and pushing the result. Note that pushing a 1 is the only form of direct data specification available to the programmer, and subtraction is the only available arithmetic operation. Concurrency: The exception mentioned above to the "always choose a single path" rule is when the two likeliest paths are at angles of both 90 and 270 degrees--both forms of conditional. In such a case, rather than choosing one or the other, both paths are chosen, and the IP is cloned (including stack) to cover the other path.