-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into truffle-head
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
Showing
36 changed files
with
1,182 additions
and
1,137 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
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
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
24 changes: 24 additions & 0 deletions
24
truffle/src/main/java/org/jruby/truffle/interop/AbstractExecuteMethodNode.java
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,24 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
abstract class AbstractExecuteMethodNode extends RubyNode { | ||
public AbstractExecuteMethodNode(RubyContext context, | ||
SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public abstract Object executeWithTarget(VirtualFrame frame, Object method); | ||
} |
89 changes: 89 additions & 0 deletions
89
truffle/src/main/java/org/jruby/truffle/interop/ExecuteMethodNode.java
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,89 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CallTarget; | ||
import com.oracle.truffle.api.Truffle; | ||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.nodes.DirectCallNode; | ||
import com.oracle.truffle.api.nodes.IndirectCallNode; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.Layouts; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.arguments.RubyArguments; | ||
import org.jruby.truffle.language.methods.DeclarationContext; | ||
import org.jruby.truffle.language.methods.InternalMethod; | ||
|
||
import java.util.List; | ||
|
||
@NodeChild(value="method", type = RubyNode.class) | ||
abstract class ExecuteMethodNode extends AbstractExecuteMethodNode { | ||
@Child private IndirectCallNode callNode; | ||
public ExecuteMethodNode(RubyContext context, | ||
SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
callNode = Truffle.getRuntime().createIndirectCallNode(); | ||
} | ||
|
||
@Specialization(guards = {"isRubyProc(proc)", "proc == cachedProc"}) | ||
protected Object doCallProc(VirtualFrame frame, DynamicObject proc, | ||
@Cached("proc") DynamicObject cachedProc, | ||
@Cached("create(getCallTarget(cachedProc))") DirectCallNode callNode) { | ||
final List<Object> faArgs = ForeignAccess.getArguments(frame); | ||
Object[] args = faArgs.toArray(); | ||
return callNode.call(frame, RubyArguments.pack(Layouts.PROC.getDeclarationFrame(cachedProc), null, Layouts.PROC.getMethod(cachedProc), DeclarationContext.METHOD, null, Layouts.PROC.getSelf(cachedProc), null, args)); | ||
} | ||
|
||
@Specialization(guards = "isRubyProc(proc)") | ||
protected Object doCallProc(VirtualFrame frame, DynamicObject proc) { | ||
final List<Object> faArgs = ForeignAccess.getArguments(frame); | ||
Object[] args = faArgs.toArray(); | ||
return callNode.call(frame, Layouts.PROC.getCallTargetForType(proc), RubyArguments.pack(Layouts.PROC.getDeclarationFrame(proc), null, Layouts.PROC.getMethod(proc), DeclarationContext.METHOD, null, Layouts.PROC.getSelf(proc), null, args)); | ||
} | ||
|
||
@Specialization(guards = {"isRubyMethod(method)", "method == cachedMethod"}) | ||
protected Object doCall(VirtualFrame frame, DynamicObject method, | ||
@Cached("method") DynamicObject cachedMethod, | ||
@Cached("getMethod(cachedMethod)") InternalMethod internalMethod, | ||
@Cached("create(getMethod(cachedMethod).getCallTarget())") DirectCallNode callNode) { | ||
final List<Object> faArgs = ForeignAccess.getArguments(frame); | ||
|
||
Object[] args = faArgs.subList(0, faArgs.size()).toArray(); | ||
return callNode.call(frame, RubyArguments.pack(null, null, internalMethod, DeclarationContext.METHOD, null, Layouts.METHOD.getReceiver(cachedMethod), null, args)); | ||
} | ||
|
||
@Specialization(guards = "isRubyMethod(method)") | ||
protected Object doCall(VirtualFrame frame, DynamicObject method) { | ||
final InternalMethod internalMethod = Layouts.METHOD.getMethod(method); | ||
final List<Object> faArgs = ForeignAccess.getArguments(frame); | ||
|
||
Object[] args = faArgs.subList(0, faArgs.size()).toArray(); | ||
return callNode.call(frame, internalMethod.getCallTarget(), RubyArguments.pack(null, null, internalMethod, DeclarationContext.METHOD, null, Layouts.METHOD.getReceiver(method), null, args)); | ||
} | ||
|
||
protected InternalMethod getMethodFromProc(DynamicObject proc) { | ||
return Layouts.PROC.getMethod(proc); | ||
} | ||
|
||
protected CallTarget getCallTarget(DynamicObject proc) { | ||
return Layouts.PROC.getCallTargetForType(proc); | ||
} | ||
|
||
protected InternalMethod getMethod(DynamicObject method) { | ||
return Layouts.METHOD.getMethod(method); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
truffle/src/main/java/org/jruby/truffle/interop/InteropArgumentNode.java
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,30 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
class InteropArgumentNode extends RubyNode { | ||
private final int index; | ||
|
||
public InteropArgumentNode(RubyContext context, SourceSection sourceSection, int index) { | ||
super(context, sourceSection); | ||
this.index = index; | ||
} | ||
|
||
public Object execute(VirtualFrame frame) { | ||
return ForeignAccess.getArguments(frame).get(index); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
truffle/src/main/java/org/jruby/truffle/interop/InteropArgumentsNode.java
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,47 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.ExplodeLoop; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
class InteropArgumentsNode extends RubyNode { | ||
|
||
@Children private final InteropArgumentNode[] arguments; | ||
|
||
public InteropArgumentsNode(RubyContext context, SourceSection sourceSection, int arity) { | ||
super(context, sourceSection); | ||
this.arguments = new InteropArgumentNode[arity]; | ||
// index 0 is the lable | ||
for (int i = 1; i < 1 + arity; i++) { | ||
arguments[i - 1] = new InteropArgumentNode(context, sourceSection, i); | ||
} | ||
} | ||
|
||
public int getCount(VirtualFrame frame) { | ||
return arguments.length; | ||
} | ||
|
||
public Object execute(VirtualFrame frame) { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(); | ||
} | ||
|
||
@ExplodeLoop | ||
public void executeFillObjectArray(VirtualFrame frame, Object[] args) { | ||
for (int i = 0; i < arguments.length; i++) { | ||
args[i] = arguments[i].execute(frame); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
truffle/src/main/java/org/jruby/truffle/interop/InteropExecute.java
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,31 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
public class InteropExecute extends RubyNode { | ||
@Child private ExecuteMethodNode execute; | ||
|
||
public InteropExecute(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
this.execute = ExecuteMethodNodeGen.create(context, sourceSection, null); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object result = execute.executeWithTarget(frame, ForeignAccess.getReceiver(frame)); | ||
return result; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
truffle/src/main/java/org/jruby/truffle/interop/InteropGetSizeProperty.java
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,33 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
public class InteropGetSizeProperty extends RubyNode { | ||
|
||
@Child private DispatchHeadNode head; | ||
public InteropGetSizeProperty(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), "size", null, new Object[] {}); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
truffle/src/main/java/org/jruby/truffle/interop/InteropInstanceVariableReadNode.java
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,42 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.objects.ReadInstanceVariableNode; | ||
|
||
class InteropInstanceVariableReadNode extends RubyNode { | ||
|
||
@Child private ReadInstanceVariableNode read; | ||
private final String name; | ||
private final int labelIndex; | ||
|
||
public InteropInstanceVariableReadNode(RubyContext context, SourceSection sourceSection, String name, int labelIndex) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.read = new ReadInstanceVariableNode(context, sourceSection, name, new RubyInteropReceiverNode(context, sourceSection)); | ||
this.labelIndex = labelIndex; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(ForeignAccess.getArguments(frame).get(labelIndex))) { | ||
return read.execute(frame); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Not implemented"); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
truffle/src/main/java/org/jruby/truffle/interop/InteropInstanceVariableWriteNode.java
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,42 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.objects.WriteInstanceVariableNode; | ||
|
||
class InteropInstanceVariableWriteNode extends RubyNode { | ||
|
||
@Child private WriteInstanceVariableNode write; | ||
private final String name; | ||
private final int labelIndex; | ||
|
||
public InteropInstanceVariableWriteNode(RubyContext context, SourceSection sourceSection, String name, int labelIndex, int valueIndex) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.labelIndex = labelIndex; | ||
this.write = new WriteInstanceVariableNode(context, sourceSection, name, new RubyInteropReceiverNode(context, sourceSection), new RubyInteropArgumentNode(context, sourceSection, valueIndex)); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(ForeignAccess.getArguments(frame).get(labelIndex))) { | ||
return write.execute(frame); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Not implemented"); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
truffle/src/main/java/org/jruby/truffle/interop/InteropIsNull.java
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,27 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
public class InteropIsNull extends RubyNode { | ||
public InteropIsNull(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return ForeignAccess.getReceiver(frame) == nil(); | ||
} | ||
} |
745 changes: 0 additions & 745 deletions
745
truffle/src/main/java/org/jruby/truffle/interop/InteropNode.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
truffle/src/main/java/org/jruby/truffle/interop/InteropReadStringByteNode.java
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,47 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.Layouts; | ||
import org.jruby.truffle.core.string.StringOperations; | ||
import org.jruby.truffle.language.RubyGuards; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
class InteropReadStringByteNode extends RubyNode { | ||
|
||
private final int labelIndex; | ||
|
||
public InteropReadStringByteNode(RubyContext context, SourceSection sourceSection, int labelIndex) { | ||
super(context, sourceSection); | ||
this.labelIndex = labelIndex; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (RubyGuards.isRubyString(ForeignAccess.getReceiver(frame))) { | ||
final DynamicObject string = (DynamicObject) ForeignAccess.getReceiver(frame); | ||
final int index = (int) ForeignAccess.getArguments(frame).get(labelIndex); | ||
if (index >= Layouts.STRING.getRope(string).byteLength()) { | ||
return 0; | ||
} else { | ||
return (byte) StringOperations.getByteListReadOnly(string).get(index); | ||
} | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Not implemented"); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
truffle/src/main/java/org/jruby/truffle/interop/InteropStringIsBoxed.java
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,32 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.string.StringOperations; | ||
import org.jruby.truffle.language.RubyGuards; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
public class InteropStringIsBoxed extends RubyNode { | ||
|
||
public InteropStringIsBoxed(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object o = ForeignAccess.getReceiver(frame); | ||
return RubyGuards.isRubyString(o) && StringOperations.rope((DynamicObject) o).byteLength() == 1; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
truffle/src/main/java/org/jruby/truffle/interop/InteropStringUnboxNode.java
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,30 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.string.StringOperations; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
public class InteropStringUnboxNode extends RubyNode { | ||
|
||
public InteropStringUnboxNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return StringOperations.getByteListReadOnly(((DynamicObject) ForeignAccess.getReceiver(frame))).get(0); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropExecuteAfterReadNode.java
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,49 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropExecuteAfterReadNode extends RubyNode { | ||
|
||
@Child private DispatchHeadNode head; | ||
@Child private InteropArgumentsNode arguments; | ||
private final String name; | ||
private final int labelIndex; | ||
private final int receiverIndex; | ||
|
||
public ResolvedInteropExecuteAfterReadNode(RubyContext context, SourceSection sourceSection, String name, int arity) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.arguments = new InteropArgumentsNode(context, sourceSection, arity); // [0] is receiver, [1] is the label | ||
this.labelIndex = 1; | ||
this.receiverIndex = 0; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(frame.getArguments()[labelIndex])) { | ||
Object[] args = new Object[arguments.getCount(frame)]; | ||
arguments.executeFillObjectArray(frame, args); | ||
return head.dispatch(frame, frame.getArguments()[receiverIndex], frame.getArguments()[labelIndex], null, args); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Name changed"); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropIndexedReadNode.java
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 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropIndexedReadNode extends RubyNode { | ||
|
||
private final String name; | ||
@Child private DispatchHeadNode head; | ||
@Child private IndexLabelToRubyNode toRubyIndex; | ||
private final int indexIndex; | ||
|
||
public ResolvedInteropIndexedReadNode(RubyContext context, SourceSection sourceSection, int indexIndex) { | ||
super(context, sourceSection); | ||
this.name = "[]"; | ||
this.indexIndex = indexIndex; | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.toRubyIndex = IndexLabelToRubyNodeGen.create(context, sourceSection, null); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object index = toRubyIndex.executeWithTarget(frame, ForeignAccess.getArguments(frame).get(indexIndex)); | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), name, null, new Object[] {index}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropIndexedWriteNode.java
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,44 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropIndexedWriteNode extends RubyNode { | ||
|
||
private final String name; | ||
@Child private DispatchHeadNode head; | ||
@Child private IndexLabelToRubyNode toRubyIndex; | ||
private final int indexIndex; | ||
private final int valueIndex; | ||
|
||
public ResolvedInteropIndexedWriteNode(RubyContext context, SourceSection sourceSection, int indexIndex, int valueIndex) { | ||
super(context, sourceSection); | ||
this.name = "[]="; | ||
this.indexIndex = indexIndex; | ||
this.valueIndex = valueIndex; | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.toRubyIndex = IndexLabelToRubyNodeGen.create(context, sourceSection, null); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object index = toRubyIndex.executeWithTarget(frame, ForeignAccess.getArguments(frame).get(indexIndex)); | ||
Object value = ForeignAccess.getArguments(frame).get(valueIndex); | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), name, null, new Object[] {index, value}); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropReadFromSymbolNode.java
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,45 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropReadFromSymbolNode extends RubyNode { | ||
|
||
@Child private DispatchHeadNode head; | ||
private final DynamicObject name; | ||
private final int labelIndex; | ||
|
||
public ResolvedInteropReadFromSymbolNode(RubyContext context, SourceSection sourceSection, DynamicObject name, int labelIndex) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.labelIndex = labelIndex; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(ForeignAccess.getArguments(frame).get(labelIndex))) { | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), name, null, new Object[]{}); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Name changed"); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropReadNode.java
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,44 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropReadNode extends RubyNode { | ||
|
||
@Child private DispatchHeadNode head; | ||
private final String name; | ||
private final int labelIndex; | ||
|
||
public ResolvedInteropReadNode(RubyContext context, SourceSection sourceSection, String name, int labelIndex) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.labelIndex = labelIndex; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(ForeignAccess.getArguments(frame).get(labelIndex))) { | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), name, null, new Object[]{}); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Name changed"); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropWriteNode.java
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,49 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropWriteNode extends RubyNode { | ||
|
||
@Child private DispatchHeadNode head; | ||
private final String name; | ||
private final String accessName; | ||
private final int labelIndex; | ||
private final int valueIndex; | ||
|
||
public ResolvedInteropWriteNode(RubyContext context, SourceSection sourceSection, String name, int labelIndex, int valueIndex) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.accessName = name + "="; | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.labelIndex = labelIndex; | ||
this.valueIndex = valueIndex; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(ForeignAccess.getArguments(frame).get(labelIndex))) { | ||
Object value = ForeignAccess.getArguments(frame).get(valueIndex); | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), accessName, null, new Object[]{value}); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Name changed"); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
truffle/src/main/java/org/jruby/truffle/interop/ResolvedInteropWriteToSymbolNode.java
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,51 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.Layouts; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.dispatch.DispatchAction; | ||
import org.jruby.truffle.language.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.language.dispatch.MissingBehavior; | ||
|
||
class ResolvedInteropWriteToSymbolNode extends RubyNode { | ||
|
||
@Child private DispatchHeadNode head; | ||
private final DynamicObject name; | ||
private final DynamicObject accessName; | ||
private final int labelIndex; | ||
private final int valueIndex; | ||
|
||
public ResolvedInteropWriteToSymbolNode(RubyContext context, SourceSection sourceSection, DynamicObject name, int labelIndex, int valueIndex) { | ||
super(context, sourceSection); | ||
this.name = name; | ||
this.accessName = context.getSymbolTable().getSymbol(Layouts.SYMBOL.getString(name) + "="); | ||
this.head = new DispatchHeadNode(context, true, MissingBehavior.CALL_METHOD_MISSING, DispatchAction.CALL_METHOD); | ||
this.labelIndex = labelIndex; | ||
this.valueIndex = valueIndex; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (name.equals(ForeignAccess.getArguments(frame).get(labelIndex))) { | ||
Object value = ForeignAccess.getArguments(frame).get(valueIndex); | ||
return head.dispatch(frame, ForeignAccess.getReceiver(frame), accessName, null, new Object[]{value}); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException("Name changed"); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
truffle/src/main/java/org/jruby/truffle/interop/RubyInteropArgumentNode.java
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,31 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
class RubyInteropArgumentNode extends RubyNode { | ||
|
||
private final int index; | ||
|
||
public RubyInteropArgumentNode(RubyContext context, SourceSection sourceSection, int index) { | ||
super(context, sourceSection); | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return ForeignAccess.getArguments(frame).get(index); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
truffle/src/main/java/org/jruby/truffle/interop/RubyInteropReceiverNode.java
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,27 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
class RubyInteropReceiverNode extends RubyNode { | ||
public RubyInteropReceiverNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return ForeignAccess.getReceiver(frame); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
truffle/src/main/java/org/jruby/truffle/interop/RubyInteropRootNode.java
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,36 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.RootNode; | ||
import org.jruby.truffle.RubyLanguage; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.backtrace.InternalRootNode; | ||
|
||
public class RubyInteropRootNode extends RootNode implements InternalRootNode { | ||
|
||
@Child private RubyNode node; | ||
|
||
public RubyInteropRootNode(RubyNode node) { | ||
super(RubyLanguage.class, null, null); | ||
this.node = node; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame virtualFrame) { | ||
return node.execute(virtualFrame); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Root of: " + node.toString(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
truffle/src/main/java/org/jruby/truffle/interop/UnresolvedInteropExecuteAfterReadNode.java
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,39 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
public class UnresolvedInteropExecuteAfterReadNode extends RubyNode { | ||
|
||
private final int arity; | ||
private final int labelIndex; | ||
|
||
public UnresolvedInteropExecuteAfterReadNode(RubyContext context, SourceSection sourceSection, int arity){ | ||
super(context, sourceSection); | ||
this.arity = arity; | ||
this.labelIndex = 0; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (ForeignAccess.getArguments(frame).get(labelIndex) instanceof String) { | ||
return this.replace(new ResolvedInteropExecuteAfterReadNode(getContext(), getSourceSection(), (String) ForeignAccess.getArguments(frame).get(labelIndex), arity)).execute(frame); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(ForeignAccess.getArguments(frame).get(0) + " not allowed as name"); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
truffle/src/main/java/org/jruby/truffle/interop/UnresolvedInteropReadNode.java
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,60 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.module.ModuleOperations; | ||
import org.jruby.truffle.language.RubyGuards; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.methods.InternalMethod; | ||
|
||
public class UnresolvedInteropReadNode extends RubyNode { | ||
|
||
private final int labelIndex; | ||
|
||
public UnresolvedInteropReadNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
this.labelIndex = 0; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object label = ForeignAccess.getArguments(frame).get(labelIndex); | ||
if (label instanceof String || RubyGuards.isRubySymbol(label) || label instanceof Integer) { | ||
if (label instanceof String) { | ||
String name = (String) label; | ||
if (name.startsWith("@")) { | ||
return this.replace(new InteropInstanceVariableReadNode(getContext(), getSourceSection(), name, labelIndex)).execute(frame); | ||
} | ||
} | ||
DynamicObject receiver = (DynamicObject) ForeignAccess.getReceiver(frame); | ||
InternalMethod labelMethod = ModuleOperations.lookupMethod(coreLibrary().getMetaClass(receiver), label.toString()); | ||
InternalMethod indexedSetter = ModuleOperations.lookupMethod(coreLibrary().getMetaClass(receiver), "[]="); | ||
if (labelMethod == null && indexedSetter != null) { | ||
return this.replace(new ResolvedInteropIndexedReadNode(getContext(), getSourceSection(), labelIndex)).execute(frame); | ||
} else if (label instanceof String) { | ||
return this.replace(new ResolvedInteropReadNode(getContext(), getSourceSection(), (String) label, labelIndex)).execute(frame); | ||
} else if (RubyGuards.isRubySymbol(label)) { | ||
return this.replace(new ResolvedInteropReadFromSymbolNode(getContext(), getSourceSection(), (DynamicObject) label, labelIndex)).execute(frame); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(label + " not allowed as name"); | ||
} | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(label + " not allowed as name"); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
truffle/src/main/java/org/jruby/truffle/interop/UnresolvedInteropStringReadNode.java
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,55 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.language.RubyGuards; | ||
import org.jruby.truffle.language.RubyNode; | ||
|
||
public class UnresolvedInteropStringReadNode extends RubyNode { | ||
|
||
private final int labelIndex; | ||
|
||
public UnresolvedInteropStringReadNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
this.labelIndex = 0; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object label = ForeignAccess.getArguments(frame).get(labelIndex); | ||
if (label instanceof String || RubyGuards.isRubySymbol(label) || label instanceof Integer) { | ||
if (label instanceof String) { | ||
String name = (String) label; | ||
if (name.startsWith("@")) { | ||
return this.replace(new InteropInstanceVariableReadNode(getContext(), getSourceSection(), name, labelIndex)).execute(frame); | ||
} | ||
} | ||
if (label instanceof Integer || label instanceof Long) { | ||
return this.replace(new InteropReadStringByteNode(getContext(), getSourceSection(), labelIndex)).execute(frame); | ||
} else if (label instanceof String) { | ||
return this.replace(new ResolvedInteropReadNode(getContext(), getSourceSection(), (String) label, labelIndex)).execute(frame); | ||
} else if (RubyGuards.isRubySymbol(label)) { | ||
return this.replace(new ResolvedInteropReadFromSymbolNode(getContext(), getSourceSection(), (DynamicObject) label, labelIndex)).execute(frame); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(label + " not allowed as name"); | ||
} | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(label + " not allowed as name"); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
truffle/src/main/java/org/jruby/truffle/interop/UnresolvedInteropWriteNode.java
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,62 @@ | ||
/* | ||
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.interop; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.ForeignAccess; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.module.ModuleOperations; | ||
import org.jruby.truffle.language.RubyGuards; | ||
import org.jruby.truffle.language.RubyNode; | ||
import org.jruby.truffle.language.methods.InternalMethod; | ||
|
||
public class UnresolvedInteropWriteNode extends RubyNode { | ||
|
||
private final int labelIndex; | ||
private final int valueIndex; | ||
|
||
public UnresolvedInteropWriteNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
this.labelIndex = 0; | ||
this.valueIndex = 1; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
Object label = ForeignAccess.getArguments(frame).get(labelIndex); | ||
if (label instanceof String || RubyGuards.isRubySymbol(label) || label instanceof Integer) { | ||
if (label instanceof String) { | ||
String name = (String) label; | ||
if (name.startsWith("@")) { | ||
return this.replace(new InteropInstanceVariableWriteNode(getContext(), getSourceSection(), name, labelIndex, valueIndex)).execute(frame); | ||
} | ||
} | ||
DynamicObject receiver = (DynamicObject) ForeignAccess.getReceiver(frame); | ||
InternalMethod labelMethod = ModuleOperations.lookupMethod(coreLibrary().getMetaClass(receiver), label.toString()); | ||
InternalMethod indexedSetter = ModuleOperations.lookupMethod(coreLibrary().getMetaClass(receiver), "[]="); | ||
if (labelMethod == null && indexedSetter != null) { | ||
return this.replace(new ResolvedInteropIndexedWriteNode(getContext(), getSourceSection(), labelIndex, valueIndex)).execute(frame); | ||
} else if (label instanceof String) { | ||
return this.replace(new ResolvedInteropWriteNode(getContext(), getSourceSection(), (String) label, labelIndex, valueIndex)).execute(frame); | ||
} else if (RubyGuards.isRubySymbol(label)) { | ||
return this.replace(new ResolvedInteropWriteToSymbolNode(getContext(), getSourceSection(), (DynamicObject) label, labelIndex, valueIndex)).execute(frame); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(label + " not allowed as name"); | ||
} | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(label + " not allowed as name"); | ||
} | ||
} | ||
} |
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