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) shallowCopy.
method(#dual) shallowCopy
{
<primitive: #_shallow_copy>
self primitiveFailed(thisContext method).
}
method(#dual,#primitive,#lenient) _shallowCopy.
method(#dual,#primitive) shallowCopy.
## -------------------------------------------------------
## -------------------------------------------------------
method(#dual,#primitive,#lenient) _basicSize.
method(#dual,#primitive) basicSize.
method(#dual) basicAt: index
{
| 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 }
}
method(#dual,#primitive) basicAt: index.
method(#dual,#primitive) basicAt: index put: value.
(* ------------------------------------------------------------------
* FINALIZATION SUPPORT
* ------------------------------------------------------------------ *)
method(#dual,#primitive) addToBeFinalized.
##method(#dual,#primitive) removeToBeFinalized.
method(#dual,#primitive) removeToBeFinalized.
(* ------------------------------------------------------------------
* HASHING
* ------------------------------------------------------------------ *)
method(#dual,#primitive) hash.
(*
method(#dual) hash
{
<primitive: #_hash>
<primitive: #Apex_hash>
self subclassResponsibility: #hash
}
}*)
(* ------------------------------------------------------------------
* IDENTITY TEST
* ------------------------------------------------------------------ *)
method(#dual) == anObject
{
(* check if the receiver is identical to anObject.
* this doesn't compare the contents *)
<primitive: #_identical>
self primitiveFailed.
}
## check if the receiver is identical to anObject.
## this doesn't compare the contents
method(#dual, #primitive) == anObject.
method(#dual) ~~ anObject
{
<primitive: #_not_identical>
<primitive: #'Apex_~~'>
^(self == anObject) not.
}
@ -168,13 +138,13 @@ extend Apex
* ------------------------------------------------------------------ *)
method(#dual) = anObject
{
<primitive: #_equal>
<primitive: #'Apex_='>
self subclassResponsibility: #=
}
method(#dual) ~= anObject
{
<primitive: #_not_equal>
<primitive: #'Apex_~='>
^(self = anObject) not.
}
@ -184,7 +154,7 @@ extend Apex
* ------------------------------------------------------------------ *)
method(#dual,#primitive) class.
method(#dual) isNil
{
## ^self == nil.
@ -243,50 +213,41 @@ extend Apex
method(#dual) isKindOf: aClass
{
<primitive: #_is_kind_of>
<primitive: #Apex_isKindOf:>
^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass].
}
## -------------------------------------------------------
## -------------------------------------------------------
method(#dual) respondsTo: selector
{
<primitive: #_responds_to>
self primitiveFailed
}
method(#dual,#primitive) respondsTo: selector.
## -------------------------------------------------------
## -------------------------------------------------------
method(#dual,#variadic) perform(selector)
{
<primitive: #_perform>
self primitiveFailed
}
method(#dual,#variadic,#primitive) perform(selector).
method(#dual) perform: selector
{
<primitive: #_perform>
<primitive: #Apex_perform>
self primitiveFailed
}
method(#dual) perform: selector with: arg1
{
<primitive: #_perform>
<primitive: #Apex_perform>
self primitiveFailed
}
method(#dual) perform: selector with: arg1 with: arg2
{
<primitive: #_perform>
<primitive: #Apex_perform>
self primitiveFailed
}
method(#dual) perform: selector with: arg1 with: arg2 with: arg3
{
<primitive: #_perform>
<primitive: #Apex_perform>
self primitiveFailed
}

View File

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

View File

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

View File

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