diff options
author | Andy Wingo <wingo@pobox.com> | 2009-02-10 11:53:23 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-02-10 11:53:23 +0100 |
commit | 028e3d06665d4eb50b5d0f0d0101acc039c2ae68 (patch) | |
tree | e101393d98ca1fc67b724822bf0fb2e0d531aaf9 /libguile/programs.c | |
parent | dae318a63140ac7b1f396440bc341fea901be9b9 (diff) | |
download | guile-028e3d06665d4eb50b5d0f0d0101acc039c2ae68.tar.gz |
propagate much more source info through compilation
* module/language/ghil/compile-glil.scm (codegen): Record source location
for offset 0 into a lambda, if we can.
* module/language/scheme/compile-ghil.scm (translate-1)
(define-scheme-translator): In the retrans procedures, propagate the
location information from the enclosing expression if the subexpression
has no location information. Gives source information to many more
expressions.
(location): Just propagate the source properties as they are, the
glil->assembly compiler will interpret them.
* module/language/glil.scm (<glil>): Change glil-source to take "props"
and not "loc", as it's the source properties that we're interested in.
* module/language/glil/compile-assembly.scm (limn-sources): New function,
takes a list of addr-source property pairs and "compresses" them for
serialization to disk.
(glil->assembly): Limn the sources before writing them to disk. Avoid
non-tail recursion when determining total byte length of code.
* module/system/vm/program.scm (source:file, source:line, source:column):
Update for new source representation.
(program-source): Export.
(write-program): Nicer pretty-printing of anonymous procedures.
* libguile/backtrace.c (display_backtrace_get_file_line): Update for the
new VM source representation.
* libguile/programs.h:
* libguile/programs.c (scm_program_sources): Update for the new
serialized source representation, where the filename is not in the
stream unless it changes.
(scm_program_source): New exported function, looks up the source for a
given ip offset.
(scm_c_program_source): Update to return the last source information
that was <= the given IP, because we only serialize source info when it
changes.
Diffstat (limited to 'libguile/programs.c')
-rw-r--r-- | libguile/programs.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/libguile/programs.c b/libguile/programs.c index b4d43bf6e..1c42e15d6 100644 --- a/libguile/programs.c +++ b/libguile/programs.c @@ -49,6 +49,7 @@ #include "modules.h" #include "programs.h" #include "procprop.h" // scm_sym_name +#include "srcprop.h" // scm_sym_filename #include "vm.h" @@ -219,7 +220,7 @@ SCM_DEFINE (scm_program_sources, "program-sources", 1, 0, 0, "") #define FUNC_NAME s_scm_program_sources { - SCM meta; + SCM meta, sources, ret, filename; SCM_VALIDATE_PROGRAM (1, program); @@ -227,7 +228,25 @@ SCM_DEFINE (scm_program_sources, "program-sources", 1, 0, 0, if (scm_is_false (meta)) return SCM_EOL; - return scm_cadr (scm_call_0 (meta)); + filename = SCM_BOOL_F; + ret = SCM_EOL; + for (sources = scm_cadr (scm_call_0 (meta)); !scm_is_null (sources); + sources = scm_cdr (sources)) + { + SCM x = scm_car (sources); + if (scm_is_pair (x)) + { + if (scm_is_number (scm_car (x))) + { + SCM addr = scm_car (x); + ret = scm_acons (addr, scm_cons (filename, scm_cdr (x)), + ret); + } + else if (scm_is_eq (scm_car (x), scm_sym_filename)) + filename = scm_cdr (x); + } + } + return scm_reverse_x (ret, SCM_UNDEFINED); } #undef FUNC_NAME @@ -258,17 +277,28 @@ SCM_DEFINE (scm_program_name, "program-name", 1, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_program_source, "program-source", 2, 0, 0, + (SCM program, SCM ip), + "") +#define FUNC_NAME s_scm_program_source +{ + SCM_VALIDATE_PROGRAM (1, program); + return scm_c_program_source (program, scm_to_size_t (ip)); +} +#undef FUNC_NAME + extern SCM scm_c_program_source (SCM program, size_t ip) { - SCM sources, source; - - sources = scm_program_sources (program); - source = scm_assv (scm_from_size_t (ip), sources); - if (scm_is_false (source)) - return SCM_BOOL_F; + SCM sources, source = SCM_BOOL_F; - return scm_cdr (source); /* a #(line column file) vector */ + for (sources = scm_program_sources (program); + !scm_is_null (sources) + && scm_to_size_t (scm_caar (sources)) <= ip; + sources = scm_cdr (sources)) + source = scm_car (sources); + + return source; /* (addr . (filename . (line . column))) */ } SCM_DEFINE (scm_program_external, "program-external", 1, 0, 0, |