move error.c to main.c

This commit is contained in:
yoyo 2024-09-08 17:27:39 +09:00
parent cf54be4c78
commit 184aab3420
3 changed files with 29 additions and 36 deletions

31
error.c
View File

@ -1,31 +0,0 @@
#include "dat.h"
#include "fn.h"
#include <stdlib.h>
#include <stdarg.h>
#include <setjmp.h>
void
panic(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
void
error(char *fmt, ...)
{
extern jmp_buf *errptr;
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "ERROR => ");
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
longjmp(*errptr, 1);
exit(1);
}

33
main.c
View File

@ -1,10 +1,37 @@
#include "dat.h" #include "dat.h"
#include "fn.h" #include "fn.h"
#include <setjmp.h> #include <setjmp.h>
#include <stdarg.h>
#include <stdlib.h>
jmp_buf *errptr; jmp_buf err;
GC *gc; GC *gc;
void
panic(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
void
error(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "ERROR => ");
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
longjmp(err, 1);
exit(1);
}
static void static void
SExprint(Object *obj) SExprint(Object *obj)
{ {
@ -64,9 +91,7 @@ printexpr(Object *obj)
static void static void
loop(Object *env, FILE *f) loop(Object *env, FILE *f)
{ {
jmp_buf buf; if(setjmp(err) == 1){
errptr = &buf;
if(setjmp(buf) == 1){
if(feof(f)) if(feof(f))
return; return;
skipline(f); skipline(f);

View File

@ -1,7 +1,6 @@
NAME=lisp NAME=lisp
OFILES=\ OFILES=\
bltin.o\ bltin.o\
error.o\
eval.o\ eval.o\
main.o\ main.o\
gc.o\ gc.o\