changed to accept identifer instead of symbols in pooldic definition

This commit is contained in:
hyunghwan.chung 2017-03-08 13:53:41 +00:00
parent 1ebfe8d5e9
commit 308318b615
3 changed files with 62 additions and 23 deletions

View File

@ -408,30 +408,33 @@ class UndefinedObject(Apex)
} }
pooldic ErrorCode
class Error(Apex)
{ {
(* migrate it into Error class *) }
#NONE := error(0).
#GENERIC := error(1). pooldic Error.Code
#NOIMPL := error(2). {
#SYSERR := error(3). GENERIC := error(0).
#INTERN := error(4). NOIMPL := error(1).
#SYSMEM := error(5). SYSERR := error(2).
#OOMEM := error(6). INTERN := error(3).
#INVAL := error(7). SYSMEM := error(4).
#NOENT := error(8). OOMEM := error(5).
INVAL := error(6).
NOENT := error(7).
(* add more items... *) (* add more items... *)
} }
class Error(Apex) extend Error
{ {
(* ---------------------------- (* ----------------------------
TODO: support constant declaration... TODO: support constant declaration...
#const #const
{ {
#NONE := error(0). NONE := error(0).
#GENERIC := error(1). GENERIC := error(1).
} }
-------------------------------- *) -------------------------------- *)

View File

@ -1,6 +1,42 @@
class Collection(Object) 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]. ##upsert ifFalse: [^ErrorCode.NOENT].
if (upsert) {} else { ^ErrorCode.NOENT }. if (upsert) {} else { ^Error.Code.NOENT }.
ntally := self.tally + 1. ntally := self.tally + 1.
if (ntally >= bs) if (ntally >= bs)
@ -280,7 +316,7 @@ class Set(Collection)
index := (index + 1) rem: bs. index := (index + 1) rem: bs.
}. }.
^ErrorCode.NOENT. ^Error.Code.NOENT.
} }
method __remove_at: index method __remove_at: index
@ -472,11 +508,11 @@ pooldic Log
## these items must follow defintions in moo.h ## these items must follow defintions in moo.h
## ----------------------------------------------------------- ## -----------------------------------------------------------
#DEBUG := 1. DEBUG := 1.
#INFO := 2. INFO := 2.
#WARN := 4. WARN := 4.
#ERROR := 8. ERROR := 8.
#FATAL := 16. FATAL := 16.
} }
class SystemDictionary(Set) class SystemDictionary(Set)

View File

@ -6630,9 +6630,9 @@ static int __compile_pooldic_definition (moo_t* moo)
GET_TOKEN (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; if (!lit || add_to_array_literal_buffer (moo, lit) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);