1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

gpgscm: Keep a history of calls for error messages.

* tests/gpgscm/init.scm (vm-history-print): New function.
* tests/gpgscm/opdefines.h: New opcodes 'CALLSTACK_POP', 'APPLY_CODE',
and 'VM_HISTORY'.
* tests/gpgscm/scheme-private.h (struct history): New definition.
(struct scheme): New field 'history'.
* tests/gpgscm/scheme.c (gc): Mark objects in the history.
(history_free): New function.
(history_init): Likewise.
(history_mark): Likewise.
(add_mod): New macro.
(sub_mod): Likewise.
(tailstack_clear): New function.
(callstack_pop): Likewise.
(callstack_push): Likewise.
(tailstack_push): Likewise.
(tailstack_flatten): Likewise.
(callstack_flatten): Likewise.
(history_flatten): Likewise.
(opexe_0): New variable 'callsite', keep track of the expression if it
is a call, implement the new opcodes, record function applications in
the history.
(opexe_6): Implement new opcode.
(scheme_init_custom_alloc): Initialize history.
(scheme_deinit): Free history.
* tests/gpgscm/scheme.h (USE_HISTORY): New macro.
--

This patch makes TinySCHEME keep a history of function calls.  This
history can be used to produce helpful error messages.  The history
data structure is inspired by MIT/GNU Scheme.

Signed-off-by: Justus Winter <justus@g10code.com>

fu history
This commit is contained in:
Justus Winter 2016-11-18 10:58:18 +01:00
parent 01256694f0
commit 404e8a4136
5 changed files with 339 additions and 4 deletions

View file

@ -534,6 +534,28 @@
`(define ,(cadr form)
(call/cc (lambda (return) ,@(cddr form)))))
;; Print the given history.
(define (vm-history-print history)
(let loop ((n 0) (skip 0) (frames history))
(cond
((null? frames)
#t)
((> skip 0)
(loop 0 (- skip 1) (cdr frames)))
(else
(let ((f (car frames)))
(display n)
(display ": ")
(let ((tag (get-tag f)))
(unless (null? tag)
(display (basename (car tag)))
(display ":")
(display (+ 1 (cdr tag)))
(display ": ")))
(write f))
(newline)
(loop (+ n 1) skip (cdr frames))))))
;;;; Simple exception handling
;
; Exceptions are caught as follows: