added t/insta-2.hcl

This commit is contained in:
hyung-hwan 2022-03-22 14:45:56 +00:00
parent fa1c4ac896
commit 88808b1fae
4 changed files with 47 additions and 0 deletions

View File

@ -85,9 +85,41 @@ send the message dump to the object pointed to by x with arguments 1, 2, 3.
## method types
- class method
- class instantiation method
(defclass P
| x y |
(defun ::* new ()
(set x 1)
(set y 1)
(return self)
)
(defun get-x() x)
(defun get-y() y)
)
(defclass X ::: P
| x y |
(defun ::* new (a b)
(:super new)
x = a
y = b
(return self)
)
(defun get-xx() x)
(defun get-yy() y)
)
(set t (:X new 10 20)) ;t is an instance of X
(printf "%d %d %d %d\n" (:t get-x) (:t get-y) (:t get-xx) (:t get-yy)) ; must print 1 1 10 20
(:t new 100 300) ;the x, y in the X part get reset to 100 and 300. doesn't create a new instance
(printf "%d %d %d %d\n" (:t get-x) (:t get-y) (:t get-xx) (:t get-yy)) ; must print 1 1 100 300
- instance method
## dynamic dispatching by method name
(defclass X
(defun t1 (x) (printf "t1 = %d\n" (+ x x x)))

View File

@ -2,6 +2,7 @@ AUTOMAKE_OPTIONS = nostdinc
check_SCRIPTS = \
insta-01.hcl \
insta-02.hcl \
ret-01.hcl \
retvar-01.hcl

View File

@ -463,6 +463,7 @@ top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = nostdinc
check_SCRIPTS = \
insta-01.hcl \
insta-02.hcl \
ret-01.hcl \
retvar-01.hcl

13
t/insta-02.hcl Normal file
View File

@ -0,0 +1,13 @@
(set t
(defclass X
| x |
(defun ::* make() (set x 1234) self)
(defun get-x() x)
)
)
(if (nqv? t X) (printf "ERROR: t must point to X\n"))
(printf "OK: t points to X\n")
(set t (:(:t make) get-x))
(if (nqv? t 1234) (printf "ERROR: t must be 1234\n"))
(printf "OK: t is %d\n" t)