I try to write a lexer for ASN.1 using Silex and Gambit. It worked pretty well in the beginning but now I am a bit stuck because of the following error:
*** ERROR IN out-print-table-data, "silex/silex.scm"@4774.13 -- Number of arguments exceeds implementation limit (string-append "#" "(" "(" "70" " " "(" "46" " " "(" "32" " " "(" "10" " " "(" ...)
I am not sure if it is a problem with my lexer specification, with Silex or with Gambit. I have attached my lexer, my test program and the LDAP ASN.1 definition I am using for my tests.
Can anybody tell me who is causing the error and how this can be fixed?
Afficher les réponses par date
On 2012-01-13, at 12:21 PM, Sascha Ziemann wrote:
I try to write a lexer for ASN.1 using Silex and Gambit. It worked pretty well in the beginning but now I am a bit stuck because of the following error:
*** ERROR IN out-print-table-data, "silex/silex.scm"@4774.13 -- Number of arguments exceeds implementation limit (string-append "#" "(" "(" "70" " " "(" "46" " " "(" "32" " " "(" "10" " " "(" ...)
I am not sure if it is a problem with my lexer specification, with Silex or with Gambit. I have attached my lexer, my test program and the LDAP ASN.1 definition I am using for my tests.
Can anybody tell me who is causing the error and how this can be fixed?
Gambit has an upper limit on the number of arguments which can be passed in a function call. The limit is 8192 arguments by default. The limit is due to the way the stack is managed. The limit can be changed by modifying the definition of ___MAX_NB_ARGS in lib/mem.h and recompiling Gambit :
#define ___MAX_NB_ARGS 8192
but there will be a limit whatever you choose.
In the particular case of Silex, there is a call (apply string-append x) where x is a list containing more than 8192 strings. You can avoid this problem by using Gambit's append-strings procedure :
(append-strings (list "a" "b" "c"))
"abc"
(apply string-append (list "a" "b" "c"))
"abc"
Just replace (apply string-append x) with (append-strings x).
Marc
2012/1/13 Marc Feeley feeley@iro.umontreal.ca:
*** ERROR IN out-print-table-data, "silex/silex.scm"@4774.13 -- Number of arguments exceeds implementation limit (string-append
Just replace (apply string-append x) with (append-strings x).
Thanks! This fixes the problem without the need to patch silex:
(cond-expand (gambit (define %apply apply) (define-syntax apply (syntax-rules (string-append) ((_ string-append list) (append-strings list)) ((_ func list) (%apply func list))))) (else #f))
On 2012-01-14, at 7:34 AM, Sascha Ziemann wrote:
2012/1/13 Marc Feeley feeley@iro.umontreal.ca:
*** ERROR IN out-print-table-data, "silex/silex.scm"@4774.13 -- Number of arguments exceeds implementation limit (string-append
Just replace (apply string-append x) with (append-strings x).
Thanks! This fixes the problem without the need to patch silex:
(cond-expand (gambit (define %apply apply) (define-syntax apply (syntax-rules (string-append) ((_ string-append list) (append-strings list)) ((_ func list) (%apply func list))))) (else #f))
Something like the following definition will also solve the problem, but without relying on a syntactic pattern.
(define apply (let ((old-apply apply)) (lambda (f args) (cond ((eq? f string-append) (append-strings args)) ((eq? f string) (list->string args)) ;;... (else (old-apply f args))))))
Marc