-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add degenerate implementation of MVars.
This implementation will error out whenever a code path blocks on an MVar, as the non-concurrent environment guarantees that no other thread will come along to unblock the MVar. This commit fixes half of #11.
- Loading branch information
Showing
5 changed files
with
73 additions
and
8 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ Data-Files: | |
stdlib.js | ||
eval.js | ||
eval-trampoline.js | ||
MVar.js | ||
|
||
Library | ||
Hs-Source-Dirs: src | ||
|
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,56 @@ | ||
// MVar implementation. | ||
// Since Haste isn't concurrent, takeMVar and putMVar don't block on empty | ||
// and full MVars respectively, but terminate the program since they would | ||
// otherwise be blocking forever. | ||
|
||
function newMVar(st) { | ||
return [1, st, {empty: true}]; | ||
} | ||
|
||
function tryTakeMVar(mv, st) { | ||
if(mv.empty) { | ||
return [1, st, 0, undefined]; | ||
} else { | ||
mv.empty = true; | ||
mv.x = null; | ||
return [1, st, 1, mv.x]; | ||
} | ||
} | ||
|
||
function takeMVar(mv, st) { | ||
if(mv.empty) { | ||
// TODO: real BlockedOnDeadMVar exception, perhaps? | ||
err("Attempted to take empty MVar!"); | ||
} | ||
mv.empty = true; | ||
mv.x = null; | ||
return [1,st,mv.x]; | ||
} | ||
|
||
function putMVar(mv, val, st) { | ||
if(!mv.empty) { | ||
// TODO: real BlockedOnDeadMVar exception, perhaps? | ||
err("Attempted to put full MVar!"); | ||
} | ||
mv.empty = false; | ||
mv.x = val; | ||
return [1,st]; | ||
} | ||
|
||
function tryPutMVar(mv, val, st) { | ||
if(!mv.empty) { | ||
return [1, st, 0]; | ||
} else { | ||
mv.empty = false; | ||
mv.x = val; | ||
return [1, st, 1]; | ||
} | ||
} | ||
|
||
function sameMVar(a, b) { | ||
return (a == b); | ||
} | ||
|
||
function isEmptyMVar(mv, st) { | ||
return [1, st, mv.empty ? 1 : 0]; | ||
} |
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
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