From 48e6df233b86f114165c5ad1884c9ecf8f827b01 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 4 Feb 2024 01:57:53 +0900 Subject: [PATCH] changed ::: to :: to indicate class variables, parent class, retvar --- README.md | 8 ++++---- lang.txt | 12 ++++++------ lib/cnode.c | 5 +++++ lib/comp.c | 34 ++++++++++++++++++++-------------- lib/hcl-prv.h | 3 +++ lib/print.c | 1 + lib/read.c | 6 +++++- t/Makefile.am | 1 + t/Makefile.in | 1 + t/class-5001.err | 2 +- t/feed-01.hcl | 2 +- t/feed-5007.err | 1 + t/insta-01.hcl | 6 +++--- t/retvar-01.hcl | 8 ++++---- t/va-01.hcl | 2 +- t/var-01.hcl | 2 +- t/var-02.hcl | 2 +- 17 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 t/feed-5007.err diff --git a/README.md b/README.md index 7b7effe..7752c7b 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/lang.txt b/lang.txt index dd9ed99..eb0f247 100644 --- a/lang.txt +++ b/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)) diff --git a/lib/cnode.c b/lib/cnode.c index f46aaa8..89026c2 100644 --- a/lib/cnode.c +++ b/lib/cnode.c @@ -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); diff --git a/lib/comp.c b/lib/comp.c index dfe5dbf..9aacf5e 100644 --- a/lib/comp.c +++ b/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; } diff --git a/lib/hcl-prv.h b/lib/hcl-prv.h index 371081e..7c08cce 100644 --- a/lib/hcl-prv.h +++ b/lib/hcl-prv.h @@ -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); diff --git a/lib/print.c b/lib/print.c index d20f171..aa0be5e 100644 --- a/lib/print.c +++ b/lib/print.c @@ -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: diff --git a/lib/read.c b/lib/read.c index 56c0d3f..328dfa5 100644 --- a/lib/read.c +++ b/lib/read.c @@ -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; diff --git a/t/Makefile.am b/t/Makefile.am index cc54066..ad8bd46 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -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 \ diff --git a/t/Makefile.in b/t/Makefile.in index 4ec40f4..8f25d3c 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -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 \ diff --git a/t/class-5001.err b/t/class-5001.err index 4ae97c6..2d2a817 100644 --- a/t/class-5001.err +++ b/t/class-5001.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; diff --git a/t/feed-01.hcl b/t/feed-01.hcl index e53155b..d99db72 100644 --- a/t/feed-01.hcl +++ b/t/feed-01.hcl @@ -5,7 +5,7 @@ | J | defun xxx (x y z - ::: r ) { + :: r ) { | k b diff --git a/t/feed-5007.err b/t/feed-5007.err new file mode 100644 index 0000000..7d5dfe6 --- /dev/null +++ b/t/feed-5007.err @@ -0,0 +1 @@ +printf :*; ##ERROR: syntax error - prohibited in this context diff --git a/t/insta-01.hcl b/t/insta-01.hcl index 1154cf7..0609352 100644 --- a/t/insta-01.hcl +++ b/t/insta-01.hcl @@ -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; diff --git a/t/retvar-01.hcl b/t/retvar-01.hcl index 03d4a77..5506caa 100644 --- a/t/retvar-01.hcl +++ b/t/retvar-01.hcl @@ -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); }; diff --git a/t/va-01.hcl b/t/va-01.hcl index 01d2dbc..01d12ac 100644 --- a/t/va-01.hcl +++ b/t/va-01.hcl @@ -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); diff --git a/t/var-01.hcl b/t/var-01.hcl index 7b15b09..350a338 100644 --- a/t/var-01.hcl +++ b/t/var-01.hcl @@ -1,4 +1,4 @@ -(defun x (a b ::: r) +(defun x (a b :: r) | x y | diff --git a/t/var-02.hcl b/t/var-02.hcl index f3ddf1f..5dc34b2 100644 --- a/t/var-02.hcl +++ b/t/var-02.hcl @@ -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);