50 char *location_descriptor ) {
56 fprintf( stderr,
"ERROR: Exception at %s: ", location_descriptor );
147 "bind_symbol_value" );
152 cell->
count = UINT32_MAX;
173 fwprintf( stdout, L
"Post-Scarcity Software Environment version %s\n\n",
183 fwprintf( stream, L
"Expected options are:\n" );
185 L
"\t-d\tDump memory to standard out at end of run (copious!);\n" );
186 fwprintf( stream, L
"\t-h\tPrint this message and exit;\n" );
187 fwprintf( stream, L
"\t-p\tShow a prompt (default is no prompt);\n" );
189 L
"\t-v LEVEL\n\t\tSet verbosity to the specified level (0...512)\n" );
190 fwprintf( stream, L
"\t\tWhere bits are interpreted as follows:\n" );
191 fwprintf( stream, L
"\t\t1\tALLOC;\n" );
192 fwprintf( stream, L
"\t\t2\tARITH;\n" );
193 fwprintf( stream, L
"\t\t4\tBIND;\n" );
194 fwprintf( stream, L
"\t\t8\tBOOTSTRAP;\n" );
195 fwprintf( stream, L
"\t\t16\tEVAL;\n" );
196 fwprintf( stream, L
"\t\t32\tINPUT/OUTPUT;\n" );
197 fwprintf( stream, L
"\t\t64\tLAMBDA;\n" );
198 fwprintf( stream, L
"\t\t128\tREPL;\n" );
199 fwprintf( stream, L
"\t\t256\tSTACK.\n" );
206int main(
int argc,
char *argv[] ) {
208 bool dump_at_end =
false;
209 bool show_prompt =
false;
210 char *infilename = NULL;
212 setlocale( LC_ALL,
"" );
214 fputs(
"Failed to initialise I/O subsystem\n", stderr );
218 while ( ( option = getopt( argc, argv,
"phdv:i:" ) ) != -1 ) {
238 fwprintf( stderr, L
"Unexpected option %c\n", option );
274 fwide( sink->
handle.file, 1 );
276 FILE *infile = infilename == NULL ? stdin : fopen( infilename,
"r" );
286 ( L
"system:standard input" ) ),
295 ( L
"system:standard output]" ) ),
303 ( L
"system:standard log" ) ),
311 ( L
"system:standard sink" ) ),
396 curl_global_cleanup( );
void dump_pages(URL_FILE *output)
dump the allocated pages to this output stream.
void summarise_allocation()
void initialise_cons_pages()
initialise the cons page system; to be called exactly once during startup.
struct cons_pointer make_special(struct cons_pointer meta, struct cons_pointer(*executable)(struct stack_frame *frame, struct cons_pointer, struct cons_pointer env))
Construct a cell which points to an executable Lisp special form.
struct cons_pointer c_string_to_lisp_keyword(wchar_t *symbol)
Return a lisp keyword representation of this wide character string.
struct cons_pointer make_function(struct cons_pointer meta, struct cons_pointer(*executable)(struct stack_frame *, struct cons_pointer, struct cons_pointer))
Construct a cell which points to an executable Lisp function.
struct cons_pointer make_write_stream(URL_FILE *output, struct cons_pointer metadata)
Construct a cell which points to a stream open for writing.
struct cons_pointer c_string_to_lisp_string(wchar_t *string)
Return a lisp string representation of this wide character string.
struct cons_pointer make_read_stream(URL_FILE *input, struct cons_pointer metadata)
Construct a cell which points to a stream open for reading.
struct cons_pointer c_string_to_lisp_symbol(wchar_t *symbol)
Return a lisp symbol representation of this wide character string.
struct cons_pointer dec_ref(struct cons_pointer pointer)
Decrement the reference count of the object at this cons pointer.
struct cons_pointer make_cons(struct cons_pointer car, struct cons_pointer cdr)
Construct a cons cell from this pair of pointers.
#define exceptionp(conspoint)
true if conspoint points to an exception, else false
union cons_space_object::@3 payload
#define NIL
a cons pointer which points to the special NIL cell
#define nilp(conspoint)
true if conspoint points to the special cell NIL, else false (there should only be one of these so it...
uint32_t count
the count of the number of references to this cell
#define TRUE
a cons pointer which points to the special T cell
struct cons_pointer c_string_to_lisp_symbol(wchar_t *symbol)
Return a lisp symbol representation of this wide character string.
struct cons_pointer dec_ref(struct cons_pointer pointer)
Decrement the reference count of the object at this cons pointer.
#define pointer2cell(pointer)
given a cons_pointer as argument, return the cell.
An indirect pointer to a cons cell.
int verbosity
the controlling flags for debug_print; set in init.c, q.v.
void debug_dump_object(struct cons_pointer pointer, int level)
Like dump_object, q.v., but protected by the verbosity mechanism.
void debug_print(wchar_t *message, int level)
print this debug message to stderr, if verbosity matches level.
#define DEBUG_BOOTSTRAP
Print messages debugging bootstrapping and teardown.
URL_FILE * url_fopen(const char *url, const char *operation)
union fcurl_data::@0 handle
struct cons_pointer lisp_hashmap_put_all(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Lisp function expecting two arguments, a hashmap and an assoc list.
struct cons_pointer lisp_get_hash(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
A lisp function signature conforming wrapper around get_hash, q.v.
struct cons_pointer lisp_hashmap_put(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Expects frame->arg[1] to be a hashmap or namespace; frame->arg[2] to be a string-like-thing (perhaps ...
struct cons_pointer lisp_make_hashmap(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Lisp funtion of up to four args (all optional), where.
struct cons_pointer check_exception(struct cons_pointer pointer, char *location_descriptor)
If pointer is an exception, display that exception to stderr, decrement that exception,...
int main(int argc, char *argv[])
main entry point; parse command line arguments, initialise the environment, and enter the read-eval-p...
void maybe_bind_init_symbols()
void print_options(FILE *stream)
Print command line options to this stream.
struct cons_pointer bind_special(wchar_t *name, struct cons_pointer(*executable)(struct stack_frame *, struct cons_pointer, struct cons_pointer))
Bind this compiled executable function, as a Lisp special form, to this name in the oblist.
struct cons_pointer bind_function(wchar_t *name, struct cons_pointer(*executable)(struct stack_frame *, struct cons_pointer, struct cons_pointer))
Bind this compiled executable function, as a Lisp function, to this name in the oblist.
struct cons_pointer init_name_symbol
struct cons_pointer init_primitive_symbol
struct cons_pointer bind_symbol_value(struct cons_pointer symbol, struct cons_pointer value, bool lock)
Bind this value to this symbol in the oblist.
struct cons_pointer bind_value(wchar_t *name, struct cons_pointer value, bool lock)
Bind this value to this name in the oblist.
struct cons_pointer privileged_symbol_nil
the symbol NIL, which is special!
struct cons_pointer make_hashmap(uint32_t n_buckets, struct cons_pointer hash_fn, struct cons_pointer write_acl)
Make a hashmap with this number of buckets, using this hash_fn.
struct cons_pointer oblist
The global object list/or, to put it differently, the root namespace.
struct cons_pointer deep_bind(struct cons_pointer key, struct cons_pointer value)
Binds this key to this value in the global oblist.
int io_init()
Initialise the I/O subsystem.
struct cons_pointer lisp_io_in
bound to the Lisp string representing C_IO_IN in initialisation.
struct cons_pointer lisp_open(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return a stream open on the URL indicated by the first argument; if a second argument is pr...
struct cons_pointer lisp_io_out
bound to the Lisp string representing C_IO_OUT in initialisation.
struct cons_pointer lisp_slurp(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return a string representing all characters from the stream indicated by arg 0; further arg...
URL_FILE * file_to_url_file(FILE *f)
given this file handle f, return a new url_file handle wrapping it.
struct cons_pointer lisp_close(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function, sort-of: close the file indicated by my first arg, and return nil.
struct cons_pointer lisp_read_char(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return the next character from the stream indicated by arg 0; further arguments are ignored...
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_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_source(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function.
struct cons_pointer lisp_mapcar(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
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_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_exception(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; create an exception.
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_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_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_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...
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...
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...
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.
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 v...
struct cons_pointer lisp_keys(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
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_repl(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: the read/eval/print loop.
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,...
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_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 ...
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...
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_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_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_list(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
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_cond(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Special form: conditional.
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 prompt_name
the name of the symbol to which the prompt is bound;
struct cons_pointer lisp_absolute(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: calculate the absolute value of a number.
struct cons_pointer lisp_ratio_to_real(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return a real (approcimately) equal in value to the ratio which is the first argument.
struct cons_pointer lisp_is_negative(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: is this number negative?
struct cons_pointer lisp_subtract(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Subtract one number from another.
struct cons_pointer lisp_divide(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Divide one number by another.
struct cons_pointer lisp_multiply(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Multiply an indefinite number of numbers together.
struct cons_pointer lisp_add(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Add an indefinite number of numbers together.
struct cons_pointer print(URL_FILE *output, struct cons_pointer pointer)
Print the cons-space object indicated by pointer to the stream indicated by output.
struct cons_pointer lisp_time(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function; return a time representation of the first argument in the frame; further arguments are igno...
void repl()
The read/eval/print loop.