From 2d8c6ed5f35ea2ed5f5d706ff100e1563e990b25 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 13 Jul 2015 21:46:21 -0400 Subject: [PATCH] Added basic call history reporting --- TODO | 13 ------------- runtime.c | 8 +++++--- test2.scm | 8 ++++++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/TODO b/TODO index 9c9aaae5..5de28edb 100644 --- a/TODO +++ b/TODO @@ -13,19 +13,6 @@ Working TODO list: - self-hosting, there are a lot of accumulated TODO's that need to be addressed - improved error handling: - (1) - code traces - could pass filename and define name (if applicable) to c-compile-exp, - and record it for each lambda. could then add code to each lambda to - write that info to a circular buffer when the function is called. - that would enable a primitive stack trace to be maintained at runtime. - - ideally use an array of (char *) and a pointer incremented like (i = (i + 1) % size) - to treat it as a circular buffer - - as a starting point, could encode lambda name and filename and get the - circular buffer and runtime reporting working. then come back and add - Scheme function names. - - type checking ideally want to do this in a way that minimized performance impacts. will probaby require extensive checks within apply() though, since that diff --git a/runtime.c b/runtime.c index 0bd1e6b7..d162c7bb 100644 --- a/runtime.c +++ b/runtime.c @@ -80,9 +80,11 @@ void Cyc_st_init() { } void Cyc_st_add(char *frame) { - // TODO: do not add if (idx - 1) == frame, since that causes recursion to remove older frames - Cyc_Stack_Traces[Cyc_Stack_Trace_Idx] = frame; - Cyc_Stack_Trace_Idx = (Cyc_Stack_Trace_Idx + 1) % MAX_STACK_TRACES; + // Do not allow recursion to remove older frames + if (frame != Cyc_Stack_Traces[(Cyc_Stack_Trace_Idx - 1) % MAX_STACK_TRACES]) { + Cyc_Stack_Traces[Cyc_Stack_Trace_Idx] = frame; + Cyc_Stack_Trace_Idx = (Cyc_Stack_Trace_Idx + 1) % MAX_STACK_TRACES; + } } void Cyc_st_print(FILE *out) { diff --git a/test2.scm b/test2.scm index 8b35f804..183dfb6f 100644 --- a/test2.scm +++ b/test2.scm @@ -2,10 +2,14 @@ (scheme file) (scheme write)) +(map + (lambda (_) (set! x 1) -(write x) -(write 'Cyc_procedure) +;(write x) +;(write 'Cyc_procedure) (open-input-file "1.scm") +) +(list 1)) ;;; TODO: C macros for funcall1, etc are not being generated even though entries are set ;;; in the vector. must be another problem inspecting the vector ??? ;(write 'hello)