diff --git a/moo/kernel/Apex.moo b/moo/kernel/Apex.moo index 07fe91e..b6de516 100644 --- a/moo/kernel/Apex.moo +++ b/moo/kernel/Apex.moo @@ -408,30 +408,33 @@ class UndefinedObject(Apex) } -pooldic ErrorCode + +class Error(Apex) { -(* migrate it into Error class *) - #NONE := error(0). - #GENERIC := error(1). - #NOIMPL := error(2). - #SYSERR := error(3). - #INTERN := error(4). - #SYSMEM := error(5). - #OOMEM := error(6). - #INVAL := error(7). - #NOENT := error(8). +} + +pooldic Error.Code +{ + GENERIC := error(0). + NOIMPL := error(1). + SYSERR := error(2). + INTERN := error(3). + SYSMEM := error(4). + OOMEM := error(5). + INVAL := error(6). + NOENT := error(7). (* add more items... *) } -class Error(Apex) +extend Error { (* ---------------------------- TODO: support constant declaration... #const { - #NONE := error(0). - #GENERIC := error(1). + NONE := error(0). + GENERIC := error(1). } -------------------------------- *) diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index ddfd9a9..15090a1 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -1,6 +1,42 @@ class Collection(Object) { + method isEmpty + { + ^self size <= 0 + } + + method notEmpty + { + ^self size > 0 + } + + method size + { + (* Each subclass must override this method because + * it interates over the all elements for counting *) + | count | + count := 0. + self do: [ :el | count := count + 1 ]. + ^count + } + + method do: block + { + ^self subclassResponsibility: #do + } + + method detect: block + { + self do: [ :el | if (block value: el) { ^el } ]. + ^Error.Code.NOENT + } + + method detect: block ifNone: exception_block + { + self do: [ :el | if (block value: el) { ^el } ]. + ^exception_block value. + } } ## ------------------------------------------------------------------------------- @@ -193,7 +229,7 @@ class Set(Collection) }. ##upsert ifFalse: [^ErrorCode.NOENT]. - if (upsert) {} else { ^ErrorCode.NOENT }. + if (upsert) {} else { ^Error.Code.NOENT }. ntally := self.tally + 1. if (ntally >= bs) @@ -280,7 +316,7 @@ class Set(Collection) index := (index + 1) rem: bs. }. - ^ErrorCode.NOENT. + ^Error.Code.NOENT. } method __remove_at: index @@ -472,11 +508,11 @@ pooldic Log ## these items must follow defintions in moo.h ## ----------------------------------------------------------- - #DEBUG := 1. - #INFO := 2. - #WARN := 4. - #ERROR := 8. - #FATAL := 16. + DEBUG := 1. + INFO := 2. + WARN := 4. + ERROR := 8. + FATAL := 16. } class SystemDictionary(Set) diff --git a/moo/lib/comp.c b/moo/lib/comp.c index d83417d..eea8bc8 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -6630,9 +6630,9 @@ static int __compile_pooldic_definition (moo_t* moo) GET_TOKEN (moo); - while (TOKEN_TYPE(moo) == MOO_IOTOK_SYMLIT) + while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { - lit = moo_makesymbol (moo, TOKEN_NAME_PTR(moo) + 1, TOKEN_NAME_LEN(moo) - 1); + lit = moo_makesymbol (moo, TOKEN_NAME_PTR(moo), TOKEN_NAME_LEN(moo)); if (!lit || add_to_array_literal_buffer (moo, lit) <= -1) return -1; GET_TOKEN (moo);