From 78afa275c70909f06854f50b490e9c016d81934c Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 14 Jan 2024 15:27:10 -0800 Subject: [PATCH] Merge into a single file --- makefile | 3 +- src/{main.c => lispkit.c} | 83 ++++++++++----------------------------- 2 files changed, 23 insertions(+), 63 deletions(-) rename src/{main.c => lispkit.c} (94%) diff --git a/makefile b/makefile index 267d6b0..cd1d01e 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/src/main.c b/src/lispkit.c similarity index 94% rename from src/main.c rename to src/lispkit.c index 8650e41..ba99e32 100644 --- a/src/main.c +++ b/src/lispkit.c @@ -1,16 +1,11 @@ -#include -#include #include #include #include -#include #include -#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[]) { -- 2.45.2