Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java] expand the dependency circle with Context and ThreadContext
- Loading branch information
Martin Berends
committed
Aug 28, 2010
1 parent
1de869a
commit 78103c0
Showing
7 changed files
with
197 additions
and
44 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
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,9 @@ | ||
package Rakudo.Metamodel; | ||
|
||
import Rakudo.Metamodel.RakudoObject; | ||
import Rakudo.Runtime.ThreadContext; | ||
|
||
public interface IFindMethod { | ||
public RakudoObject FindMethod( | ||
ThreadContext tc, RakudoObject ro, String s, int i); | ||
} |
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
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,102 @@ | ||
package Rakudo.Runtime; | ||
|
||
import java.util.*; // HashMap | ||
import Rakudo.Metamodel.RakudoObject; | ||
import Rakudo.Metamodel.Representations.RakudoCodeRef; | ||
|
||
/// <summary> | ||
/// A context represents a given invocation of a block. (Note this is | ||
/// fairly sketchy at the moment.) | ||
/// </summary> | ||
public class Context | ||
{ | ||
/// <summary> | ||
/// The static chain. | ||
/// </summary> | ||
public Context Outer; | ||
|
||
/// <summary> | ||
/// The dynamic chain. | ||
/// </summary> | ||
public Context Caller; | ||
|
||
/// <summary> | ||
/// The static code object. | ||
/// </summary> | ||
public RakudoCodeRef.Instance StaticCodeObject; | ||
|
||
/// <summary> | ||
/// Lexpad. Note that we'll in the end have something much smarter | ||
/// for this but it'll do for now. | ||
/// </summary> | ||
public HashMap<String, RakudoObject> LexPad; | ||
|
||
/// <summary> | ||
/// The capture passed as part of the current call. | ||
/// </summary> | ||
public RakudoObject Capture; | ||
|
||
/// <summary> | ||
/// Creates an empty, uninitialized context. | ||
/// </summary> | ||
public Context() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes the context. | ||
/// </summary> | ||
/// <param name="StaticCodeObject"></param> | ||
/// <param name="Caller"></param> | ||
public Context(RakudoCodeRef.Instance StaticCodeObject, Context Caller, RakudoObject Capture) | ||
{ | ||
// Set up static code object and caller pointers. | ||
this.StaticCodeObject = StaticCodeObject; | ||
this.Caller = Caller; | ||
this.Capture = Capture; | ||
|
||
// Static sub object should have this as the current | ||
// context. | ||
// StaticCodeObject.CurrentContext = this; | ||
|
||
// Lex pad should be copy of the static one. | ||
// XXX This isn't quite what we want in the long run, but it | ||
// does fine for now. | ||
// this.LexPad = new HashMap<String, RakudoObject>(StaticCodeObject.StaticLexPad); | ||
|
||
// Set outer context. | ||
RakudoCodeRef.Instance OuterBlock = StaticCodeObject.OuterBlock; | ||
// if (OuterBlock.CurrentContext != null) | ||
// { | ||
// this.Outer = OuterBlock.CurrentContext; | ||
// } | ||
// else | ||
{ | ||
// Auto-close. In this we go setting up fake contexts | ||
// that use the static lexpad until we find a real one. | ||
Context CurContext = this; | ||
while (OuterBlock != null) | ||
{ | ||
// If we found a block with a context, we're done. | ||
// if (OuterBlock.CurrentContext != null) | ||
// { | ||
// CurContext.Outer = OuterBlock.CurrentContext; | ||
// break; | ||
// } | ||
|
||
// Build the fake context. | ||
Context OuterContext = new Context(); | ||
OuterContext.StaticCodeObject = OuterBlock; | ||
// OuterContext.LexPad = OuterBlock.StaticLexPad; | ||
|
||
// Link it. | ||
CurContext.Outer = OuterContext; | ||
|
||
// Step back one level. | ||
CurContext = OuterContext; | ||
OuterBlock = OuterBlock.OuterBlock; | ||
} | ||
} | ||
} | ||
} | ||
|
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,41 @@ | ||
package Rakudo.Runtime; | ||
|
||
import Rakudo.Metamodel.RakudoObject; | ||
import Rakudo.Runtime.Context; | ||
|
||
/// <summary> | ||
/// We have one of these per thread that we are running. | ||
/// </summary> | ||
public class ThreadContext | ||
{ | ||
/// <summary> | ||
/// The execution domain that we're operating under. | ||
/// </summary> | ||
public ExecutionDomain Domain; | ||
|
||
/// <summary> | ||
/// The current context we're in. | ||
/// </summary> | ||
public Context CurrentContext; | ||
|
||
/// <summary> | ||
/// The type object of the bool type we box to. | ||
/// </summary> | ||
public RakudoObject DefaultBoolBoxType; | ||
|
||
/// <summary> | ||
/// The type object of the integer type we box to. | ||
/// </summary> | ||
public RakudoObject DefaultIntBoxType; | ||
|
||
/// <summary> | ||
/// The type object of the number type we box to. | ||
/// </summary> | ||
public RakudoObject DefaultNumBoxType; | ||
|
||
/// <summary> | ||
/// The type object of the string type we box to. | ||
/// </summary> | ||
public RakudoObject DefaultStrBoxType; | ||
} | ||
|