-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up source files and export to
soundness
- Loading branch information
1 parent
f6e5dc0
commit 1d33aa2
Showing
5 changed files
with
108 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Feudalism, version [unreleased]. Copyright 2024 Jon Pretty, Propensive OÜ. | ||
The primary distribution site is: https://propensive.com/ | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this | ||
file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
either express or implied. See the License for the specific language governing permissions | ||
and limitations under the License. | ||
*/ | ||
|
||
package feudalism | ||
|
||
import scala.reflect.* | ||
|
||
import language.experimental.captureChecking | ||
|
||
trait Immutable[MutableType, ImmutableType]: | ||
def snapshot(ref: ImmutableType): ImmutableType = ref | ||
def make(ref: MutableType): ImmutableType | ||
|
||
object Immutable: | ||
given [ElementType: ClassTag] => Immutable[Array[ElementType], IArray[ElementType]] as array: | ||
def make(value: Array[ElementType]): IArray[ElementType] = value.asInstanceOf[IArray[ElementType]] | ||
|
||
override def snapshot(value: IArray[ElementType]): IArray[ElementType] = | ||
val array = new Array[ElementType](value.length) | ||
System.arraycopy(value, 0, array, 0, value.length) | ||
array.asInstanceOf[IArray[ElementType]] | ||
|
||
given Immutable[StringBuilder, String] as stringBuilder = _.toString | ||
given [ValueType](using DummyImplicit) => Immutable[ValueType, ValueType] as any = identity(_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Feudalism, version [unreleased]. Copyright 2024 Jon Pretty, Propensive OÜ. | ||
The primary distribution site is: https://propensive.com/ | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this | ||
file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
either express or implied. See the License for the specific language governing permissions | ||
and limitations under the License. | ||
*/ | ||
|
||
package feudalism | ||
|
||
import language.experimental.captureChecking | ||
|
||
class MutexRef[ValueType](value: ValueType, makeSnapshot: ValueType => ValueType): | ||
def apply(): ValueType = value | ||
def snapshot(): ValueType = makeSnapshot(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Feudalism, version [unreleased]. Copyright 2024 Jon Pretty, Propensive OÜ. | ||
The primary distribution site is: https://propensive.com/ | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this | ||
file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
either express or implied. See the License for the specific language governing permissions | ||
and limitations under the License. | ||
*/ | ||
|
||
package feudalism | ||
|
||
import language.experimental.captureChecking | ||
|
||
class Semaphore(): | ||
private var count: Int = 0 | ||
|
||
def access[ResultType](evaluate: => ResultType): ResultType = | ||
synchronized: | ||
while count == -1 do wait() | ||
count += 1 | ||
|
||
try evaluate finally synchronized: | ||
count -= 1 | ||
notify() | ||
|
||
def isolate[ResultType](evaluate: => ResultType): ResultType = | ||
synchronized: | ||
while count != 0 do wait() | ||
count = -1 | ||
|
||
try evaluate finally synchronized: | ||
count = 0 | ||
notify() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package soundness | ||
|
||
export feudalism.{Immutable, Mutex, MutexRef, Semaphore} |