This commit is contained in:
parent
9aa1bde1a1
commit
c2928615a4
6
lang.txt
6
lang.txt
@ -51,7 +51,7 @@
|
||||
|
||||
default return value for some class methods.
|
||||
::: method -> return what??
|
||||
::* method -> return the new instance
|
||||
:* method -> return the new instance
|
||||
normal method -> return the last evaluated value?
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ send the message dump to the object pointed to by x with arguments 1, 2, 3.
|
||||
|
||||
(defclass P
|
||||
| x y |
|
||||
(defun ::* new ()
|
||||
(defun :* new ()
|
||||
(set x 1)
|
||||
(set y 1)
|
||||
(return self)
|
||||
@ -158,7 +158,7 @@ send the message dump to the object pointed to by x with arguments 1, 2, 3.
|
||||
)
|
||||
(defclass X ::: P
|
||||
| x y |
|
||||
(defun ::* new (a b)
|
||||
(defun :* new (a b)
|
||||
(super:new)
|
||||
x = a
|
||||
y = b
|
||||
|
@ -86,9 +86,14 @@ 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_makecnodedcstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
hcl_cnode_t* hcl_makecnodecolonplus (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
{
|
||||
return make_cnode(hcl, HCL_CNODE_DCSTAR, flags, loc, tok);
|
||||
return make_cnode(hcl, HCL_CNODE_COLONPLUS, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecolonstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok)
|
||||
{
|
||||
return make_cnode(hcl, HCL_CNODE_COLONSTAR, flags, loc, tok);
|
||||
}
|
||||
|
||||
hcl_cnode_t* hcl_makecnodecharlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooch_t v)
|
||||
|
@ -2745,10 +2745,11 @@ 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_DCSTAR(defun_name)))
|
||||
if ((HCL_CNODE_IS_TRPCOLONS(defun_name) || HCL_CNODE_IS_COLONSTAR(defun_name)))
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
|
@ -187,8 +187,9 @@ enum hcl_tok_type_t
|
||||
HCL_TOK_COLON, /* : */
|
||||
HCL_TOK_DBLCOLONS, /* :: */
|
||||
HCL_TOK_TRPCOLONS, /* ::: */
|
||||
HCL_TOK_DCSTAR, /* ::* */
|
||||
HCL_TOK_COLONEQ, /* := */
|
||||
HCL_TOK_COLONPLUS, /* :+ */
|
||||
HCL_TOK_COLONSTAR, /* :* */
|
||||
HCL_TOK_SEMICOLON, /* ; */
|
||||
HCL_TOK_COMMA, /* , */
|
||||
HCL_TOK_LPAREN, /* ( */
|
||||
@ -256,7 +257,8 @@ enum hcl_cnode_type_t
|
||||
HCL_CNODE_SUPER,
|
||||
HCL_CNODE_ELLIPSIS,
|
||||
HCL_CNODE_TRPCOLONS,
|
||||
HCL_CNODE_DCSTAR,
|
||||
HCL_CNODE_COLONPLUS, /* :+ */
|
||||
HCL_CNODE_COLONSTAR, /* :* */
|
||||
|
||||
HCL_CNODE_CONS,
|
||||
HCL_CNODE_ELIST, /* empty list */
|
||||
@ -279,7 +281,8 @@ 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_DCSTAR(x) ((x)->cn_type == HCL_CNODE_DCSTAR)
|
||||
#define HCL_CNODE_IS_COLONPLUS(x) ((x)->cn_type == HCL_CNODE_COLONPLUS)
|
||||
#define HCL_CNODE_IS_COLONSTAR(x) ((x)->cn_type == HCL_CNODE_COLONSTAR)
|
||||
|
||||
#define HCL_CNODE_IS_SYMBOL(x) ((x)->cn_type == HCL_CNODE_SYMBOL)
|
||||
#define HCL_CNODE_IS_SYMBOL_PLAIN(x) ((x)->cn_type == HCL_CNODE_SYMBOL && (x)->u.symbol.syncode == 0)
|
||||
@ -1777,7 +1780,8 @@ 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_makecnodedcstar (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
|
||||
hcl_cnode_t* hcl_makecnodecolonplus (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_makecnodecharlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_ooch_t v);
|
||||
hcl_cnode_t* hcl_makecnodebchrlit (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok, hcl_oob_t v);
|
||||
hcl_cnode_t* hcl_makecnodesymbol (hcl_t* hcl, int flags, const hcl_loc_t* loc, const hcl_oocs_t* tok);
|
||||
|
@ -817,7 +817,8 @@ 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_DCSTAR:
|
||||
case HCL_CNODE_COLONSTAR:
|
||||
case HCL_CNODE_COLONPLUS:
|
||||
hcl_logbfmt (hcl, HCL_LOG_FATAL, " %.*js ", HCL_CNODE_GET_TOKLEN(cnode), HCL_CNODE_GET_TOKPTR(cnode));
|
||||
break;
|
||||
|
||||
|
11
lib/read.c
11
lib/read.c
@ -1432,8 +1432,12 @@ 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_DCSTAR:
|
||||
frd->obj = hcl_makecnodedcstar(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
case HCL_TOK_COLONPLUS:
|
||||
frd->obj = hcl_makecnodecolonplus(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
goto auto_xlist;
|
||||
|
||||
case HCL_TOK_COLONSTAR:
|
||||
frd->obj = hcl_makecnodecolonstar(hcl, 0, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||
goto auto_xlist;
|
||||
|
||||
case HCL_TOK_SMPTRLIT:
|
||||
@ -1652,8 +1656,9 @@ static delim_token_t delim_token_tab[] =
|
||||
|
||||
{ ":", 1, HCL_TOK_COLON }, /* key-value separator in dictionary */
|
||||
{ ":=", 2, HCL_TOK_COLONEQ }, /* assignment */
|
||||
{ ":+", 2, HCL_TOK_COLONPLUS },
|
||||
{ ":*", 2, HCL_TOK_COLONSTAR }, /* class instantiation method */
|
||||
{ "::", 2, HCL_TOK_DBLCOLONS },
|
||||
{ "::*", 3, HCL_TOK_DCSTAR }, /* class instantiation method */
|
||||
{ ":::", 3, HCL_TOK_TRPCOLONS }, /* superclass, class variables, class methods */
|
||||
|
||||
{ ";", 1, HCL_TOK_SEMICOLON }
|
||||
|
@ -3,7 +3,7 @@ defclass B | x y | {
|
||||
};
|
||||
|
||||
defclass X ::: B | a b | {
|
||||
defun ::* new(t) {
|
||||
defun :* new(t) {
|
||||
| a |
|
||||
set self.a t;
|
||||
set a 100;
|
||||
|
@ -32,7 +32,7 @@ if (= k 70) {
|
||||
## --------------------------------------
|
||||
|
||||
defclass A | a b c | {
|
||||
defun ::* newInstance(x y z) {
|
||||
defun :* newInstance(x y z) {
|
||||
(set a x)
|
||||
(set b y)
|
||||
(set c z)
|
||||
|
@ -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;
|
||||
@ -16,7 +16,7 @@ defclass A | a b c | {
|
||||
|
||||
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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
set t (
|
||||
class | x | {
|
||||
defun ::* make() { set x 1234; return self; };
|
||||
defun :* make() { set x 1234; return self; };
|
||||
defun get-x() { return x };
|
||||
}
|
||||
);
|
||||
|
@ -68,7 +68,7 @@
|
||||
(defclass T
|
||||
| j |
|
||||
|
||||
(defun ::* new()
|
||||
(defun :* new()
|
||||
(set j 99)
|
||||
(return self)
|
||||
)
|
||||
|
@ -1,5 +1,5 @@
|
||||
defclass A | a | {
|
||||
defun ::* init1() {
|
||||
defun :* init1() {
|
||||
| b |
|
||||
set b (+ 1 2);
|
||||
set a b;
|
||||
@ -15,7 +15,7 @@ defclass A | a | {
|
||||
printf ">>> %d\n" j;
|
||||
}
|
||||
|
||||
defun ::* init2() {
|
||||
defun :* init2() {
|
||||
| b |
|
||||
set b (+ 10 20);
|
||||
set a b;
|
||||
|
Loading…
Reference in New Issue
Block a user