changeset 59:f05f6a7896a3

doc: Extend description of built-ins.
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 24 Aug 2019 21:24:37 +0200
parents 06aa18744cb3
children 2144052c96b4
files doc/execution.md doc/syntax.md
diffstat 2 files changed, 33 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/doc/execution.md	Sat Aug 24 19:38:11 2019 +0200
+++ b/doc/execution.md	Sat Aug 24 21:24:37 2019 +0200
@@ -10,10 +10,6 @@
 
 ## Scoping.
 
-Every function call pushes an ID to the scope stack. The scope stack is used
-to identify variables/IDs in a scope. Variable and function definitions then
-always use the scope ID to resolve IDs.
-
 **Example**:
 
 ```
@@ -116,4 +112,9 @@
 expects and the numeric references that it expects arguments in. Before calling,
 expressions are copied into those references.
 
-TODO: Pass-by-value copies value/duplicates reference
+Arguments are passed by value, so expressions are cloned into the argument's
+slot.
+
+The return value is the value of the last expression. It is pushed onto the call
+stack; it will be popped from there after the function's execution.
+
--- a/doc/syntax.md	Sat Aug 24 19:38:11 2019 +0200
+++ b/doc/syntax.md	Sat Aug 24 21:24:37 2019 +0200
@@ -4,6 +4,10 @@
 
 ### Definitions
 
+The following IDs are represented as `YBUILTIN_TYPE` in `yexpr_t` values. Each
+of them has a `ybuiltin_fn` associated with it that can be called with a pointer
+to the call stack, executing the defined logic.
+
 #### `defn`: Define function
 
 ```
@@ -13,6 +17,9 @@
 Result of the function is the last expression. The name is visible in the same
 and all lower scopes, where a scope is an s-expr.
 
+NOTE: This is only used during preprocessing. All expressions of this type shall
+be removed before the execution phase.
+
 #### `let`: Assign variable
 
 ```
@@ -24,6 +31,8 @@
 
 ### Control structures
 
+#### `for`
+
 ```
 (for var (list-item list-item list-item) (expr ...) (expr ...) ...)
 ```
@@ -31,6 +40,24 @@
 Run the given expressions once for every `list-item`. `var` is bound in the
 expressions to the respective item.
 
+#### `if`
+
+```
+(if cond then [else])
+```
+
+Where `cond` evaluates to a boolean value (numeric 1 or 0) and `then`, `else`
+are expressions. If multiple expressions should be executed, `seq` can be used
+to chain them.
+
+#### `seq`
+
+```
+(seq expr expr ...)
+```
+
+Execute `expr`s and return the result of the last `expr`.
+
 ### Arithmetic operations
 
 ```