| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'content/wyrd_v1')
| -rw-r--r-- | content/wyrd_v1/_index.md | 56 | ||||
| -rw-r--r-- | content/wyrd_v1/computations/_index.md | 99 | ||||
| -rw-r--r-- | content/wyrd_v1/extensions/_index.md | 4 | ||||
| -rw-r--r-- | content/wyrd_v1/instructions/_index.md | 75 | 
4 files changed, 234 insertions, 0 deletions
| diff --git a/content/wyrd_v1/_index.md b/content/wyrd_v1/_index.md new file mode 100644 index 0000000..4d902e2 --- /dev/null +++ b/content/wyrd_v1/_index.md @@ -0,0 +1,56 @@ +--- +menuTitle: Wyrd +title: Wyrd (Version 1) +--- +Wyrd is the language in which the narrative is given to the game engine. It is +purposefully kept small and simple to facilitate porting Tonkadur to a new +engine. + +The memory is seen as a table mapping strings to values. These values may also +be tables. Thus a reference is a list of strings corresponding to a move from +one table to the next. + +The program is a list of instructions. These instructions may use computations +as parameters. They sometimes use hard-coded strings parameters as well. +Instructions cannot take instructions as parameters. Instructions are not +associated to any value. + +An integer, called _Program Counter_ is used to indicate the current +instruction. In most cases, this integer is incremented by one after every +instruction. There is an instruction to modify the value of the Program Counter, +which allows conditional jumps and loops to be described. + +Computations are values and operations returning values. These are solely used +as parameters of instructions. They do not alter memory (with one exception) +and do not interact with the Program Counter in any way. An execution cannot be +stopped during the evaluation of a computation: it is part of its parent +instruction and is thus completed exactly when that instruction is performed. +Computations may _read_ from the memory, as they may need to fetch the value +associated with an address or traverse tables. All computations have a return +type. + +Wyrd does not have the notion of sequence or that lambda functions. It does not +even associate player choices with lists of actions. It's all done by carefully +managing the Program Counter. + +Lambda functions are stored as an `INT` corresponding to a line in the program. + +## Types +* `ADDRESS` (or `POINTER`, or `REFERENCE`), a list of `STRING` (note: not a +   `STRING COLLECTION`). +* `BOOL`. This should be changed to `BOOL` soon, for consistency's sake. +* `[SOMETHING] COLLECTION`, table mapping `STRING` to `[SOMETHING]`. +* `FLOAT`. +* `INT`. +* `RICH TEXT`, a list of `STRINGS` with attributes attached. +* `STRING`. +* `STRUCTURE` (or `DICTIONARY`), table mapping `STRING` to values of any type. +* `{String}`, a hard-coded string. + +#### Aliases sometimes used to refer to types +* `? ADDRESS`: an `ADDRESS` pointing to a particular type. +* `BASE TYPE`: `INT`, `FLOAT`, `BOOL`, `STRING`. +* `COMPARABLE`: `INT`, `FLOAT`, `BOOL`, `STRING`, `RICH TEXT`, `ADDRESS`. +* `COLLECTION`: any `? COLLECTION`. +* `COMPUTATION`: any type. +* `NUMBER`: `INT` or `FLOAT`. diff --git a/content/wyrd_v1/computations/_index.md b/content/wyrd_v1/computations/_index.md new file mode 100644 index 0000000..028a82e --- /dev/null +++ b/content/wyrd_v1/computations/_index.md @@ -0,0 +1,99 @@ +--- +title: Computations +--- +This page presents all the computations that can be performed in Wyrd. +Computations may access the current memory, but, with one exception, do not +change it. The one exception is `(new t)`. All computations return values. +The terms 'value' and 'computation' are interchangeable. + +## CONSTANT +{{< fatecode >}}(const [BASE TYPE] {string}){{< /fatecode >}} +Returns the `[BASE TYPE]` represented by `{string}`. + +## CAST +{{< fatecode >}}(cast [COMPUTATION] [BASE TYPE]){{< /fatecode >}} +Converts `[COMPUTATION]` to `[BASE TYPE]`, returns the result. + +Note: +* Converting from `FLOAT` to `INT` returns `floor(v)`. +* Converting from `BOOL` to `STRING` yields either `True` or `False`. + +The following must be supported: +* `[FLOAT]` to `[FLOAT]`, `[INT]`, and `[STRING]`. +* `[INT]` to `[FLOAT]`, `[INT]`, and `[STRING]`. +* `[BOOL]` to `[BOOL]` and `[STRING]`. +* `[STRING]` to `[BOOL]` (`true` and `false`), `[FLOAT]`, `[INT]`, and`[STRING]`. + +## IF-ELSE +{{< fatecode >}}(if_else [BOOL] [C0 = COMPUTATION] [C1 = COMPUTATION]){{< /fatecode >}} +Returns `C0` if `[BOOL]` holds _true_, `C1` otherwise. `C0` and `C1` both +have the same type. + +## EQUALS +{{< fatecode >}}(equals [C0 = COMPUTATION] [C1 = COMPUTATION]){{< /fatecode >}} +Returns a `BOOL`, _true_ if `C0` and `C1` hold the same value. `C0` and `C1` +are both of the same type. + +## MATHEMATICAL OPERATORS +{{< fatecode >}}(divide [C0 = NUMBER] [C1 = NUMBER]){{< /fatecode >}} + +{{< fatecode >}}(minus [C0 = NUMBER] [C1 = NUMBER]){{< /fatecode >}} + +{{< fatecode >}}(plus [C0 = NUMBER] [C1 = NUMBER]){{< /fatecode >}} + +{{< fatecode >}}(power [C0 = NUMBER] [C1 = NUMBER]){{< /fatecode >}} + +{{< fatecode >}}(times [C0 = NUMBER] [C1 = NUMBER]){{< /fatecode >}} +The operation returns a value of the same type as `C0` and `C1` (both `C0` and +`C1` are also of the same type). Thus, `(divide C0 C1)` is an integer division +(the remainder is discarded) if `C0` and `C1` are of type `INT`, and a standard +division if they are of type `FLOAT`. + +{{< fatecode >}}(rand [C0 = INT] [C1 = INT]){{< /fatecode >}} +Returns a random value between `C0` and `C1`, inclusive. Raises a runtime error +if `C0 > C1`. + +## MATHEMATICAL COMPARISON +{{< fatecode >}}(less_than [C0 = COMPARABLE] [C1 = COMPARABLE]){{< /fatecode >}} +Returns a `[BOOL]` indicating if `C0` is strictly less than `C1`. +`C0` and `C1` are both of the same type. + +## LOGICAL OPERATORS +{{< fatecode >}}(and [C0 = BOOL] [C1 = BOOL]){{< /fatecode >}} + +{{< fatecode >}}(not [C0 = BOOL]){{< /fatecode >}} + +## SIZE +{{< fatecode >}}(size [COLLECTION ADDRESS]){{< /fatecode >}} +Returns the number of elements held by the collection at +`[COLLECTION ADDRESS]`. + +## REFERENCES +{{< fatecode >}}(address [COMPUTATION]){{< /fatecode >}} +Returns an `ADDRESS` to the memory element at address `[COMPUTATION]`. Raises a +runtime error if `[COMPUTATION]` is not a memory element. + +{{< fatecode >}}(relative_address <R0 = (COLLECTION|STRUCTURE) ADDRESS> [STRING]){{< /fatecode >}} +Returns a `REFERENCE` to member `[STRING]` of `R0`. + +{{< fatecode >}}(value_of [ADDRESS]){{< /fatecode >}} +Returns the value held at the memory location `[ADDRESS]`. + +{{< fatecode >}}(new [TYPE]){{< /fatecode >}} +Returns an `[TYPE] ADDRESS` to a newly allocated memory element of +type `[TYPE]`. + +## RICH TEXT +{{< fatecode >}}(newline){{< /fatecode >}} +Returns a `RICH TEXT` value corresponding to a newline. + +{{< fatecode >}}(rich_text [S0 = STRING] ... [SN = STRING]){{< /fatecode >}} +Returns a single value `RICH TEXT` representing the elements `S0` ... `S1`. + +{{< fatecode >}}(add_rich_text_effect ({string} [V0 = COMPUTATION] ... [VN = COMPUTATION]) [RICH TEXT]){{< /fatecode >}} +Returns a `RICH TEXT` value of `[RICH TEXT]` with the given effect enabled. + +## LAST USER CHOICE +{{< fatecode >}}(get_last_user_choice){{< /fatecode >}} +Returns the number corresponding to the option last chosen by the user in a +`(resolve_choices)`, or `-1` if there is no such value. diff --git a/content/wyrd_v1/extensions/_index.md b/content/wyrd_v1/extensions/_index.md new file mode 100644 index 0000000..a21559c --- /dev/null +++ b/content/wyrd_v1/extensions/_index.md @@ -0,0 +1,4 @@ +--- +title: Extensions +--- +Not available in Version 1. diff --git a/content/wyrd_v1/instructions/_index.md b/content/wyrd_v1/instructions/_index.md new file mode 100644 index 0000000..9d43a5a --- /dev/null +++ b/content/wyrd_v1/instructions/_index.md @@ -0,0 +1,75 @@ +--- +title: Instructions +--- +This page presents all the instructions that can be performed in Wyrd. +Instructions do not return values. With one exception, all instructions increase +the Program Counter by 1. + + +## ADD CHOICE +{{< fatecode >}}(add_choice [RICH TEXT]){{< /fatecode >}} +Adds a new option for the next `resolve_choices` instruction. The new option +presents the player with `[RICH TEXT]`. + +## INTEGER PROMPT +{{< fatecode >}}(prompt_integer [INT REFERENCE] [MIN = INT] [MAX = INT] [RICH TEXT]){{< /fatecode >}} + +Prompts the user for an integer between `[MIN]` and `[MAX]` by displaying the +message `[RICH TEXT]`. The result is stored in `[INT REFERENCE]`. + +## STRING PROMPT +{{< fatecode >}}(prompt_string [STRING REFERENCE] [MIN = INT] [MAX = INT] [RICH TEXT]){{< /fatecode >}} + +Prompts the user for a string of size between `[MIN]` and `[MAX]` by displaying +the message `[RICH TEXT]`. The result is stored in `[STRING REFERENCE]`. + + +## ASSERT +{{< fatecode >}}(assert [BOOL] [RICH TEXT]){{< /fatecode >}} +If `[BOOL]` isn't _true_, raise a runtime error containing `[RICH TEXT]`. + + +## DISPLAY +{{< fatecode >}}(display [RICH TEXT]){{< /fatecode >}} +Displays `[RICH TEXT]` to the player. + + +## END +{{< fatecode >}}(end){{< /fatecode >}} +Marks the end of the narration. Interrupts the execution. + + +## EVENT CALL +{{< fatecode >}}(event_call {string} [C0 = COMPUTATION] ... [CN = COMPUTATION]){{< /fatecode >}} +Interrupts execution, informs the interpreter that the given event `{String}` +was triggered with the parameters `C0 ... CN`. + + +## REMOVE +{{< fatecode >}}(remove [ADDRESS]){{< /fatecode >}} +The memory at `[ADDRESS]` is freed. + + +## RESOLVE CHOICES +{{< fatecode >}}(resolve_choices){{< /fatecode >}} +Present the player with all options that where added using `add_choice` since +the last `resolve_choices`. The execution is paused and should be resumed by +the interpreter setting the Program Counter according to the chosen option. + + +## SET PC +{{< fatecode >}}(set_pc [INT]){{< /fatecode >}} +Sets the Program Counter to `[INT]`. The program counter is not automatically +increased by 1 in this case. + + +## SET VALUE +{{< fatecode >}}(set_value [ADDRESS] [COMPUTATION]){{< /fatecode >}} +Sets the memory pointed by `[ADDRESS]` to `[COMPUTATION]`. +`[COMPUTATION]` is passed by value, not reference (i.e. no aliasing can occur +without it being done explicitly through pointers). + +## INITIALIZE MEMORY ELEMENT +{{< fatecode >}}(initialize [ADDRESS] [TYPE]){{< /fatecode >}} +Initializes a memory element at `[ADDRESS]` with the default value for the type +`[TYPE]`. | 


