changed ::: to :: to indicate class variables, parent class, retvar
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-02-04 01:57:53 +09:00
parent b20d6b14d8
commit 48e6df233b
17 changed files with 59 additions and 37 deletions

View File

@ -49,7 +49,7 @@ do { | k | set k 20; printf "k=%d\n" k; };
- function calls `( )` - function calls `( )`
- message sends `(: )` - message sends `(: )`
- variable declaration `| |` - variable declaration `| |`
- class variable delcarations `::: | |` - class variable delcarations `:: | |`
## Builtin functions ## Builtin functions
@ -98,11 +98,11 @@ do { | k | set k 20; printf "k=%d\n" k; };
``` ```
(defclass T (defclass T
::: | A B C | ; class variables :: | A B C | ; class variables
(printf "initializing....\n") (printf "initializing....\n")
(defun ::: dump() (defun :: dump()
(printf "%d %d %d\n" A B C) (printf "%d %d %d\n" A B C)
) )
@ -139,7 +139,7 @@ do { | k | set k 20; printf "k=%d\n" k; };
) )
) )
(defun x(a b ... ::: x y z) (defun x(a b ... :: x y z)
|i| |i|
; (printf "VA_COUNT(x) = %d\n" (va-count)) ; (printf "VA_COUNT(x) = %d\n" (va-count))

View File

@ -50,7 +50,7 @@
isn't : for method call confliting with key value spearator in a dictionary? isn't : for method call confliting with key value spearator in a dictionary?
default return value for some class methods. default return value for some class methods.
::: method -> return what?? :: method -> return what??
:* method -> return the new instance :* method -> return the new instance
normal method -> return the last evaluated value? normal method -> return the last evaluated value?
@ -93,7 +93,7 @@
(defclass X (defclass X
| x y | ; instance variables | x y | ; instance variables
::: | bob jim | ; class variables :: | bob jim | ; class variables
; instance variables and class variables must not collide with those of parent classes. ; instance variables and class variables must not collide with those of parent classes.
; they must not collide with method names of parent classes ; they must not collide with method names of parent classes
@ -115,7 +115,7 @@
(printf "Y=>%d [%s]\n" a bob) (printf "Y=>%d [%s]\n" a bob)
) )
(defun ::: KK (a b) (defun :: KK (a b)
(printf "K=>%s\n" bob) ; a class method can access class variables but not instance variables (printf "K=>%s\n" bob) ; a class method can access class variables but not instance variables
(return (+ a b)) (return (+ a b))
) )
@ -156,7 +156,7 @@ send the message dump to the object pointed to by x with arguments 1, 2, 3.
(defun get-x() x) (defun get-x() x)
(defun get-y() y) (defun get-y() y)
) )
(defclass X ::: P (defclass X :: P
| x y | | x y |
(defun :* new (a b) (defun :* new (a b)
(super:new) (super:new)
@ -275,7 +275,7 @@ x.show (40, 50);
variadic arguments -> supported variadic arguments -> supported
multiple return variables -> supported multiple return variables -> supported
(defun ff(a b ::: x y z) (defun ff(a b :: x y z)
(set x (+ a b)) (set x (+ a b))
(set y (+ x x)) (set y (+ x x))
(set z (+ 999 x)) (set z (+ 999 x))
@ -285,7 +285,7 @@ multiple return variables -> supported
variadic multiple return variables -> not supported as of now variadic multiple return variables -> not supported as of now
(defun ff(a b ::: x y z ...) <--- can i support something like this??? (defun ff(a b :: x y z ...) <--- can i support something like this???
(set x (+ a b)) (set x (+ a b))
(set y (+ x x)) (set y (+ x x))
(set z (+ 999 x)) (set z (+ 999 x))

View File

@ -86,6 +86,11 @@ hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc
return make_cnode(hcl, HCL_CNODE_TRPCOLONS, flags, loc, tok); return make_cnode(hcl, HCL_CNODE_TRPCOLONS, flags, loc, tok);
} }
hcl_cnode_t* hcl_makecnodedblcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{
return make_cnode(hcl, HCL_CNODE_DBLCOLONS, flags, loc, tok);
}
hcl_cnode_t* hcl_makecnodecolongt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok) hcl_cnode_t* hcl_makecnodecolongt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
{ {
return make_cnode(hcl, HCL_CNODE_COLONGT, flags, loc, tok); return make_cnode(hcl, HCL_CNODE_COLONGT, flags, loc, tok);

View File

@ -2406,7 +2406,7 @@ static int compile_class (hcl_t* hcl, hcl_cnode_t* src, int defclass)
hcl_cnode_t* tmp, * dcl; hcl_cnode_t* tmp, * dcl;
tmp = HCL_CNODE_CONS_CAR(obj); tmp = HCL_CNODE_CONS_CAR(obj);
if (!HCL_CNODE_IS_TRPCOLONS(tmp)) goto no_superclass; if (!HCL_CNODE_IS_DBLCOLONS(tmp)) goto no_superclass;
tmp = obj; tmp = obj;
obj = HCL_CNODE_CONS_CDR(obj); obj = HCL_CNODE_CONS_CDR(obj);
@ -2485,18 +2485,18 @@ static HCL_INLINE int compile_class_p1 (hcl_t* hcl)
hcl_cnode_t* tmp; hcl_cnode_t* tmp;
hcl_oow_t dclcount; hcl_oow_t dclcount;
/* /*
(defclass X ::: T (defclass X :: T
::: | a b c | ## class variables :: | a b c | ## class variables
) )
(defclass X (defclass X
::: T | a b c | ## instance varaiables. :: T | a b c | ## instance varaiables.
) )
(defclass X (defclass X
::: | a b c | ## class variables :: | a b c | ## class variables
) )
*/ */
tmp = HCL_CNODE_CONS_CAR(obj); tmp = HCL_CNODE_CONS_CAR(obj);
if (HCL_CNODE_IS_TRPCOLONS(tmp)) if (HCL_CNODE_IS_DBLCOLONS(tmp))
{ {
/* class variables */ /* class variables */
hcl_oow_t checkpoint; hcl_oow_t checkpoint;
@ -2745,10 +2745,9 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
defun_name = HCL_CNODE_CONS_CAR(obj); defun_name = HCL_CNODE_CONS_CAR(obj);
if (is_in_class_init_scope(hcl)) if (is_in_class_init_scope(hcl))
{ {
if ((HCL_CNODE_IS_TRPCOLONS(defun_name) || HCL_CNODE_IS_COLONSTAR(defun_name))) if ((HCL_CNODE_IS_DBLCOLONS(defun_name) || HCL_CNODE_IS_COLONSTAR(defun_name)))
{ {
/* class method - (defun ::: xxxx () ...) inside class definition */ /* class method - (defun ::xxxx () ...) inside class definition */
/* class method - (defun:+ xxxx() ...) inside class definition */
/* class instantiation method - (defun :*xxxx() ...) inside class definition */ /* class instantiation method - (defun :*xxxx() ...) inside class definition */
obj = HCL_CNODE_CONS_CDR(obj); obj = HCL_CNODE_CONS_CDR(obj);
if (!obj) if (!obj)
@ -2757,7 +2756,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
return -1; return -1;
} }
fun_type = HCL_CNODE_IS_TRPCOLONS(defun_name)? FUN_CM: FUN_CIM; fun_type = HCL_CNODE_IS_DBLCOLONS(defun_name)? FUN_CM: FUN_CIM;
defun_name = HCL_CNODE_CONS_CAR(obj); /* advance to the actual name */ defun_name = HCL_CNODE_CONS_CAR(obj); /* advance to the actual name */
} }
else else
@ -2849,7 +2848,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
} }
else if (va) else if (va)
{ {
if (HCL_CNODE_IS_TRPCOLONS(arg)) if (HCL_CNODE_IS_DBLCOLONS(arg))
{ {
in_ret_args = 1; in_ret_args = 1;
} }
@ -2861,7 +2860,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
} }
else else
{ {
if (HCL_CNODE_IS_TRPCOLONS(arg)) if (HCL_CNODE_IS_DBLCOLONS(arg))
{ {
in_ret_args = 1; in_ret_args = 1;
} }
@ -4609,8 +4608,15 @@ redo:
hcl_setsynerrbfmt (hcl, HCL_SYNERR_TRPCOLONSBANNED, HCL_CNODE_GET_LOC(oprnd), HCL_CNODE_GET_TOK(oprnd), "triple colons disallowed in this context", HCL_CNODE_GET_TYPE(oprnd)); hcl_setsynerrbfmt (hcl, HCL_SYNERR_TRPCOLONSBANNED, HCL_CNODE_GET_LOC(oprnd), HCL_CNODE_GET_TOK(oprnd), "triple colons disallowed in this context", HCL_CNODE_GET_TYPE(oprnd));
return -1; return -1;
case HCL_CNODE_DBLCOLONS:
case HCL_CNODE_COLONLT:
case HCL_CNODE_COLONGT:
case HCL_CNODE_COLONSTAR:
default: default:
/*
hcl_setsynerrbfmt (hcl, HCL_SYNERR_INTERN, HCL_CNODE_GET_LOC(oprnd), HCL_CNODE_GET_TOK(oprnd), "internal error - unexpected object type %d", HCL_CNODE_GET_TYPE(oprnd)); hcl_setsynerrbfmt (hcl, HCL_SYNERR_INTERN, HCL_CNODE_GET_LOC(oprnd), HCL_CNODE_GET_TOK(oprnd), "internal error - unexpected object type %d", HCL_CNODE_GET_TYPE(oprnd));
*/
hcl_setsynerrbfmt (hcl, HCL_SYNERR_BANNED, HCL_CNODE_GET_LOC(oprnd), HCL_CNODE_GET_TOK(oprnd), "prohibited in this context", HCL_CNODE_GET_TYPE(oprnd));
return -1; return -1;
} }
@ -4699,7 +4705,7 @@ static int compile_object_list (hcl_t* hcl)
car = HCL_CNODE_CONS_CAR(oprnd); car = HCL_CNODE_CONS_CAR(oprnd);
/* this optimization is buggy for now... need to perfect the break condition here */ /* this optimization is buggy for now... need to perfect the break condition here */
if (HCL_CNODE_IS_CONS(car) || (HCL_CNODE_IS_SYMBOL(car) && HCL_CNODE_SYMBOL_SYNCODE(car)) || HCL_CNODE_IS_ELLIPSIS(car) || HCL_CNODE_IS_TRPCOLONS(car)) break; if (HCL_CNODE_IS_CONS(car) || (HCL_CNODE_IS_SYMBOL(car) && HCL_CNODE_SYMBOL_SYNCODE(car)) || HCL_CNODE_IS_ELLIPSIS(car) || HCL_CNODE_IS_DBLCOLONS(car)) break;
oprnd = cdr; oprnd = cdr;
} }

View File

@ -258,6 +258,7 @@ enum hcl_cnode_type_t
HCL_CNODE_SUPER, HCL_CNODE_SUPER,
HCL_CNODE_ELLIPSIS, HCL_CNODE_ELLIPSIS,
HCL_CNODE_TRPCOLONS, HCL_CNODE_TRPCOLONS,
HCL_CNODE_DBLCOLONS, /* :: */
HCL_CNODE_COLONGT, /* :> */ HCL_CNODE_COLONGT, /* :> */
HCL_CNODE_COLONLT, /* :< */ HCL_CNODE_COLONLT, /* :< */
HCL_CNODE_COLONSTAR, /* :* */ HCL_CNODE_COLONSTAR, /* :* */
@ -283,6 +284,7 @@ typedef enum hcl_cnode_flagt hcl_cnode_flag_t;
#define HCL_CNODE_IS_ELLIPSIS(x) ((x)->cn_type == HCL_CNODE_ELLIPSIS) #define HCL_CNODE_IS_ELLIPSIS(x) ((x)->cn_type == HCL_CNODE_ELLIPSIS)
#define HCL_CNODE_IS_TRPCOLONS(x) ((x)->cn_type == HCL_CNODE_TRPCOLONS) #define HCL_CNODE_IS_TRPCOLONS(x) ((x)->cn_type == HCL_CNODE_TRPCOLONS)
#define HCL_CNODE_IS_DBLCOLONS(x) ((x)->cn_type == HCL_CNODE_DBLCOLONS)
#define HCL_CNODE_IS_COLONGT(x) ((x)->cn_type == HCL_CNODE_COLONGT) #define HCL_CNODE_IS_COLONGT(x) ((x)->cn_type == HCL_CNODE_COLONGT)
#define HCL_CNODE_IS_COLONLT(x) ((x)->cn_type == HCL_CNODE_COLONLT) #define HCL_CNODE_IS_COLONLT(x) ((x)->cn_type == HCL_CNODE_COLONLT)
#define HCL_CNODE_IS_COLONSTAR(x) ((x)->cn_type == HCL_CNODE_COLONSTAR) #define HCL_CNODE_IS_COLONSTAR(x) ((x)->cn_type == HCL_CNODE_COLONSTAR)
@ -1783,6 +1785,7 @@ hcl_cnode_t* hcl_makecnodeself (hcl_t* hcl, int flags, const hcl_loc_t* loc, con
hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodesuper (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodeellipsis (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodetrpcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodedblcolons (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodecolongt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodecolongt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodecolonlt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodecolonlt (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
hcl_cnode_t* hcl_makecnodecolonstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok); hcl_cnode_t* hcl_makecnodecolonstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);

View File

@ -817,6 +817,7 @@ void hcl_dumpcnode (hcl_t* hcl, hcl_cnode_t* cnode, int newline)
case HCL_CNODE_SUPER: case HCL_CNODE_SUPER:
case HCL_CNODE_ELLIPSIS: case HCL_CNODE_ELLIPSIS:
case HCL_CNODE_TRPCOLONS: case HCL_CNODE_TRPCOLONS:
case HCL_CNODE_DBLCOLONS:
case HCL_CNODE_COLONGT: case HCL_CNODE_COLONGT:
case HCL_CNODE_COLONLT: case HCL_CNODE_COLONLT:
case HCL_CNODE_COLONSTAR: case HCL_CNODE_COLONSTAR:

View File

@ -210,7 +210,7 @@ static HCL_INLINE int is_delimchar (hcl_ooci_t c)
return c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || return c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' ||
c == '|' || c == ',' || c == '.' || c == ':' || c == ';' || c == '|' || c == ',' || c == '.' || c == ':' || c == ';' ||
/* the first characters of tokens in delim_token_tab up to this point */ /* the first characters of tokens in delim_token_tab up to this point */
c == '#' || c == '\"' || c == '\'' || c == '\\' || is_spacechar(c) || c == HCL_UCI_EOF; c == '#' || c == '\"' || c == '\'' || c == '\\' || is_spacechar(c) || c == HCL_OOCI_EOF;
} }
/* TODO: remove this use the one in comp.c */ /* TODO: remove this use the one in comp.c */
@ -1432,6 +1432,10 @@ static int feed_process_token (hcl_t* hcl)
frd->obj = hcl_makecnodetrpcolons(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodetrpcolons(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;
case HCL_TOK_DBLCOLONS:
frd->obj = hcl_makecnodedblcolons(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist;
case HCL_TOK_COLONGT: case HCL_TOK_COLONGT:
frd->obj = hcl_makecnodecolongt(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl)); frd->obj = hcl_makecnodecolongt(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
goto auto_xlist; goto auto_xlist;

View File

@ -21,6 +21,7 @@ check_ERRORS = \
feed-5004.err \ feed-5004.err \
feed-5005.err \ feed-5005.err \
feed-5006.err \ feed-5006.err \
feed-5007.err \
mlist-5001.err \ mlist-5001.err \
var-5001.err \ var-5001.err \
var-5002.err \ var-5002.err \

View File

@ -492,6 +492,7 @@ check_ERRORS = \
feed-5004.err \ feed-5004.err \
feed-5005.err \ feed-5005.err \
feed-5006.err \ feed-5006.err \
feed-5007.err \
mlist-5001.err \ mlist-5001.err \
var-5001.err \ var-5001.err \
var-5002.err \ var-5002.err \

View File

@ -2,7 +2,7 @@ defclass B | x y | {
}; };
defclass X ::: B | a b | { defclass X :: B | a b | {
defun :* new(t) { defun :* new(t) {
| a | | a |
set self.a t; set self.a t;

View File

@ -5,7 +5,7 @@
| J | | J |
defun xxx (x y z defun xxx (x y z
::: r ) { :: r ) {
| k | k
b b

1
t/feed-5007.err Normal file
View File

@ -0,0 +1 @@
printf :*; ##ERROR: syntax error - prohibited in this context

View File

@ -14,7 +14,7 @@ defclass A | a b c | {
defun get-c() { return self.c; }; defun get-c() { return self.c; };
}; };
defclass B ::: A | d e f | { defclass B :: A | d e f | {
defun :*newInstance(x y z) { defun :*newInstance(x y z) {
super:newInstance (* x 2) (* y 2) (* z 2); super:newInstance (* x 2) (* y 2) (* z 2);

View File

@ -6,7 +6,7 @@
set i 100; set i 100;
defun ff(a b ::: x y z) { defun ff(a b :: x y z) {
set x (+ a b i); set x (+ a b i);
set y (+ x x); set y (+ x x);
set z (+ 999 i); set z (+ 999 i);
@ -29,17 +29,17 @@
## test return variables in message sends ## test return variables in message sends
defclass B ::: | X1 X2 | { defclass B :: | X1 X2 | {
set X1 999; set X1 999;
set X2 888; set X2 888;
defun ::: get ( ::: x y) { defun :: get ( :: x y) {
set x X1; set x X1;
set y X2; set y X2;
}; };
defun ::: get2 (inc ::: x y) { defun :: get2 (inc :: x y) {
set x (+ X1 inc); set x (+ X1 inc);
set y (+ X2 inc); set y (+ X2 inc);
}; };

View File

@ -7,7 +7,7 @@ defun fn-y (t1 t2 va-ctx) {
}; };
}; };
defun x(a b ... ::: x y z) { defun x(a b ... :: x y z) {
|i| |i|
set x (va-count); set x (va-count);

View File

@ -1,4 +1,4 @@
(defun x (a b ::: r) (defun x (a b :: r)
| x y | | x y |

View File

@ -1,4 +1,4 @@
defun x (a ::: x y z) { defun x (a :: x y z) {
x := (* a a); x := (* a a);
y := (+ a a); y := (+ a a);
z := (- x y); z := (- x y);