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:48:36 +0100 [thread overview]
Message-ID: <CADEOaddra0FRH+LHL-ywHSrTHSdF4r5X8o62ihY8HDv0s7irrQ@mail.gmail.com> (raw)
In-Reply-To: <CADEOade8=4w=8o4bw4WZ6JfYoWk8zK+vGiM1JNxVhqxd=CONGw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2537 bytes --]
i forgot a few definitions and include file in the previous post.
It is okay now with the new attachments.
Damien
On Fri, Nov 3, 2023 at 11:42 AM Damien Mattei <damien.mattei@gmail.com> wrote:
>
> 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: 3319 bytes --]
(module-name test-define)
(require 'srfi-1)
(require 'srfi-69)
;;(require infix-operators)
(export define-overload-existing-operator
overload-existing-operator)
;;+)
(include "condx.scm")
(define $ovrld-ht$ (make-hash-table)) ;; for procedure and operators
(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))))))
[-- Attachment #4: condx.scm --]
[-- Type: application/octet-stream, Size: 3038 bytes --]
;; condx: cond(itionals) with optional execution of statements before
;
; This file is part of Scheme+
;; Copyright 2021 Damien MATTEI
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
; example:
;(define x 1)
;(condx ((= x 7) 'never)
; (exec
; (define y 3)
; (set! x 7))
; ((= y 1) 'definitely_not)
; (exec
; (set! y 10)
; (define z 2))
; ((= x 7) (+ x y z))
; (else 'you_should_not_be_here))
;
; 19
(define-syntax condx
(syntax-rules (exec else)
((_) '()) ;; allow no else clause
((_ (else e ...))
(let () e ...))
((_ (exec s ...) d1 ...)
(let () s ... (condx d1 ...)))
((_ (t e ...) tail ...)
(if t
(let () e ...)
(condx tail ...)))))
;; (define-syntax condx
;; (syntax-rules (exec else)
;; ((_)
;; (error 'condx "No else clause"))
;; ((_ (else e ...))
;; (let () e ...))
;; ((_ (exec s ...) d1 ...)
;; (let () s ... (condx d1 ...)))
;; ((_ (t e ...) tail ...)
;; (if t
;; (let () e ...)
;; (condx tail ...)))))
;; warning this ones behaves differently (can not remember the problem)
(define-syntax condx-begin
(syntax-rules (exec else)
((_) '()) ;; allow no else clause
((_ (else e ...))
(begin e ...))
((_ (exec s ...) d1 ...)
(begin s ... (condx-begin d1 ...)))
((_ (t e ...) tail ...)
(if t
(begin e ...)
(condx-begin tail ...)))))
;; (define-syntax condx-begin
;; (syntax-rules (exec else)
;; ((_)
;; (error 'condx-begin "No else clause"))
;; ((_ (else e ...))
;; (begin e ...))
;; ((_ (exec s ...) d1 ...)
;; (begin s ... (condx-begin d1 ...)))
;; ((_ (t e ...) tail ...)
;; (if t
;; (begin e ...)
;; (condx-begin tail ...)))))
;; (define x 1)
;; (condx ((= x 7) 'never)
;; (exec
;; (define y 3)
;; (set! x 7))
;; ((= y 1) 'definitely_not)
;; (exec
;; (set! y 10)
;; (define z 2))
;; ((= x 7) (+ x y z))
;; (else 'you_should_not_be_here))
;; (define y 0)
;; (define z 0)
;; (set! x 1)
;; (condx-begin ((= x 7) 'never)
;; (exec
;; (set! y 3)
;; (set! x 7))
;; ((= y 1) 'definitely_not)
;; (exec
;; (set! y 10)
;; (set! z 2))
;; ((= x 7) (+ x y z))
;; (else 'you_should_not_be_here))
next prev parent reply other threads:[~2023-11-03 10:48 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
2023-11-03 10:48 ` Damien Mattei [this message]
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=CADEOaddra0FRH+LHL-ywHSrTHSdF4r5X8o62ihY8HDv0s7irrQ@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).