From 117473f63887e2e75d84e5550402fc8aabff6748 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Wed, 16 Mar 2016 10:13:03 +0000 Subject: [PATCH] fixed a bug in stix_oowtoint() fixed bugs of SemaphoreHeap --- stix/kernel/Context.st | 7 +++++++ stix/kernel/Process.st | 43 +++++++++++++++++++++++++++--------------- stix/lib/bigint.c | 4 +++- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/stix/kernel/Context.st b/stix/kernel/Context.st index 58a261c..4d9ddba 100644 --- a/stix/kernel/Context.st +++ b/stix/kernel/Context.st @@ -146,6 +146,13 @@ ## self value ifTrue: [ aBlock value. thisContext restart. ]. } + #method whileFalse: aBlock + { + (self value) ifTrue: [^nil]. + aBlock value. + self whileFalse: aBlock. + } + #method pc { ^ip diff --git a/stix/kernel/Process.st b/stix/kernel/Process.st index 49048e9..8498580 100644 --- a/stix/kernel/Process.st +++ b/stix/kernel/Process.st @@ -119,6 +119,11 @@ ^self.size } + #method at: anIndex + { + ^self.arr at: anIndex. + } + #method insert: aSemaphore { self.size >= (self.arr size) ifTrue: [ @@ -197,27 +202,36 @@ #method siftUp: anIndex { - | pindex cindex par cur | + | pindex cindex par item stop | - anIndex <= 1 ifTrue: [ ^anIndex ]. + (anIndex <= 1) ifTrue: [ ^anIndex ]. - cindex := anIndex. - pindex := self parentIndex: anIndex. + pindex := anIndex. + item := self.arr at: anIndex. - par := self.arr at: pindex. - cur := self.arr at: cindex. - - [ cur youngerThan: par ] whileTrue: [ + stop := false. + [ stop ] whileFalse: [ cindex := pindex. - pindex := self parentIndex: pindex. - par := self.arr at: pindex. - cur := self.arr at: cindex. + (cindex > 1) + ifTrue: [ + pindex := self parentIndex: cindex. + par := self.arr at: pindex. + + (item youngerThan: par) + ifTrue: [ + ## move the parent down + self.arr at: cindex put: par. + par heapIndex: cindex. + ] + ifFalse: [ stop := true ]. + ] + ifFalse: [ stop := true ]. ]. - self.arr at: cindex put: cur. - cur heapIndex: cindex. + self.arr at: cindex put: item. + item heapIndex: cindex. ^cindex } @@ -226,8 +240,7 @@ { | base capa cindex item | - - base := self.size quo: 2. + base := (self.size quo: 2) + 1. (anIndex > base) ifTrue: [^anIndex]. cindex := anIndex. diff --git a/stix/lib/bigint.c b/stix/lib/bigint.c index 2760757..ed8b977 100644 --- a/stix/lib/bigint.c +++ b/stix/lib/bigint.c @@ -439,7 +439,9 @@ static STIX_INLINE stix_oop_t make_bigint_with_intmax (stix_t* stix, stix_intmax stix_oop_t stix_oowtoint (stix_t* stix, stix_oow_t w) { - if (STIX_IN_SMOOI_RANGE(w)) + STIX_ASSERT (STIX_TYPE_IS_UNSIGNED(stix_oow_t)); + /*if (STIX_IN_SMOOI_RANGE(w))*/ + if (w <= STIX_SMOOI_MAX) { return STIX_SMOOI_TO_OOP(w); }