This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add partial continuation stuff for maglev, for later use
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 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,3 @@ | ||
class Exception | ||
primitive '__resume', 'resume:' | ||
end |
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,21 @@ | ||
require File.expand_path("../method.rb", __FILE__) | ||
require File.expand_path("../thread.rb", __FILE__) | ||
|
||
class ExecBlock | ||
primitive 'shift', 'shift' | ||
primitive 'reset', 'reset' | ||
end | ||
|
||
class Proc | ||
def __shift | ||
@_st_block.shift | ||
end | ||
|
||
def __reset | ||
@_st_block.reset | ||
end | ||
end | ||
|
||
class Thread | ||
primitive 'call', 'call:' | ||
end |
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,50 @@ | ||
class PartialContinuation | ||
attr_accessor :markerBlock, :partial | ||
|
||
def self.currentDomarkerBlock(block, markerBlock) | ||
if (marker = markerBlock.call).nil? | ||
raise RuntimeError, 'Marker not found when capturing partial continuation.' | ||
end | ||
return block.call to_offset_markerBlock(marker, 1, markerBlock) | ||
end | ||
|
||
def self.to_offset_markerBlock(method, offset, &block) | ||
idx = find_frame_for(method) | ||
partial = Thread.__partialContinuationFromLevel_to(3 + offset, idx) | ||
new.tap do |o| | ||
o.partial = partial | ||
o.markerBlock = block | ||
end | ||
end | ||
|
||
def self.find_frame_for(method) | ||
index = 1 | ||
while frame = Thread.current.__frame_contents_at(index) do | ||
if frame[0] == method | ||
return level | ||
else | ||
level += 1 | ||
end | ||
end | ||
nil | ||
end | ||
|
||
def call(arg = nil) | ||
marker = markerBlock.call | ||
if marker.nil? | ||
marker = Thread.current.__frame_contents_at(2).first | ||
frameIndex = 2 | ||
else | ||
frameIndex = self.class.find_frame_for marker | ||
end | ||
Thread.current.__installPartialContinuation_atLevel_value partial, frameIndex, arg | ||
end | ||
|
||
alias [] call | ||
end | ||
|
||
def test_callcc | ||
PartialContinuation.currentDomarkerBlock | ||
currentDo: aBlock | ||
markerBlock: [ self callbackMarker ] | ||
end |