Skip to content

Commit

Permalink
RD-9460 implement function package in truffle for invoke after (#117)
Browse files Browse the repository at this point in the history
- Added Function.InvokeAfter entry
  • Loading branch information
alexzerntev authored Aug 23, 2023
1 parent f097d9b commit 942b10d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import raw.compiler.base.source.Type
import raw.compiler.rql2.builtin.FunctionInvokeAfterEntry
import raw.compiler.rql2.truffle.{TruffleArg, TruffleEntryExtension}
import raw.runtime.truffle.ExpressionNode
import raw.runtime.truffle.ast.expressions.builtin.function_package.FunctionInvokeAfterNodeGen

class TruffleFunctionInvokeAfterEntry extends FunctionInvokeAfterEntry with TruffleEntryExtension {
override def toTruffle(t: Type, args: Seq[TruffleArg]): ExpressionNode = super.toTruffle(t, args)
override def toTruffle(t: Type, args: Seq[TruffleArg]): ExpressionNode =
FunctionInvokeAfterNodeGen.create(args.head.e, args(1).e)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import raw.testing.tags.TruffleTests
@TruffleTests class EnvironmentPackageTruffleTest extends TruffleCompilerTestContext with EnvironmentPackageTest
@TruffleTests class ErrorPackageTruffleTest extends TruffleCompilerTestContext with ErrorPackageTest
@TruffleTests class FloatPackageTruffleTest extends TruffleCompilerTestContext with FloatPackageTest

// InvokeAfter
// class FunctionPackageTruffleTest extends TruffleCompilerTestContext with FunctionPackageTest

@TruffleTests class FunctionPackageTruffleTest extends TruffleCompilerTestContext with FunctionPackageTest
@TruffleTests class HttpPackageTruffleTest extends TruffleCompilerTestContext with HttpPackageTest
@TruffleTests class IntervalPackageTruffleTest extends TruffleCompilerTestContext with IntervalPackageTest
@TruffleTests class IntPackageTruffleTest extends TruffleCompilerTestContext with IntPackageTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2023 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

package raw.runtime.truffle.ast.expressions.builtin.function_package;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.NodeInfo;
import raw.runtime.truffle.ExpressionNode;
import raw.runtime.truffle.runtime.exceptions.RawTruffleInternalErrorException;
import raw.runtime.truffle.runtime.function.Closure;

@NodeInfo(shortName = "Function.InvokeAfter")
@NodeChild(value = "function")
@NodeChild(value = "sleepTime")
public abstract class FunctionInvokeAfterNode extends ExpressionNode {

@Specialization
protected Object invokeAfter(Closure function, long sleepTime) {
try {
Thread.sleep(sleepTime);
return function.call();
} catch (InterruptedException e) {
throw new RawTruffleInternalErrorException(e);
}
}

}

0 comments on commit 942b10d

Please sign in to comment.