@@ 1,7 1,7 @@
RELEASE_flags=-Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas
DEBUG_flags=-DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined
TARG=-std=c99
-SRC=src/lispkit.c src/main.c
+SRC=src/lispkit.c
.PHONY: all clean run test format archive
@@ 33,6 33,7 @@ format:
archive:
@ cp utils/lispkit.secd ../oscean/etc/lispkit.secd.txt
@ cp utils/lispkit.lisp ../oscean/etc/lispkit.lisp.txt
+ @ cp src/lispkit.c ../oscean/etc/lispkit.c.txt
all: bin/lispkit bin/compiler.secd
@@ 1,16 1,11 @@
-#include <ctype.h>
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
#include <unistd.h>
-#include "lispkit.h"
-
/*
Copyright (c) 2011 A. Carl Douglas
-Copyright (c) 2023 Devine Lu Linvega
+Copyright (c) 2024 Devine Lu Linvega
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ 42,45 37,18 @@ struct GCHeader {
int size, type, marked, id;
};
-/* gc */
-void gc_init();
-Object *gc_alloc();
-void gc_collect_garbage();
-void gc_collect();
-void gc_mark();
-void gc_exit();
-void gc_stats();
-
-#define gc_header(o) ((struct GCHeader *)o - 1)
-
-/* secd */
-extern Object *_rS, *_rE, *_rC, *_rD;
-extern Object *_t, *_f, *_nil;
-void secd_init();
-Object *secd_eval(Object *fn, Object *args);
-
-/* core */
-void crash(char *err, const char *value, const char *id);
-void crashnum(char *err, int id);
-
-/* dict */
-void dict_init(void);
-
-/* special opcodes */
-Object *implode(Object *obj);
-Object *explode(Object *obj);
-void device_write(Object *obj);
-
-/* misc */
+Object *_rS, *_rE, *_rC, *_rD;
+Object *_t, *_f, *_nil;
Object *cons(Object *, Object *);
Object *car(Object *);
Object *cdr(Object *);
Object *newnum(int);
Object *newsym(const char *);
-int isequ(Object *a, Object *b);
-int getnum(Object *);
-const char *getstr(int);
+void gc_collect_garbage();
+
+#define ciws(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r')
+#define gc_header(o) ((struct GCHeader *)o - 1)
#define gettype(o) gc_header(o)->type
#define isnum(o) (gettype(o) == NUMBER)
#define issym(o) (gettype(o) == SYMBOL)
@@ 89,6 57,19 @@ const char *getstr(int);
#define istrue(o) (o->sym != _f->sym)
#define isnull(o) (o == _nil)
+void
+crash(char *err, const char *value, const char *id)
+{
+ fprintf(stderr, err, value, id);
+ exit(-1);
+}
+
+void
+crashnum(char *err, int id)
+{
+ fprintf(stderr, err, id);
+ exit(-1);
+}
/* - GC -------------------------------------- */
@@ 99,8 80,7 @@ unsigned collect_counter;
unsigned num_cells;
void *mem;
-Object **cells;
-Object *ff;
+Object **cells, *ff;
void
gc_mark(Object *object)
@@ 206,23 186,6 @@ gc_stats()
#define DICTLEN 0x8000
static char dict_buf[DICTLEN], *dict_end;
-
-void
-crash(char *err, const char *value, const char *id)
-{
- fprintf(stderr, err, value, id);
- exit(-1);
-}
-
-void
-crashnum(char *err, int id)
-{
- fprintf(stderr, err, id);
- exit(-1);
-}
-
-/* print */
-
static int needws;
static void
@@ 604,8 567,6 @@ enum {
Object *get_exp(FILE *fp);
Object *get_exp_list(FILE *fp);
-#define ciws(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r')
-
#define BUFLEN 80
static char buffer[BUFLEN];
@@ 771,8 732,6 @@ get_exp_list(FILE *fp)
return s_exp_list();
}
-/* - MAIN ------------------------------------ */
-
int
main(int argc, char *argv[])
{