This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
prpl:prpl_notation_styles [2016/10/17 13:55] – acnot set swap planetfall | prpl:prpl_notation_styles [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | PRPL is typically referred to as a " | ||
- | |||
- | There are 3 distinct ways to write PRPL code. | ||
- | |||
- | * Stack Notation (traditional) | ||
- | * Warp Notation (developed for CW3) | ||
- | * Accessor Notation (new for PRPL) | ||
- | |||
- | ==== Stack Notation ==== | ||
- | |||
- | Every PRPL operand takes zero or more arguments from a " | ||
- | |||
- | * The term is defined by two dashes: %% -- %% | ||
- | * Preceding the term are the arguments consumed from the stack. | ||
- | * Following the term are the arguments pushed onto the stack. | ||
- | For instance, the instruction to add two numbers are: | ||
- | |||
- | < | ||
- | |||
- | Stack notation to represent this will be: | ||
- | |||
- | < | ||
- | In general, if we do not know the exact values of the arguments, an indicator of the argument would be given. Thus if we know the add command takes two input arguments and produces one output argument, then we notate it like this | ||
- | < | ||
- | |||
- | |||
- | **Note:** Unless explicitly noted otherwise, all instructions are destructive stack operations in that they will remove as many arguments as is required for their execution from the stack and replace those with the output from their execution. In the example above, the original two items on the stack have been replaced by their sum. | ||
- | |||
- | Likewise, note that the most recent item pushed on to the stack will also be the first item to be removed. This is referred to as LIFO (**L**ast **I**n, **F**irst **O**ut) processing. | ||
- | |||
- | The following convention is followed to represent items on the stack notation | ||
- | |||
- | |< 80% 15% >| | ||
- | |b |**Boolean** ; nominally a 1 or a zero, representing True or False| | ||
- | |i |**Integer** ; an integer. The PRPL run-time will, if possible, convert the argumant to an integer.| | ||
- | |n |**Term** ; a generic argument. Any term that will be accepted by the instruction. If possible, the PRPL run-time will attempt conversion between types.| | ||
- | |f |**Float** ; a floating point value. If possible, the PRPL run-time will attempt conversion between types.| | ||
- | |x, y |**Coordinate** ; an integer that represents a valid X- or Y-coordinate on the map.| | ||
- | |L |**List** ; a list is capable of storing multiple values in an orderly system.| | ||
- | |s |**String** ; a string of one or more text characters. If possible, numeric values will be converted at run-time.| | ||
- | |||
- | ==== Warp Notation ==== | ||
- | |||
- | An extra and optional operator to PRPL allows for a reversed order that you write some things in PRPL. It doesn' | ||
- | |||
- | This operator is the " | ||
- | |||
- | < | ||
- | |||
- | This means to push 3 to the stack, push 4 to the stack, then to call " | ||
- | < | ||
- | This means two items on the stack before the operation, and one item on the stack afterwards. | ||
- | This is all PRPL (or RPL, or forth...) standard stuff and the primary principle of the language. | ||
- | |||
- | Take a second example: | ||
- | |||
- | < | ||
- | CurrentCoords GetCreeper 1 gt if | ||
- | " | ||
- | endif | ||
- | </ | ||
- | |||
- | This looks at the current coordinates, | ||
- | |||
- | Again, PRPL 101. | ||
- | |||
- | Now, introducing the Warp operator. | ||
- | |||
- | < | ||
- | can become | ||
- | < | ||
- | |||
- | The open parenthesis " | ||
- | |||
- | This also means the same thing: | ||
- | < | ||
- | Here, the " | ||
- | |||
- | Take the second example. | ||
- | < | ||
- | if ( GetCreeper(CurrentCoords) | ||
- | Trace (" | ||
- | endif | ||
- | </ | ||
- | Notice that spaces before or after a warp operator ( which are parentheses) don't matter. | ||
- | |||
- | Note also that this syntax is totally optional and can be intermixed with standard RPL notation as seems appropriate. | ||
- | < | ||
- | 7 -> | ||
- | This means to assign 7 to the variable " | ||
- | So does this: | ||
- | < | ||
- | |||
- | Like any language, you can write some really obfuscated code if you try ([[http:// | ||
- | |||
- | For instance take this clean piece of code: | ||
- | < | ||
- | CurrentCoords GetCreeper 1 gt if | ||
- | | ||
- | endif | ||
- | </ | ||
- | |||
- | Here it is in bizarro form: | ||
- | < | ||
- | endif(SetCreeper(-10(CurrentCoords(if(gt(1(GetCreeper(CurrentCoords))))))))</ | ||
- | |||
- | |||
- | Here's the same code with just one oddball warp: | ||
- | < | ||
- | endif ( if (GetCreeper(CurrentCoords) gt (1)) | ||
- | SetCreeper(CurrentCoords -10) | ||
- | ) | ||
- | </ | ||
- | |||
- | ==== Accessor | ||
- | |||
- | // Direct copy from forum post introducing Accessor notation // | ||
- | |||
- | Previously let's say you had created an emitter and wanted to set some properties on the emitter. | ||
- | <code PRPL> | ||
- | CreateUnit(" | ||
- | SetEmitterParticleType(< | ||
- | SetEmitterProductionInterval(< | ||
- | SetEmitterMaxParticles(< | ||
- | </ | ||
- | |||
- | That's cool, and it works just fine. AcNot just allows it to be a little tighter. It works similar to warp notation in that it is really just a preprocessor sweep over the PRPL code. So the following will now produce the exact same opcodes as the above example. | ||
- | |||
- | <code PRPL> | ||
- | CreateUnit(" | ||
- | 1 -> | ||
- | 5 -> | ||
- | 500 -> | ||
- | </ | ||
- | |||
- | |||
- | AcNot can also be used for reading a ' | ||
- | Old way | ||
- | <code PRPL> | ||
- | GetEmitterParticleType(< | ||
- | </ | ||
- | |||
- | |||
- | New way | ||
- | <code PRPL> | ||
- | < | ||
- | </ | ||
- | |||
- | |||
- | The way this works is the compiler just rearranges the PRPL source (roughly speaking) so that AcNot syntax produces the old syntax. | ||
- | |||
- | So for an AcNot read operation this happens: | ||
- | < | ||
- | becomes | ||
- | <-var GetProperty | ||
- | |||
- | For an AcNot write operation this happens: | ||
- | -> | ||
- | <-var swap SetProperty | ||
- | |||
- | This syntax only works (is only useful) on single argument ' | ||
- | |||
- | |||
- | |||