From 88808b1faef5142fc7ef1a831b56e38b828dfe0a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 22 Mar 2022 14:45:56 +0000 Subject: [PATCH] added t/insta-2.hcl --- lang.txt | 32 ++++++++++++++++++++++++++++++++ t/Makefile.am | 1 + t/Makefile.in | 1 + t/insta-02.hcl | 13 +++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 t/insta-02.hcl diff --git a/lang.txt b/lang.txt index f0f5e8e..e8701fb 100644 --- a/lang.txt +++ b/lang.txt @@ -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))) diff --git a/t/Makefile.am b/t/Makefile.am index 25074d7..0bd0b8e 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -2,6 +2,7 @@ AUTOMAKE_OPTIONS = nostdinc check_SCRIPTS = \ insta-01.hcl \ + insta-02.hcl \ ret-01.hcl \ retvar-01.hcl diff --git a/t/Makefile.in b/t/Makefile.in index da21ec5..ee8b6ab 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -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 diff --git a/t/insta-02.hcl b/t/insta-02.hcl new file mode 100644 index 0000000..fc731a7 --- /dev/null +++ b/t/insta-02.hcl @@ -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)