marcomaggi / vicare

A native compiler for Scheme compliant with R6RS
http://marcomaggi.github.com/vicare.html
Other
200 stars 34 forks source link

Understanding compile errors #85

Closed svenha closed 8 years ago

svenha commented 8 years ago

I managed to port a large Scheme program to vicare, so that it loads without visible errors. The compiler runs for 30 minutes (which is fine for 140 KLOC and let me hope for good results :-) ). But then I receive error messages from the compiler. They differ depending on the calling options. Here are two tries:

/usr/local/bin64/vicare -O1 --raw-repl Vicare Scheme version 0.4d0, 64-bit Build 2015-11-26

Copyright (c) 2006-2010 Abdulaziz Ghuloum and contributors Copyright (c) 2011-2015 Marco Maggi and contributors

vicare> (load "vic.scm") Unhandled exception Condition components:

  1. &compile-time-arity-error
  2. &library: compiler
  3. &module: pass-introduce-unsafe-primrefs
  4. &who: %E-primref-call
  5. &message: "wrong number of arguments in core primitive application"
  6. &irritants: ((funcall (primref substring) g95608_0 (known (funcall (primref string-length) g95607_0) (T:fixnum T:non-false T:exact-real T:real T:exact-integer T:exact T:number T:immediate T:object)))) vicare>

/usr/local/bin64/vicare -d --optimizer-passes-count 1 -O1 --raw-repl
Vicare Scheme version 0.4d0, 64-bit Build 2015-11-26

Copyright (c) 2006-2010 Abdulaziz Ghuloum and contributors Copyright (c) 2011-2015 Marco Maggi and contributors

vicare> (load "vic.scm") Exception trapped by debugger. Condition components:

  1. &undefined
  2. &who: top-level-value
  3. &message: "unbound variable"
  4. &irritants: (g41070)
marcomaggi commented 8 years ago

The first error shows the limits of a dynamically typed language: somewhere in your code there is the following form which calls substring with the wrong number of arguments:

(substring ?var1 (string-length ?var2))

where ?var1 and ?var2 are some variables of which the compiler does not know the original name or some variables introduced by the compiler's source code optimiser. Vicare's compiler does not keep enough source informations sorry. (In future the expander will detect these errors.) The gXXX where XXX are numbers are string names of gensyms generated by the expander and compiler; I would suggest you to use the options --option expander-descriptive-gensyms and --option compiler-descriptive-labels or just enable debugging mode with -g, but with your compile times any debugging strategy is deathly.

The second error is probably a genuine compiler error. top-level-value is a core primitive used to retrieve the current value of a global variable from the location gensym that contains it, but such gensym (whose string name is g41070) appears to be unbound. You can easily get such error by evaluating:

(top-level-value (gensym))

you need knowledge of Vicare's internals to debug this.

I suggest you to: split your source code into proper libraries and a top level program so that you can compile them incrementally (your compile times are unbearable!!!); try also other Scheme implementations, for example the free Petite Chez Scheme which has a very fast compiler.