Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[java] various changes catching up to dotnet/ without passing more tests

  • Loading branch information...
commit 4252adf6a1ad2dc6ca112ef5b5bdcb867f37cbbb 1 parent a0fc0dd
@mberends mberends authored
View
1  java/compiler/JST2Java.pm
@@ -439,6 +439,7 @@ sub literal_escape($str_in) {
while pir::length($str_in) {
my $char := pir::substr($str_in, 0, 1);
$str_in := pir::substr($str_in, 1);
+ if $char eq "\"" { $char := "\\\""; }
if $char eq "\n" { $char := "\\n"; }
if $char eq "\t" { $char := "\\t"; }
$str_out := $str_out ~ $char;
View
10 java/compiler/Makefile
@@ -18,6 +18,9 @@ gen_grammar.pir: Grammar.pm
gen_past2jst.pir: PAST2JSTCompiler.pm
parrot-nqp --target=pir PAST2JSTCompiler.pm > gen_past2jst.pir
+gen_nqpoptimizer.pir: ../../dotnet/compiler/NQPOptimizer.pm
+ parrot-nqp --target=pir ../../dotnet/compiler/NQPOptimizer.pm > gen_nqpoptimizer.pir
+
gen_jst.pir: JST.pm
parrot-nqp --target=pir JST.pm > gen_jst.pir
@@ -36,6 +39,13 @@ NQPSetting.jar: NQPSetting.java
$(JAVAC) -classpath ../runtime/RakudoRuntime.jar NQPSetting.java
jar cf NQPSetting.jar -C $(CLASSES) .
+P6Objects.java: compile.pir gen_actions.pir gen_grammar.pir gen_nqpoptimizer.pir gen_jst.pir gen_past2jst.pir gen_jst2java.pir ../../common/NQP/P6Objects.pm NQPSetting.jar
+ parrot compile.pir ../../common/NQP/P6Objects.pm --no-core-libs > P6Objects.java
+
+P6Objects.jar: P6Objects.java
+ $(JAVAC) P6Objects.java
+ jar cf P6Objects.jar P6Objects.class
+
test: all
prove -r --exec try.sh ..\..\t\nqp
View
71 java/compiler/PAST2JSTCompiler.pm
@@ -882,7 +882,7 @@ sub form_capture(@args, $inv?) {
);
my $pos_part := JST::ArrayLiteral.new( :type('RakudoObject') );
my $named_part := JST::DictionaryLiteral.new(
- :key_type('string'), :value_type('RakudoObject') );
+ :key_type('String'), :value_type('RakudoObject') );
my $flatten_flags := JST::ArrayLiteral.new( :type('int') );
my $has_flats := 0;
@@ -1018,25 +1018,76 @@ our multi sub jst_for(PAST::Var $var) {
}
}
elsif $scope eq 'package' {
- if $var.isdecl { pir::die("Don't know how to handle is_decl on package"); }
-
# Get all parts of the name.
my @parts;
- if $var.namespace {
+ @parts.push('GLOBAL');
+ if pir::isa($var.namespace, 'ResizablePMCArray') {
for $var.namespace { @parts.push($_); }
}
+ elsif +@*CURRENT_NS {
+ for @*CURRENT_NS {
+ @parts.push($_)
+ }
+ }
@parts.push($var.name);
# First, we need to look up the first part.
- my $lookup := emit_lexical_lookup(@parts.shift);
+ my $lookup;
+ {
+ my $*BIND_CONTEXT := 0;
+ $lookup := emit_lexical_lookup(@parts.shift);
+ }
+
+ # Also need to treat last part specially.
+ my $target := @parts.pop;
# Now chase down the rest.
for @parts {
- # XXX todo: wrap the lookup in postcircumfix:<{ }> call(s).
- pir::die('Multi-level package lookups NYI');
+ $lookup := jst_for(PAST::Op.new(
+ :pasttype('callmethod'), :name('get_namespace'),
+ $lookup,
+ PAST::Val.new( :value(~$_) )
+ ));
+ }
+
+ # Binding, if needed.
+ if $*BIND_CONTEXT {
+ my $*BIND_CONTEXT := 0;
+ $lookup := jst_for(PAST::Op.new(
+ :pasttype('callmethod'), :name('bind_key'),
+ $lookup,
+ PAST::Val.new( :value(~$target) ),
+ $*BIND_VALUE
+ ));
+ }
+ else {
+ $lookup := jst_for(PAST::Op.new(
+ :pasttype('callmethod'), :name('at_key'),
+ $lookup,
+ PAST::Val.new( :value(~$target) )
+ ));
}
return $lookup;
+# if $var.isdecl { pir::die("PAST2JSTCompiler.pm does not know how to handle is_decl on package"); }
+
+ # Get all parts of the name.
+ # my @parts;
+ # if $var.namespace {
+ # for $var.namespace { @parts.push($_); }
+ # }
+ # @parts.push($var.name);
+
+ # First, we need to look up the first part.
+ # my $lookup := emit_lexical_lookup(@parts.shift);
+
+ # Now chase down the rest.
+ # for @parts {
+ # # XXX todo: wrap the lookup in postcircumfix:<{ }> call(s).
+ # pir::die('Multi-level package lookups NYI');
+ # }
+
+# return $lookup;
}
elsif $scope eq 'register' {
if $var.isdecl {
@@ -1213,7 +1264,7 @@ sub temp_int($arg?, :$name) {
sub temp_str($arg?, :$name) {
JST::Local.new(
- :name(get_unique_id('string_' ~ ($name || ''))), :isdecl(1), :type('string'),
+ :name(get_unique_id('string_' ~ ($name || ''))), :isdecl(1), :type('String'),
pir::defined($arg) ?? jst_for($arg) !! lits("")
)
}
@@ -1238,7 +1289,7 @@ sub unbox($type, $arg) {
# Maps a hand-wavey type (one of the three we box/unbox with) to a CLR type.
sub vm_type_for($type) {
$type eq 'num' ?? 'double' !!
- $type eq 'str' ?? 'string' !!
+ $type eq 'str' ?? 'String' !!
$type eq 'int' ?? 'int' !!
$type eq 'obj' ?? 'RakudoObject' !!
pir::die("Don't know VM type for $type")
@@ -1427,7 +1478,7 @@ sub returns_array($expr, *@result_slots) {
JST::Local.new(:name($tmp.name)),
lit(~($i / 2))))
!!
- @result_slots[$i + 1] eq 'string'
+ @result_slots[$i + 1] eq 'String'
?? unbox('str', emit_op('lllist_get_at_pos',
JST::Local.new(:name($tmp.name)),
lit(~($i / 2))))
View
44 java/runtime/Makefile
@@ -85,6 +85,7 @@ OTHER_DEPENDENT_TARGETS = \
$(CLASSES)Rakudo/Runtime/Ops.class \
$(CLASSES)Rakudo/Runtime/ThreadContext.class \
$(CLASSES)Rakudo/Metamodel/IFindMethod.class \
+ $(CLASSES)Rakudo/Metamodel/ISpecialFindMethod.class \
$(CLASSES)Rakudo/Metamodel/SharedTable.class
INNER_CLASSES = \
@@ -125,14 +126,17 @@ $(CLASSES)Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.jav
$(CLASSES)Rakudo/Runtime/DefinednessConstraint.class \
Rakudo/Serialization/SerializationContext.java \
Rakudo/Metamodel/Representation.java \
- Rakudo/Runtime/CaptureHelper.java \
- Rakudo/Runtime/Lexpad.java \
- Rakudo/Runtime/Parameter.java \
- Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/Representations/P6capture.java \
+ Rakudo/Metamodel/Representations/P6int.java \
Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6mapping.java \
+ Rakudo/Metamodel/Representations/P6num.java \
+ Rakudo/Metamodel/Representations/P6str.java \
Rakudo/Metamodel/Representations/RakudoCodeRef.java \
+ Rakudo/Runtime/CaptureHelper.java \
+ Rakudo/Runtime/Lexpad.java \
+ Rakudo/Runtime/Parameter.java \
+ Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/REPRRegistry.java \
Rakudo/Runtime/Context.java \
Rakudo/Runtime/ExecutionDomain.java \
@@ -144,18 +148,22 @@ $(CLASSES)Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.jav
Rakudo/Runtime/Ops.java \
Rakudo/Runtime/ThreadContext.java \
Rakudo/Metamodel/IFindMethod.java \
+ Rakudo/Metamodel/ISpecialFindMethod.java \
Rakudo/Metamodel/SharedTable.java
$(JAVAC) \
Rakudo/Metamodel/RakudoObject.java \
Rakudo/Metamodel/Representation.java \
- Rakudo/Runtime/CaptureHelper.java \
- Rakudo/Runtime/Lexpad.java \
- Rakudo/Runtime/Parameter.java \
- Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/Representations/P6capture.java \
+ Rakudo/Metamodel/Representations/P6int.java \
Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6mapping.java \
+ Rakudo/Metamodel/Representations/P6num.java \
+ Rakudo/Metamodel/Representations/P6str.java \
Rakudo/Metamodel/Representations/RakudoCodeRef.java \
+ Rakudo/Runtime/CaptureHelper.java \
+ Rakudo/Runtime/Lexpad.java \
+ Rakudo/Runtime/Parameter.java \
+ Rakudo/Runtime/Signature.java \
Rakudo/Metamodel/REPRRegistry.java \
Rakudo/Runtime/Context.java \
Rakudo/Runtime/ExecutionDomain.java \
@@ -167,6 +175,7 @@ $(CLASSES)Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.jav
Rakudo/Runtime/Ops.java \
Rakudo/Runtime/ThreadContext.java \
Rakudo/Metamodel/IFindMethod.java \
+ Rakudo/Metamodel/ISpecialFindMethod.java \
Rakudo/Metamodel/SharedTable.java
$(CLASSES)Rakudo/Metamodel/KnowHOW/KnowHOWREPR.class: Rakudo/Metamodel/KnowHOW/KnowHOWREPR.java \
@@ -283,8 +292,7 @@ TRANSLATED_SOURCE_FILES = \
Rakudo/Metamodel/SharedTable.java \
Rakudo/Metamodel/Representations/P6capture.java \
Rakudo/Metamodel/Representations/P6hash.java \
- Rakudo/Metamodel/Representations/P6int.java \
- Rakudo/Metamodel/Representations/P6list.java \
+ Rakudo/Metamodel/Representations/P6int.java \ Rakudo/Metamodel/Representations/P6list.java \
Rakudo/Metamodel/Representations/P6mapping.java \
Rakudo/Metamodel/Representations/P6num.java \
Rakudo/Metamodel/Representations/P6opaque.java \
@@ -390,8 +398,20 @@ Rakudo/Runtime/MultiDispatch/DispatchCache.java: ../../dotnet/runtime/Runtime/Mu
Rakudo/Runtime/MultiDispatch/MultiDispatcher.java: ../../dotnet/runtime/Runtime/MultiDispatch/MultiDispatcher.cs
@echo "todo: Rakudo/Runtime/MultiDispatch/MultiDispatcher.java is older than ../../dotnet/runtime/Runtime/MultiDispatch/MultiDispatcher.cs"
-#Rakudo/Runtime/Ops.java: ../../dotnet/runtime/Runtime/Ops.cs
-# @echo "todo: Rakudo/Runtime/Ops.java is older than ../../dotnet/runtime/Runtime/Ops.cs"
+Rakudo/Runtime/Ops.java: ../../dotnet/runtime/Runtime/Ops/Boxing.cs \
+ ../../dotnet/runtime/Runtime/Ops/Coercion.cs \
+ ../../dotnet/runtime/Runtime/Ops/Comparison.cs \
+ ../../dotnet/runtime/Runtime/Ops/ControlFlow.cs \
+ ../../dotnet/runtime/Runtime/Ops/Dispatch.cs \
+ ../../dotnet/runtime/Runtime/Ops/Introspection.cs \
+ ../../dotnet/runtime/Runtime/Ops/Library.cs \
+ ../../dotnet/runtime/Runtime/Ops/Metamodel.cs \
+ ../../dotnet/runtime/Runtime/Ops/P6capture.cs \
+ ../../dotnet/runtime/Runtime/Ops/P6list.cs \
+ ../../dotnet/runtime/Runtime/Ops/P6mapping.cs \
+ ../../dotnet/runtime/Runtime/Ops/Primitive.cs \
+ ../../dotnet/runtime/Runtime/Ops/Variables.cs
+ @echo "todo: Rakudo/Runtime/Ops.java is older than one of the files in ../../dotnet/runtime/Runtime/Ops/"
Rakudo/Runtime/Parameter.java: ../../dotnet/runtime/Runtime/Signatures/Parameter.cs
@echo "todo: Rakudo/Runtime/Parameter.java is older than ../../dotnet/runtime/Runtime/Signatures/Parameter.cs"
View
53 java/runtime/Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.java
@@ -23,7 +23,7 @@
/// for implementing the various other bits of the object model.
/// Works in conjunction with KnowHOWREPR.
/// </summary>
-public class KnowHOWBootstrapper // public static in the C# version
+public class KnowHOWBootstrapper // C# has public static
{
/// <summary>
/// Bootstraps the KnowHOW. This is were things "bottom out" in the
@@ -44,12 +44,16 @@ public static RakudoObject Bootstrap()
// We'll set up a dictionary of our various methods to go into
// KnowHOW's HOW, since we'll want to work with them a bit.
HashMap<String, RakudoObject> KnowHOWMeths = new HashMap<String, RakudoObject>();
- KnowHOWMeths.put("new_type", CodeObjectUtility.WrapNativeMethod( new RakudoCodeRef.IFunc_Body() { // an anonymous class where C# uses a lambda
+ KnowHOWMeths.put("new_type", CodeObjectUtility.WrapNativeMethod( new RakudoCodeRef.IFunc_Body() { // C# has a lambda
public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject capture)
{
// We first create a new HOW instance.
RakudoObject knowHOWTypeObj = CaptureHelper.GetPositional(capture, 0);
- RakudoObject HOW = knowHOWTypeObj.getSTable().REPR.instance_of(tc, knowHOWTypeObj.getSTable().WHAT);
+ RakudoObject HOW = knowHOWTypeObj.getSTable().REPR.instance_of(tc, knowHOWTypeObj.getSTable().WHAT);
+
+ // If we have a name arg, stash that value away.
+ RakudoObject typeName = CaptureHelper.GetNamed(capture, "name");
+ ((KnowHOWREPR.KnowHOWInstance)HOW).Name = typeName != null ? typeName : Ops.box_str(tc, "<anon>");
// Now create a new type object to go with it of the
// desired REPR; we default to P6opaque (note that the
@@ -96,9 +100,7 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject
// We go to some effort to be really fast in here, 'cus it's a
// hot path for dynamic dispatches.
RakudoObject[] Positionals = ((P6capture.Instance)capture).Positionals;
- if (Positionals.length < 3) {
- throw new IllegalArgumentException("Positionals has only " + Positionals.length + " elements");
- }
+ assert Positionals.length >= 3;
KnowHOWREPR.KnowHOWInstance HOW = (KnowHOWREPR.KnowHOWInstance)Positionals[0];
if (HOW.Methods.containsKey(Ops.unbox_str(tc, Positionals[2])))
return HOW.Methods.get(Ops.unbox_str(tc, Positionals[2]));
@@ -120,9 +122,11 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject
{
// Safe to just return a P6list instance that points at
// the same thing we hold internally, since a list is
- // immutable.
+ // immutable. However, if default list type has no HOW,
+ // we will see if we can find one that does have it.
KnowHOWREPR.KnowHOWInstance HOW = (KnowHOWREPR.KnowHOWInstance)CaptureHelper.GetPositional(capture, 0);
- RakudoObject result = tc.DefaultListType.getSTable().REPR.instance_of(tc, tc.DefaultListType);
+ RakudoObject listType = MostDefinedListType(tc);
+ RakudoObject result = listType.getSTable().REPR.instance_of(tc, listType);
((P6list.Instance)result).Storage = HOW.Attributes;
return result;
}
@@ -132,7 +136,8 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject
{
// Return the methods list.
KnowHOWREPR.KnowHOWInstance HOW = (KnowHOWREPR.KnowHOWInstance)CaptureHelper.GetPositional(capture, 0);
- RakudoObject result = tc.DefaultListType.getSTable().REPR.instance_of(tc, tc.DefaultListType);
+ RakudoObject listType = MostDefinedListType(tc);
+ RakudoObject result = listType.getSTable().REPR.instance_of(tc, listType);
((P6list.Instance)result).Storage.addAll(HOW.Methods.values());
return result;
}
@@ -141,7 +146,18 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject
public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject capture)
{
// A pure prototype never has any parents, so return an empty list.
- return tc.DefaultListType.getSTable().REPR.instance_of(tc, tc.DefaultListType);
+ RakudoObject listType = MostDefinedListType(tc);
+ return listType.getSTable().REPR.instance_of(tc, listType);
+ }
+ }));
+
+ KnowHOWMeths.put("type_check", CodeObjectUtility.WrapNativeMethod(new RakudoCodeRef.IFunc_Body() { // an anonymous class
+ public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject capture)
+ {
+ // Can only match against ourselves.
+ RakudoObject self = CaptureHelper.GetPositional(capture, 1);
+ RakudoObject check = CaptureHelper.GetPositional(capture, 2);
+ return Ops.box_int(tc, self.getSTable().WHAT == check.getSTable().WHAT ? 1 : 0, tc.DefaultBoolBoxType);
}
}));
@@ -214,5 +230,22 @@ public RakudoObject Invoke(ThreadContext tc, RakudoObject obj, RakudoObject capt
return knowHOWAttribute;
}
+
+ /// <summary>
+ /// Makes sure that we hand back an NQPList that has a HOW once it
+ /// is defined. Important for the bootstrap.
+ /// </summary>
+ /// <param name="tc"></param>
+ /// <returns></returns>
+ private static RakudoObject MostDefinedListType(ThreadContext tc)
+ {
+ // Have a HOW? Then return it right away.
+ if (tc.DefaultListType.getSTable().HOW != null)
+ return tc.DefaultListType;
+
+ // Otherwise, go and look for a list type that has one.
+ tc.DefaultListType = Ops.get_lex(tc, "NQPList");
+ return tc.DefaultListType;
+ }
}
View
57 java/runtime/Rakudo/Metamodel/KnowHOW/KnowHOWREPR.java
@@ -1,30 +1,27 @@
package Rakudo.Metamodel.KnowHOW;
-
import java.util.ArrayList;
import java.util.HashMap;
-
import Rakudo.Metamodel.Hints;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representation;
import Rakudo.Metamodel.SharedTable;
import Rakudo.Runtime.ThreadContext;
import Rakudo.Serialization.SerializationContext;
-
/// <summary>
-/// We have a REPR especially for the KnowHOW, which is part of the
-/// "bootstrap".
+/// We have a REPR especially for the KnowHOW, which is part of the "bootstrap".
/// </summary>
-public class KnowHOWREPR implements Representation
+public final class KnowHOWREPR implements Representation
{
/// <summary>
/// This represents an instance created with this underlying
/// representation. We use .Net data types for out attribute
/// and method store.
/// </summary>
- public class KnowHOWInstance extends RakudoObject
+ public class KnowHOWInstance extends RakudoObject // C# has internal
{
public ArrayList<RakudoObject> Attributes;
public HashMap<String, RakudoObject> Methods;
+ public RakudoObject Name;
public KnowHOWInstance(SharedTable sharedTable)
{
this.setSTable(sharedTable);
@@ -78,56 +75,56 @@ public RakudoObject get_attribute_with_hint(ThreadContext tc, RakudoObject Objec
throw new UnsupportedOperationException();
}
- public String get_str(ThreadContext tc, RakudoObject object)
+ public void bind_attribute(ThreadContext tc, RakudoObject Object, RakudoObject ClassHandle, String Name, RakudoObject Value)
{
throw new UnsupportedOperationException();
}
- public void set_str(ThreadContext tc, RakudoObject object, String s)
+ public void bind_attribute_with_hint(ThreadContext tc, RakudoObject Object, RakudoObject ClassHandle, String Name, int Hint, RakudoObject Value)
{
throw new UnsupportedOperationException();
}
- public double get_num(ThreadContext tc, RakudoObject object)
+ /// <summary>
+ /// We have attribute access hints for within the KnowHOW REPR, which
+ /// we just manually map to the indexes.
+ /// </summary>
+ /// <param name="ClassHandle"></param>
+ /// <param name="Name"></param>
+ /// <returns>int</returns>
+ public int hint_for(ThreadContext tc, RakudoObject ClassHandle, String Name)
{
- throw new UnsupportedOperationException();
+ return Hints.NO_HINT;
}
- public void set_num(ThreadContext tc, RakudoObject object, double d)
+ public void set_int(ThreadContext TC, RakudoObject Object, int Value)
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("This type of representation cannot box a native int");
}
- public int get_int(ThreadContext tc, RakudoObject object)
+ public int get_int(ThreadContext TC, RakudoObject Object)
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("This type of representation cannot unbox to a native int");
}
- public void set_int(ThreadContext tc, RakudoObject object, int i)
+ public void set_num(ThreadContext TC, RakudoObject Object, double Value)
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("This type of representation cannot box a native num");
}
- public void bind_attribute(ThreadContext tc, RakudoObject Object, RakudoObject ClassHandle, String Name, RakudoObject Value)
+ public double get_num(ThreadContext TC, RakudoObject Object)
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("This type of representation cannot unbox to a native num");
}
- public void bind_attribute_with_hint(ThreadContext tc, RakudoObject Object, RakudoObject ClassHandle, String Name, int Hint, RakudoObject Value)
+ public void set_str(ThreadContext TC, RakudoObject Object, String Value)
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("This type of representation cannot box a native string");
}
- /// <summary>
- /// We have attribute access hints for within the KnowHOW REPR, which
- /// we just manually map to the indexes.
- /// </summary>
- /// <param name="ClassHandle"></param>
- /// <param name="Name"></param>
- /// <returns>int</returns>
- public int hint_for(ThreadContext tc, RakudoObject ClassHandle, String Name)
+ public String get_str(ThreadContext TC, RakudoObject Object)
{
- return Hints.NO_HINT;
+ throw new UnsupportedOperationException("This type of representation cannot unbox to a native string");
}
}
View
22 java/runtime/Rakudo/Metamodel/Representations/P6list.java
@@ -64,57 +64,57 @@ public boolean defined(ThreadContext tc, RakudoObject object)
return ((Instance)object).Storage != null;
}
- public RakudoObject get_attribute(ThreadContext TC, RakudoObject object, RakudoObject classHandle, String name)
+ public RakudoObject get_attribute(ThreadContext TC, RakudoObject object, RakudoObject classHandle, String name)
{
throw new UnsupportedOperationException();
}
- public RakudoObject get_attribute_with_hint(ThreadContext TC, RakudoObject object, RakudoObject classHandle, String name, int hint)
+ public RakudoObject get_attribute_with_hint(ThreadContext TC, RakudoObject object, RakudoObject classHandle, String name, int hint)
{
throw new UnsupportedOperationException();
}
- public void bind_attribute(ThreadContext TC, RakudoObject object, RakudoObject classHandle, String name, RakudoObject value)
+ public void bind_attribute(ThreadContext TC, RakudoObject object, RakudoObject classHandle, String name, RakudoObject value)
{
throw new UnsupportedOperationException();
}
- public void bind_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint, RakudoObject value)
+ public void bind_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint, RakudoObject value)
{
throw new UnsupportedOperationException();
}
- public int hint_for(ThreadContext tc, RakudoObject classHandle, String name)
+ public int hint_for(ThreadContext tc, RakudoObject classHandle, String name)
{
throw new UnsupportedOperationException();
}
- public void set_int(ThreadContext tc, RakudoObject object, int value)
+ public void set_int(ThreadContext tc, RakudoObject object, int value)
{
throw new UnsupportedOperationException();
}
- public int get_int(ThreadContext tc, RakudoObject object)
+ public int get_int(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
- public void set_num(ThreadContext tc, RakudoObject object, double value)
+ public void set_num(ThreadContext tc, RakudoObject object, double value)
{
throw new UnsupportedOperationException();
}
- public double get_num(ThreadContext tc, RakudoObject object)
+ public double get_num(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
- public void set_str(ThreadContext tc, RakudoObject object, String value)
+ public void set_str(ThreadContext tc, RakudoObject object, String value)
{
throw new UnsupportedOperationException();
}
- public String get_str(ThreadContext tc, RakudoObject object)
+ public String get_str(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
View
22 java/runtime/Rakudo/Metamodel/Representations/P6mapping.java
@@ -58,57 +58,57 @@ public boolean defined(ThreadContext tc, RakudoObject object)
return ((Instance)object).Storage != null;
}
- public RakudoObject get_attribute(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name)
+ public RakudoObject get_attribute(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name)
{
throw new UnsupportedOperationException();
}
- public RakudoObject get_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint)
+ public RakudoObject get_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint)
{
throw new UnsupportedOperationException();
}
- public void bind_attribute(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, RakudoObject value)
+ public void bind_attribute(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, RakudoObject value)
{
throw new UnsupportedOperationException();
}
- public void bind_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint, RakudoObject value)
+ public void bind_attribute_with_hint(ThreadContext tc, RakudoObject object, RakudoObject classHandle, String name, int hint, RakudoObject value)
{
throw new UnsupportedOperationException();
}
- public int hint_for(ThreadContext tc, RakudoObject classHandle, String name)
+ public int hint_for(ThreadContext tc, RakudoObject classHandle, String name)
{
throw new UnsupportedOperationException();
}
- public void set_int(ThreadContext tc, RakudoObject object, int value)
+ public void set_int(ThreadContext tc, RakudoObject object, int value)
{
throw new UnsupportedOperationException();
}
- public int get_int(ThreadContext tc, RakudoObject object)
+ public int get_int(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
- public void set_num(ThreadContext tc, RakudoObject object, double value)
+ public void set_num(ThreadContext tc, RakudoObject object, double value)
{
throw new UnsupportedOperationException();
}
- public double get_num(ThreadContext tc, RakudoObject object)
+ public double get_num(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
- public void set_str(ThreadContext tc, RakudoObject object, String value)
+ public void set_str(ThreadContext tc, RakudoObject object, String value)
{
throw new UnsupportedOperationException();
}
- public String get_str(ThreadContext tc, RakudoObject object)
+ public String get_str(ThreadContext tc, RakudoObject object)
{
throw new UnsupportedOperationException();
}
View
40 java/runtime/Rakudo/Metamodel/SharedTable.java
@@ -1,5 +1,7 @@
package Rakudo.Metamodel;
+import java.util.HashMap;
import Rakudo.Metamodel.IFindMethod;
+import Rakudo.Metamodel.ISpecialFindMethod;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representation;
import Rakudo.Metamodel.Representations.RakudoCodeRef;
@@ -13,7 +15,7 @@
/// a given "type". Type in this context refers to a given combination
/// of meta-object and representation.
/// </summary>
-public final class SharedTable // public sealed in the C# version
+public final class SharedTable // C# has public sealed
{
/// <summary>
/// The representation object that manages object layout.
@@ -33,17 +35,49 @@
public RakudoObject WHAT;
/// <summary>
+ /// We keep a cache of the find_method method.
+ /// </summary>
+ private RakudoObject CachedFindMethod; // C# has internal
+
+ /// <summary>
+ /// Cache of methods by name. Published by meta-objects that choose
+ /// to do so.
+ /// </summary>
+ private HashMap<String, RakudoObject> MethodCache; // C# hash internal
+
+ /// <summary>
+ /// Sometimes, we may want to install a hook for overriding method
+ /// finding. This does that. (We used to just give this a default
+ /// closure, but it makes dispatch a bit more expensive, and this is
+ /// path is red hot...)
+ /// </summary>
+ public ISpecialFindMethod SpecialFindMethod; // C# has public Func<ThreadContext, RakudoObject, string, int, RakudoObject>
+
+ /// <summary>
/// This finds a method with the given name or using a hint.
/// </summary>
public IFindMethod FindMethod = new IFindMethod() { // this anonymous class is a lambda in the C# version
public RakudoObject FindMethod(ThreadContext tc, RakudoObject obj, String name, int hint)
{
+ RakudoObject CachedMethod;
+
+ // Does this s-table have a special overridden finder?
+ if (SpecialFindMethod != null)
+ return SpecialFindMethod.SpecialFindMethod(tc, obj, name, hint);
+
// See if we can find it by hint.
if (hint != Hints.NO_HINT && obj.getSTable().VTable != null && hint < obj.getSTable().VTable.length)
{
// Yes, just grab it from the v-table.
return obj.getSTable().VTable[hint];
}
+ // Otherwise, try method cache.
+ else if (MethodCache != null && MethodCache.containsKey(name)) {
+ CachedMethod = MethodCache.get(name);
+ return CachedMethod;
+ }
+
+ // Otherwise, go ask the meta-object.
else
{
// Find the find_method method.
@@ -59,10 +93,6 @@ public RakudoObject FindMethod(ThreadContext tc, RakudoObject obj, String name,
}
}
};
- /// <summary>
- /// We keep a cache of the find_method method.
- /// </summary>
- private RakudoObject CachedFindMethod; // internal in the C# version
/// <summary>
/// The default invoke looks up a postcircumfix:<( )> and runs that.
View
2  java/runtime/Rakudo/Runtime/CodeObjectUtility.java
@@ -29,7 +29,7 @@ public static RakudoObject WrapNativeMethod(RakudoCodeRef.IFunc_Body code)
{
Representation repr = REPRRegistry.get_REPR_by_name("KnowHOWREPR");
RakudoObject wrapper = repr.type_object_for(null,null);
- wrapper.getSTable().Invoke = code;
+ wrapper.getSTable().Invoke = code; // TODO wrapper.getSTable().SpecialInvoke = code;
return wrapper;
}
View
10 java/runtime/Rakudo/Runtime/Context.java
@@ -42,10 +42,8 @@
/// Creates an empty, uninitialized context.
/// </summary>
public Context() // it could be private, except that Init() calls it.
- {
- // System.err.println( "new empty Context created" );
- // this.LexPad = new Lexpad( new String[] {} ); // parameter is an empty list of strings
- }
+ { // System.err.println( "new empty Context created" );
+ } // this.LexPad = new Lexpad( new String[] {} ); // parameter is an empty list of strings
/// <summary>
/// Constructor initializes the context.
@@ -62,10 +60,8 @@ public Context(RakudoObject staticCodeObject_Uncast, Context caller, RakudoObjec
// Static sub object should have this as the current
// context.
- staticCodeObject.CurrentContext = this;
-
+ staticCodeObject.CurrentContext = this; // TODO: drop next line?
this.LexPad = new Lexpad( new String[] {} ); // parameter is an empty list of strings
-
// Lex pad should be an "instantiation" of the static one.
// Instantiating a lexpad creates a new dynamic instance of it
// from a static one, copying over the slot storage entries
View
4 java/runtime/Rakudo/Runtime/Exceptions/ExceptionDispatcher.java
@@ -1,5 +1,4 @@
package Rakudo.Runtime.Exceptions;
-
import Rakudo.Metamodel.Hints;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representations.RakudoCodeRef;
@@ -11,7 +10,7 @@
/// <summary>
/// Various bits of logic relating to exception dispatch.
/// </summary>
-public class ExceptionDispatcher // public static in the C# version
+public class ExceptionDispatcher // C# has public static
{
/// <summary>
/// Invokes the specified exception handler with the given exception
@@ -67,3 +66,4 @@ public static void DieFromUnhandledException(ThreadContext TC, RakudoObject Exce
System.exit(1);
}
}
+
View
1  java/runtime/Rakudo/Runtime/Exceptions/Handler.java
@@ -2,6 +2,7 @@
import Rakudo.Metamodel.RakudoObject;
+
/// <summary>
/// Represents an exception handler.
/// </summary>
View
6 java/runtime/Rakudo/Runtime/Exceptions/LeaveStackUnwinderException.java
@@ -3,8 +3,12 @@
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representations.RakudoCodeRef;
+
+
+
+
/// <summary>
-/// This exception is thrown to actually unwind the (dotnet) stack after
+/// This exception is thrown to actually unwind the (JVM) stack after
/// we run an exception handler.
/// </summary>
public class LeaveStackUnwinderException extends RuntimeException // not Exception, see http://www.javapractices.com/topic/TopicAction.do?Id=129
View
394 java/runtime/Rakudo/Runtime/Ops.java
@@ -1,5 +1,8 @@
-// Ops.java is equivalent to the combination of Ops partial class
-// definitions in the following files: Boxing.cs,
+// Ops.java is equivalent to the combination of partial classes in the
+// dotnet/runtime/Runtime/Ops directory, in the following files:
+// Boxing.cs ControlFlow.cs Library.cs P6list.cs Variables.cs
+// Coercion.cs Dispatch.cs Metamodel.cs P6mapping.cs
+// Comparison.cs Introspection.cs P6capture.cs Primitive.cs
package Rakudo.Runtime;
import java.util.ArrayList;
@@ -7,8 +10,11 @@
import Rakudo.Metamodel.Hints;
import Rakudo.Metamodel.RakudoObject;
import Rakudo.Metamodel.Representation;
+import Rakudo.Metamodel.Representations.P6int;
import Rakudo.Metamodel.Representations.P6list;
import Rakudo.Metamodel.Representations.P6mapping;
+import Rakudo.Metamodel.Representations.P6num;
+import Rakudo.Metamodel.Representations.P6str;
import Rakudo.Metamodel.Representations.RakudoCodeRef;
import Rakudo.Metamodel.REPRRegistry;
import Rakudo.Metamodel.SharedTable;
@@ -22,6 +28,114 @@
/// </summary>
public class Ops // public static in the C# version
{
+ // Methods are grouped in here by the corresponing C# filename
+
+ // Boxing.cs
+ /// <summary>
+ /// Boxes a native int into its matching value type. See Boxing.cs
+ /// </summary>
+ /// <param name="Value"></param>
+ /// <returns></returns>
+ public static RakudoObject box_int(ThreadContext tc, int value, RakudoObject to)
+ {
+ Representation REPR = to.getSTable().REPR;
+ RakudoObject result = REPR.instance_of(tc, to);
+ REPR.set_int(tc, result, value);
+ return result;
+ }
+
+ /// <summary>
+ /// Boxes a native int into its matching value type. See Boxing.cs
+ /// </summary>
+ /// <param name="Value"></param>
+ /// <returns></returns>
+ public static RakudoObject box_int(ThreadContext tc, int value)
+ {
+ RakudoObject result = tc.DefaultIntBoxType.getSTable().REPR.instance_of(tc, tc.DefaultIntBoxType);
+ tc.DefaultIntBoxType.getSTable().REPR.set_int(tc, result, value);
+ return result;
+ }
+
+ /// <summary>
+ /// Boxes a native num into its matching value type. See Boxing.cs
+ /// </summary>
+ /// <param name="Value"></param>
+ /// <returns></returns>
+ public static RakudoObject box_num(ThreadContext tc, double value, RakudoObject to)
+ {
+ Representation REPR = to.getSTable().REPR;
+ RakudoObject result = REPR.instance_of(tc, to);
+ REPR.set_num(tc, result, value);
+ return result;
+ }
+
+ /// <summary>
+ /// Boxes a native num into its matching value type. See Boxing.cs
+ /// </summary>
+ /// <param name="Value"></param>
+ /// <returns></returns>
+ public static RakudoObject box_num(ThreadContext tc, int value)
+ {
+ RakudoObject result = tc.DefaultNumBoxType.getSTable().REPR.instance_of(tc, tc.DefaultNumBoxType);
+ tc.DefaultNumBoxType.getSTable().REPR.set_num(tc, result, value);
+ return result;
+ }
+
+ /// <summary>
+ /// Boxes a native string into its matching value type. See Boxing.cs
+ /// </summary>
+ /// <param name="Value"></param>
+ /// <returns></returns>
+ public static RakudoObject box_str(ThreadContext tc, String value, RakudoObject to)
+ {
+ Representation REPR = to.getSTable().REPR;
+ RakudoObject result = REPR.instance_of(tc, to);
+ REPR.set_str(tc, result, value);
+ return result;
+ }
+
+ /// <summary>
+ /// Boxes a native string into its matching value type. See Boxing.cs
+ /// </summary>
+ /// <param name="Value"></param>
+ /// <returns></returns>
+ public static RakudoObject box_str(ThreadContext tc, String value)
+ {
+ RakudoObject result = tc.DefaultStrBoxType.getSTable().REPR.instance_of(tc, tc.DefaultStrBoxType);
+ tc.DefaultStrBoxType.getSTable().REPR.set_str(tc, result, value);
+ return result;
+ }
+
+ /// <summary>
+ /// Unboxes a boxed int. See Boxing.cs
+ /// </summary>
+ /// <param name="Boxed"></param>
+ /// <returns></returns>
+ public static int unbox_int(ThreadContext tc, RakudoObject boxed)
+ {
+ return boxed.getSTable().REPR.get_int(tc, boxed);
+ }
+
+ /// <summary>
+ /// Unboxes a boxed num. See Boxing.cs
+ /// </summary>
+ /// <param name="Boxed"></param>
+ /// <returns></returns>
+ public static double unbox_num(ThreadContext tc, RakudoObject boxed)
+ {
+ return boxed.getSTable().REPR.get_num(tc, boxed);
+ }
+
+ /// <summary>
+ /// Unboxes a boxed string. See Boxing.cs
+ /// </summary>
+ /// <param name="Boxed"></param>
+ /// <returns></returns>
+ public static String unbox_str(ThreadContext tc, RakudoObject boxed)
+ {
+ return boxed.getSTable().REPR.get_str(tc, boxed);
+ }
+
/// <summary>
/// Creates a type object associated with the given HOW and of the
/// given representation. See Representation.cs
@@ -160,75 +274,7 @@ public static RakudoObject get_what(ThreadContext tc, RakudoObject object)
return object.getSTable().WHAT;
}
- /// <summary>
- /// Boxes a native int into its matching value type. See Boxing.cs
- /// </summary>
- /// <param name="Value"></param>
- /// <returns></returns>
- public static RakudoObject box_int(ThreadContext tc, int value, RakudoObject to)
- {
- Representation REPR = to.getSTable().REPR;
- RakudoObject result = REPR.instance_of(tc, to);
- REPR.set_int(tc, result, value);
- return result;
- }
-
- /// <summary>
- /// Boxes a native num into its matching value type. See Boxing.cs
- /// </summary>
- /// <param name="Value"></param>
- /// <returns></returns>
- public static RakudoObject box_num(ThreadContext tc, double value, RakudoObject to)
- {
- Representation REPR = to.getSTable().REPR;
- RakudoObject result = REPR.instance_of(tc, to);
- REPR.set_num(tc, result, value);
- return result;
- }
-
- /// <summary>
- /// Boxes a native string into its matching value type. See Boxing.cs
- /// </summary>
- /// <param name="Value"></param>
- /// <returns></returns>
- public static RakudoObject box_str(ThreadContext tc, String value, RakudoObject to)
- {
- Representation REPR = to.getSTable().REPR;
- RakudoObject result = REPR.instance_of(tc, to);
- REPR.set_str(tc, result, value);
- return result;
- }
-
- /// <summary>
- /// Unboxes a boxed int. See Boxing.cs
- /// </summary>
- /// <param name="Boxed"></param>
- /// <returns></returns>
- public static int unbox_int(ThreadContext tc, RakudoObject boxed)
- {
- return boxed.getSTable().REPR.get_int(tc, boxed);
- }
-
- /// <summary>
- /// Unboxes a boxed num. See Boxing.cs
- /// </summary>
- /// <param name="Boxed"></param>
- /// <returns></returns>
- public static double unbox_num(ThreadContext tc, RakudoObject boxed)
- {
- return boxed.getSTable().REPR.get_num(tc, boxed);
- }
-
- /// <summary>
- /// Unboxes a boxed string. See Boxing.cs
- /// </summary>
- /// <param name="Boxed"></param>
- /// <returns></returns>
- public static String unbox_str(ThreadContext tc, RakudoObject boxed)
- {
- return boxed.getSTable().REPR.get_str(tc, boxed);
- }
-
+ // Coercion.cs
/// <summary>
/// Coerces an integer into a string. See Coercion.cs
/// </summary>
@@ -306,109 +352,6 @@ public static RakudoObject coerce_str_to_num(ThreadContext tc, RakudoObject strO
/// <summary>
- /// Gets a lexical variable of the given name. See Variables.cs
- /// </summary>
- /// <param name="i"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- public static RakudoObject get_lex(ThreadContext tc, String name)
- {
- Context curContext = tc.CurrentContext;
- while (curContext != null) {
- if (curContext.LexPad.SlotMapping.containsKey(name)) {
- int index = curContext.LexPad.SlotMapping.get(name);
- return curContext.LexPad.Storage[index];
- }
- curContext = curContext.Outer;
- }
- throw new UnsupportedOperationException("No variable " + name + " found in the lexical scope");
- }
-
- /// <summary>
- /// Gets a lexical variable of the given name, but skips the current
- /// scope. See Variables.cs
- /// </summary>
- /// <param name="tc"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- public static RakudoObject get_lex_skip_current(ThreadContext tc, String name)
- {
- Context curContext = tc.CurrentContext.Outer;
- while (curContext != null)
- {
- if (curContext.LexPad.SlotMapping.containsKey(name)) {
- int index = curContext.LexPad.SlotMapping.get(name);
- return curContext.LexPad.Storage[index];
- }
- curContext = curContext.Outer;
- }
- throw new UnsupportedOperationException("No variable " + name + " found in the lexical scope");
- }
-
- /// <summary>
- /// Binds the given value to a lexical variable of the given name. See Variables.cs
- /// </summary>
- /// <param name="i"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- public static RakudoObject bind_lex(ThreadContext tc, String name, RakudoObject value)
- {
- Context curContext = tc.CurrentContext;
- while (curContext != null)
- {
- if (curContext.LexPad.SlotMapping.containsKey(name))
- {
- int index = curContext.LexPad.SlotMapping.get(name);
- curContext.LexPad.Storage[index] = value;
- return value;
- }
- curContext = curContext.Outer;
- }
- throw new UnsupportedOperationException("No variable " + name + " found in the lexical scope");
- }
-
- /// <summary>
- /// Looks up a variable in the dynamic scope. See Variables.cs
- /// </summary>
- /// <param name="C"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- public static RakudoObject get_dynamic(ThreadContext tc, String name)
- {
- Context curContext = tc.CurrentContext;
- while (curContext != null) {
- if (curContext.LexPad.SlotMapping.containsKey(name)) {
- int index = curContext.LexPad.SlotMapping.get(name);
- return curContext.LexPad.Storage[index];
- }
- curContext = curContext.Caller;
- }
- throw new UnsupportedOperationException("No variable " + name + " found in the dynamic scope");
- }
-
- /// <summary>
- /// Binds the given value to a variable in the dynamic scope. See Variables.cs
- /// </summary>
- /// <param name="C"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- public static RakudoObject bind_dynamic(ThreadContext tc, String name, RakudoObject value)
- {
- Context curContext = tc.CurrentContext;
- while (curContext != null)
- {
- if (curContext.LexPad.SlotMapping.containsKey(name))
- {
- int index = curContext.LexPad.SlotMapping.get(name);
- curContext.LexPad.Storage[index] = value;
- return value;
- }
- curContext = curContext.Caller;
- }
- throw new UnsupportedOperationException("No variable " + name + " found in the dynamic scope");
- }
-
- /// <summary>
/// Compares two floating point numbers for equality. See Comparison.cs
/// </summary>
/// <param name="x"></param>
@@ -1183,5 +1126,108 @@ public static RakudoObject load_module(ThreadContext tc, RakudoObject path)
return (RakudoObject)null;
//return (RakudoObject)method.Invoke.Invoke(null, new Object[] { tc, tc.Domain.Setting });
}
+ /// <summary>
+ /// Gets a lexical variable of the given name. See Variables.cs
+ /// </summary>
+ /// <param name="i"></param>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static RakudoObject get_lex(ThreadContext tc, String name)
+ {
+ Context curContext = tc.CurrentContext;
+ while (curContext != null) {
+ if (curContext.LexPad.SlotMapping.containsKey(name)) {
+ int index = curContext.LexPad.SlotMapping.get(name);
+ return curContext.LexPad.Storage[index];
+ }
+ curContext = curContext.Outer;
+ }
+ throw new UnsupportedOperationException("No variable " + name + " found in the lexical scope");
+ }
+
+ /// <summary>
+ /// Gets a lexical variable of the given name, but skips the current
+ /// scope. See Variables.cs
+ /// </summary>
+ /// <param name="tc"></param>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static RakudoObject get_lex_skip_current(ThreadContext tc, String name)
+ {
+ Context curContext = tc.CurrentContext.Outer;
+ while (curContext != null)
+ {
+ if (curContext.LexPad.SlotMapping.containsKey(name)) {
+ int index = curContext.LexPad.SlotMapping.get(name);
+ return curContext.LexPad.Storage[index];
+ }
+ curContext = curContext.Outer;
+ }
+ throw new UnsupportedOperationException("No variable " + name + " found in the lexical scope");
+ }
+
+ /// <summary>
+ /// Binds the given value to a lexical variable of the given name. See Variables.cs
+ /// </summary>
+ /// <param name="i"></param>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static RakudoObject bind_lex(ThreadContext tc, String name, RakudoObject value)
+ {
+ Context curContext = tc.CurrentContext;
+ while (curContext != null)
+ {
+ if (curContext.LexPad.SlotMapping.containsKey(name))
+ {
+ int index = curContext.LexPad.SlotMapping.get(name);
+ curContext.LexPad.Storage[index] = value;
+ return value;
+ }
+ curContext = curContext.Outer;
+ }
+ throw new UnsupportedOperationException("No variable " + name + " found in the lexical scope");
+ }
+
+ /// <summary>
+ /// Looks up a variable in the dynamic scope. See Variables.cs
+ /// </summary>
+ /// <param name="C"></param>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static RakudoObject get_dynamic(ThreadContext tc, String name)
+ {
+ Context curContext = tc.CurrentContext;
+ while (curContext != null) {
+ if (curContext.LexPad.SlotMapping.containsKey(name)) {
+ int index = curContext.LexPad.SlotMapping.get(name);
+ return curContext.LexPad.Storage[index];
+ }
+ curContext = curContext.Caller;
+ }
+ throw new UnsupportedOperationException("No variable " + name + " found in the dynamic scope");
+ }
+
+ /// <summary>
+ /// Binds the given value to a variable in the dynamic scope. See Variables.cs
+ /// </summary>
+ /// <param name="C"></param>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static RakudoObject bind_dynamic(ThreadContext tc, String name, RakudoObject value)
+ {
+ Context curContext = tc.CurrentContext;
+ while (curContext != null)
+ {
+ if (curContext.LexPad.SlotMapping.containsKey(name))
+ {
+ int index = curContext.LexPad.SlotMapping.get(name);
+ curContext.LexPad.Storage[index] = value;
+ return value;
+ }
+ curContext = curContext.Caller;
+ }
+ throw new UnsupportedOperationException("No variable " + name + " found in the dynamic scope");
+ }
+
}
View
9 java/runtime/Rakudo/Runtime/Signature.java
@@ -21,7 +21,6 @@ public Signature(Parameter[] parameters)
// Build and cache number of positionals.
for (int i = 0; i < parameters.length; i++)
- {
if (parameters[i].Flags == Parameter.POS_FLAG)
{
NumRequiredPositionals++;
@@ -31,10 +30,8 @@ else if (Parameters[i].Flags == Parameter.OPTIONAL_FLAG)
NumPositionals++;
else // XXX rewrite as a switch?
break;
- }
}
-
/// <summary>
/// The parameters we have.
/// </summary>
@@ -44,19 +41,19 @@ else if (Parameters[i].Flags == Parameter.OPTIONAL_FLAG)
/// The total number of positionals.
/// </summary>
/// <returns></returns>
- public int NumPositionals; // internal in the C# version
+ public int NumPositionals; // C# has internal
/// <summary>
/// The number of required positionals.
/// </summary>
/// <returns></returns>
- public int NumRequiredPositionals; // internal in the C# version
+ public int NumRequiredPositionals; // C# has internal
/// <summary>
/// Do we have a slurpy positional parameter?
/// </summary>
/// <returns></returns>
- public boolean HasSlurpyPositional() // internal in the C# version
+ public boolean HasSlurpyPositional() // C# has internal
{
for (int i = 0; i < Parameters.length; i++)
if (Parameters[i].Flags == Parameter.POS_SLURPY_FLAG)
Please sign in to comment.
Something went wrong with that request. Please try again.