Opened 4 years ago

Closed 4 years ago

#1421 closed defect (invalid)

problems with building json egg in c5 egg repo

Reported by: felix winkelmann Owned by:
Priority: critical Milestone: 5.0
Component: expander Version: 5.0.0
Keywords: Cc: sjamaan
Estimated difficulty: hard

Description

Building the json egg results in:

Error: (json.scm:109) - toplevel definition of `white' in non-toplevel context

The code looks like this:

      (define parser
	(packrat-parser (begin
			  (define (white results) ...

Changing the begin to let () results in another, more obscure error.
Apparently the proper treatment of define inside begin inside let
is not correctly expanded (packrat-parser seems to expand into a let body).

Change History (3)

comment:1 Changed 4 years ago by sjamaan

I believe this is a bug in how packrat works:

(import packrat)

(define plus-or-minus
  (packrat-parser
   (begin
     (print "here be a define")
     expr)
   (expr ((a <- '+)
          (print "plus: " a))
         ((a <- '-)
          (print "minus: " a)))))

Compiling this with csc -debug 2 produces:

[canonicalized]
(##core#callunit library)

(##core#callunit eval)

(##core#undefined)

(##core#undefined)

(##core#undefined)

(chicken.load#load-extension 'packrat '(packrat#) 'require)

(set! minus
  (let ()
    (let ((expr31 (##core#undefined)))
      (let ((t58 (set! expr31
                   (##core#lambda
                     (results2632)
                     (packrat#results->result
                       results2632
                       'expr
                       (##core#lambda
                         ()
                         (let ((g3334 (packrat#packrat-or
                                        (packrat#packrat-check-base
                                          '+
                                          (##core#lambda
                                            (a42)
                                            (##core#lambda
                                              (results4446)
                                              (packrat#make-result
                                                (chicken.base#print '"plus: " a42)
                                                results4446))))
                                        (packrat#packrat-check-base
                                          '-
                                          (##core#lambda
                                            (a53)
                                            (##core#lambda
                                              (results5557)
                                              (packrat#make-result
                                                (chicken.base#print '"minus: " a53)
                                                results5557)))))))
                           (g3334 results2632))))))))
        (let ((t59 (chicken.base#print '"here be a define"))) expr31)))))

((##sys#implicit-exit-handler))

As you can see, the expansion of the internal define of json would look something like:

(set! parser
  (let ()
     (let (...) ;; parser definitions used by begin
       (let ((t59 (begin (define (white results) ...)))) ... expr))))

This is clearly incorrect: you can't put define in the value expression of a let-variable.

comment:2 Changed 4 years ago by sjamaan

On second thought, it looks like this inner let that is the source of t59 is introduced by the compiler (through ##sys#canonicalize-body), so I'm not 100% sure it is packrat doing things wrong...

comment:3 Changed 4 years ago by sjamaan

Resolution: invalid
Status: newclosed

OK never mind, this was a complete red herring. The json egg didn't work because it contained use instead of import expressions, causing the packrat-parser call to be seen not as a module but as a procedure call, which means the defines were indeed "misplaced".

Note: See TracTickets for help on using tickets.