Skip to content

Commit

Permalink
!205 fix error message in define-case-class
Browse files Browse the repository at this point in the history
* add code in GoldfishLang.tmu
* fix error message in define-case-class
  • Loading branch information
TREE37 committed Feb 19, 2025
1 parent ab811ff commit 0b29d9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
38 changes: 24 additions & 14 deletions GoldfishLang.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,15 @@

,@static-methods

\ \ \
\;

(define (is-normal-function? msg)

\ \ (and \ (symbol? msg)\

\ \ \ \ \ \ \ \ (char=? (string-ref (symbol-\<gtr\>string msg) 0) #\\:)))

\;

(define (static-dispatcher msg . args)

Expand Down Expand Up @@ -424,7 +432,7 @@

\ \ \ \ \ \ \ \ \ \ \ (list ,@(map (lambda (field key-field)

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (string-append
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ `(string-append

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ,(symbol-\<gtr\>string key-field) " "

Expand Down Expand Up @@ -460,13 +468,23 @@

\ \ \ \ \ \ (cond

\ \ \ \ \ \ \ \ ((eq? msg :is-instance-of) (apply %is-instance-of args))
\ \ \ \ \ \ \ \ ((is-normal-function? msg)

\ \ \ \ \ \ \ \ ((eq? msg :equals) (apply %equals args))
\ \ \ \ \ \ \ \ \ \ (cond

\ \ \ \ \ \ \ \ \ \ \ \ \ \ ((eq? msg :is-instance-of) (apply %is-instance-of args))

\ \ \ \ \ \ \ \ \ \ \ \ \ \ ((eq? msg :equals) (apply %equals args))

\ \ \ \ \ \ \ \ ((eq? msg :to-string) (%to-string))
\ \ \ \ \ \ \ \ \ \ \ \ \ \ ((eq? msg :to-string) (%to-string))

\ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ ,@(map (lambda (method expected) `((eq? msg ,expected) (apply ,method args)))

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ instance-method-symbols instance-messages)

\ \ \ \ \ \ \ \ \ \ \ \ \ \ (else (value-error ,class-name "No such method: " msg))))

\ \ \ \ \ \ \ \

\ \ \ \ \ \ \ \ ,@(map (lambda (field) `((eq? msg ',(car field)) ,(car field))) fields)

Expand All @@ -484,12 +502,6 @@

\;

\ \ \ \ \ \ \ \ ,@(map (lambda (method expected) `((eq? msg ,expected) (apply ,method args)))

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ instance-method-symbols instance-messages)

\;

\ \ \ \ \ \ \ \ (else (apply %apply (cons msg args))))))

\;
Expand All @@ -513,8 +525,6 @@
) ; end of let

) ; end of define-macro

\;
</goldfish-chunk>

测试:不带用户自定义方法的样本类person
Expand Down
22 changes: 14 additions & 8 deletions goldfish/liii/lang.scm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@
`(define (,class-name msg . args)

,@static-methods


(define (is-normal-function? msg)
(and (symbol? msg)
(char=? (string-ref (symbol->string msg) 0) #\:)))

(define (static-dispatcher msg . args)
(cond
,@(map (lambda (method expected) `((eq? msg ,expected) (apply ,method args)))
Expand Down Expand Up @@ -127,10 +131,15 @@
(define (instance-dispatcher)
(lambda (msg . args)
(cond
((eq? msg :is-instance-of) (apply %is-instance-of args))
((eq? msg :equals) (apply %equals args))
((eq? msg :to-string) (%to-string))

((is-normal-function? msg)
(cond
((eq? msg :is-instance-of) (apply %is-instance-of args))
((eq? msg :equals) (apply %equals args))
((eq? msg :to-string) (%to-string))
,@(map (lambda (method expected) `((eq? msg ,expected) (apply ,method args)))
instance-method-symbols instance-messages)
(else (value-error ,class-name "No such method: " msg))))

,@(map (lambda (field) `((eq? msg ',(car field)) ,(car field))) fields)
,@(map (lambda (field key-field)
`((eq? msg ,key-field)
Expand All @@ -139,9 +148,6 @@
fields))))
fields key-fields)

,@(map (lambda (method expected) `((eq? msg ,expected) (apply ,method args)))
instance-method-symbols instance-messages)

(else (apply %apply (cons msg args))))))

(instance-dispatcher)
Expand Down

0 comments on commit 0b29d9f

Please sign in to comment.