aboutsummaryrefslogtreecommitdiff
path: root/docs/apply.rst
diff options
context:
space:
mode:
authorbozo.kopic <bozo@kopic.xyz>2022-08-02 01:20:12 +0200
committerbozo.kopic <bozo@kopic.xyz>2022-09-25 02:40:23 +0200
commit288727f09a1b3458c268497d111349e608c3f9fa (patch)
treed62565249fa3c7127856c65405752572fc41aca9 /docs/apply.rst
Diffstat (limited to 'docs/apply.rst')
-rw-r--r--docs/apply.rst63
1 files changed, 63 insertions, 0 deletions
diff --git a/docs/apply.rst b/docs/apply.rst
new file mode 100644
index 0000000..e45c31b
--- /dev/null
+++ b/docs/apply.rst
@@ -0,0 +1,63 @@
+Function/syntax application
+===========================
+
+Builtin function/syntax application
+-----------------------------------
+
+Data representing builtin function/syntax, together with type identification,
+contains number representing index of builtin entry. As described in previous
+chapters, each builtin entry contains function pointer:
+
+.. code-block:: c
+
+ typedef lsp_status_t (*lsp_builtin_cb_t)(lsp_env_t *e, lsp_addr_t ctx, lsp_addr_t args);
+
+Application of builtin function/syntax calls provided native function
+with arguments provided to function/syntax application.
+
+Only difference between builtin function and syntax application is in arguments
+provided to application itself. In case of function application, these
+arguments are previously evaluated and in case of syntax, they are provided
+without previous evaluation.
+
+
+User defined function/syntax application
+----------------------------------------
+
+Data representation of function/syntax references:
+
+ * parent context
+ * argument name list
+ * function/syntax body
+
+During function/syntax application, new context is created as copy of
+associated parent context. That context is used for evaluation of
+function/syntax content. Prior to content evaluation, provided arguments
+are added as new entries in context and are associated with symbols
+from argument name list based on their position in list. Once context
+is created and argument values are associated, function/syntax body is
+evaluated. Evaluation of function/syntax body is sequential evaluation
+of all available expression (from first to last) where value of last expression
+is used as resulting value.
+
+In case of function application, result of last expression evaluation is
+also value of function application itself. In case of syntax evaluation,
+result of last expression is data that is additionally evaluated in context
+from which syntax application was called.
+
+
+Source code
+-----------
+
+apply.h
+'''''''
+
+.. literalinclude:: ../src_c/apply.h
+ :language: c
+
+
+apply.c
+'''''''
+
+.. literalinclude:: ../src_c/apply.c
+ :language: c