Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
read.c File Reference
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
#include "memory/consspaceobject.h"
#include "debug.h"
#include "memory/dump.h"
#include "memory/hashmap.h"
#include "arith/integer.h"
#include "ops/intern.h"
#include "io/io.h"
#include "ops/lispops.h"
#include "arith/peano.h"
#include "io/print.h"
#include "arith/ratio.h"
#include "io/read.h"
#include "arith/real.h"
#include "memory/vectorspace.h"
Include dependency graph for read.c:

Go to the source code of this file.

Functions

struct cons_pointer c_quote (struct cons_pointer arg)
 quote reader macro in C (!)
 
struct cons_pointer read (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env, URL_FILE *input)
 Read the next object on this input stream and return a cons_pointer to it.
 
struct cons_pointer read_continuation (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env, URL_FILE *input, wint_t initial)
 Read the next object on this input stream and return a cons_pointer to it, treating this initial character as the first character of the object representation.
 
struct cons_pointer read_list (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env, URL_FILE *input, wint_t initial)
 Read a list from this input stream, which no longer contains the opening left parenthesis.
 
struct cons_pointer read_map (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env, URL_FILE *input, wint_t initial)
 
struct cons_pointer read_number (struct stack_frame *frame, struct cons_pointer frame_pointer, URL_FILE *input, wint_t initial, bool seen_period)
 read a number from this input stream, given this initial character.
 
struct cons_pointer read_path (URL_FILE *input, wint_t initial, struct cons_pointer q)
 Read a path macro from the stream.
 
struct cons_pointer read_string (URL_FILE *input, wint_t initial)
 Read a string.
 
struct cons_pointer read_symbol_or_key (URL_FILE *input, uint32_t tag, wint_t initial)
 

Function Documentation

◆ c_quote()

struct cons_pointer c_quote ( struct cons_pointer  arg)

quote reader macro in C (!)

Definition at line 74 of file read.c.

References c_string_to_lisp_symbol(), make_cons(), and NIL.

Referenced by read_continuation().

◆ read()

struct cons_pointer read ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env,
URL_FILE input 
)

Read the next object on this input stream and return a cons_pointer to it.

read the next object on this input stream and return a cons_pointer to it.

Definition at line 559 of file read.c.

References read_continuation(), and url_fgetwc().

Referenced by lisp_read().

◆ read_continuation()

struct cons_pointer read_continuation ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env,
URL_FILE input,
wint_t  initial 
)

Read the next object on this input stream and return a cons_pointer to it, treating this initial character as the first character of the object representation.

Definition at line 155 of file read.c.

References c_quote(), c_string_to_lisp_string(), debug_dump_object(), DEBUG_IO, debug_print(), KEYTV, LSESSION, make_cons(), make_string(), make_symbol_or_key(), NIL, nilp, read_continuation(), read_list(), read_map(), read_number(), read_path(), read_string(), read_symbol_or_key(), SYMBOLTV, throw_exception(), url_feof(), url_fgetwc(), and url_ungetwc().

Referenced by read(), read_continuation(), read_list(), and read_map().

◆ read_list()

struct cons_pointer read_list ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env,
URL_FILE input,
wint_t  initial 
)

Read a list from this input stream, which no longer contains the opening left parenthesis.

Definition at line 401 of file read.c.

References c_car(), DEBUG_IO, debug_print(), debug_printf(), LPERIOD, make_cons(), NIL, read_continuation(), read_list(), and url_fgetwc().

Referenced by read_continuation(), and read_list().

◆ read_map()

struct cons_pointer read_map ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env,
URL_FILE input,
wint_t  initial 
)

◆ read_number()

struct cons_pointer read_number ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
URL_FILE input,
wint_t  initial,
bool  seen_period 
)

read a number from this input stream, given this initial character.

Todo:
Need to do a lot of inc_ref and dec_ref, to make sure the garbage is collected.

Definition at line 288 of file read.c.

References acquire_integer(), add_integers(), c_string_to_lisp_string(), debug_dump_object(), DEBUG_IO, debug_print(), debug_print_object(), debug_printf(), dec_ref(), inc_ref(), integerp, LCOMMA, LPERIOD, LSLASH, make_ratio(), make_real(), multiply_integers(), negative(), NIL, nilp, throw_exception(), to_long_double(), url_fgetwc(), and url_ungetwc().

Referenced by read_continuation().

◆ read_path()

struct cons_pointer read_path ( URL_FILE input,
wint_t  initial,
struct cons_pointer  q 
)

Read a path macro from the stream.

A path macro is expected to be

  1. optionally a leading character such as '/' or '$', followed by
  2. one or more keywords with leading colons (':') but no intervening spaces; or
  3. one or more symbols separated by slashes; or
  4. keywords (with leading colons) interspersed with symbols (prefixed by slashes).

Definition at line 86 of file read.c.

References c_car(), c_cdr(), c_string_to_lisp_symbol(), dec_ref(), KEYTV, LSESSION, make_cons(), NIL, nilp, read_symbol_or_key(), SYMBOLTV, url_feof(), url_fgetwc(), and url_ungetwc().

Referenced by read_continuation().

◆ read_string()

struct cons_pointer read_string ( URL_FILE input,
wint_t  initial 
)

Read a string.

This means either a string delimited by double quotes (is_quoted == true), in which case it may contain whitespace but may not contain a double quote character (unless escaped), or one not so delimited in which case it may not contain whitespace (unless escaped) but may contain a double quote character (probably not a good idea!)

Definition at line 484 of file read.c.

References make_string(), NIL, read_string(), and url_fgetwc().

Referenced by read_continuation(), and read_string().

◆ read_symbol_or_key()

struct cons_pointer read_symbol_or_key ( URL_FILE input,
uint32_t  tag,
wint_t  initial 
)