blob: 016f8e59452c9b31acbb3a93d6b27924a81f6aab [file] [log] [blame]
swissChili7a6f5eb2021-04-13 16:46:02 -07001#pragma once
2
3#include <stdbool.h>
4
5extern unsigned int cons_magic;
6
7enum type
8{
9 T_INT = 0,
10 T_FLOAT,
11 T_NIL,
12 T_SYMBOL,
13 T_STRING,
14 T_VECTOR,
15 T_CLASS,
16 T_CONS,
17};
18
19struct tag
20{
21 unsigned int type : 3;
22 unsigned int length : 29;
23} __attribute__ ((packed));
24
25struct cons;
26
27union value_type {
28 int int_val;
29 float float_val;
30 struct cons *cons_val;
31 char *symbol_val; // interned
32 char *string_val;
33};
34
35struct value
36{
37 struct tag tag;
38 union value_type value;
39} __attribute__ ((packed));
40
41struct cons
42{
43 int magic;
44 int marked; // must be reserved
45 struct value car, cdr;
46};
47
48struct alloc_list
49{
50 int type;
51 union value_type data;
52 struct alloc_list *next, *prev;
53};
54
55struct istream
56{
57 void *data;
58
59 // These two return -1 on error
60 int (*peek) (struct istream *s);
61 int (*get) (struct istream *s);
62
63 int (*read) (struct istream *s, char *buffer, int size);
64};
65
66bool startswith (struct istream *s, const char *pattern);
67
68bool readsym (struct istream *is, struct value *val);
69bool readstr (struct istream *is, struct value *val);
70
71struct value cons (struct value car, struct value cdr);
72bool read1 (struct istream *is, struct value *val);
73struct value read (struct istream);
74struct value readn (struct istream);
75
76void printval (struct value v, int depth);
77
78struct istream *new_stristream (char *str, int length);
79// same as above but null terminated
80struct istream *new_stristream_nt (char *str);
81void del_stristream(struct istream *stristream);