summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--lisp.c1
-rw-r--r--lisp.h45
-rw-r--r--lisp.y1
-rw-r--r--lisp_api.h52
-rw-r--r--main.c1
-rw-r--r--test.c1
7 files changed, 57 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index a04723e..6feb95e 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ OBJS = lisp.o lisp.tab.o lex.yy.o
main: main.c $(OBJS)
$(CC) $(CFLAGS) -o $@ main.c $(OBJS) $(LIBS)
-lisp.o: lisp.c lisp.h lex.yy.o
+lisp.o: lisp.c lisp_api.h lisp.h lex.yy.o
$(CC) $(CFLAGS) -c lisp.c
lisp.tab.c lisp.tab.h: lisp.y
diff --git a/lisp.c b/lisp.c
index 4e143f1..d5f9600 100644
--- a/lisp.c
+++ b/lisp.c
@@ -3,6 +3,7 @@
#include <readline/readline.h>
#include <readline/history.h>
#include <math.h>
+#include "lisp_api.h"
#include "lisp.h"
#include "lex.yy.h"
#include "lisp.tab.h"
diff --git a/lisp.h b/lisp.h
index a422c9b..a972ecc 100644
--- a/lisp.h
+++ b/lisp.h
@@ -4,51 +4,6 @@
typedef struct value value;
typedef struct env env;
-typedef enum {
- VT_INT,
- VT_DOUBLE,
- VT_SYMBOL,
- VT_STRING,
- VT_NIL,
- VT_PAIR,
- VT_LAMBDA,
- VT_BUILTIN
-} val_type;
-
-struct value {
- val_type type;
- union {
- int i;
- double d;
- const char *sym;
- const char *str;
- struct {
- value *car;
- value *cdr;
- } pair;
- struct {
- value *params;
- value *body;
- env *env;
- } lambda;
- struct {
- value *(*fn) (env *, value *);
- } builtin;
- } as;
-};
-
-value *make_int(int i);
-value *make_double(double d);
-value *make_symbol(const char *sym);
-value *make_string(const char *str);
-value *make_nil();
-value *make_lambda(env *e, value *params, value *body);
-value *make_builtin(value *(*fn) (env *, value *));
-value *cons(value *car, value *cdr);
-value *car(value *cons);
-value *cdr(value *cons);
-value *reverse(value *list);
-
void print_value(value *val);
void println_value(value *val);
// environments, TODO: make this use hashtable
diff --git a/lisp.y b/lisp.y
index a4ed142..ec246f3 100644
--- a/lisp.y
+++ b/lisp.y
@@ -1,6 +1,7 @@
%{
#include <stdio.h>
#include <stdlib.h>
+#include "lisp_api.h"
#include "lisp.h"
int yylex(void);
diff --git a/lisp_api.h b/lisp_api.h
new file mode 100644
index 0000000..70d317b
--- /dev/null
+++ b/lisp_api.h
@@ -0,0 +1,52 @@
+#ifndef LISP_API_H
+#define LISP_API_H
+
+typedef struct value value;
+typedef struct env env;
+
+typedef enum {
+ VT_INT,
+ VT_DOUBLE,
+ VT_SYMBOL,
+ VT_STRING,
+ VT_NIL,
+ VT_PAIR,
+ VT_LAMBDA,
+ VT_BUILTIN
+} val_type;
+
+struct value {
+ val_type type;
+ union {
+ int i;
+ double d;
+ const char *sym;
+ const char *str;
+ struct {
+ value *car;
+ value *cdr;
+ } pair;
+ struct {
+ value *params;
+ value *body;
+ env *env;
+ } lambda;
+ struct {
+ value *(*fn) (env *, value *);
+ } builtin;
+ } as;
+};
+
+value *make_int(int i);
+value *make_double(double d);
+value *make_symbol(const char *sym);
+value *make_string(const char *str);
+value *make_nil();
+value *make_lambda(env *e, value *params, value *body);
+value *make_builtin(value *(*fn) (env *, value *));
+value *cons(value *car, value *cdr);
+value *car(value *cons);
+value *cdr(value *cons);
+value *reverse(value *list);
+
+#endif
diff --git a/main.c b/main.c
index b675dfa..73adf2d 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@
#include <signal.h>
#include <readline/readline.h>
#include <readline/history.h>
+#include "lisp_api.h"
#include "lisp.h"
#include "lex.yy.h"
#include "lisp.tab.h"
diff --git a/test.c b/test.c
index 95cce3f..5bc1ff4 100644
--- a/test.c
+++ b/test.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "lisp_api.h"
#include "lisp.h"
#include "lex.yy.h"
#include "lisp.tab.h"