refactored the bytecode interpretation loop with computed jump tables

added incomplete code to support a semaphore group
This commit is contained in:
hyunghwan.chung
2017-09-21 07:56:51 +00:00
parent fb48e48889
commit 6711bc01fa
13 changed files with 1673 additions and 1145 deletions

View File

@ -10,7 +10,7 @@ class Collection(Object)
{
^self size > 0
}
method size
{
(* Each subclass must override this method because
@ -20,18 +20,18 @@ class Collection(Object)
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.ENOENT
}
method detect: block ifNone: exception_block
{
self do: [ :el | if (block value: el) { ^el } ].
@ -100,12 +100,12 @@ class(#character) String(Array)
^newstr
}
method asString
{
^self
}
(* TODO: Symbol is a #final class. Symbol new is not allowed. To create a symbol programatically, you should
* build a string and send asSymbol to the string............
method asSymbol
@ -113,7 +113,6 @@ class(#character) String(Array)
}
*)
(* The strlen method returns the number of characters before a terminating null.
* if no terminating null character exists, it returns the same value as the size method *)
method(#primitive,#lenient) _strlen.
@ -252,7 +251,7 @@ class Set(Collection)
index := hv rem: bs.
while ((self.bucket at: index) notNil) { index := (index + 1) rem: bs }.
}.
ass := Association key: key value: value.
self.tally := ntally.
self.bucket at: index put: ass.

View File

@ -10,13 +10,13 @@ class Association(Magnitude)
{
^self new key: key value: value
}
method key: key value: value
{
self.key := key.
self.value := value.
}
method value: value
{
self.value := value
@ -31,12 +31,12 @@ class Association(Magnitude)
{
^self.value
}
method = ass
{
^(self.key = ass key) and: [ self.value = ass value ]
}
method hash
{
^(self.key hash) + (self.value hash)
@ -230,7 +230,7 @@ class(#limited) Number(Magnitude)
{
^self to: end by: 1 do: block.
}
method priorTo: end by: step do: block
{
| i |
@ -306,7 +306,7 @@ class(#limited) SmallInteger(Integer)
## {
## ^0
## }
method(#primitive) asCharacter.
method(#primitive) asError.
}

View File

@ -47,15 +47,16 @@ class(#pointer,#final,#limited) Process(Object)
class Semaphore(Object)
{
var count := 0,
waiting_head := nil,
var waiting_head := nil,
waiting_tail := nil,
count := 0,
heapIndex := -1,
fireTimeSec := 0,
fireTimeNsec := 0,
ioIndex := -1,
ioHandle := nil,
ioMask := 0.
ioMask := 0,
group := nil.
method(#class) forMutualExclusion
{
@ -122,10 +123,73 @@ TODO: timed wait...
^self.fireTimeSec >= (aSemaphore fireTime)
}
}
(*
xxx := Semaphore new.
xxx on: #signal do: [ ].
========= CASE 1 ====================
sg := SemaphoreGroup with (xxx, yyy, zzz).
Processor signal: xxx onInput: aaa.
Processor signal: yyy onInput: bbb.
Processor signal: zzz onOutput: ccc.
while (true)
{
sem := sg wait.
if (sem == xxx)
{
}
elsif (sem == yyy)
{
}
elsif (sem == zzz)
{
}
}
============ CASE 2====================
### ASSOCIATE CALLBACK WITH SEMAPHORE.
sg := SemaphoreGroup with (xxx, yyy, zzz).
oldaction := xxx signalAction: [ ... ]. ### similar interface like unix system call signal()???? method signalAction: block {} , method signalAction { ^self.signalAction }
yyy signalAction: [ ... ].
zzz signalAction: [ ... ].
Processor signal: xxx onInput: aaa.
Processor signal: yyy onInput: bbb.
Processor signal: zzz onOutput: ccc.
while (true)
{
sem := sg wait. ### the action associated with the semaphore must get executed. => wait may be a primitive. the primitive handler may return failure... if so, the actual primitive body can execute the action easily
}
Semaphore>>method wait
{
<primitive: #Semaphore_wait>
if (errorCode == NO ERROR)
{
self.signalAction value. ## which is better???
self.sginalAction value: self.
}
}
*)
class SemaphoreGroup(Object)
{
var arr, size := 0.
var waiting_head := nil,
waiting_tail := nil,
size := 0,
pos := 0,
semarr := nil.
(* TODO: good idea to a shortcut way to prohibit a certain method in the heirarchy chain?
@ -156,13 +220,13 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit
method initialize
{
self.arr := Array new: 10.
self.semarr := Array new: 10.
}
method initialize: arr
{
self.size := arr size.
self.arr := arr.
self.semarr := arr.
}
method(#primitive) wait.

View File

@ -104,6 +104,19 @@ extend MyObject
{
## TODO: support import in extend??
method(#class) makeBlock(a,b)
{
^[:x | a * x + b]
}
method(#class) testMakeBlock
{
|a b |
a := self makeBlock (12, 22).
b := self makeBlock (99, 4).
^(a value: 5) * (b value: 6). ## (12 * 5 + 22) * (99 * 6 + 4) => 49036
}
method(#class) main
{
| tc limit |
@ -159,7 +172,8 @@ extend MyObject
[MyObject.System.System.System.System new kk == #KK],
## 35 - 39
[MyObject.System.System.System KING == #KING]
[MyObject.System.System.System KING == #KING],
[self testMakeBlock == 49036]
).
limit := tc size.