add error.c file

This commit is contained in:
Yuichi Nishiwaki 2013-10-20 17:26:18 +09:00
parent 444fc7c750
commit 12e2f10869
3 changed files with 28 additions and 27 deletions

View File

@ -6,7 +6,7 @@ build:
cd src; \ cd src; \
yacc -d parse.y; \ yacc -d parse.y; \
lex scan.l lex scan.l
$(CC) -Wall -o bin/picrin -I./include -lreadline src/main.c src/state.c src/gc.c src/pair.c src/port.c src/symbol.c src/value.c src/y.tab.c src/lex.yy.c src/bool.c src/vm.c src/init.c src/number.c src/time.c src/codegen.c $(CC) -Wall -o bin/picrin -I./include -lreadline src/main.c src/state.c src/gc.c src/pair.c src/port.c src/symbol.c src/value.c src/y.tab.c src/lex.yy.c src/bool.c src/vm.c src/init.c src/number.c src/time.c src/codegen.c src/error.c
clean: clean:
rm -f src/y.tab.c src/y.tab.h src/lex.yy.c rm -f src/y.tab.c src/y.tab.h src/lex.yy.c

11
src/error.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
#include "picrin.h"
void
pic_raise(pic_state *pic, const char *str)
{
puts(str);
abort();
}

View File

@ -1,4 +1,3 @@
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
@ -64,7 +63,6 @@ pic_value
pic_run(pic_state *pic, struct pic_proc *proc, pic_value args) pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
{ {
struct pic_code *pc; struct pic_code *pc;
pic_value val;
int ai = pic_gc_arena_preserve(pic); int ai = pic_gc_arena_preserve(pic);
#if PIC_DIRECT_THREADED_VM #if PIC_DIRECT_THREADED_VM
@ -232,33 +230,25 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
NEXT; NEXT;
} }
CASE(OP_STOP) { CASE(OP_STOP) {
goto STOP; pic_value val;
}
} VM_LOOP_END;
STOP: val = POP();
val = POP();
#if VM_DEBUG #if VM_DEBUG
puts("**VM END STATE**"); puts("**VM END STATE**");
printf("stbase = %p\nsp = %p\n", pic->stbase, pic->sp); printf("stbase = %p\nsp = %p\n", pic->stbase, pic->sp);
printf("cibase = %p\nci = %p\n", pic->cibase, pic->ci); printf("cibase = %p\nci = %p\n", pic->cibase, pic->ci);
if (pic->stbase != pic->sp) { if (pic->stbase != pic->sp) {
pic_value *sp; pic_value *sp;
printf("* stack trace:"); printf("* stack trace:");
for (sp = pic->stbase; pic->sp != sp; ++sp) { for (sp = pic->stbase; pic->sp != sp; ++sp) {
pic_debug(pic, *sp); pic_debug(pic, *sp);
puts(""); puts("");
} }
} }
#endif #endif
return val; return val;
} }
} VM_LOOP_END;
void
pic_raise(pic_state *pic, const char *str)
{
puts(str);
abort();
} }