public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: Per Bothner <per@bothner.com>
Cc: kawa mailing list <kawa@sourceware.org>
Subject: Re: unbound location: *
Date: Fri, 3 Nov 2023 11:42:27 +0100	[thread overview]
Message-ID: <CADEOade8=4w=8o4bw4WZ6JfYoWk8zK+vGiM1JNxVhqxd=CONGw@mail.gmail.com> (raw)
In-Reply-To: <436b231e-bb91-4515-a2cf-7baca3a5a359@bothner.com>

[-- Attachment #1: Type: text/plain, Size: 2225 bytes --]

in case if you have a few time to have a look to the problem i made a
simple test-case with my overloading operator problem, it is in the
two attached files and can run like that:

kawa -Dkawa.import.path="."
#|kawa:1|# (load "main-test-define.scm")
main-test-define.scm:4:1: duplicate version reference - was #<syntax
(test-define) in #91>
main-test-define.scm:4:1: unknown library (#<syntax#8 rename in #91>)
#|kawa:2|# +
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    atInteractiveLevel-4.run(Lgnu/mapping/CallContext;)V @6: aload_3
  Reason:
    Type top (current frame, locals[3]) is not assignable to reference type
  Current Frame:
    bci: @6
    flags: { }
    locals: { 'atInteractiveLevel-4', 'gnu/mapping/CallContext',
'gnu/lists/Consumer' }
    stack: { 'gnu/lists/Consumer' }
  Bytecode:
    0000000: 2bb4 0008 4d2c 2db9 000e 0200 b1

    at java.base/java.lang.Class.getDeclaredFields0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3473)
    at java.base/java.lang.Class.getDeclaredField(Class.java:2780)
    at gnu.expr.ModuleContext.findInstance(ModuleContext.java:71)
    at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:286)
    at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211)
    at kawa.Shell.run(Shell.java:289)
    at kawa.Shell.run(Shell.java:196)
    at kawa.Shell.run(Shell.java:183)
    at kawa.repl.processArgs(repl.java:724)
    at kawa.repl.main(repl.java:830)

Damien

On Thu, Nov 2, 2023 at 10:59 PM Per Bothner <per@bothner.com> wrote:
>
>
>
> On 11/2/23 14:51, Damien Mattei wrote:
> > seems a good idea but i can not fix it, i try:
> > (import (rename (gnu kawa) (proc orig-proc)))
> ...
> > Exception in thread "main" java.lang.VerifyError: Bad local variable type
>
> That is probably a bug in the Kawa code generator.
> I'm unlikely to have time to debug that.  Certainly not without a
> simplified simple-to-reproduce test-case. Even with a good test-case, this
> is part of Kawa I haven't looked at in a long time, and I'm busy with other projects.
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

[-- Attachment #2: main-test-define.scm --]
[-- Type: application/octet-stream, Size: 230 bytes --]

;;(require overload)
(require test-define)

(define-overload-existing-operator +)

(overload-existing-operator + vector-append (vector? vector?))


(define rv (+ #(1 2) #(3 4 5)))
(newline) (display "rv=") (display rv) (newline)


[-- Attachment #3: test-define.scm --]
[-- Type: application/octet-stream, Size: 3225 bytes --]

(module-name test-define)

(require 'srfi-1)

(require 'srfi-69)

;;(require infix-operators)

(export define-overload-existing-operator
	overload-existing-operator)
	;;+)


(define (check-arguments pred-list args)
  (if (= (length pred-list) (length args))
      (let ((pred-arg-list (map cons pred-list args)))
	;;(andmap (lambda (p) ((car p) (cdr p)))
	;; replace andmap with every in Guile
	(every (lambda (p) ((car p) (cdr p)))
	       pred-arg-list))
      #f))



(define-syntax define-overload-existing-operator

  (syntax-rules ()

    ((_ proc)

     (begin

       (import (rename (test-define) (proc orig-proc)))
       ;;(import (rename (gnu kawa) (proc orig-proc)))
       ;;(require (rename-in racket/base (proc
       	;;			        orig-proc)))

       (display "proc =") (display proc) (newline)
       (display "orig-proc =") (display orig-proc) (newline)
       
       (define qproc (quote proc)) 
       
       (define (proc . args-lst)

	 ;;(display "proc=") (display proc) (newline)
	 ;;(define ht (hash-table->alist $ovrld-ht$))
	 ;;(display ht) (newline)


	 (define proc-lst (hash-table-ref $ovrld-ht$ qproc)) ;;  example: ((number? string?) (lambda (n s) (display n) (display s) (newline)))
	 ;;(display "proc-lst=") (display proc-lst)
	 ;;(newline)
	 
	 (define (check-args-lst pred-list) ; check arguments list match predicates
	   ;;(display "pred-list=") (display pred-list) (newline)
	   ;;(display "args-lst=") (display args-lst) (newline)
	   (check-arguments pred-list args-lst))



	 (define (test-proc pred-proc-list) ; test the procedure if it matches with arguments
	   ;;(display "pred-proc-list=") (display pred-proc-list) (newline)
	   (if (check-args-lst (car pred-proc-list)) ;; check args
	       (car (cdr  pred-proc-list)) ;; return procedure
	       #f))

	 
	 (define proc-search-result (ormap test-proc proc-lst)) ; search for a procedure matching arguments

	 
	 ;;(display "proc-search-result=") (display proc-search-result) (newline)
	 
	 (condx (proc-search-result (apply proc-search-result args-lst))
		(exec
		 (define nb-args (length args-lst)))
		((> nb-args 2)   ;;(display ">2 args") (newline)
		 (proc (car args-lst) (apply proc (cdr args-lst))))
		(else
		 ;;(display "else") (newline)
		 (apply orig-proc args-lst))))
       
       ;;(hash-table-set! $ovrld-ht$ qproc (list (list (list number? number?) orig-proc)))
       (hash-table-set! $ovrld-ht$ qproc '())

       ;;(replace-operator! orig-proc proc)
       
       )))) 




(define-syntax overload-existing-operator
  
  (syntax-rules ()

    ((_ orig-funct funct (pred-arg1 ...))

     (overload orig-funct funct (pred-arg1 ...)))))


(define-syntax overload

  (syntax-rules ()

    ;; arguments are function to be overloaded, procedure that do the overloading, list of predicate to check the arguments

    ((_ orig-funct funct (pred-arg1 ...))

     (let* ((qorig-funct (quote orig-funct))
	    (ovrld-lst (hash-table-ref $ovrld-ht$ qorig-funct)))
       ;;(display qorig-funct) (newline)
       (hash-table-set! $ovrld-ht$ qorig-funct
			(cons (list (list pred-arg1 ...) ;; example: ((number? string?) (lambda (n s) (display n) (display s) (newline)))
				    funct)
			      ovrld-lst))))))
 	 


  reply	other threads:[~2023-11-03 10:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01  8:39 Damien Mattei
2023-11-01 12:22 ` Damien Mattei
2023-11-01 12:50   ` Damien Mattei
2023-11-01 14:02     ` Damien Mattei
2023-11-01 16:11       ` Damien Mattei
2023-11-01 16:47         ` Damien Mattei
2023-11-01 16:57           ` Per Bothner
2023-11-02 21:51             ` Damien Mattei
2023-11-02 21:58               ` Per Bothner
2023-11-03 10:42                 ` Damien Mattei [this message]
2023-11-03 10:48                   ` Damien Mattei
2023-11-01 14:55   ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADEOade8=4w=8o4bw4WZ6JfYoWk8zK+vGiM1JNxVhqxd=CONGw@mail.gmail.com' \
    --to=damien.mattei@gmail.com \
    --cc=kawa@sourceware.org \
    --cc=per@bothner.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).