Skip to content

Commit

Permalink
Showing 2 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -91,6 +91,10 @@ protected OutgoingNode createHelperNode(int argsLength) {
return new CallOutgoingNode(argsLength);
} else if (name.equals("nil?") && argsLength == 0) {
return new IsNilOutgoingNode();
} else if (name.endsWith("!") && argsLength == 0) {
return new InvokeOutgoingNode(name.substring(0, name.length() - 1), argsLength);
} else if (argsLength == 0) {
return new PropertyReadOutgoingNode(name);
} else {
return new InvokeOutgoingNode(name, argsLength);
}
@@ -179,6 +183,31 @@ public Object executeCall(VirtualFrame frame, TruffleObject receiver, Object[] a

}

protected class PropertyReadOutgoingNode extends OutgoingNode {

private final String name;

@Child private Node node;

public PropertyReadOutgoingNode(String name) {
this.name = name;
node = Message.READ.createNode();
}

@Override
public Object executeCall(VirtualFrame frame, TruffleObject receiver, Object[] args) {
assert args.length == 0;

try {
return ForeignAccess.sendRead(node, frame, receiver, name);
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
exceptionProfile();
throw new RuntimeException(e);
}
}

}

protected class PropertyWriteOutgoingNode extends OutgoingNode {

private final String name;
14 changes: 7 additions & 7 deletions truffle/src/test/ruby/tck.rb
Original file line number Diff line number Diff line change
@@ -79,23 +79,23 @@ def evaluate_source(mime, source)
Truffle::Interop.export_method(:evaluate_source)

def complex_add(a, b)
a.imaginary = a[:imaginary] + b[:imaginary]
a.real = a[:real] + b[:real]
a.imaginary = a.imaginary + b.imaginary
a.real = a.real + b.real
end

Truffle::Interop.export_method(:complex_add)

def complex_add_with_method(a, b)
a.imaginary = a[:imaginary] + b[:imaginary]
a.real = a[:real] + b[:real]
a.imaginary = a.imaginary + b.imaginary
a.real = a.real + b.real
end

Truffle::Interop.export_method(:complex_add_with_method)

def complex_sum_real(complexes)
complexes = Truffle::Interop.enumerable(complexes)

complexes.map{ |c| c[:real] }.inject(&:+)
complexes.map{ |c| c.real }.inject(&:+)
end

Truffle::Interop.export_method(:complex_sum_real)
@@ -111,8 +111,8 @@ def complex_copy(a, b)
b = b.to_a

a.zip(b).each do |x, y|
x.imaginary = y[:imaginary]
x.real = y[:real]
x.imaginary = y.imaginary
x.real = y.real
end
end

0 comments on commit 919cf42

Please sign in to comment.