changed ::: to :: to indicate class variables, parent class, retvar
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
b20d6b14d8
commit
48e6df233b
@ -49,7 +49,7 @@ do { | k | set k 20; printf "k=%d\n" k; };
|
||||
- function calls `( )`
|
||||
- message sends `(: )`
|
||||
- variable declaration `| |`
|
||||
- class variable delcarations `::: | |`
|
||||
- class variable delcarations `:: | |`
|
||||
|
||||
## Builtin functions
|
||||
|
||||
@ -98,11 +98,11 @@ do { | k | set k 20; printf "k=%d\n" k; };
|
||||
|
||||
```
|
||||
(defclass T
|
||||
::: | A B C | ; class variables
|
||||
:: | A B C | ; class variables
|
||||
|
||||
(printf "initializing....\n")
|
||||
|
||||
(defun ::: dump()
|
||||
(defun :: dump()
|
||||
(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|
|
||||
|
||||
; (printf "VA_COUNT(x) = %d\n" (va-count))
|
||||
|
12
lang.txt
12
lang.txt
@ -50,7 +50,7 @@
|
||||
isn't : for method call confliting with key value spearator in a dictionary?
|
||||
|
||||
default return value for some class methods.
|
||||
::: method -> return what??
|
||||
:: method -> return what??
|
||||
:* method -> return the new instance
|
||||
normal method -> return the last evaluated value?
|
||||
|
||||
@ -93,7 +93,7 @@
|
||||
(defclass X
|
||||
|
||||
| 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.
|
||||
; they must not collide with method names of parent classes
|
||||
@ -115,7 +115,7 @@
|
||||
(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
|
||||
(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-y() y)
|
||||
)
|
||||
(defclass X ::: P
|
||||
(defclass X :: P
|
||||
| x y |
|
||||
(defun :* new (a b)
|
||||
(super:new)
|
||||
@ -275,7 +275,7 @@ x.show (40, 50);
|
||||
variadic arguments -> supported
|
||||
|
||||
multiple return variables -> supported
|
||||
(defun ff(a b ::: x y z)
|
||||
(defun ff(a b :: x y z)
|
||||
(set x (+ a b))
|
||||
(set y (+ x x))
|
||||
(set z (+ 999 x))
|
||||
@ -285,7 +285,7 @@ multiple return variables -> supported
|
||||
|
||||
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 y (+ x x))
|
||||
(set z (+ 999 x))
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return make_cnode(hcl, HCL_CNODE_COLONGT, flags, loc, tok);
|
||||
|
34
lib/comp.c
34
lib/comp.c
@ -2406,7 +2406,7 @@ static int compile_class (hcl_t* hcl, hcl_cnode_t* src, int defclass)
|
||||
hcl_cnode_t* tmp, * dcl;
|
||||
|
||||
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;
|
||||
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_oow_t dclcount;
|
||||
/*
|
||||
(defclass X ::: T
|
||||
::: | a b c | ## class variables
|
||||
(defclass X :: T
|
||||
:: | a b c | ## class variables
|
||||
)
|
||||
(defclass X
|
||||
::: T | a b c | ## instance varaiables.
|
||||
:: T | a b c | ## instance varaiables.
|
||||
)
|
||||
(defclass X
|
||||
::: | a b c | ## class variables
|
||||
:: | a b c | ## class variables
|
||||
)
|
||||
*/
|
||||
tmp = HCL_CNODE_CONS_CAR(obj);
|
||||
if (HCL_CNODE_IS_TRPCOLONS(tmp))
|
||||
if (HCL_CNODE_IS_DBLCOLONS(tmp))
|
||||
{
|
||||
/* class variables */
|
||||
hcl_oow_t checkpoint;
|
||||
@ -2745,11 +2745,10 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
|
||||
defun_name = HCL_CNODE_CONS_CAR(obj);
|
||||
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 instantiation method - (defun:* xxxx() ...) inside class definition */
|
||||
/* class method - (defun ::xxxx () ...) inside class definition */
|
||||
/* class instantiation method - (defun :*xxxx() ...) inside class definition */
|
||||
obj = HCL_CNODE_CONS_CDR(obj);
|
||||
if (!obj)
|
||||
{
|
||||
@ -2757,7 +2756,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
|
||||
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 */
|
||||
}
|
||||
else
|
||||
@ -2849,7 +2848,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
|
||||
}
|
||||
else if (va)
|
||||
{
|
||||
if (HCL_CNODE_IS_TRPCOLONS(arg))
|
||||
if (HCL_CNODE_IS_DBLCOLONS(arg))
|
||||
{
|
||||
in_ret_args = 1;
|
||||
}
|
||||
@ -2861,7 +2860,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (HCL_CNODE_IS_TRPCOLONS(arg))
|
||||
if (HCL_CNODE_IS_DBLCOLONS(arg))
|
||||
{
|
||||
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));
|
||||
return -1;
|
||||
|
||||
case HCL_CNODE_DBLCOLONS:
|
||||
case HCL_CNODE_COLONLT:
|
||||
case HCL_CNODE_COLONGT:
|
||||
case HCL_CNODE_COLONSTAR:
|
||||
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_BANNED, HCL_CNODE_GET_LOC(oprnd), HCL_CNODE_GET_TOK(oprnd), "prohibited in this context", HCL_CNODE_GET_TYPE(oprnd));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -4699,7 +4705,7 @@ static int compile_object_list (hcl_t* hcl)
|
||||
|
||||
car = HCL_CNODE_CONS_CAR(oprnd);
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -258,6 +258,7 @@ enum hcl_cnode_type_t
|
||||
HCL_CNODE_SUPER,
|
||||
HCL_CNODE_ELLIPSIS,
|
||||
HCL_CNODE_TRPCOLONS,
|
||||
HCL_CNODE_DBLCOLONS, /* :: */
|
||||
HCL_CNODE_COLONGT, /* :> */
|
||||
HCL_CNODE_COLONLT, /* :< */
|
||||
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_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_COLONLT(x) ((x)->cn_type == HCL_CNODE_COLONLT)
|
||||
#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_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_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_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);
|
||||
|
@ -817,6 +817,7 @@ void hcl_dumpcnode (hcl_t* hcl, hcl_cnode_t* cnode, int newline)
|
||||
case HCL_CNODE_SUPER:
|
||||
case HCL_CNODE_ELLIPSIS:
|
||||
case HCL_CNODE_TRPCOLONS:
|
||||
case HCL_CNODE_DBLCOLONS:
|
||||
case HCL_CNODE_COLONGT:
|
||||
case HCL_CNODE_COLONLT:
|
||||
case HCL_CNODE_COLONSTAR:
|
||||
|
@ -210,7 +210,7 @@ static HCL_INLINE int is_delimchar (hcl_ooci_t c)
|
||||
return c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' ||
|
||||
c == '|' || c == ',' || c == '.' || c == ':' || c == ';' ||
|
||||
/* 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 */
|
||||
@ -1432,6 +1432,10 @@ static int feed_process_token (hcl_t* hcl)
|
||||
frd->obj = hcl_makecnodetrpcolons(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
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:
|
||||
frd->obj = hcl_makecnodecolongt(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
goto auto_xlist;
|
||||
|
@ -21,6 +21,7 @@ check_ERRORS = \
|
||||
feed-5004.err \
|
||||
feed-5005.err \
|
||||
feed-5006.err \
|
||||
feed-5007.err \
|
||||
mlist-5001.err \
|
||||
var-5001.err \
|
||||
var-5002.err \
|
||||
|
@ -492,6 +492,7 @@ check_ERRORS = \
|
||||
feed-5004.err \
|
||||
feed-5005.err \
|
||||
feed-5006.err \
|
||||
feed-5007.err \
|
||||
mlist-5001.err \
|
||||
var-5001.err \
|
||||
var-5002.err \
|
||||
|
@ -2,7 +2,7 @@ defclass B | x y | {
|
||||
|
||||
};
|
||||
|
||||
defclass X ::: B | a b | {
|
||||
defclass X :: B | a b | {
|
||||
defun :* new(t) {
|
||||
| a |
|
||||
set self.a t;
|
||||
|
@ -5,7 +5,7 @@
|
||||
| J |
|
||||
|
||||
defun xxx (x y z
|
||||
::: r ) {
|
||||
:: r ) {
|
||||
|
||||
| k
|
||||
b
|
||||
|
1
t/feed-5007.err
Normal file
1
t/feed-5007.err
Normal file
@ -0,0 +1 @@
|
||||
printf :*; ##ERROR: syntax error - prohibited in this context
|
@ -2,7 +2,7 @@
|
||||
|
||||
defclass A | a b c | {
|
||||
|
||||
defun:*newInstance(x y z) {
|
||||
defun :*newInstance(x y z) {
|
||||
set a x;
|
||||
set b y;
|
||||
set c z;
|
||||
@ -14,9 +14,9 @@ defclass A | a b 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);
|
||||
set d x;
|
||||
set e y;
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
set i 100;
|
||||
|
||||
defun ff(a b ::: x y z) {
|
||||
defun ff(a b :: x y z) {
|
||||
set x (+ a b i);
|
||||
set y (+ x x);
|
||||
set z (+ 999 i);
|
||||
@ -29,17 +29,17 @@
|
||||
|
||||
|
||||
## test return variables in message sends
|
||||
defclass B ::: | X1 X2 | {
|
||||
defclass B :: | X1 X2 | {
|
||||
|
||||
set X1 999;
|
||||
set X2 888;
|
||||
|
||||
defun ::: get ( ::: x y) {
|
||||
defun :: get ( :: x y) {
|
||||
set x X1;
|
||||
set y X2;
|
||||
};
|
||||
|
||||
defun ::: get2 (inc ::: x y) {
|
||||
defun :: get2 (inc :: x y) {
|
||||
set x (+ X1 inc);
|
||||
set y (+ X2 inc);
|
||||
};
|
||||
|
@ -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|
|
||||
|
||||
set x (va-count);
|
||||
|
@ -1,4 +1,4 @@
|
||||
(defun x (a b ::: r)
|
||||
(defun x (a b :: r)
|
||||
|
||||
| x y |
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
defun x (a ::: x y z) {
|
||||
defun x (a :: x y z) {
|
||||
x := (* a a);
|
||||
y := (+ a a);
|
||||
z := (- x y);
|
||||
|
Loading…
Reference in New Issue
Block a user