touched up some primitive functions

This commit is contained in:
hyunghwan.chung 2017-12-03 17:08:04 +00:00
parent a817083543
commit 7395a5d2d2
7 changed files with 135 additions and 190 deletions

View File

@ -90,76 +90,46 @@ extend Apex
## ------------------------------------------------------- ## -------------------------------------------------------
## ------------------------------------------------------- ## -------------------------------------------------------
##method(#dual,#primitive,#lenient) _shallowCopy. method(#dual,#primitive,#lenient) _shallowCopy.
##method(#dual,#primitive) shallowCopy. method(#dual,#primitive) shallowCopy.
method(#dual) shallowCopy
{
<primitive: #_shallow_copy>
self primitiveFailed(thisContext method).
}
## ------------------------------------------------------- ## -------------------------------------------------------
## ------------------------------------------------------- ## -------------------------------------------------------
method(#dual,#primitive,#lenient) _basicSize. method(#dual,#primitive,#lenient) _basicSize.
method(#dual,#primitive) basicSize. method(#dual,#primitive) basicSize.
method(#dual) basicAt: index method(#dual,#primitive) basicAt: index.
{ method(#dual,#primitive) basicAt: index put: value.
| perr |
<primitive: #_basic_at>
## TODO: create a common method that translate a primitive error to some standard exceptions of primitive failure.
perr := thisProcess primError.
if (perr == Error.Code.ERANGE) { self index: index outOfRange: (self basicSize) }
elsif (perr == Error.Code.EPERM) { self messageProhibited: #basicAt }
else { self primitiveFailed }
}
method(#dual) basicAt: index put: anObject
{
| perr |
<primitive: #_basic_at_put>
perr := thisProcess primError.
if (perr == Error.Code.ERANGE) { self index: index outOfRange: (self basicSize) }
elsif (perr == Error.Code.EPERM) { self messageProhibited: #basicAt:put: }
else { self primitiveFailed }
}
(* ------------------------------------------------------------------ (* ------------------------------------------------------------------
* FINALIZATION SUPPORT * FINALIZATION SUPPORT
* ------------------------------------------------------------------ *) * ------------------------------------------------------------------ *)
method(#dual,#primitive) addToBeFinalized. method(#dual,#primitive) addToBeFinalized.
##method(#dual,#primitive) removeToBeFinalized. method(#dual,#primitive) removeToBeFinalized.
(* ------------------------------------------------------------------ (* ------------------------------------------------------------------
* HASHING * HASHING
* ------------------------------------------------------------------ *) * ------------------------------------------------------------------ *)
method(#dual,#primitive) hash.
(*
method(#dual) hash method(#dual) hash
{ {
<primitive: #_hash> <primitive: #Apex_hash>
self subclassResponsibility: #hash self subclassResponsibility: #hash
} }*)
(* ------------------------------------------------------------------ (* ------------------------------------------------------------------
* IDENTITY TEST * IDENTITY TEST
* ------------------------------------------------------------------ *) * ------------------------------------------------------------------ *)
method(#dual) == anObject ## check if the receiver is identical to anObject.
{ ## this doesn't compare the contents
(* check if the receiver is identical to anObject. method(#dual, #primitive) == anObject.
* this doesn't compare the contents *)
<primitive: #_identical>
self primitiveFailed.
}
method(#dual) ~~ anObject method(#dual) ~~ anObject
{ {
<primitive: #_not_identical> <primitive: #'Apex_~~'>
^(self == anObject) not. ^(self == anObject) not.
} }
@ -168,13 +138,13 @@ extend Apex
* ------------------------------------------------------------------ *) * ------------------------------------------------------------------ *)
method(#dual) = anObject method(#dual) = anObject
{ {
<primitive: #_equal> <primitive: #'Apex_='>
self subclassResponsibility: #= self subclassResponsibility: #=
} }
method(#dual) ~= anObject method(#dual) ~= anObject
{ {
<primitive: #_not_equal> <primitive: #'Apex_~='>
^(self = anObject) not. ^(self = anObject) not.
} }
@ -184,7 +154,7 @@ extend Apex
* ------------------------------------------------------------------ *) * ------------------------------------------------------------------ *)
method(#dual,#primitive) class. method(#dual,#primitive) class.
method(#dual) isNil method(#dual) isNil
{ {
## ^self == nil. ## ^self == nil.
@ -243,50 +213,41 @@ extend Apex
method(#dual) isKindOf: aClass method(#dual) isKindOf: aClass
{ {
<primitive: #_is_kind_of> <primitive: #Apex_isKindOf:>
^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass]. ^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass].
} }
## ------------------------------------------------------- ## -------------------------------------------------------
## ------------------------------------------------------- ## -------------------------------------------------------
method(#dual) respondsTo: selector method(#dual,#primitive) respondsTo: selector.
{
<primitive: #_responds_to>
self primitiveFailed
}
## ------------------------------------------------------- ## -------------------------------------------------------
## ------------------------------------------------------- ## -------------------------------------------------------
method(#dual,#variadic) perform(selector) method(#dual,#variadic,#primitive) perform(selector).
{
<primitive: #_perform>
self primitiveFailed
}
method(#dual) perform: selector method(#dual) perform: selector
{ {
<primitive: #_perform> <primitive: #Apex_perform>
self primitiveFailed self primitiveFailed
} }
method(#dual) perform: selector with: arg1 method(#dual) perform: selector with: arg1
{ {
<primitive: #_perform> <primitive: #Apex_perform>
self primitiveFailed self primitiveFailed
} }
method(#dual) perform: selector with: arg1 with: arg2 method(#dual) perform: selector with: arg1 with: arg2
{ {
<primitive: #_perform> <primitive: #Apex_perform>
self primitiveFailed self primitiveFailed
} }
method(#dual) perform: selector with: arg1 with: arg2 with: arg3 method(#dual) perform: selector with: arg1 with: arg2 with: arg3
{ {
<primitive: #_perform> <primitive: #Apex_perform>
self primitiveFailed self primitiveFailed
} }

View File

@ -205,14 +205,14 @@ class(#character,#final,#limited,#immutable) Symbol(String)
method = anObject method = anObject
{ {
(* for a symbol, equality check is the same as the identity check *) (* for a symbol, equality check is the same as the identity check *)
<primitive: #_identical> <primitive: #'Apex_=='>
self primitiveFailed. self primitiveFailed.
} }
method ~= anObject method ~= anObject
{ {
(* for a symbol, equality check is the same as the identity check *) (* for a symbol, equality check is the same as the identity check *)
<primitive: #_not_identical> <primitive: #'Apex_~~'>
^(self == anObject) not. ^(self == anObject) not.
} }
} }

View File

@ -56,22 +56,20 @@ class(#pointer,#final,#limited) MethodContext(Context)
^self.ip + 1 ^self.ip + 1
} }
method goto: anInteger
{
<primitive: #_context_goto>
self primitiveFailed. ## TODO: need to make this a hard failure?
}
method pc: anInteger method pc: anInteger
{ {
self.ip := anInteger. self.ip := anInteger.
} }
## it is similar to the pc: method but it doesn't
## push the return value to the stack.
method(#primitive) goto: pc.
method sp method sp
{ {
^self.sp. ^self.sp.
} }
method sp: new_sp method sp: new_sp
{ {
self.sp := new_sp self.sp := new_sp
@ -113,55 +111,43 @@ class(#pointer,#final,#limited) BlockContext(Context)
^self.home vargAt: index ^self.home vargAt: index
} }
## TODO: how can i pass variadic arguments to newProcess
## method(#variadic) fork() -> how to pass them to newProcess???
method fork method fork
{ {
## crate a new process in the runnable state ## crate a new process in the runnable state
^self newProcess resume. ^self newProcess resume.
} }
method newProcess ## create a new process in the suspended state
{ method(#variadic,#primitive) newProcess().
## create a new process in the suspended state
<primitive: #_block_new_process>
self primitiveFailed.
}
method newProcessWith: anArray ## evaluate the block
{ method(#variadic,#primitive) value().
## create a new process in the suspended state passing the elements
## of anArray as block arguments
<primitive: #_block_new_process>
self primitiveFailed.
}
method value
{
<primitive: #_block_value>
self primitiveFailed.
}
method value: a method value: a
{ {
<primitive: #_block_value> <primitive: #BlockContext_value>
self primitiveFailed. self primitiveFailed.
} }
method value: a value: b method value: a value: b
{ {
<primitive: #_block_value> <primitive: #BlockContext_value>
self primitiveFailed. self primitiveFailed.
} }
method value: a value: b value: c method value: a value: b value: c
{ {
<primitive: #_block_value> <primitive: #BlockContext_value>
self primitiveFailed. self primitiveFailed.
} }
method value: a value: b value: c value: d method value: a value: b value: c value: d
{ {
<primitive: #_block_value> <primitive: #BlockContext_value>
self primitiveFailed. self primitiveFailed.
} }
method value: a value: b value: c value: d value: e method value: a value: b value: c value: d value: e
{ {
<primitive: #_block_value> <primitive: #BlockContext_value>
self primitiveFailed. self primitiveFailed.
} }

View File

@ -39,7 +39,7 @@ TODO: can i convert 'thisProcess primError' to a relevant exception?
{ {
^(self class name) & ' - ' & self.messageText. ^(self class name) & ' - ' & self.messageText.
} }
method signal method signal
{ {
| exctx exblk retval actpos ctx | | exctx exblk retval actpos ctx |
@ -487,6 +487,11 @@ extend Apex
if (msg isNil) { msg := ec asString }. if (msg isNil) { msg := ec asString }.
if (method notNil) { msg := msg & ' - ' & (method owner name) & '>>' & (method name) }. if (method notNil) { msg := msg & ' - ' & (method owner name) & '>>' & (method name) }.
### 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 }.
(PrimitiveFailureException (* in: method *) withErrorCode: ec) signal: msg. (PrimitiveFailureException (* in: method *) withErrorCode: ec) signal: msg.
} }

View File

@ -1751,8 +1751,7 @@ static int _equal_objects (moo_t* moo, moo_oop_t rcv, moo_oop_t arg)
MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(rcv) == MOO_OBJ_TYPE_OOP); MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(rcv) == MOO_OBJ_TYPE_OOP);
#if 1 #if 1
MOO_DEBUG1 (moo, "<_equal_objects> Cannot compare objects of type %d\n", (int)MOO_OBJ_GET_FLAGS_TYPE(rcv)); moo_seterrbfmt (moo, MOO_ENOIMPL, "no builtin comparison implemented for %O and %O", rcv, arg); /* TODO: better error code */
moo_seterrnum (moo, MOO_ENOIMPL); /* TODO: better error code */
return -1; return -1;
#else #else
for (i = 0; i < MOO_OBJ_GET_SIZE(rcv); i++) for (i = 0; i < MOO_OBJ_GET_SIZE(rcv); i++)
@ -1911,7 +1910,7 @@ static moo_pfrc_t pf_basic_at (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_POINTER(rcv)) if (!MOO_OOP_IS_POINTER(rcv))
{ {
/* the receiver is a special numeric object, not a normal pointer */ /* the receiver is a special numeric object, not a normal pointer */
moo_seterrnum (moo, MOO_EINVAL); moo_seterrbfmt (moo, MOO_EMSGRCV, "receiver not indexable - %O", rcv);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -1919,13 +1918,13 @@ static moo_pfrc_t pf_basic_at (moo_t* moo, moo_ooi_t nargs)
if (moo_inttooow (moo, pos, &idx) <= 0) if (moo_inttooow (moo, pos, &idx) <= 0)
{ {
/* negative integer or not integer */ /* negative integer or not integer */
moo_seterrnum (moo, MOO_EINVAL); moo_seterrbfmt (moo, MOO_EINVAL, "invalid position - %O", pos);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
if (idx >= MOO_OBJ_GET_SIZE(rcv)) if (idx >= MOO_OBJ_GET_SIZE(rcv))
{ {
/* index out of range */ /* index out of range */
moo_seterrnum (moo, MOO_ERANGE); moo_seterrbfmt (moo, MOO_ERANGE, "position out of bound - %O", pos);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -1973,14 +1972,14 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_POINTER(rcv)) if (!MOO_OOP_IS_POINTER(rcv))
{ {
/* the receiver is a special numeric object, not a normal pointer */ /* the receiver is a special numeric object, not a normal pointer */
moo_seterrnum (moo, MOO_EINVAL); moo_seterrbfmt (moo, MOO_EMSGRCV, "receiver not indexable - %O", rcv);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
if (MOO_OBJ_GET_FLAGS_RDONLY(rcv)) if (MOO_OBJ_GET_FLAGS_RDONLY(rcv))
{ {
/* TODO: better error handling */ /* TODO: better error handling */
moo_seterrnum (moo, MOO_EPERM); moo_seterrbfmt (moo, MOO_EPERM, "now allowed to change a read-only object - %O", rcv);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -1990,13 +1989,13 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (moo_inttooow (moo, pos, &idx) <= 0) if (moo_inttooow (moo, pos, &idx) <= 0)
{ {
/* negative integer or not integer */ /* negative integer or not integer */
moo_seterrnum (moo, MOO_EINVAL); moo_seterrbfmt (moo, MOO_EINVAL, "invalid position - %O", pos);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
if (idx >= MOO_OBJ_GET_SIZE(rcv)) if (idx >= MOO_OBJ_GET_SIZE(rcv))
{ {
/* index out of range */ /* index out of range */
moo_seterrnum (moo, MOO_ERANGE); moo_seterrbfmt (moo, MOO_ERANGE, "position out of bound - %O", pos);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -2131,8 +2130,7 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_ooi_t nargs)
default: default:
/* MOO_OBJ_TYPE_OOP, ... */ /* MOO_OBJ_TYPE_OOP, ... */
MOO_DEBUG1 (moo, "<pf_hash> Cannot hash an object of type %d\n", type); moo_seterrbfmt(moo, MOO_ENOIMPL, "no builtin hash implemented for %O", rcv); /* TODO: better error code? */
moo_seterrnum (moo, MOO_ENOIMPL); /* TODO: better error code? */
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
break; break;
@ -2177,7 +2175,7 @@ static moo_pfrc_t pf_responds_to (moo_t* moo, moo_ooi_t nargs)
if (MOO_CLASSOF(moo,selector) != moo->_symbol) if (MOO_CLASSOF(moo,selector) != moo->_symbol)
{ {
moo_seterrnum (moo, MOO_EINVAL); moo_seterrbfmt (moo, MOO_EINVAL, "invalid argument - %O", selector);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -2207,7 +2205,7 @@ static moo_pfrc_t pf_perform (moo_t* moo, moo_ooi_t nargs)
if (MOO_CLASSOF(moo,selector) != moo->_symbol) if (MOO_CLASSOF(moo,selector) != moo->_symbol)
{ {
moo_seterrnum (moo, MOO_EINVAL); moo_seterrbfmt (moo, MOO_EINVAL, "invalid argument - %O", selector);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -2227,6 +2225,8 @@ static moo_pfrc_t pf_perform (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
/* ------------------------------------------------------------------ */
static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs) static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs)
{ {
moo_oop_t rcv; moo_oop_t rcv;
@ -2245,9 +2245,7 @@ static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs)
pc = MOO_STACK_GETARG(moo, nargs, 0); pc = MOO_STACK_GETARG(moo, nargs, 0);
if (!MOO_OOP_IS_SMOOI(pc) || MOO_OOP_TO_SMOOI(pc) < 0) if (!MOO_OOP_IS_SMOOI(pc) || MOO_OOP_TO_SMOOI(pc) < 0)
{ {
MOO_LOG1 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, moo_seterrbfmt (moo, MOO_EINVAL, "invalid pc - %O", pc);
"Error(%hs) - invalid pc\n", __PRIMITIVE_NAME__);
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -2259,6 +2257,8 @@ static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
/* ------------------------------------------------------------------ */
static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_ooi_t nargs, moo_ooi_t num_first_arg_elems, moo_oop_context_t* pblkctx) static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_ooi_t nargs, moo_ooi_t num_first_arg_elems, moo_oop_context_t* pblkctx)
{ {
/* prepare a new block context for activation. /* prepare a new block context for activation.
@ -2291,21 +2291,16 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
* you can't send 'value' again to reactivate it. * you can't send 'value' again to reactivate it.
* For example, [thisContext value] value. */ * For example, [thisContext value] value. */
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) > MOO_CONTEXT_NAMED_INSTVARS); MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) > MOO_CONTEXT_NAMED_INSTVARS);
MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, moo_seterrbfmt (moo, MOO_EPERM, "re-valuing of a block context - %O", rcv_blkctx);
"Error(%hs) - re-valuing of a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx);
moo_seterrnum (moo, MOO_EPERM);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) == MOO_CONTEXT_NAMED_INSTVARS); MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) == MOO_CONTEXT_NAMED_INSTVARS);
if (MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs) != actual_arg_count /* nargs */) if (MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs) != actual_arg_count /* nargs */)
{ {
MOO_LOG4 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, moo_seterrbfmt (moo, MOO_ENUMARGS,
"Error(%hs) - wrong number of arguments to a block context %O - %zd expected, %zd given\n", "wrong number of arguments to a block context %O - %zd expected, %zd given",
__PRIMITIVE_NAME__, rcv_blkctx, MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs), actual_arg_count); rcv_blkctx, MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs), actual_arg_count);
moo_seterrnum (moo, MOO_ENUMARGS);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
@ -2320,10 +2315,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
moo_pushtmp (moo, (moo_oop_t*)&rcv_blkctx); moo_pushtmp (moo, (moo_oop_t*)&rcv_blkctx);
blkctx = (moo_oop_context_t) moo_instantiate (moo, moo->_block_context, MOO_NULL, local_ntmprs); blkctx = (moo_oop_context_t) moo_instantiate (moo, moo->_block_context, MOO_NULL, local_ntmprs);
moo_poptmp (moo); moo_poptmp (moo);
if (!blkctx) if (!blkctx) return MOO_PF_FAILURE;
{
return MOO_PF_FAILURE;
}
#if 0 #if 0
/* shallow-copy the named part including home, origin, etc. */ /* shallow-copy the named part including home, origin, etc. */
@ -2393,12 +2385,13 @@ static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs)
/* create a new process from a block context. /* create a new process from a block context.
* the receiver must be be a block. * the receiver must be be a block.
* [ 1 + 2 ] newProcess. * [ 1 + 2 ] newProcess.
* [ :a :b | a + b ] newProcess: #(1 2) * [ :a :b | a + b ] newProcess(1, 2)
*/ */
int x; int x;
moo_oop_context_t rcv_blkctx, blkctx; moo_oop_context_t rcv_blkctx, blkctx;
moo_oop_process_t proc; moo_oop_process_t proc;
#if 0
moo_ooi_t num_first_arg_elems = 0; moo_ooi_t num_first_arg_elems = 0;
MOO_ASSERT (moo, nargs <= 1); MOO_ASSERT (moo, nargs <= 1);
@ -2418,20 +2411,18 @@ static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs)
num_first_arg_elems = MOO_OBJ_GET_SIZE(xarg); num_first_arg_elems = MOO_OBJ_GET_SIZE(xarg);
} }
#endif
rcv_blkctx = (moo_oop_context_t)MOO_STACK_GETRCV(moo, nargs); rcv_blkctx = (moo_oop_context_t)MOO_STACK_GETRCV(moo, nargs);
if (MOO_CLASSOF(moo, rcv_blkctx) != moo->_block_context) MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo,rcv_blkctx) == moo->_block_context);
{
/* the receiver must be a block context */
MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR,
"Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx);
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
/* this primitive creates a new process with a block as if the block /* this primitive creates a new process with a block as if the block
* is sent the value message */ * is sent the value message */
#if 0
x = __block_value (moo, rcv_blkctx, nargs, num_first_arg_elems, &blkctx); x = __block_value (moo, rcv_blkctx, nargs, num_first_arg_elems, &blkctx);
#else
x = __block_value (moo, rcv_blkctx, nargs, 0, &blkctx);
#endif
if (x <= 0) return x; /* both hard failure and soft failure */ if (x <= 0) return x; /* both hard failure and soft failure */
/* reset the sender field to moo->_nil because this block context /* reset the sender field to moo->_nil because this block context
@ -2441,7 +2432,7 @@ static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs)
blkctx->sender = (moo_oop_context_t)moo->_nil; blkctx->sender = (moo_oop_context_t)moo->_nil;
proc = make_process (moo, blkctx); proc = make_process (moo, blkctx);
if (!proc) return MOO_PF_HARD_FAILURE; /* hard failure */ /* TOOD: can't this be treated as a soft failure? throw an exception instead?? */ if (!proc) return MOO_PF_FAILURE; /* hard failure */ /* TOOD: can't this be treated as a soft failure? throw an exception instead?? */
/* __block_value() has popped all arguments and the receiver. /* __block_value() has popped all arguments and the receiver.
* PUSH the return value instead of changing the stack top */ * PUSH the return value instead of changing the stack top */
@ -4305,29 +4296,6 @@ typedef struct pf_t pf_t;
static pf_t pftab[] = static pf_t pftab[] =
{ {
{ "_dump", { pf_dump, 0, MA } }, { "_dump", { pf_dump, 0, MA } },
{ "_identical", { pf_identical, 1, 1 } },
{ "_not_identical", { pf_not_identical, 1, 1 } },
{ "_equal", { pf_equal, 1, 1 } },
{ "_not_equal", { pf_not_equal, 1, 1 } },
{ "_shallow_copy", { pf_shallow_copy, 0, 0 } },
{ "_basic_at", { pf_basic_at, 1, 1 } },
{ "_basic_at_put", { pf_basic_at_put, 2, 2 } },
{ "_hash", { pf_hash, 0, 0 } },
{ "_is_kind_of", { pf_is_kind_of, 1, 1, } },
{ "_responds_to", { pf_responds_to, 1, 1 } },
{ "_perform", { pf_perform, 1, MA } },
{ "_context_goto", { pf_context_goto, 1, 1 } },
{ "_block_value", { pf_block_value, 0, MA } },
{ "_block_new_process", { pf_block_new_process, 0, 1 } },
{ "_processor_schedule", { pf_processor_schedule, 1, 1 } }, { "_processor_schedule", { pf_processor_schedule, 1, 1 } },
@ -4354,6 +4322,8 @@ static pf_t pftab[] =
{ "_integer_inttostr", { pf_integer_inttostr, 1, 1 } }, { "_integer_inttostr", { pf_integer_inttostr, 1, 1 } },
{ "Apex_addToBeFinalized", { pf_add_to_be_finalized, 0, 0 } }, { "Apex_addToBeFinalized", { pf_add_to_be_finalized, 0, 0 } },
{ "Apex_basicAt:", { pf_basic_at, 1, 1 } },
{ "Apex_basicAt:put:", { pf_basic_at_put, 2, 2 } },
{ "Apex_basicNew", { pf_basic_new, 0, 0 } }, { "Apex_basicNew", { pf_basic_new, 0, 0 } },
{ "Apex_basicNew:", { pf_basic_new, 1, 1 } }, { "Apex_basicNew:", { pf_basic_new, 1, 1 } },
{ "Apex_basicSize", { pf_basic_size, 0, 0 } }, { "Apex_basicSize", { pf_basic_size, 0, 0 } },
@ -4361,7 +4331,20 @@ static pf_t pftab[] =
{ "Apex_basicNew:", { pf_basic_new, 1, 1 } }, { "Apex_basicNew:", { pf_basic_new, 1, 1 } },
{ "Apex_basicSize", { pf_basic_size, 0, 0 } }, { "Apex_basicSize", { pf_basic_size, 0, 0 } },
{ "Apex_class", { pf_class, 0, 0 } }, { "Apex_class", { pf_class, 0, 0 } },
{ "Apex_hash", { pf_hash, 0, 0 } },
{ "Apex_isKindOf:", { pf_is_kind_of, 1, 1, } },
{ "Apex_perform", { pf_perform, 1, MA } },
{ "Apex_removeToBeFinalized", { pf_remove_to_be_finalized, 0, 0 } }, { "Apex_removeToBeFinalized", { pf_remove_to_be_finalized, 0, 0 } },
{ "Apex_respondsTo:", { pf_responds_to, 1, 1 } },
{ "Apex_shallowCopy", { pf_shallow_copy, 0, 0 } },
{ "Apex_==", { pf_identical, 1, 1 } },
{ "Apex_~~", { pf_not_identical, 1, 1 } },
{ "Apex_=", { pf_equal, 1, 1 } },
{ "Apex_~=", { pf_not_equal, 1, 1 } },
{ "BlockContext_value", { pf_block_value, 0, MA } },
{ "BlockContext_newProcess", { pf_block_new_process, 0, MA } },
{ "Character_asInteger", { pf_character_as_smooi, 0, 0 } }, { "Character_asInteger", { pf_character_as_smooi, 0, 0 } },
@ -4369,6 +4352,8 @@ static pf_t pftab[] =
{ "Error_asInteger", { pf_error_as_integer, 0, 0 } }, { "Error_asInteger", { pf_error_as_integer, 0, 0 } },
{ "Error_asString", { pf_error_as_string, 0, 0 } }, { "Error_asString", { pf_error_as_string, 0, 0 } },
{ "MethodContext_goto:", { pf_context_goto, 1, 1 } },
{ "Process_resume", { pf_process_resume, 0, 0 } }, { "Process_resume", { pf_process_resume, 0, 0 } },
{ "Process_sp", { pf_process_sp, 0, 0 } }, { "Process_sp", { pf_process_sp, 0, 0 } },
{ "Process_suspend", { pf_process_suspend, 0, 0 } }, { "Process_suspend", { pf_process_suspend, 0, 0 } },
@ -4405,34 +4390,34 @@ static pf_t pftab[] =
{ "String_strlen", { pf_strlen, 0, 0 } }, { "String_strlen", { pf_strlen, 0, 0 } },
{ "System_calloc", { pf_system_calloc, 1, 1 } }, { "System_calloc", { pf_system_calloc, 1, 1 } },
{ "System_free", { pf_system_free, 1, 1 } }, { "System_free", { pf_system_free, 1, 1 } },
{ "System_getInt16", { pf_system_get_int16, 2, 2 } }, { "System_getInt16", { pf_system_get_int16, 2, 2 } },
{ "System_getInt32", { pf_system_get_int32, 2, 2 } }, { "System_getInt32", { pf_system_get_int32, 2, 2 } },
{ "System_getInt64", { pf_system_get_int64, 2, 2 } }, { "System_getInt64", { pf_system_get_int64, 2, 2 } },
{ "System_getInt8", { pf_system_get_int8, 2, 2 } }, { "System_getInt8", { pf_system_get_int8, 2, 2 } },
{ "System_getUint16", { pf_system_get_uint16, 2, 2 } }, { "System_getUint16", { pf_system_get_uint16, 2, 2 } },
{ "System_getUint32", { pf_system_get_uint32, 2, 2 } }, { "System_getUint32", { pf_system_get_uint32, 2, 2 } },
{ "System_getUint64", { pf_system_get_uint64, 2, 2 } }, { "System_getUint64", { pf_system_get_uint64, 2, 2 } },
{ "System_getUint8", { pf_system_get_uint8, 2, 2 } }, { "System_getUint8", { pf_system_get_uint8, 2, 2 } },
{ "System_malloc", { pf_system_malloc, 1, 1 } }, { "System_malloc", { pf_system_malloc, 1, 1 } },
{ "System_popCollectable", { pf_system_pop_collectable, 0, 0 } }, { "System_popCollectable", { pf_system_pop_collectable, 0, 0 } },
{ "System_putInt8", { pf_system_put_int8, 3, 3 } }, { "System_putInt8", { pf_system_put_int8, 3, 3 } },
{ "System_putInt16", { pf_system_put_int16, 3, 3 } }, { "System_putInt16", { pf_system_put_int16, 3, 3 } },
{ "System_putInt32", { pf_system_put_int32, 3, 3 } }, { "System_putInt32", { pf_system_put_int32, 3, 3 } },
{ "System_putInt64", { pf_system_put_int64, 3, 3 } }, { "System_putInt64", { pf_system_put_int64, 3, 3 } },
{ "System_putUint8", { pf_system_put_uint8, 3, 3 } }, { "System_putUint8", { pf_system_put_uint8, 3, 3 } },
{ "System_putUint16", { pf_system_put_uint16, 3, 3 } }, { "System_putUint16", { pf_system_put_uint16, 3, 3 } },
{ "System_putUint32", { pf_system_put_uint32, 3, 3 } }, { "System_putUint32", { pf_system_put_uint32, 3, 3 } },
{ "System_putUint64", { pf_system_put_uint64, 3, 3 } }, { "System_putUint64", { pf_system_put_uint64, 3, 3 } },
{ "System_signal:afterSecs:", { pf_system_add_timed_semaphore, 2, 2 } }, { "System_signal:afterSecs:", { pf_system_add_timed_semaphore, 2, 2 } },
{ "System_signal:afterSecs:nanosecs:", { pf_system_add_timed_semaphore, 3, 3 } }, { "System_signal:afterSecs:nanosecs:", { pf_system_add_timed_semaphore, 3, 3 } },
{ "System_signal:onInput:", { pf_system_add_input_semaphore, 2, 2 } }, { "System_signal:onInput:", { pf_system_add_input_semaphore, 2, 2 } },
{ "System_signal:onInOutput:", { pf_system_add_inoutput_semaphore, 2, 2 } }, { "System_signal:onInOutput:", { pf_system_add_inoutput_semaphore, 2, 2 } },
{ "System_signal:onOutput:", { pf_system_add_output_semaphore, 2, 2 } }, { "System_signal:onOutput:", { pf_system_add_output_semaphore, 2, 2 } },
{ "System_signalOnGCFin:", { pf_system_add_gcfin_semaphore, 1, 1 } }, { "System_signalOnGCFin:", { pf_system_add_gcfin_semaphore, 1, 1 } },
{ "System_unsignal:", { pf_system_remove_semaphore, 1, 1 } }, { "System_unsignal:", { pf_system_remove_semaphore, 1, 1 } },
{ "System_collectGarbage", { pf_system_collect_garbage, 0, 0 } }, { "System_collectGarbage", { pf_system_collect_garbage, 0, 0 } },
{ "System_log", { pf_system_log, 2, MA } }, { "System_log", { pf_system_log, 2, MA } },

View File

@ -2098,7 +2098,7 @@ static int handle_logopt (moo_t* moo, const moo_bch_t* str)
} }
while (cm); while (cm);
xtn->logmask |= MOO_LOG_ALL_LEVELS; /* TODO: parse leves also */ xtn->logmask |= MOO_LOG_ALL_LEVELS; /* TODO: parse levels also */
} }
else else
{ {
@ -2130,10 +2130,15 @@ int main (int argc, char* argv[])
int i, xret; int i, xret;
moo_bci_t c; moo_bci_t c;
static moo_bopt_lng_t lopt[] =
{
{ ":log", 'l' },
{ MOO_NULL, '\0' }
};
static moo_bopt_t opt = static moo_bopt_t opt =
{ {
"l:", "l:",
MOO_NULL lopt
}; };
const char* logopt = MOO_NULL; const char* logopt = MOO_NULL;
@ -2229,15 +2234,19 @@ int main (int argc, char* argv[])
return -1; return -1;
} }
} }
else
{
/* default logging mask when no logging option is set */
xtn->logmask = MOO_LOG_ALL_TYPES | MOO_LOG_ERROR | MOO_LOG_FATAL;
}
if (moo_ignite(moo) <= -1) if (moo_ignite(moo) <= -1)
{ {
moo_logbfmt (moo, MOO_LOG_ERROR, "ERROR: cannot ignite moo - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo)); moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, "ERROR: cannot ignite moo - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo));
close_moo (moo); close_moo (moo);
return -1; return -1;
} }
#if defined(macintosh) #if defined(macintosh)
i = 20; i = 20;
xtn->source_path = "test.st"; xtn->source_path = "test.st";

View File

@ -193,7 +193,6 @@ void moo_fini (moo_t* moo)
if (cb->fini) cb->fini (moo); if (cb->fini) cb->fini (moo);
} }
moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */ moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */
moo_rbt_fini (&moo->modtab); moo_rbt_fini (&moo->modtab);