diff --git a/moo/README.md b/moo/README.md index ea5e410..8bf1e69 100644 --- a/moo/README.md +++ b/moo/README.md @@ -70,7 +70,14 @@ class MyClass(Object) k := if (i < 20) { 30 } else { 40 }. if (a < 10) { ... } -elsif (a < 20) { ... } +elif (a < 20) { ... } +else { ... }. + +ifnot (i < 20) { 30 } else { 40 }. +nif (i < 20) { 30 } else { 40 }. + +if (a < 10) { .. } +elifnot (a > 20) { ... } else { ... }. ~~~ diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index 0423b89..b4bb117 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -167,10 +167,10 @@ class(#pointer) Array(SequenceableCollection) s := anArray size. if (start < 0) { start := 0 } - elsif (start >= s) { start := s - 1 }. + elif (start >= s) { start := s - 1 }. if (end < 0) { end := 0 } - elsif (end >= s) { end := s - 1 }. + elif (end >= s) { end := s - 1 }. */ i := 0. ss := self size. @@ -457,11 +457,11 @@ class(#byte) ByteArray(Array) | firstByte | firstByte := self at: 0. if ((firstByte bitAnd:2r10000000) == 0) { 1 } - elsif (firstByte bitAnd:2r11000000) == 2r10000000) { 2 } - elsif (firstByte bitAnd:2r11100000) == 2r11000000) { 3 } - elsif (firstByte bitAnd:2r11110000) == 2r11100000) { 4 } - elsif (firstByte bitAnd:2r11111000) == 2r11110000) { 5 } - elsif (firstByte bitAnd:2r11111100) == 2r11111000) { 6 }. + elif (firstByte bitAnd:2r11000000) == 2r10000000) { 2 } + elif (firstByte bitAnd:2r11100000) == 2r11000000) { 3 } + elif (firstByte bitAnd:2r11110000) == 2r11100000) { 4 } + elif (firstByte bitAnd:2r11111000) == 2r11110000) { 5 } + elif (firstByte bitAnd:2r11111100) == 2r11111000) { 6 }. */ } } diff --git a/moo/kernel/Except.moo b/moo/kernel/Except.moo index bc1f2b2..36a5ea2 100644 --- a/moo/kernel/Except.moo +++ b/moo/kernel/Except.moo @@ -514,8 +514,8 @@ extend Apex //# TODO: convert an exception to a more specific one depending on the error code. //#if (ec == Error.Code.ERANGE) { self index: index outOfRange: (self basicSize) } - //# elsif (ec == Error.Code.EPERM) { self messageProhibited: method name } - //# elsif (ec == Error.Code.ENOIMPL) { self subclassResponsibility: method name }. + //# elif (ec == Error.Code.EPERM) { self messageProhibited: method name } + //# elif (ec == Error.Code.ENOIMPL) { self subclassResponsibility: method name }. (PrimitiveFailureException /* in: method */ withErrorCode: ec) signal: msg. } diff --git a/moo/kernel/Magnitu.moo b/moo/kernel/Magnitu.moo index bf6b57b..c7a43b7 100644 --- a/moo/kernel/Magnitu.moo +++ b/moo/kernel/Magnitu.moo @@ -92,11 +92,11 @@ class(#limited) Character(Magnitude) { ^self asInteger - $0 asInteger } - elsif ((self >= $A) and (self <= $Z)) + elif ((self >= $A) and (self <= $Z)) { ^self asInteger - $A asInteger + 10 } - elsif ((self >= $a) and (self <= $z)) + elif ((self >= $a) and (self <= $z)) { ^self asInteger - $a asInteger + 10 }. @@ -359,7 +359,7 @@ class(#limited) Number(Magnitude) /* self < 0 ifTrue: [^-1]. self > 0 ifTrue: [^1]. ^0.*/ - ^if (self < 0) { -1 } elsif (self > 0) { 1 } else { 0 } + ^if (self < 0) { -1 } elif (self > 0) { 1 } else { 0 } } } diff --git a/moo/kernel/Mill.moo b/moo/kernel/Mill.moo index 1a0b0b8..6176b54 100644 --- a/moo/kernel/Mill.moo +++ b/moo/kernel/Mill.moo @@ -113,15 +113,15 @@ class MyObject(Object) System logNl: "XXXXXXXXX". 1111 } - elsif ("abcd" ~= "abcd") + elif ("abcd" ~= "abcd") { System logNl: "second if". } - elsif ([k := 20. System logNl: "k => " & (k asString). k + 20. true] value) + elif ([k := 20. System logNl: "k => " & (k asString). k + 20. true] value) { System logNl: "THIRID forever............." & (k asString) } - elsif (true = true) + elif (true = true) { System logNl: "forever............." } @@ -168,7 +168,7 @@ class MyObject(Object) }.*/ - a := if(false) { 10 } elsif (false) { 20 } elsif (false) { 30} else { 40}. + a := if(false) { 10 } elif (false) { 20 } elif (false) { 30} else { 40}. //a := if(false) { 999 } else { 888 }. a dump. diff --git a/moo/kernel/Process.moo b/moo/kernel/Process.moo index c7b7fe2..5c96d63 100644 --- a/moo/kernel/Process.moo +++ b/moo/kernel/Process.moo @@ -231,7 +231,7 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit // if the internal semaphore has been signaled, // arrange to return nil to indicate timeout. if (r == s) { r := nil } // timed out - elsif (r signalAction notNil) { r signalAction value: r }. // run the signal action block + elif (r signalAction notNil) { r signalAction value: r }. // run the signal action block ] ensure: [ // System< 255) { Exception signal: ('invalid IPv4 address B ' & str). }. digits := digits + 1. } - elsif (c == $.) + elif (c == $.) { if (dots >= 3 or: [digits == 0]) { ^Error.Code.EINVAL }. self basicAt: (dots + address_offset) put: acc. @@ -151,7 +151,7 @@ class(#byte(16)) IP6Address(IP4Address) colonpos := tgpos. continue. } - elsif (pos >= size) + elif (pos >= size) { // a colon can't be the last character ^Error.Code.EINVAL @@ -194,7 +194,7 @@ class(#byte(16)) IP6Address(IP4Address) self basicShiftFrom: colonpos to: (colonpos + (mysize - tgpos)) count: (tgpos - colonpos). //tgpos := tgpos + (mysize - tgpos). } - elsif (tgpos ~~ mysize) + elif (tgpos ~~ mysize) { ^Error.Code.EINVAL }. @@ -379,7 +379,7 @@ class SyncSocket(Socket) self __wait_for_output. soerr := self _socketError. if (soerr == 0) { break } - elsif (soerr > 0) + elif (soerr > 0) { Exception signal: ('unable to connect - error ' & soerr asString). }. diff --git a/moo/kernel/X11.moo b/moo/kernel/X11.moo index e1c6573..76ee5bd 100644 --- a/moo/kernel/X11.moo +++ b/moo/kernel/X11.moo @@ -432,7 +432,7 @@ class X11.Button(X11.Label) self.bgcolor := x. self onPaintEvent: llevent. } - elsif (type == X11.LLEventType.BUTTON_RELEASE) + elif (type == X11.LLEventType.BUTTON_RELEASE) { x := self.fgcolor. self.fgcolor := self.bgcolor. diff --git a/moo/lib/comp.c b/moo/lib/comp.c index d749f1a..9c5c55d 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -121,9 +121,9 @@ static struct voca_t { 8, { 'c','o','n','t','i','n','u','e' } }, { 2, { 'd','o' } }, { 5, { '#','d','u','a','l' } }, + { 4, { 'e','l','i','f' } }, + { 7, { 'e','l','i','f','n','o','t' } }, { 4, { 'e','l','s','e' } }, - { 5, { 'e','l','s','i','f' } }, - { 8, { 'e','l','s','i','f','n','o','t' } }, { 6, { 'e','n','s','u','r','e', } }, { 9, { 'e','x','c','e','p','t','i','o','n' } }, { 6, { 'e','x','t','e','n','d' } }, @@ -131,6 +131,7 @@ static struct voca_t { 6, { '#','f','i','n','a','l' } }, { 4, { 'f','r','o','m' } }, { 4, { '#','g','e','t' } }, + { 4, { 'g','o','t','o' } }, { 9, { '#','h','a','l','f','w','o','r','d' } }, { 2, { 'i','f' } }, { 5, { 'i','f','n','o','t' } }, @@ -189,9 +190,9 @@ enum voca_id_t VOCA_CONTINUE, VOCA_DO, VOCA_DUAL_S, + VOCA_ELIF, + VOCA_ELIFNOT, VOCA_ELSE, - VOCA_ELSIF, - VOCA_ELSIFNOT, VOCA_ENSURE, VOCA_EXCEPTION, VOCA_EXTEND, @@ -199,6 +200,7 @@ enum voca_id_t VOCA_FINAL_S, VOCA_FROM, VOCA_GET_S, + VOCA_GOTO, VOCA_HALFWORD_S, VOCA_IF, VOCA_IFNOT, @@ -376,33 +378,45 @@ static MOO_INLINE int is_word (const moo_oocs_t* oocs, voca_id_t id) moo_equal_oochars(oocs->ptr, vocas[id].str, vocas[id].len); } -static int is_reserved_word (const moo_oocs_t* ucs) +static int is_reserved_word (const moo_oocs_t* ucs, moo_iotok_type_t* token_type) { - static int rw[] = + static struct { - VOCA_SELF, - VOCA_SUPER, - VOCA_NIL, - VOCA_TRUE, - VOCA_FALSE, - VOCA_THIS_CONTEXT, - VOCA_THIS_PROCESS, - VOCA_SELFNS, - VOCA_IF, - VOCA_ELSE, - VOCA_ELSIF, - VOCA_ELSIFNOT, - VOCA_WHILE, - VOCA_UNTIL, - VOCA_DO, - VOCA_BREAK, - VOCA_CONTINUE + voca_id_t voca_id; + moo_iotok_type_t token_type; + } rw[] = + { + { VOCA_SELF, MOO_IOTOK_SELF }, + { VOCA_SUPER, MOO_IOTOK_SUPER }, + { VOCA_NIL, MOO_IOTOK_NIL }, + { VOCA_TRUE, MOO_IOTOK_TRUE }, + { VOCA_FALSE, MOO_IOTOK_FALSE }, + { VOCA_THIS_CONTEXT, MOO_IOTOK_THIS_CONTEXT }, + { VOCA_THIS_PROCESS, MOO_IOTOK_THIS_PROCESS }, + { VOCA_SELFNS, MOO_IOTOK_SELFNS }, + { VOCA_IF, MOO_IOTOK_IF }, + { VOCA_IFNOT, MOO_IOTOK_IFNOT }, + { VOCA_ELIF, MOO_IOTOK_ELIF }, + { VOCA_ELIFNOT, MOO_IOTOK_ELIFNOT }, + { VOCA_ELSE, MOO_IOTOK_ELSE }, + { VOCA_WHILE, MOO_IOTOK_WHILE }, + { VOCA_UNTIL, MOO_IOTOK_UNTIL }, + { VOCA_DO, MOO_IOTOK_DO }, + { VOCA_BREAK, MOO_IOTOK_BREAK }, + { VOCA_CONTINUE, MOO_IOTOK_CONTINUE }, + { VOCA_GOTO, MOO_IOTOK_GOTO }, + { VOCA_AND, MOO_IOTOK_AND }, + { VOCA_OR, MOO_IOTOK_OR } }; int i; for (i = 0; i < MOO_COUNTOF(rw); i++) { - if (is_word(ucs, rw[i])) return 1; + if (is_word(ucs, rw[i].voca_id)) + { + if (token_type) *token_type = rw[i].token_type; + return 1; + } } return 0; @@ -1297,6 +1311,8 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) } else { + moo_iotok_type_t token_type; + if (c == '.') { moo_iolxc_t period; @@ -1334,86 +1350,10 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) unget_char (moo, &moo->c->lxc); } - /* handle reserved words */ - if (is_token_word(moo, VOCA_SELF)) + if (is_reserved_word(TOKEN_NAME(moo), &token_type)) { - SET_TOKEN_TYPE (moo, MOO_IOTOK_SELF); - } - else if (is_token_word(moo, VOCA_SUPER)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_SUPER); - } - else if (is_token_word(moo, VOCA_NIL)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_NIL); - } - else if (is_token_word(moo, VOCA_TRUE)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_TRUE); - } - else if (is_token_word(moo, VOCA_FALSE)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_FALSE); - } - else if (is_token_word(moo, VOCA_THIS_CONTEXT)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_THIS_CONTEXT); - } - else if (is_token_word(moo, VOCA_THIS_PROCESS)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_THIS_PROCESS); - } - else if (is_token_word(moo, VOCA_SELFNS)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_SELFNS); - } - else if (is_token_word(moo, VOCA_IF)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_IF); - } - else if (is_token_word(moo, VOCA_IFNOT)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_IFNOT); - } - else if (is_token_word(moo, VOCA_ELSE)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_ELSE); - } - else if (is_token_word(moo, VOCA_ELSIF)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_ELSIF); - } - else if (is_token_word(moo, VOCA_ELSIFNOT)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_ELSIFNOT); - } - else if (is_token_word(moo, VOCA_WHILE)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_WHILE); - } - else if (is_token_word(moo, VOCA_UNTIL)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_UNTIL); - } - else if (is_token_word(moo, VOCA_DO)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_DO); - } - else if (is_token_word(moo, VOCA_BREAK)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_BREAK); - } - else if (is_token_word(moo, VOCA_CONTINUE)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_CONTINUE); - } - else if (is_token_word(moo, VOCA_AND)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_AND); - } - else if (is_token_word(moo, VOCA_OR)) - { - SET_TOKEN_TYPE (moo, MOO_IOTOK_OR); + /* handle reserved words */ + SET_TOKEN_TYPE (moo, token_type); } } @@ -3551,7 +3491,7 @@ static int preprocess_dotted_name (moo_t* moo, int flags, moo_oop_nsdic_t topdic seg.len = dot - ptr; - if (is_reserved_word(&seg)) goto wrong_name; + if (is_reserved_word(&seg, MOO_NULL)) goto wrong_name; ass = moo_lookupdic(moo, (moo_oop_dic_t)dic, &seg); if (ass) @@ -3621,7 +3561,7 @@ static int preprocess_dotted_name (moo_t* moo, int flags, moo_oop_nsdic_t topdic /* this is the last segment. it should be a class name or an item name */ seg.len = len; - if (is_reserved_word(&seg)) goto wrong_name; + if (is_reserved_word(&seg, MOO_NULL)) goto wrong_name; *name = seg; *ns_oop = dic; @@ -4508,7 +4448,7 @@ static MOO_INLINE int find_dotted_ident (moo_t* moo, const moo_oocs_t* name, con last.ptr = name->ptr + pxlen + 1; last.len = name->len - pxlen - 1; - if (is_reserved_word(&last)) + if (is_reserved_word(&last, MOO_NULL)) { /* self. is followed by a reserved word. * a proper variable name is expected. */ @@ -6246,9 +6186,9 @@ static int compile_if_expression (moo_t* moo) GET_TOKEN (moo); /* get the next token after } */ - if (TOKEN_TYPE(moo) != MOO_IOTOK_ELSIF && TOKEN_TYPE(moo) != MOO_IOTOK_ELSIFNOT) break; + if (TOKEN_TYPE(moo) != MOO_IOTOK_ELIF && TOKEN_TYPE(moo) != MOO_IOTOK_ELIFNOT) break; - if (TOKEN_TYPE(moo) == MOO_IOTOK_ELSIF) + if (TOKEN_TYPE(moo) == MOO_IOTOK_ELIF) { push_true_inst = BCODE_PUSH_TRUE; push_false_inst = BCODE_PUSH_FALSE; @@ -6549,7 +6489,7 @@ static int compile_method_expression (moo_t* moo, int pop) /* * method-expression := method-assignment-expression | basic-expression | if-expression | while-expression | do-while-expression * method-assignment-expression := identifier ":=" method-expression - * if-expression := if ( ) { } elsif { } else { } + * if-expression := if ( ) { } elif { } else { } * while-expression := while () {} * do-while-expression := do { } while () */ diff --git a/moo/lib/debug.c b/moo/lib/debug.c index 1423e0a..39f3c87 100644 --- a/moo/lib/debug.c +++ b/moo/lib/debug.c @@ -128,7 +128,7 @@ int moo_addfiletodbgi (moo_t* moo, const moo_ooch_t* file_name, moo_oow_t* start if (!moo->dbgi) { - if (start_offset) *start_offset = MOO_NULL; + if (start_offset) *start_offset = 0; return 0; /* debug information is disabled*/ } diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 8fe95ff..3de0e89 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -2279,7 +2279,7 @@ static moo_pfrc_t pf_method_get_ip_source_line (moo_t* moo, moo_mod_t* mod, moo_ moo_oop_method_t rcv; moo_oop_t ip; moo_dbgi_method_t* di; - moo_oow_t retv = MOO_SMOOI_TO_OOP(0); + moo_oop_t retv = MOO_SMOOI_TO_OOP(0); rcv = (moo_oop_method_t)MOO_STACK_GETRCV(moo, nargs); MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo, rcv) == moo->_method); @@ -2310,7 +2310,7 @@ static moo_pfrc_t pf_method_get_source_line (moo_t* moo, moo_mod_t* mod, moo_ooi { moo_oop_method_t rcv; moo_dbgi_method_t* di; - moo_oow_t retv = MOO_SMOOI_TO_OOP(0); + moo_oop_t retv = MOO_SMOOI_TO_OOP(0); rcv = (moo_oop_method_t)MOO_STACK_GETRCV(moo, nargs); MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo, rcv) == moo->_method); @@ -2322,7 +2322,7 @@ static moo_pfrc_t pf_method_get_source_line (moo_t* moo, moo_mod_t* mod, moo_ooi if (!retv) return MOO_PF_FAILURE; } - MOO_STACK_SETRET (moo, nargs,retv); + MOO_STACK_SETRET (moo, nargs, retv); return MOO_PF_SUCCESS; } diff --git a/moo/lib/moo-prv.h b/moo/lib/moo-prv.h index 0a645eb..85d6bf3 100644 --- a/moo/lib/moo-prv.h +++ b/moo/lib/moo-prv.h @@ -300,14 +300,15 @@ enum moo_iotok_type_t MOO_IOTOK_IF, MOO_IOTOK_IFNOT, MOO_IOTOK_ELSE, - MOO_IOTOK_ELSIF, - MOO_IOTOK_ELSIFNOT, + MOO_IOTOK_ELIF, + MOO_IOTOK_ELIFNOT, MOO_IOTOK_WHILE, MOO_IOTOK_UNTIL, MOO_IOTOK_DO, MOO_IOTOK_BREAK, MOO_IOTOK_CONTINUE, + MOO_IOTOK_GOTO, MOO_IOTOK_AND, MOO_IOTOK_OR,