added moo_iskindof().
changed isKindOf: to utilize a new primitive _is_kind_of. marked BlockContext and MethodContext to be #final and #limited
This commit is contained in:
@ -215,10 +215,15 @@ extend Apex
|
||||
{
|
||||
| c |
|
||||
c := self superclass.
|
||||
[c notNil] whileTrue: [
|
||||
(* [c notNil] whileTrue: [
|
||||
[ c == aClass ] ifTrue: [^true].
|
||||
c := c superclass.
|
||||
].
|
||||
]. *)
|
||||
while (c notNil)
|
||||
{
|
||||
if (c == aClass) { ^true }.
|
||||
c := c superclass.
|
||||
}.
|
||||
^false
|
||||
}
|
||||
|
||||
@ -233,6 +238,7 @@ extend Apex
|
||||
|
||||
method(#class) isKindOf: aClass
|
||||
{
|
||||
<primitive: #_is_kind_of>
|
||||
^(self isMemberOf: aClass) or: [self inheritsFrom: aClass].
|
||||
}
|
||||
|
||||
@ -243,6 +249,7 @@ extend Apex
|
||||
|
||||
method isKindOf: aClass
|
||||
{
|
||||
<primitive: #_is_kind_of>
|
||||
^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass].
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ block context...
|
||||
---------------------------------- *)
|
||||
}
|
||||
|
||||
class(#pointer) MethodContext(Context)
|
||||
class(#pointer,#final,#limited) MethodContext(Context)
|
||||
{
|
||||
var method, receiver, home, origin.
|
||||
|
||||
@ -99,7 +99,7 @@ class(#pointer) MethodContext(Context)
|
||||
}
|
||||
}
|
||||
|
||||
class(#pointer) BlockContext(Context)
|
||||
class(#pointer,#final,#limited) BlockContext(Context)
|
||||
{
|
||||
var nargs, source, home, origin.
|
||||
|
||||
|
@ -94,12 +94,14 @@ TODO: timed wait...
|
||||
}
|
||||
*)
|
||||
|
||||
(* TODO: MIGRATE TO MUTEX...
|
||||
method critical: aBlock
|
||||
{
|
||||
self wait.
|
||||
^aBlock ensure: [ self signal ]
|
||||
}
|
||||
}*)
|
||||
|
||||
|
||||
## ==================================================================
|
||||
|
||||
method heapIndex
|
||||
@ -133,6 +135,26 @@ TODO: timed wait...
|
||||
}
|
||||
}
|
||||
|
||||
class Mutex(Semaphore)
|
||||
{
|
||||
method(#class) new
|
||||
{
|
||||
| s |
|
||||
s := super new.
|
||||
s signal.
|
||||
^s.
|
||||
}
|
||||
|
||||
method lock { ^self wait }
|
||||
method unlock { ^self signal }
|
||||
|
||||
method critical: block
|
||||
{
|
||||
self wait.
|
||||
^block ensure: [ self signal ]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
(*
|
||||
xxx := Semaphore new.
|
||||
|
@ -1,5 +1,7 @@
|
||||
## TODO: use this file as a regress testing source.
|
||||
## rename it to test-001.moo and use it as a test case file.
|
||||
##
|
||||
## TEST CASES for namespacing
|
||||
##
|
||||
|
||||
#include 'Moo.moo'.
|
||||
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
##
|
||||
## TEST CASES for basic methods
|
||||
##
|
||||
|
||||
#include 'Moo.moo'.
|
||||
|
||||
@ -50,8 +53,30 @@ class MyObject(TestObject)
|
||||
|
||||
method(#class) main
|
||||
{
|
||||
'START OF MAIN' dump.
|
||||
'EDN OF MAIN' dump.
|
||||
}
|
||||
| tc limit |
|
||||
|
||||
tc := %(
|
||||
## 0 - 4
|
||||
[(Object isKindOf: Class) == true],
|
||||
[(Object isKindOf: Apex) == true],
|
||||
[(Class isKindOf: Class) == true],
|
||||
[(Class isKindOf: Apex) == true],
|
||||
[(Class isKindOf: Object) == false],
|
||||
|
||||
[(Apex isKindOf: Class) == true],
|
||||
[(SmallInteger isKindOf: Integer) == false],
|
||||
[(10 isKindOf: Integer) == true],
|
||||
|
||||
[(Apex isMemberOf: Class) == true],
|
||||
[(Class isMemberOf: Class) == true]
|
||||
).
|
||||
|
||||
limit := tc size.
|
||||
|
||||
0 priorTo: limit by: 1 do: [ :idx |
|
||||
| tb |
|
||||
tb := tc at: idx.
|
||||
System log(System.Log.INFO, idx asString, (if (tb value) { ' PASS' } else { ' FAIL' }), S'\n').
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user