changed the superclass marker from '::' to ':'
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0dbaa264f7
commit
6896da6870
@ -2548,7 +2548,7 @@ static int compile_class (hcl_t* hcl, hcl_cnode_t* src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tmp = HCL_CNODE_CONS_CAR(obj);
|
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;
|
hcl_cnode_t* marker;
|
||||||
|
|
||||||
|
16
lib/read.c
16
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 */
|
if (rstl->count <= 0) return 0; /* not allowed at the list beginning */
|
||||||
|
|
||||||
/* mark the state that a colon has appeared in the list */
|
/* 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 */
|
if (rstl->count == 1) rstl->flagv |= JSON; /* mark that the first key is colon-delimited */
|
||||||
else if (!(rstl->flagv & JSON))
|
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
|
/* 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) */
|
* is delimited by a colon. e.g. (obj:new 10 20 30) */
|
||||||
tmp = HCL_CNODE_CONS_CAR(rstl->head);
|
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);
|
LIST_FLAG_SET_CONCODE(rstl->flagv, HCL_CONCODE_MLIST);
|
||||||
rstl->flagv &= ~JSON;
|
rstl->flagv &= ~JSON;
|
||||||
|
@ -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) {
|
fun(#ci) new(t) {
|
||||||
| a |
|
| a |
|
||||||
set self.a t;
|
set self.a t;
|
||||||
@ -231,3 +231,16 @@ class a {
|
|||||||
fun() { ##ERROR: syntax error - unnamed function defined with 'fun' prohibited in class initialziation context
|
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"
|
||||||
|
}
|
||||||
|
@ -26,7 +26,7 @@ class A [ a b c ] {
|
|||||||
fun get-c() { return self.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) {
|
fun(#ci) newInstance(x y z) {
|
||||||
super:newInstance (* x 2) (* y 2) (* z 2);
|
super:newInstance (* x 2) (* y 2) (* z 2);
|
||||||
|
@ -31,11 +31,12 @@ else { printf "OK: t is %d\n" t };
|
|||||||
j := #{ ((X:make):get-x): 9999, 4512: ((X: make): get-x) };
|
j := #{ ((X:make):get-x): 9999, 4512: ((X: make): get-x) };
|
||||||
v := (dic.get j 1234);
|
v := (dic.get j 1234);
|
||||||
if (nqv? v 9999) { printf "ERROR: v is not 9999\n" } \
|
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);
|
v := (dic.get j 4512);
|
||||||
if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \
|
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)
|
}; a := (X0:new); v := (a:x)
|
||||||
if (nqv? v 100) { printf "ERROR: v is not 100\n" } \
|
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);
|
v := ((a:y) 20);
|
||||||
if (nqv? v 21) { printf "ERROR: v is not 21\n" } \
|
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)
|
v := ((X1:new):get_a)
|
||||||
if (nqv? v 20) { printf "ERROR: v is not 20 - %d\n" v } \
|
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)
|
v := (((X1:new):make 5 6 7):get_j)
|
||||||
if (nqv? v 79) { printf "ERROR: v is not 79 - %d\n" v } \
|
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)
|
v := (((X1:new):make 6 6 7):get_j)
|
||||||
if (nqv? v 70) { printf "ERROR: v is not 70 - %d\n" v } \
|
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 }
|
v := { X5:t; (X6:t) + 10 }
|
||||||
if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \
|
if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \
|
||||||
else { printf "OK: value is %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 }
|
||||||
|
Loading…
Reference in New Issue
Block a user