Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
lispops.h
Go to the documentation of this file.
1/**
2 * lispops.h
3 *
4 * List processing operations.
5 *
6 * The general idea here is that a list processing operation is a
7 * function which takes two arguments, both cons_pointers:
8 *
9 * 1. args, the argument list to this function;
10 * 2. env, the environment in which this function should be evaluated;
11 *
12 * and returns a cons_pointer, the result.
13 *
14 * They must all have the same signature so that I can call them as
15 * function pointers.
16 *
17 *
18 * (c) 2017 Simon Brooke <simon@journeyman.cc>
19 * Licensed under GPL version 2.0, or, at your option, any later version.
20 */
21
22#ifndef __psse_lispops_h
23#define __psse_lispops_h
24
25extern struct cons_pointer prompt_name;
26
27/*
28 * utilities
29 */
30
31struct cons_pointer c_keys( struct cons_pointer store );
32
33struct cons_pointer c_reverse( struct cons_pointer arg );
34
35struct cons_pointer c_progn( struct stack_frame *frame,
36 struct cons_pointer frame_pointer,
37 struct cons_pointer expressions,
38 struct cons_pointer env );
39
40/**
41 * Useful building block; evaluate this single form in the context of this
42 * parent stack frame and this environment.
43 * @param parent the parent stack frame.
44 * @param form the form to be evaluated.
45 * @param env the evaluation environment.
46 * @return the result of evaluating the form.
47 */
48struct cons_pointer eval_form( struct stack_frame *parent,
49 struct cons_pointer parent_pointer,
50 struct cons_pointer form,
51 struct cons_pointer env );
52
53/**
54 * eval all the forms in this `list` in the context of this stack `frame`
55 * and this `env`, and return a list of their values. If the arg passed as
56 * `list` is not in fact a list, return nil.
57 */
58struct cons_pointer eval_forms( struct stack_frame *frame,
59 struct cons_pointer frame_pointer,
60 struct cons_pointer list,
61 struct cons_pointer env );
62
63/*
64 * special forms
65 */
66struct cons_pointer lisp_eval( struct stack_frame *frame,
67 struct cons_pointer frame_pointer,
68 struct cons_pointer env );
69struct cons_pointer lisp_apply( struct stack_frame *frame,
70 struct cons_pointer frame_pointer,
71 struct cons_pointer env );
72
73struct cons_pointer lisp_keys( struct stack_frame *frame,
74 struct cons_pointer frame_pointer,
75 struct cons_pointer env );
76
77struct cons_pointer lisp_oblist( struct stack_frame *frame,
78 struct cons_pointer frame_pointer,
79 struct cons_pointer env );
80
81struct cons_pointer lisp_set( struct stack_frame *frame,
82 struct cons_pointer frame_pointer,
83 struct cons_pointer env );
84
85struct cons_pointer lisp_set_shriek( struct stack_frame *frame,
86 struct cons_pointer frame_pointer,
87 struct cons_pointer env );
88
89/**
90 * Construct an interpretable function.
91 *
92 * @param frame the stack frame in which the expression is to be interpreted;
93 * @param lexpr the lambda expression to be interpreted;
94 * @param env the environment in which it is to be intepreted.
95 */
96struct cons_pointer lisp_lambda( struct stack_frame *frame,
97 struct cons_pointer frame_pointer,
98 struct cons_pointer env );
99struct cons_pointer lisp_length( struct stack_frame *frame,
100 struct cons_pointer frame_pointer,
101 struct cons_pointer env );
102/**
103 * Construct an interpretable special form.
104 *
105 * @param frame the stack frame in which the expression is to be interpreted;
106 * @param env the environment in which it is to be intepreted.
107 */
108struct cons_pointer lisp_nlambda( struct stack_frame *frame,
109 struct cons_pointer frame_pointer,
110 struct cons_pointer env );
111
112struct cons_pointer lisp_quote( struct stack_frame *frame,
113 struct cons_pointer frame_pointer,
114 struct cons_pointer env );
115
116/*
117 * functions
118 */
119struct cons_pointer lisp_assoc( struct stack_frame *frame,
120 struct cons_pointer frame_pointer,
121 struct cons_pointer env );
122struct cons_pointer lisp_cons( struct stack_frame *frame,
123 struct cons_pointer frame_pointer,
124 struct cons_pointer env );
125struct cons_pointer lisp_car( struct stack_frame *frame,
126 struct cons_pointer frame_pointer,
127 struct cons_pointer env );
128struct cons_pointer lisp_cdr( struct stack_frame *frame,
129 struct cons_pointer frame_pointer,
130 struct cons_pointer env );
131struct cons_pointer lisp_inspect( struct stack_frame *frame,
132 struct cons_pointer frame_pointer,
133 struct cons_pointer env );
134struct cons_pointer lisp_eq( struct stack_frame *frame,
135 struct cons_pointer frame_pointer,
136 struct cons_pointer env );
137struct cons_pointer lisp_equal( struct stack_frame *frame,
138 struct cons_pointer frame_pointer,
139 struct cons_pointer env );
140struct cons_pointer lisp_print( struct stack_frame *frame,
141 struct cons_pointer frame_pointer,
142 struct cons_pointer env );
143struct cons_pointer lisp_read( struct stack_frame *frame,
144 struct cons_pointer frame_pointer,
145 struct cons_pointer env );
146struct cons_pointer lisp_repl( struct stack_frame *frame,
147 struct cons_pointer frame_pointer,
148 struct cons_pointer env );
149struct cons_pointer lisp_reverse( struct stack_frame *frame,
150 struct cons_pointer frame_pointer,
151 struct cons_pointer env );
152
153/**
154 * Function: Get the Lisp type of the single argument.
155 * @param frame My stack frame.
156 * @param env My environment (ignored).
157 * @return As a Lisp string, the tag of the object which is the argument.
158 */
159struct cons_pointer lisp_type( struct stack_frame *frame,
160 struct cons_pointer frame_pointer,
161 struct cons_pointer env );
162
163/**
164 * Function; evaluate the forms which are listed in my single argument
165 * sequentially and return the value of the last. This function is called 'do'
166 * in some dialects of Lisp.
167 *
168 * @param frame My stack frame.
169 * @param env My environment (ignored).
170 * @return the value of the last form on the sequence which is my single
171 * argument.
172 */
173struct cons_pointer lisp_progn( struct stack_frame *frame,
174 struct cons_pointer frame_pointer,
175 struct cons_pointer env );
176
177/**
178 * Special form: conditional. Each arg is expected to be a list; if the first
179 * item in such a list evaluates to non-NIL, the remaining items in that list
180 * are evaluated in turn and the value of the last returned. If no arg (clause)
181 * has a first element which evaluates to non NIL, then NIL is returned.
182 * @param frame My stack frame.
183 * @param env My environment (ignored).
184 * @return the value of the last form of the first successful clause.
185 */
186struct cons_pointer lisp_cond( struct stack_frame *frame,
187 struct cons_pointer frame_pointer,
188 struct cons_pointer env );
189
190/**
191 * Throw an exception.
192 * `throw_exception` is a misnomer, because it doesn't obey the calling
193 * signature of a lisp function; but it is nevertheless to be preferred to
194 * make_exception. A real `throw_exception`, which does, will be needed.
195 */
196struct cons_pointer throw_exception( struct cons_pointer message,
197 struct cons_pointer frame_pointer );
198
199struct cons_pointer lisp_exception( struct stack_frame *frame,
200 struct cons_pointer frame_pointer,
201 struct cons_pointer env );
202
203struct cons_pointer lisp_source( struct stack_frame *frame,
204 struct cons_pointer frame_pointer,
205 struct cons_pointer env );
206
207struct cons_pointer c_append( struct cons_pointer l1, struct cons_pointer l2 );
208
209struct cons_pointer lisp_append( struct stack_frame *frame,
210 struct cons_pointer frame_pointer,
211 struct cons_pointer env );
212
213struct cons_pointer lisp_mapcar( struct stack_frame *frame,
214 struct cons_pointer frame_pointer,
215 struct cons_pointer env );
216
217struct cons_pointer lisp_list( struct stack_frame *frame,
218 struct cons_pointer frame_pointer,
219 struct cons_pointer env );
220
221struct cons_pointer lisp_let( struct stack_frame *frame,
222 struct cons_pointer frame_pointer,
223 struct cons_pointer env );
224
225struct cons_pointer lisp_try( struct stack_frame *frame,
226 struct cons_pointer frame_pointer,
227 struct cons_pointer env );
228#endif
An indirect pointer to a cons cell.
A stack frame.
struct cons_pointer lisp_nlambda(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Construct an interpretable special form.
Definition lispops.c:240
struct cons_pointer lisp_assoc(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; look up the value of a key in a store.
Definition lispops.c:835
struct cons_pointer lisp_source(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function.
Definition lispops.c:1377
struct cons_pointer lisp_mapcar(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Definition lispops.c:1468
struct cons_pointer lisp_cons(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; returns a cell constructed from a and b.
Definition lispops.c:702
struct cons_pointer lisp_eq(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; are these two objects the same object? Shallow, cheap equality.
Definition lispops.c:870
struct cons_pointer lisp_read(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; read one complete lisp form and return it.
Definition lispops.c:906
struct cons_pointer throw_exception(struct cons_pointer message, struct cons_pointer frame_pointer)
Throw an exception.
Definition lispops.c:1208
struct cons_pointer lisp_exception(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; create an exception.
Definition lispops.c:1244
struct cons_pointer c_reverse(struct cons_pointer arg)
reverse a sequence (if it is a sequence); else return it unchanged.
Definition lispops.c:943
struct cons_pointer lisp_car(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; returns the first item (head) of a sequence.
Definition lispops.c:735
struct cons_pointer eval_form(struct stack_frame *parent, struct cons_pointer parent_pointer, struct cons_pointer form, struct cons_pointer env)
Useful building block; evaluate this single form in the context of this parent stack frame and this e...
Definition lispops.c:64
struct cons_pointer lisp_let(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Special form: evaluate a series of forms in an environment in which these bindings are bound.
Definition lispops.c:1528
struct cons_pointer lisp_inspect(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: dump/inspect one complete lisp expression and return NIL.
Definition lispops.c:1001
struct cons_pointer lisp_length(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return, as an integer, the length of the sequence indicated by the first argument,...
Definition lispops.c:818
struct cons_pointer lisp_try(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
OK, the idea here (and I know this is less than perfect) is that the basic try special form in PSSE t...
Definition lispops.c:157
struct cons_pointer lisp_apply(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; apply the function which is the result of evaluating the first argument to the list of valu...
Definition lispops.c:564
struct cons_pointer c_progn(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer expressions, struct cons_pointer env)
Evaluate each of these expressions in this environment over this frame, returning only the value of t...
Definition lispops.c:1096
struct cons_pointer lisp_eval(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; evaluate the expression which is the first argument in the frame; further arguments are ign...
Definition lispops.c:504
struct cons_pointer eval_forms(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer list, struct cons_pointer env)
eval all the forms in this list in the context of this stack frame and this env, and return a list of...
Definition lispops.c:129
struct cons_pointer lisp_type(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: Get the Lisp type of the single argument.
Definition lispops.c:1086
struct cons_pointer c_keys(struct cons_pointer store)
Definition lispops.c:840
struct cons_pointer lisp_progn(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; evaluate the forms which are listed in my single argument sequentially and return the value...
Definition lispops.c:1127
struct cons_pointer lisp_keys(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Definition lispops.c:854
struct cons_pointer lisp_equal(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; are these two arguments identical? Deep, expensive equality.
Definition lispops.c:887
struct cons_pointer lisp_repl(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: the read/eval/print loop.
Definition lispops.c:1263
struct cons_pointer lisp_set_shriek(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Special form; binds symbol in the namespace to value of value, altering the namespace in so doing,...
Definition lispops.c:654
struct cons_pointer lisp_append(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
should really be overwritten with a version in Lisp, since this is much easier to write in Lisp
Definition lispops.c:1456
struct cons_pointer lisp_quote(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Special form; returns its argument (strictly first argument - only one is expected but this isn't at ...
Definition lispops.c:594
struct cons_pointer lisp_set(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; binds the value of name in the namespace to value of value, altering the namespace in so do...
Definition lispops.c:616
struct cons_pointer lisp_lambda(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Construct an interpretable function.
Definition lispops.c:223
struct cons_pointer lisp_print(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; print one complete lisp expression and return NIL.
Definition lispops.c:1040
struct cons_pointer lisp_cdr(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; returns the remainder of a sequence when the head is removed.
Definition lispops.c:779
struct cons_pointer lisp_list(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Definition lispops.c:1510
struct cons_pointer c_append(struct cons_pointer l1, struct cons_pointer l2)
A version of append which can conveniently be called from C.
Definition lispops.c:1410
struct cons_pointer lisp_oblist(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Return the object list (root namespace).
Definition lispops.c:186
struct cons_pointer lisp_cond(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Special form: conditional.
Definition lispops.c:1161
struct cons_pointer lisp_reverse(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; reverse the order of members in s sequence.
Definition lispops.c:981
struct cons_pointer prompt_name
lispops.h
Definition lispops.c:46