Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
lispops.c File Reference
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "memory/consspaceobject.h"
#include "memory/conspage.h"
#include "debug.h"
#include "memory/dump.h"
#include "ops/equal.h"
#include "arith/integer.h"
#include "ops/intern.h"
#include "io/io.h"
#include "ops/lispops.h"
#include "io/print.h"
#include "io/read.h"
#include "memory/stack.h"
#include "memory/vectorspace.h"
Include dependency graph for lispops.c:

Go to the source code of this file.

Functions

struct cons_pointer c_append (struct cons_pointer l1, struct cons_pointer l2)
 A version of append which can conveniently be called from C.
 
struct cons_pointer c_apply (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Internal guts of apply.
 
struct cons_pointer c_keys (struct cons_pointer store)
 
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 the last.
 
struct cons_pointer c_reverse (struct cons_pointer arg)
 reverse a sequence (if it is a sequence); else return it unchanged.
 
struct cons_pointer compose_body (struct stack_frame *frame)
 Used to construct the body for lambda and nlambda expressions.
 
bool end_of_stringp (struct cons_pointer arg)
 
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 environment.
 
struct cons_pointer eval_forms (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer list, struct cons_pointer env)
 Evaluate all the forms in this list in the context of this stack frame and this env, and return a list of their values.
 
struct cons_pointer eval_lambda (struct cons_space_object cell, struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Evaluate a lambda or nlambda expression.
 
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
 
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 values which is the result of evaluating the second argument.
 
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.
 
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.
 
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.
 
struct cons_pointer lisp_cond (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Special form: conditional.
 
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.
 
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.
 
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.
 
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 ignored.
 
struct cons_pointer lisp_exception (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Function; create an exception.
 
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.
 
struct cons_pointer lisp_keys (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 
struct cons_pointer lisp_lambda (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Construct an interpretable function.
 
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, or zero if it is not a sequence.
 
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.
 
struct cons_pointer lisp_list (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 
struct cons_pointer lisp_mapcar (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 
struct cons_pointer lisp_nlambda (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Construct an interpretable special form.
 
struct cons_pointer lisp_oblist (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Return the object list (root namespace).
 
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.
 
struct cons_pointer lisp_progn (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Special form; evaluate the expressions which are listed in my arguments sequentially and return the value of the last.
 
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 this stage checked) unevaluated.
 
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.
 
struct cons_pointer lisp_repl (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Function: the read/eval/print loop.
 
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.
 
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 doing.
 
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, and returns value.
 
struct cons_pointer lisp_source (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Function.
 
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 takes two arguments, the first, body, being a list of forms, and the second, catch, being a catch handler (which is also a list of forms).
 
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.
 
void log_binding (struct cons_pointer name, struct cons_pointer val)
 
struct cons_pointer throw_exception (struct cons_pointer message, struct cons_pointer frame_pointer)
 Throw an exception.
 

Variables

struct cons_pointer prompt_name
 the name of the symbol to which the prompt is bound;
 

Function Documentation

◆ c_append()

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 at line 1410 of file lispops.c.

References c_append(), c_car(), c_cdr(), c_string_to_lisp_string(), CONSTV, KEYTV, make_cons(), make_string_like_thing(), NIL, nilp, pointer2cell, STRINGTV, SYMBOLTV, and throw_exception().

Referenced by c_append(), c_assoc(), and lisp_append().

◆ c_apply()

struct cons_pointer c_apply ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Internal guts of apply.

Parameters
framethe stack frame, expected to have only one argument, a list comprising something that evaluates to a function and its arguments.
envThe evaluation environment.
Returns
the result of evaluating the function with its arguments.

Definition at line 340 of file lispops.c.

References c_assoc(), c_car(), c_cdr(), c_string_to_lisp_string(), DEBUG_EVAL, debug_print(), debug_print_object(), debug_println(), dec_ref(), eval_form(), eval_lambda(), exceptionp, EXCEPTIONTV, FUNCTIONTV, get_stack_frame(), HASHTV, inc_ref(), KEYTV, LAMBDATV, make_special_frame(), make_stack_frame(), NIL, NLAMBDATV, cons_space_object::payload, pointer2cell, pointer_to_vso, SPECIALTV, cons_space_object::tag, throw_exception(), and VECTORPOINTTV.

Referenced by lisp_apply(), and lisp_eval().

◆ c_keys()

struct cons_pointer c_keys ( struct cons_pointer  store)

Definition at line 840 of file lispops.c.

References c_car(), c_cdr(), consp, hashmap_keys(), hashmapp, make_cons(), NIL, and nilp.

Referenced by lisp_keys(), and lisp_loop().

◆ c_progn()

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 the last.

Definition at line 1096 of file lispops.c.

References c_car(), c_cdr(), consp, dec_ref(), eval_form(), exceptionp, inc_ref(), and NIL.

Referenced by lisp_cond(), lisp_progn(), and lisp_try().

◆ c_reverse()

struct cons_pointer c_reverse ( struct cons_pointer  arg)

reverse a sequence (if it is a sequence); else return it unchanged.

Definition at line 943 of file lispops.c.

References c_cdr(), CONSTV, make_cons(), make_string(), make_symbol_or_key(), NIL, cons_space_object::payload, pointer2cell, sequencep, STRINGTV, SYMBOLTV, and cons_space_object::tag.

Referenced by eval_forms(), lisp_mapcar(), and lisp_reverse().

◆ compose_body()

struct cons_pointer compose_body ( struct stack_frame frame)

Used to construct the body for lambda and nlambda expressions.

Definition at line 194 of file lispops.c.

References args_in_frame, debug_dump_object(), DEBUG_LAMBDA, debug_print(), make_cons(), and nilp.

Referenced by lisp_lambda(), and lisp_nlambda().

◆ end_of_stringp()

bool end_of_stringp ( struct cons_pointer  arg)
Returns
true if arg represents an end of string, else false.
Todo:
candidate for moving to a memory/string.c file

Definition at line 680 of file lispops.c.

References nilp, pointer2cell, and stringp.

Referenced by lisp_cons().

◆ eval_form()

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 environment.

Parameters
parentthe parent stack frame.
formthe form to be evaluated.
envthe evaluation environment.
Returns
the result of evaluating the form.

Definition at line 64 of file lispops.c.

References stack_frame::args, DEBUG_EVAL, debug_print(), debug_print_object(), debug_println(), dec_ref(), exceptionp, EXCEPTIONTV, FREETV, get_stack_frame(), inc_ref(), INTEGERTV, KEYTV, lisp_eval(), LOOPTV, make_empty_frame(), NILTV, pointer2cell, RATIOTV, READTV, REALTV, set_reg(), STRINGTV, TIMETV, TRUETV, and WRITETV.

Referenced by c_apply(), c_progn(), eval_forms(), eval_lambda(), lisp_cond(), lisp_let(), lisp_mapcar(), lisp_progn(), lisp_repl(), lisp_set_shriek(), make_stack_frame(), and read_map().

◆ eval_forms()

struct cons_pointer eval_forms ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  list,
struct cons_pointer  env 
)

Evaluate all the forms in this list in the context of this stack frame and this env, and return a list of their values.

eval all the forms in this list in the context of this stack frame and this env, and return a list of their values.

If the arg passed as list is not in fact a list, return NIL.

Parameters
framethe stack frame.
listthe list of forms to be evaluated.
envthe evaluation environment.
Returns
a list of the the results of evaluating the forms.

Definition at line 129 of file lispops.c.

References c_car(), c_cdr(), c_reverse(), consp, eval_form(), make_cons(), and NIL.

Referenced by eval_lambda(), and make_stack_frame().

◆ eval_lambda()

struct cons_pointer eval_lambda ( struct cons_space_object  cell,
struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Evaluate a lambda or nlambda expression.

Definition at line 256 of file lispops.c.

References args_in_frame, c_car(), c_cdr(), consp, DEBUG_LAMBDA, debug_print(), debug_print_object(), debug_println(), dec_ref(), eval_form(), eval_forms(), exceptionp, inc_ref(), log_binding(), make_cons(), NIL, nilp, set(), and symbolp.

Referenced by c_apply().

◆ lisp_append()

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 at line 1456 of file lispops.c.

References c_append(), and fetch_arg().

Referenced by main().

◆ lisp_apply()

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 values which is the result of evaluating the second argument.

  • (apply fn args)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment.
Returns
the result of applying fn to args.

Definition at line 564 of file lispops.c.

References c_apply(), debug_dump_object(), DEBUG_EVAL, debug_print(), make_cons(), NIL, and set_reg().

Referenced by main().

◆ lisp_assoc()

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.

  • (assoc key store)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
the value associated with key in store, or nil if not found.

Definition at line 835 of file lispops.c.

References c_assoc().

Referenced by main().

◆ lisp_car()

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.

Valid for cons cells, strings, read streams and TODO other things which can be considered as sequences.

  • (car expression)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
the first item (head) of expression.
Exceptions
if`expression` is not a sequence.

Definition at line 735 of file lispops.c.

References c_string_to_lisp_string(), CONSTV, make_string(), NIL, NILTV, cons_space_object::payload, pointer2cell, READTV, STRINGTV, cons_space_object::tag, throw_exception(), and url_fgetwc().

Referenced by main().

◆ lisp_cdr()

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.

Valid for cons cells, strings, read streams and TODO other things which can be considered as sequences. NOTE that if the argument is an input stream, the first character is removed AND DISCARDED.

  • (cdr expression)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
the remainder of expression when the head is removed.
Exceptions
if`expression` is not a sequence.

Definition at line 779 of file lispops.c.

References c_string_to_lisp_string(), CONSTV, NIL, NILTV, cons_space_object::payload, pointer2cell, READTV, STRINGTV, cons_space_object::tag, throw_exception(), and url_fgetwc().

Referenced by main().

◆ lisp_cond()

struct cons_pointer lisp_cond ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Special form: conditional.

Each clause is expected to be a list; if the first item in such a list evaluates to non-NIL, the remaining items in that list are evaluated in turn and the value of the last returned. If no arg clause has a first element which evaluates to non NIL, then NIL is returned.

  • (cond clauses...)
Parameters
framemy stack frame.
frame_pointera pointer to my stack_frame.
envthe environment in which arguments will be evaluated.
Returns
the value of the last expression of the first successful clause.

Definition at line 1161 of file lispops.c.

References args_in_frame, c_car(), c_cdr(), c_progn(), c_string_to_lisp_string(), consp, debug_dump_object(), DEBUG_EVAL, debug_print(), eval_form(), NIL, nilp, pointer2cell, and throw_exception().

Referenced by main().

◆ lisp_cons()

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.

If a is of type string but its cdr is nill, and b is of type string, then returns a new string cell; otherwise returns a new cons cell.

Thus: (cons "a" "bcd") -> "abcd", but (cons "ab" "cd") -> ("ab" . "cd")

  • (cons a b)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
a new cons cell whose car is a and whose cdr is b.

Definition at line 702 of file lispops.c.

References c_cdr(), end_of_stringp(), make_cons(), make_string(), NIL, nilp, pointer2cell, and stringp.

Referenced by main().

◆ lisp_eq()

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.

  • (eq a b)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
t if a and b are pointers to the same object, else nil;

Definition at line 870 of file lispops.c.

References eq(), NIL, and TRUE.

Referenced by main().

◆ lisp_equal()

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.

  • (equal a b)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
t if a and b are recursively identical, else nil.

Definition at line 887 of file lispops.c.

References equal(), NIL, and TRUE.

Referenced by main().

◆ lisp_eval()

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 ignored.

  • (eval expression)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment.
Returns
  • If expression is a number, string, nil, or t, returns expression.
  • If expression is a symbol, returns the value that expression is bound to in the evaluation environment (env).
  • If expression is a list, expects the car to be something that evaluates to a function or special form:
    • If a function, evaluates all the other top level elements in expression and passes them in a stack frame as arguments to the function;
    • If a special form, passes the cdr of expression to the special form as argument.
Exceptions
if`expression` is a symbol which is not bound in `env`.

Definition at line 504 of file lispops.c.

References c_apply(), c_assoc(), c_string_to_lisp_string(), CONSTV, debug_dump_object(), DEBUG_EVAL, debug_print(), inc_ref(), internedp(), make_cons(), nilp, pointer2cell, SYMBOLTV, cons_space_object::tag, and throw_exception().

Referenced by eval_form(), and main().

◆ lisp_exception()

struct cons_pointer lisp_exception ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Function; create an exception.

Exceptions are special in as much as if an exception is created in the binding of the arguments of any function, the function will return the exception rather than whatever else it would normally return. A function which detects a problem it cannot resolve should return an exception.

  • (exception message frame)
Parameters
framemy stack frame.
frame_pointera pointer to my stack_frame.
envthe environment in which arguments will be evaluated.
Returns
areturns an exception whose message is this message, and whose stack frame is the parent stack frame when the function is invoked. message does not have to be a string but should be something intelligible which can be read. If message is itself an exception, returns that instead.

Definition at line 1244 of file lispops.c.

References exceptionp, and throw_exception().

Referenced by main().

◆ lisp_inspect()

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.

If write-stream is specified and is a write stream, then print to that stream, else the stream which is the value of *out* in the environment.

  • (inspect expr)
  • (inspect expr write-stream)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (from which the stream may be extracted).
Returns
NIL.

Definition at line 1001 of file lispops.c.

References debug_dump_object(), DEBUG_IO, debug_print(), dump_object(), file_to_url_file(), get_default_stream(), NIL, pointer2cell, and writep.

Referenced by main().

◆ lisp_keys()

struct cons_pointer lisp_keys ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Definition at line 854 of file lispops.c.

References c_keys().

Referenced by main().

◆ lisp_lambda()

struct cons_pointer lisp_lambda ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Construct an interpretable function.

NOTE that if args is a single symbol rather than a list, a varargs function will be created.

(lambda args body)

Parameters
framethe stack frame in which the expression is to be interpreted;
frame_pointera pointer to my stack_frame.
envthe environment in which it is to be intepreted.
Returns
an interpretable function with these args and this body.

Definition at line 223 of file lispops.c.

References compose_body(), and make_lambda().

Referenced by main().

◆ lisp_length()

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, or zero if it is not a sequence.

  • (length any)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
the length of any, if it is a sequence, or zero otherwise.

Definition at line 818 of file lispops.c.

References c_length(), make_integer(), and NIL.

◆ lisp_let()

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.

This is let* in Common Lisp parlance; let in Clojure parlance.

Definition at line 1528 of file lispops.c.

References c_car(), c_cdr(), c_string_to_lisp_string(), eval_form(), exceptionp, fetch_arg(), make_cons(), NIL, symbolp, throw_exception(), and truep.

Referenced by main().

◆ lisp_list()

struct cons_pointer lisp_list ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Definition at line 1510 of file lispops.c.

References args_in_frame, fetch_arg(), make_cons(), and nilp.

Referenced by main().

◆ lisp_mapcar()

struct cons_pointer lisp_mapcar ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

◆ lisp_nlambda()

struct cons_pointer lisp_nlambda ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Construct an interpretable special form.

NOTE that if args is a single symbol rather than a list, a varargs special form will be created.

(nlambda args body)

Parameters
framethe stack frame in which the expression is to be interpreted;
frame_pointera pointer to my stack_frame.
envthe environment in which it is to be intepreted.
Returns
an interpretable special form with these args and this body.

Definition at line 240 of file lispops.c.

References compose_body(), and make_nlambda().

Referenced by main().

◆ lisp_oblist()

struct cons_pointer lisp_oblist ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Return the object list (root namespace).

  • (oblist)
Parameters
framethe stack frame in which the expression is to be interpreted;
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
the root namespace.

Definition at line 186 of file lispops.c.

References oblist.

Referenced by main().

◆ lisp_print()

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.

If write-stream is specified and is a write stream, then print to that stream, else the stream which is the value of *out* in the environment.

  • (print expr)
  • (print expr write-stream)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (from which the stream may be extracted).
Returns
NIL.

Definition at line 1040 of file lispops.c.

References debug_dump_object(), DEBUG_IO, debug_print(), dec_ref(), file_to_url_file(), get_default_stream(), inc_ref(), NIL, pointer2cell, print(), and writep.

Referenced by main().

◆ lisp_progn()

struct cons_pointer lisp_progn ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Special form; evaluate the expressions which are listed in my arguments sequentially and return the value of the last.

Function; evaluate the forms which are listed in my single argument sequentially and return the value of the last.

This function is called 'do' in some dialects of Lisp.

  • (progn expressions...)
Parameters
framemy stack frame.
frame_pointera pointer to my stack_frame.
envthe environment in which expressions are evaluated.
Returns
the value of the last expression of the sequence which is my single argument.

Definition at line 1127 of file lispops.c.

References args_in_frame, c_progn(), consp, dec_ref(), eval_form(), inc_ref(), NIL, and nilp.

Referenced by main().

◆ lisp_quote()

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 this stage checked) unevaluated.

  • (quote a)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
a, unevaluated,

Definition at line 594 of file lispops.c.

Referenced by main().

◆ lisp_read()

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.

If read-stream is specified and is a read stream, then read from that stream, else the stream which is the value of *in* in the environment.

  • (read)
  • (read read-stream)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment.
Returns
the expression read.

Definition at line 906 of file lispops.c.

References debug_dump_object(), DEBUG_IO, debug_print(), dec_ref(), file_to_url_file(), get_default_stream(), inc_ref(), pointer2cell, read(), and readp.

Referenced by lisp_repl(), and main().

◆ lisp_repl()

struct cons_pointer lisp_repl ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Function: the read/eval/print loop.

  • (repl)
  • (repl prompt)
  • (repl prompt input_stream output_stream)
Parameters
framemy stack frame.
frame_pointera pointer to my stack_frame.
envthe environment in which epressions will be evaluated.
Returns
the value of the last expression read.

Definition at line 1263 of file lispops.c.

References c_assoc(), c_car(), c_cdr(), c_string_to_lisp_symbol(), debug_print(), debug_print_object(), debug_printf(), debug_println(), DEBUG_REPL, dec_ref(), eq(), eval_form(), exceptionp, get_default_stream(), get_stack_frame(), inc_ref(), lisp_read(), make_cons(), NIL, nilp, oblist, pointer2cell, print(), println(), prompt_name, readp, set(), truep, url_feof(), and writep.

Referenced by main(), and repl().

◆ lisp_reverse()

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.

  • (reverse sequence)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
a sequence like this sequence but with the members in the reverse order.

Definition at line 981 of file lispops.c.

References c_reverse().

Referenced by main().

◆ lisp_set()

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 doing.

Retuns value. namespace defaults to the oblist.

Todo:
doesn't actually work yet for namespaces which are not the oblist.
  • (set name value)
  • (set name value namespace)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
value

Definition at line 616 of file lispops.c.

References c_string_to_lisp_string(), deep_bind(), make_cons(), NIL, nilp, oblist, symbolp, and throw_exception().

Referenced by main().

◆ lisp_set_shriek()

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, and returns value.

namespace defaults to the value of oblist.

Todo:
doesn't actually work yet for namespaces which are not the oblist.
  • (set! symbol value)
  • (set! symbol value namespace)
Parameters
framemy stack_frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
value

Definition at line 654 of file lispops.c.

References c_string_to_lisp_string(), deep_bind(), eval_form(), make_cons(), NIL, symbolp, and throw_exception().

Referenced by main().

◆ lisp_source()

struct cons_pointer lisp_source ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Function.

return the source code of the object which is its first argument, if it is an executable and has source code.

  • (source object)
Parameters
framemy stack frame.
frame_pointera pointer to my stack_frame.
envthe environment (ignored).
Returns
the source of the object indicated, if it is a function, a lambda, an nlambda, or a spcial form; else nil.

Definition at line 1377 of file lispops.c.

References c_assoc(), c_string_to_lisp_keyword(), c_string_to_lisp_symbol(), FUNCTIONTV, inc_ref(), LAMBDATV, make_cons(), NIL, NLAMBDATV, cons_space_object::payload, pointer2cell, SPECIALTV, and cons_space_object::tag.

Referenced by main().

◆ lisp_try()

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 takes two arguments, the first, body, being a list of forms, and the second, catch, being a catch handler (which is also a list of forms).

Forms from body are evaluated in turn until one returns an exception object, or until the list is exhausted. If the list was exhausted, then the value of evaluating the last form in body is returned. If an exception was encountered, then each of the forms in catch is evaluated and the value of the last of those is returned.

This is experimental. It almost certainly WILL change.

Definition at line 157 of file lispops.c.

References c_progn(), c_string_to_lisp_symbol(), exceptionp, and make_cons().

Referenced by main().

◆ lisp_type()

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.

Function: Get the Lisp type of the single argument.

  • (type expression)
Parameters
framemy stack frame.
frame_pointera pointer to my stack_frame.
envmy environment (ignored).
Returns
As a Lisp string, the tag of expression.

Definition at line 1086 of file lispops.c.

References c_type().

Referenced by main().

◆ log_binding()

void log_binding ( struct cons_pointer  name,
struct cons_pointer  val 
)

Definition at line 245 of file lispops.c.

References DEBUG_ALLOC, debug_dump_object(), and debug_print().

Referenced by eval_lambda().

◆ throw_exception()

struct cons_pointer throw_exception ( struct cons_pointer  message,
struct cons_pointer  frame_pointer 
)

Throw an exception.

throw_exception is a misnomer, because it doesn't obey the calling signature of a lisp function; but it is nevertheless to be preferred to make_exception. A real throw_exception, which does, will be needed. object pointing to it. Then this should become a normal lisp function which expects a normally bound frame and environment, such that frame->arg[0] is the message, and frame->arg[1] is the cons-space pointer to the frame in which the exception occurred.

Definition at line 1208 of file lispops.c.

References debug_dump_object(), DEBUG_EVAL, debug_print(), EXCEPTIONTV, make_exception(), NIL, pointer2cell, and cons_space_object::tag.

Referenced by add_2(), add_integer_ratio(), add_ratio_ratio(), c_append(), c_apply(), c_assoc(), lisp_car(), lisp_cdr(), lisp_cond(), lisp_divide(), lisp_eval(), lisp_exception(), lisp_let(), lisp_set(), lisp_set_shriek(), make_ratio(), multiply_2(), multiply_integer_ratio(), multiply_ratio_ratio(), read_continuation(), read_number(), and subtract_2().

Variable Documentation

◆ prompt_name

struct cons_pointer prompt_name

the name of the symbol to which the prompt is bound;

lispops.h

Set in init to *prompt*

Definition at line 46 of file lispops.c.

Referenced by lisp_repl(), and main().