Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
repl.c
Go to the documentation of this file.
1/*
2 * repl.c
3 *
4 * the read/eval/print loop
5 *
6 * (c) 2017 Simon Brooke <simon@journeyman.cc>
7 * Licensed under GPL version 2.0, or, at your option, any later version.
8 */
9
10#include <stdbool.h>
11#include <stdio.h>
12#include <wchar.h>
13#include <signal.h>
14
16#include "debug.h"
17#include "ops/intern.h"
18#include "ops/lispops.h"
19#include "memory/stack.h"
20
21/**
22 * @brief Handle an interrupt signal.
23 *
24 * @param dummy
25 */
26void int_handler( int dummy ) {
27 wprintf( L"TODO: handle ctrl-C in a more interesting way\n" );
28}
29
30/**
31 * The read/eval/print loop.
32 */
33void repl( ) {
34 signal( SIGINT, int_handler );
35 debug_print( L"Entered repl\n", DEBUG_REPL );
36
37 struct cons_pointer env =
39
40 /* bottom of stack */
41 struct cons_pointer frame_pointer = make_stack_frame( NIL, NIL, env );
42
43 if ( !nilp( frame_pointer ) ) {
44 lisp_repl( get_stack_frame( frame_pointer ), frame_pointer, env );
45
46 dec_ref( frame_pointer );
47 }
48
49 debug_print( L"Leaving repl\n", DEBUG_REPL );
50}
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 NIL
a cons pointer which points to the special NIL cell
#define consp(conspoint)
true if conspoint points to a cons cell, else false
#define nilp(conspoint)
true if conspoint points to the special cell NIL, else false (there should only be one of these so it...
An indirect pointer to a cons cell.
void debug_print(wchar_t *message, int level)
print this debug message to stderr, if verbosity matches level.
Definition debug.c:41
#define DEBUG_REPL
Print messages debugging the read eval print loop.
Definition debug.h:70
struct cons_pointer oblist
The global object list/or, to put it differently, the root namespace.
Definition intern.c:48
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
void repl()
The read/eval/print loop.
Definition repl.c:33
void int_handler(int dummy)
Handle an interrupt signal.
Definition repl.c:26
struct stack_frame * get_stack_frame(struct cons_pointer pointer)
get the actual stackframe object from this pointer, or NULL if pointer is not a stackframe pointer.
Definition stack.c:53
struct cons_pointer make_stack_frame(struct cons_pointer previous, struct cons_pointer args, struct cons_pointer env)
Allocate a new stack frame with its previous pointer set to this value, its arguments set up from the...
Definition stack.c:116