blob: 7eaa6d21305c5ab9144d85f486a8e7cc7bd1a449 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
Context
=======
Context (also known as environment in some of Lisp implementations)
is association between symbols and their data values that apply to
specific evaluation scope. This implementation provides single
lexical context for evaluation of all names regarding of associated data
type (also known as Lisp-1 namespaces).
Basic method of introducing new scope is function definition and application.
During function definition, new function is associated with scope in which
function itself is defined. Exact copy of current context as is in moment
of definition is used as functions parent scope. During function application
new context is created which inherit all associations that were available
in parent scope.
Initial context, which is used as starting context, is initialized with
associations to builtin functions and syntaxes.
Each context contains arbitrary number of mutable entries. Single entry
defines association where any kind of data is referenced by symbol.
Together with functions that add new entries (`lsp_ctx_add`) or obtain
data associated with provided symbol (`lsp_ctx_get`), context enables
modification of data referenced by provided symbol (`lsp_ctx_set`).
During entry modification, previous data instance itself is not changed, only
entry reference is modified to point to newly provided data instance.
If child context modifies existing entry in parent context, this modifications
will also be visible in parent context.
Because of support for
`tail call optimization <https://en.wikipedia.org/wiki/Tail_call>`_,
implementation of context hierarchy relies on `lsp_ctx_copy` operation instead
of referencing parent context from child context. This method induces
additional overhead in context operation. Never the less, additional memory
allocation overhead is mostly neutralized by usage of immutable linked list
as basis for entry storage.
Source code
-----------
ctx.h
'''''
.. literalinclude:: ../src_c/ctx.h
:language: c
ctx.c
'''''
.. literalinclude:: ../src_c/ctx.c
:language: c
|