3 Commits 9e4ea8a0f6 ... 3c91d41bb7

Auteur SHA1 Message Date
  rain1 3c91d41bb7 0 il y a 7 ans
  rain1 2f30301694 stack trace when crashing inside car/cdr il y a 7 ans
  rain1 77f112ab4e error instead of crashing for invalid or missing TAROTPATH il y a 7 ans
7 fichiers modifiés avec 34 ajouts et 2 suppressions
  1. 2 0
      .gitignore
  2. 2 0
      compiler/app/debug-build.scm
  3. 3 0
      compiler/compiler.scm
  4. 13 0
      compiler/mac/macros.scm
  5. 1 1
      vm/Makefile
  6. 2 0
      vm/builtins.c
  7. 11 1
      vm/main.c

+ 2 - 0
.gitignore

@@ -1 +1,3 @@
 *~
+*.o
+vm/vm

+ 2 - 0
compiler/app/debug-build.scm

@@ -0,0 +1,2 @@
+(load-macros)
+(debug-build-file (car argv))

+ 3 - 0
compiler/compiler.scm

@@ -109,3 +109,6 @@
 
 (define (compile-and-run-file filename)
   (for-each eval `((include ,filename))))
+
+(define (debug-build-file filename)
+  (compile `(include ,filename) #t #f '(halt)))

+ 13 - 0
compiler/mac/macros.scm

@@ -149,3 +149,16 @@
 	  (args (cdddr exp))
 	  (x (gensym "x")))
       `(map (lambda (,x) (,f ,x . ,args)) ,xs))))
+
+
+;;; ADDED
+
+(defmacro inc!
+ (lambda (form)
+  (let ((x (cadr form)))
+     `(set-box! ,x (+ (unbox ,x) 1)))))
+
+(defmacro dec!
+ (lambda (form)
+  (let ((x (cadr form)))
+     `(set-box! ,x (- (unbox ,x) 1)))))

+ 1 - 1
vm/Makefile

@@ -1,5 +1,5 @@
 CC=gcc
-CFLAGS+=-O3 -std=c99 -Wall -Werror -Wno-unused-but-set-variable -D_GNU_SOURCE -falign-functions=8
+CFLAGS+=-g -std=c99 -Wall -Werror -Wno-unused-but-set-variable -D_GNU_SOURCE -falign-functions=8
 
 SOURCES=read_word.c vm.c \
  allocator.c gc.c symboltable.c builtins.c ports.c\

+ 2 - 0
vm/builtins.c

@@ -30,12 +30,14 @@ scm bltn_cons(void) {
 scm bltn_car(void) {
 	scm a = stack[reg_rbp + 1];
 
+	info_assert(scm_gettag(a) == TAG_CONS);
 	return get_cons_car(a);
 }
 
 scm bltn_cdr(void) {
 	scm a = stack[reg_rbp + 1];
 
+	info_assert(scm_gettag(a) == TAG_CONS);
 	return get_cons_cdr(a);
 }
 

+ 11 - 1
vm/main.c

@@ -20,6 +20,7 @@ void load_and_exec(char *filename);
 void load_qcode_dir();
 
 void stack_and_quit() {
+	puts("SIGSEGV");
 	stack_trace();
 	exit(1);
 }
@@ -32,7 +33,7 @@ int main(int argc, char **argv) {
 
 	int i = 0;
 	
-	signal(SIGSEGV, stack_and_quit);
+	//signal(SIGSEGV, stack_and_quit);
 
 	/// SETUP ARGV
 	reg_acc = ATOM_NUL;
@@ -82,10 +83,19 @@ void load_qcode_dir(char *p)
 	char buf2[256] = { 0 };
 	DIR *dir;
 	struct dirent *ent;
+
+	if(!getenv("TAROTPATH")) {
+		puts("Please set TAROTPATH.");
+		exit(2);
+	}
 	
 	strcat(buf, getenv("TAROTPATH"));
 	strcat(buf, p);
 	dir = opendir(buf);
+	if(!dir) {
+		printf("Could not open qcode directory <%s%s>. Check TAROTPATH.\n", getenv("TAROTPATH"), p);
+		exit(2);
+	}
 	while((ent = readdir(dir))) {
 		if(ent->d_type == DT_REG) {
 		        strcpy(buf2, buf);