From 6896da6870fcaf9aaf32b53f32946a1e381b365e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 3 Oct 2024 22:54:03 +0900 Subject: [PATCH] changed the superclass marker from '::' to ':' --- lib/comp.c | 2 +- lib/read.c | 16 +++++++++++++++- t/class-5001.err | 21 +++++++++++++++++---- t/insta-01.hcl | 2 +- t/insta-02.hcl | 29 ++++++++++++++++++++++------- 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/lib/comp.c b/lib/comp.c index 6f1f891..1d41481 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -2548,7 +2548,7 @@ static int compile_class (hcl_t* hcl, hcl_cnode_t* src) } tmp = HCL_CNODE_CONS_CAR(obj); - if (/*HCL_CNODE_IS_COLON(tmp) || */HCL_CNODE_IS_DBLCOLONS(tmp)) + if (HCL_CNODE_IS_COLON(tmp)) /* check for superclass marker */ { hcl_cnode_t* marker; diff --git a/lib/read.c b/lib/read.c index 4b212b2..9f91279 100644 --- a/lib/read.c +++ b/lib/read.c @@ -893,6 +893,13 @@ static HCL_INLINE int can_colon_list (hcl_t* hcl) if (rstl->count <= 0) return 0; /* not allowed at the list beginning */ /* mark the state that a colon has appeared in the list */ + if (HCL_CNODE_IS_TYPED(HCL_CNODE_CONS_CAR(rstl->head), HCL_CNODE_CLASS)) + { + /* class :superclassame ... + * class name:superclassname ... */ + return 2; + } + if (rstl->count == 1) rstl->flagv |= JSON; /* mark that the first key is colon-delimited */ else if (!(rstl->flagv & JSON)) { @@ -945,7 +952,14 @@ static HCL_INLINE int can_colon_list (hcl_t* hcl) /* ugly dual use of a colon sign. switch to MLIST if the first element * is delimited by a colon. e.g. (obj:new 10 20 30) */ tmp = HCL_CNODE_CONS_CAR(rstl->head); - if (!HCL_CNODE_IS_FOR_DATA(tmp)) return 0; + if (!HCL_CNODE_IS_FOR_DATA(tmp)) + { + /* check if the first element can refer to or represent an object. + * for example, '#[1 2 3]:at 1' is proper message send. + * while 'class:xxx {}' is not a method call. it is unamed class + * that inherits from xxx */ + return 0; + } LIST_FLAG_SET_CONCODE(rstl->flagv, HCL_CONCODE_MLIST); rstl->flagv &= ~JSON; diff --git a/t/class-5001.err b/t/class-5001.err index b403103..5e3bc6c 100644 --- a/t/class-5001.err +++ b/t/class-5001.err @@ -36,18 +36,18 @@ class super.a [ a ] { ##ERROR: syntax error - invalid class name 'super.a' for ' --- -class a :: 20 { ##ERROR: syntax error - invalid superclass name '20' after '::' for 'class' +class a: 20 { ##ERROR: syntax error - invalid superclass name '20' after ':' for 'class' } --- -class a :: class { ##ERROR: syntax error - invalid superclass name 'class' after '::' for 'class' +class a: class { ##ERROR: syntax error - invalid superclass name 'class' after ':' for 'class' } --- -class a :: #(1 2) { ##ERROR: syntax error - no valid superclass name after '::' for 'class' +class a: #(1 2) { ##ERROR: syntax error - no valid superclass name after ':' for 'class' } --- @@ -81,7 +81,7 @@ class B [ x y ] { }; -class X :: B [ a b ] { +class X: B [ a b ] { fun(#ci) new(t) { | a | set self.a t; @@ -231,3 +231,16 @@ class a { fun() { ##ERROR: syntax error - unnamed function defined with 'fun' prohibited in class initialziation context } } + +--- + +class X10 [ x ] { + fun(#ci) make() { x := 1234; return self; }; + fun get-x() { return x }; +} + +X11 := (class:X10 { +}) + +class X11 { ##ERROR: exception not handled - "prohibited redefintion of X11" +} diff --git a/t/insta-01.hcl b/t/insta-01.hcl index b2be6f9..14b10de 100644 --- a/t/insta-01.hcl +++ b/t/insta-01.hcl @@ -26,7 +26,7 @@ class A [ a b c ] { fun get-c() { return self.c; }; }; -class B :: A [ d e f ] { +class B: A [ d e f ] { fun(#ci) newInstance(x y z) { super:newInstance (* x 2) (* y 2) (* z 2); diff --git a/t/insta-02.hcl b/t/insta-02.hcl index 91e4d41..8098a9e 100644 --- a/t/insta-02.hcl +++ b/t/insta-02.hcl @@ -31,11 +31,12 @@ else { printf "OK: t is %d\n" t }; j := #{ ((X:make):get-x): 9999, 4512: ((X: make): get-x) }; v := (dic.get j 1234); if (nqv? v 9999) { printf "ERROR: v is not 9999\n" } \ -else { printf "OK: value is %d\n" v }; +else { printf "OK: value is %d\n" v }; v := (dic.get j 4512); if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \ -else { printf "OK: value is %d\n" v }; +else { printf "OK: value is %d\n" v }; + ## -------------------------------------------------------------- @@ -58,11 +59,11 @@ class X0 [ a b c d ] { }; a := (X0:new); v := (a:x) if (nqv? v 100) { printf "ERROR: v is not 100\n" } \ -else { printf "OK: value is %d\n" v } +else { printf "OK: value is %d\n" v } v := ((a:y) 20); if (nqv? v 21) { printf "ERROR: v is not 21\n" } \ -else { printf "OK: value is %d\n" v } +else { printf "OK: value is %d\n" v } ## -------------------------------------------------------------- @@ -92,15 +93,15 @@ fun X1:get_a() { v := ((X1:new):get_a) if (nqv? v 20) { printf "ERROR: v is not 20 - %d\n" v } \ -else { printf "OK: value is %d\n" v } +else { printf "OK: value is %d\n" v } v := (((X1:new):make 5 6 7):get_j) if (nqv? v 79) { printf "ERROR: v is not 79 - %d\n" v } \ -else { printf "OK: value is %d\n" v } +else { printf "OK: value is %d\n" v } v := (((X1:new):make 6 6 7):get_j) if (nqv? v 70) { printf "ERROR: v is not 70 - %d\n" v } \ -else { printf "OK: value is %d\n" v } +else { printf "OK: value is %d\n" v } ## -------------------------------------------------------------- @@ -175,3 +176,17 @@ else { printf "OK: value is %d\n" v } v := { X5:t; (X6:t) + 10 } if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \ else { printf "OK: value is %d\n" v } + +## -------------------------------------------------------------- +class X10 [ x ] { + fun(#ci) make() { x := 1234; return self; }; + fun get-x() { return x }; +} + +X11 := (class:X10 { +}) + +v := (X11:make) +v := (v:get-x) +if (== v 1234) { printf "OK: v is %d\n" v } \ +else {printf "ERROR: v is %d, not 1234\n" v }