changed System to be a class instead of an instance of a system dictionary

This commit is contained in:
hyunghwan.chung 2017-03-22 16:55:41 +00:00
parent 46ba3bb3f5
commit 65722cf89b
5 changed files with 113 additions and 102 deletions

View File

@ -1,7 +1,5 @@
class Apex(nil)
{
dcl(#class) sysdic.
## -------------------------------------------------------
## -------------------------------------------------------
@ -541,3 +539,86 @@ extend Error
<primitive: #_error_as_string>
}
}
class System(Apex)
{
}
pooldic System.Log
{
## -----------------------------------------------------------
## defines log levels
## these items must follow defintions in moo.h
## -----------------------------------------------------------
DEBUG := 1.
INFO := 2.
WARN := 4.
ERROR := 8.
FATAL := 16.
}
extend System
{
## the following methods may not look suitable to be placed
## inside a system dictionary. but they are here for quick and dirty
## output production from the moo code.
## System logNl: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'.
##
method(#class) atLevel: level log: message
{
<primitive: #_log>
## do nothing upon logging failure
}
method(#class) atLevel: level log: message and: message2
{
<primitive: #_log>
## do nothing upon logging failure
}
method(#class) atLevel: level log: message and: message2 and: message3
{
<primitive: #_log>
## do nothing upon logging failure
}
method(#class) atLevel: level logNl: message
{
## the #_log primitive accepts an array.
## so the following lines should work also.
## | x |
## x := Array new: 2.
## x at: 0 put: message.
## x at: 1 put: S'\n'.
## ^self atLevel: level log: x.
^self atLevel: level log: message and: S'\n'.
}
method(#class) atLevel: level logNl: message and: message2
{
^self atLevel: level log: message and: message2 and: S'\n'.
}
method(#class) log: message
{
^self atLevel: System.Log.INFO log: message.
}
method(#class) log: message and: message2
{
^self atLevel: System.Log.INFO log: message and: message2.
}
method(#class) logNl: message
{
^self atLevel: System.Log.INFO logNl: message.
}
method(#class) logNl: message and: message2
{
^self atLevel: System.Log.INFO logNl: message and: message2.
}
}

View File

@ -500,86 +500,8 @@ class Dictionary(Set)
}
}
pooldic Log
{
## -----------------------------------------------------------
## defines log levels
## these items must follow defintions in moo.h
## -----------------------------------------------------------
DEBUG := 1.
INFO := 2.
WARN := 4.
ERROR := 8.
FATAL := 16.
}
class SystemDictionary(Set)
{
## the following methods may not look suitable to be placed
## inside a system dictionary. but they are here for quick and dirty
## output production from the moo code.
## System logNl: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'.
##
dcl(#pooldic) Log.
method atLevel: level log: message
{
<primitive: #_log>
## do nothing upon logging failure
}
method atLevel: level log: message and: message2
{
<primitive: #_log>
## do nothing upon logging failure
}
method atLevel: level log: message and: message2 and: message3
{
<primitive: #_log>
## do nothing upon logging failure
}
method atLevel: level logNl: message
{
## the #_log primitive accepts an array.
## so the following lines should work also.
## | x |
## x := Array new: 2.
## x at: 0 put: message.
## x at: 1 put: S'\n'.
## ^self atLevel: level log: x.
^self atLevel: level log: message and: S'\n'.
}
method atLevel: level logNl: message and: message2
{
^self atLevel: level log: message and: message2 and: S'\n'.
}
method log: message
{
^self atLevel: Log.INFO log: message.
}
method log: message and: message2
{
^self atLevel: Log.INFO log: message and: message2.
}
method logNl: message
{
^self atLevel: Log.INFO logNl: message.
}
method logNl: message and: message2
{
^self atLevel: Log.INFO logNl: message and: message2.
}
method at: key
{
if (key class ~= Symbol) { InvalidArgumentException signal: 'key is not a symbol' }.

View File

@ -318,7 +318,16 @@ class MyObject(Object)
}
}*)
Processor sleepFor: 20.
System logNl: 'Sleeping start now....'.
(* basicAt: 12 to access the nsdic field. use a proper method once it's defined in Class *)
(System basicAt: 12) keysAndValuesDo: [:k :v |
k dump.
v dump.
'------------' dump.
].
Processor sleepFor: 3. ## DEBUG VM... VM WAITING FOR 10 SECS instead of 3.
}
(*

View File

@ -113,7 +113,9 @@ static kernel_class_info_t kernel_classes[] =
{ 12, { 'S','m','a','l','l','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _small_integer) },
{ 20, { 'L','a','r','g','e','P','o','s','i','t','i','v','e','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _large_positive_integer) },
{ 20, { 'L','a','r','g','e','N','e','g','a','t','i','v','e','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _large_negative_integer) }
{ 20, { 'L','a','r','g','e','N','e','g','a','t','i','v','e','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _large_negative_integer) },
{ 6, { 'S','y','s','t','e','m' }, MOO_OFFSETOF(moo_t, _system) },
};
/* -----------------------------------------------------------------------
@ -168,7 +170,7 @@ static int ignite_1 (moo_t* moo)
* Character
* SmallIntger
* -------------------------------------------------------------- */
moo->_apex = alloc_kernel_class (moo, 1, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP));
moo->_apex = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP));
moo->_undefined_object = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP));
moo->_object = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP));
moo->_string = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_CHAR));
@ -203,6 +205,8 @@ static int ignite_1 (moo_t* moo)
moo->_large_positive_integer = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_LIWORD));
moo->_large_negative_integer = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_LIWORD));
moo->_system = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP));
if (!moo->_apex || !moo->_undefined_object ||
!moo->_object || !moo->_string ||
@ -218,7 +222,7 @@ static int ignite_1 (moo_t* moo)
!moo->_true_class || !moo->_false_class ||
!moo->_character || !moo->_small_integer ||
!moo->_large_positive_integer || !moo->_large_negative_integer) return -1;
!moo->_large_positive_integer || !moo->_large_negative_integer || !moo->_system) return -1;
MOO_OBJ_SET_CLASS (moo->_nil, (moo_oop_t)moo->_undefined_object);
return 0;
@ -267,8 +271,8 @@ static int ignite_2 (moo_t* moo)
moo->processor->tally = MOO_SMOOI_TO_OOP(0);
moo->processor->active = moo->nil_process;
/* Export the system dictionary via the first class variable of the Stix class */
moo->_apex->slot[0] = (moo_oop_t)moo->sysdic;
/* Attach the system dictionary to the nsdic field of the System class */
moo->_system->nsdic = moo->sysdic;
return 0;
}
@ -276,8 +280,6 @@ static int ignite_2 (moo_t* moo)
static int ignite_3 (moo_t* moo)
{
/* Register kernel classes manually created so far to the system dictionary */
static moo_ooch_t str_system[] = { 'S','y','s','t','e', 'm' };
static moo_ooch_t str_processor[] = { 'P', 'r', 'o', 'c', 'e', 's', 's', 'o', 'r' };
static moo_ooch_t str_dicnew[] = { 'n', 'e', 'w', ':' };
static moo_ooch_t str_dicputassoc[] = { 'p', 'u', 't', '_', 'a', 's', 's', 'o', 'c', ':' };
@ -297,11 +299,6 @@ static int ignite_3 (moo_t* moo)
moo_ptr++;
}
/* Make the system dictionary available as the global name 'System' */
sym = moo_makesymbol (moo, str_system, MOO_COUNTOF(str_system));
if (!sym) return -1;
if (!moo_putatsysdic(moo, sym, (moo_oop_t)moo->sysdic)) return -1;
/* Make the process scheduler avaialble as the global name 'Processor' */
sym = moo_makesymbol (moo, str_processor, MOO_COUNTOF(str_processor));
if (!sym) return -1;

View File

@ -992,6 +992,8 @@ struct moo_t
moo_oop_class_t _large_positive_integer; /* LargePositiveInteger */
moo_oop_class_t _large_negative_integer; /* LargeNegativeInteger */
moo_oop_class_t _system;
/* =============================================================
* END KERNEL CLASSES
* ============================================================= */