├── .gitignore
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── ci.jsonnet
├── generate_parser.sh
├── language
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ │ ├── META-INF
│ │ │ └── native-image
│ │ │ │ └── org.graalvm.truffle
│ │ │ │ └── truffle-sl
│ │ │ │ └── native-image.properties
│ │ │ ├── com
│ │ │ └── oracle
│ │ │ │ └── truffle
│ │ │ │ └── sl
│ │ │ │ ├── SLEvaluateLocalNode.java
│ │ │ │ ├── SLException.java
│ │ │ │ ├── SLFileDetector.java
│ │ │ │ ├── SLLanguage.java
│ │ │ │ ├── builtins
│ │ │ │ ├── SLAddToHostClassPathBuiltin.java
│ │ │ │ ├── SLBuiltinNode.java
│ │ │ │ ├── SLDefineFunctionBuiltin.java
│ │ │ │ ├── SLEvalBuiltin.java
│ │ │ │ ├── SLExitBuiltin.java
│ │ │ │ ├── SLGetSizeBuiltin.java
│ │ │ │ ├── SLHasSizeBuiltin.java
│ │ │ │ ├── SLHelloEqualsWorldBuiltin.java
│ │ │ │ ├── SLImportBuiltin.java
│ │ │ │ ├── SLInNativeImageBuiltin.java
│ │ │ │ ├── SLIsExecutableBuiltin.java
│ │ │ │ ├── SLIsInstanceBuiltin.java
│ │ │ │ ├── SLIsNullBuiltin.java
│ │ │ │ ├── SLJavaTypeBuiltin.java
│ │ │ │ ├── SLNanoTimeBuiltin.java
│ │ │ │ ├── SLNewObjectBuiltin.java
│ │ │ │ ├── SLPrintlnBuiltin.java
│ │ │ │ ├── SLReadlnBuiltin.java
│ │ │ │ ├── SLRegisterShutdownHookBuiltin.java
│ │ │ │ ├── SLStackTraceBuiltin.java
│ │ │ │ ├── SLTypeOfBuiltin.java
│ │ │ │ └── SLWrapPrimitiveBuiltin.java
│ │ │ │ ├── bytecode
│ │ │ │ ├── SLBytecodeRootNode.java
│ │ │ │ ├── SLBytecodeScopeExports.java
│ │ │ │ └── SLBytecodeSerialization.java
│ │ │ │ ├── nodes
│ │ │ │ ├── SLAstRootNode.java
│ │ │ │ ├── SLBinaryNode.java
│ │ │ │ ├── SLBuiltinAstNode.java
│ │ │ │ ├── SLEvalRootNode.java
│ │ │ │ ├── SLExpressionNode.java
│ │ │ │ ├── SLRootNode.java
│ │ │ │ ├── SLStatementNode.java
│ │ │ │ ├── SLTypes.java
│ │ │ │ ├── SLUndefinedFunctionRootNode.java
│ │ │ │ ├── controlflow
│ │ │ │ │ ├── SLBlockNode.java
│ │ │ │ │ ├── SLBreakException.java
│ │ │ │ │ ├── SLBreakNode.java
│ │ │ │ │ ├── SLContinueException.java
│ │ │ │ │ ├── SLContinueNode.java
│ │ │ │ │ ├── SLDebuggerNode.java
│ │ │ │ │ ├── SLFunctionBodyNode.java
│ │ │ │ │ ├── SLIfNode.java
│ │ │ │ │ ├── SLReturnException.java
│ │ │ │ │ ├── SLReturnNode.java
│ │ │ │ │ ├── SLWhileNode.java
│ │ │ │ │ └── SLWhileRepeatingNode.java
│ │ │ │ ├── expression
│ │ │ │ │ ├── SLAddNode.java
│ │ │ │ │ ├── SLBigIntegerLiteralNode.java
│ │ │ │ │ ├── SLDivNode.java
│ │ │ │ │ ├── SLEqualNode.java
│ │ │ │ │ ├── SLFunctionLiteralNode.java
│ │ │ │ │ ├── SLInvokeNode.java
│ │ │ │ │ ├── SLLessOrEqualNode.java
│ │ │ │ │ ├── SLLessThanNode.java
│ │ │ │ │ ├── SLLogicalAndNode.java
│ │ │ │ │ ├── SLLogicalNotNode.java
│ │ │ │ │ ├── SLLogicalOrNode.java
│ │ │ │ │ ├── SLLongLiteralNode.java
│ │ │ │ │ ├── SLMulNode.java
│ │ │ │ │ ├── SLParenExpressionNode.java
│ │ │ │ │ ├── SLReadPropertyNode.java
│ │ │ │ │ ├── SLShortCircuitNode.java
│ │ │ │ │ ├── SLStringLiteralNode.java
│ │ │ │ │ ├── SLSubNode.java
│ │ │ │ │ └── SLWritePropertyNode.java
│ │ │ │ ├── interop
│ │ │ │ │ ├── NodeObjectDescriptor.java
│ │ │ │ │ └── NodeObjectDescriptorKeys.java
│ │ │ │ ├── local
│ │ │ │ │ ├── SLReadArgumentNode.java
│ │ │ │ │ ├── SLReadLocalVariableNode.java
│ │ │ │ │ ├── SLScopedNode.java
│ │ │ │ │ └── SLWriteLocalVariableNode.java
│ │ │ │ └── util
│ │ │ │ │ ├── SLToBooleanNode.java
│ │ │ │ │ ├── SLToMemberNode.java
│ │ │ │ │ ├── SLToTruffleStringNode.java
│ │ │ │ │ └── SLUnboxNode.java
│ │ │ │ ├── parser
│ │ │ │ ├── SLBaseParser.java
│ │ │ │ ├── SLBytecodeParser.java
│ │ │ │ ├── SLNodeParser.java
│ │ │ │ ├── SLParseError.java
│ │ │ │ ├── SimpleLanguage.g4
│ │ │ │ ├── SimpleLanguage.interp
│ │ │ │ ├── SimpleLanguage.tokens
│ │ │ │ ├── SimpleLanguageBaseVisitor.java
│ │ │ │ ├── SimpleLanguageLexer.interp
│ │ │ │ ├── SimpleLanguageLexer.java
│ │ │ │ ├── SimpleLanguageLexer.tokens
│ │ │ │ ├── SimpleLanguageParser.java
│ │ │ │ └── SimpleLanguageVisitor.java
│ │ │ │ └── runtime
│ │ │ │ ├── FunctionsObject.java
│ │ │ │ ├── SLBigInteger.java
│ │ │ │ ├── SLContext.java
│ │ │ │ ├── SLFunction.java
│ │ │ │ ├── SLFunctionRegistry.java
│ │ │ │ ├── SLLanguageView.java
│ │ │ │ ├── SLNull.java
│ │ │ │ ├── SLObject.java
│ │ │ │ ├── SLStrings.java
│ │ │ │ └── SLType.java
│ │ │ └── module-info.java
│ └── test
│ │ └── java
│ │ ├── com
│ │ └── oracle
│ │ │ └── truffle
│ │ │ └── sl
│ │ │ └── test
│ │ │ ├── AbstractSLTest.java
│ │ │ ├── PassItselfBackViaContextTest.java
│ │ │ ├── SLCodeSharingTest.java
│ │ │ ├── SLDebugALot.java
│ │ │ ├── SLDebugDirectTest.java
│ │ │ ├── SLDebugTest.java
│ │ │ ├── SLExceptionTest.java
│ │ │ ├── SLExecutionListenerTest.java
│ │ │ ├── SLExitTest.java
│ │ │ ├── SLFactorialTest.java
│ │ │ ├── SLInstrumentTest.java
│ │ │ ├── SLInteropControlFlowTest.java
│ │ │ ├── SLInteropObjectTest.java
│ │ │ ├── SLInteropOperatorTest.java
│ │ │ ├── SLInteropPrimitiveTest.java
│ │ │ ├── SLJavaInteropConversionTest.java
│ │ │ ├── SLJavaInteropDebugTest.java
│ │ │ ├── SLJavaInteropExceptionTest.java
│ │ │ ├── SLJavaInteropTest.java
│ │ │ ├── SLLoggerTest.java
│ │ │ ├── SLParseErrorTest.java
│ │ │ ├── SLParseInContextTest.java
│ │ │ ├── SLReadPropertyTest.java
│ │ │ ├── SLSeparatedClassLoadersTest.java
│ │ │ ├── SLSharedCodeSeparatedEnvTest.java
│ │ │ ├── SLTestRunner.java
│ │ │ ├── SLTestSuite.java
│ │ │ ├── SLTestSuiteAST.java
│ │ │ ├── SLTestSuiteBytecode.java
│ │ │ ├── SLTestSuiteBytecodeCached.java
│ │ │ ├── SLTestSuiteBytecodeUncached.java
│ │ │ ├── SLValueSharingTest.java
│ │ │ ├── ToStringOfEvalTest.java
│ │ │ └── TruffleTestAssumptions.java
│ │ └── module-info.java
└── tests
│ ├── Add.output
│ ├── Add.sl
│ ├── Arithmetic.output
│ ├── Arithmetic.sl
│ ├── Break.output
│ ├── Break.sl
│ ├── Builtins.output
│ ├── Builtins.sl
│ ├── Call.output
│ ├── Call.sl
│ ├── Comparison.output
│ ├── Comparison.sl
│ ├── ControlFlow.output
│ ├── ControlFlow.sl
│ ├── CreateContext.output
│ ├── CreateContext.sl
│ ├── DefineFunction.output
│ ├── DefineFunction.sl
│ ├── Div.output
│ ├── Div.sl
│ ├── Equal.output
│ ├── Equal.sl
│ ├── Eval.output
│ ├── Eval.sl
│ ├── Fibonacci.output
│ ├── Fibonacci.sl
│ ├── FunctionLiteral.output
│ ├── FunctionLiteral.sl
│ ├── HelloEqualsWorld.output
│ ├── HelloEqualsWorld.sl
│ ├── HelloWorld.output
│ ├── Inlining.output
│ ├── Inlining.sl
│ ├── IsMetaInstance.output
│ ├── IsMetaInstance.sl
│ ├── LocalTypeChange.output
│ ├── LocalTypeChange.sl
│ ├── Logical.output
│ ├── Logical.sl
│ ├── Loop.output
│ ├── Loop.sl
│ ├── LoopCall.output
│ ├── LoopCall.sl
│ ├── LoopInvalidate.output
│ ├── LoopInvalidate.sl
│ ├── LoopObject.output
│ ├── LoopObject.sl
│ ├── LoopObjectDyn.output
│ ├── LoopObjectDyn.sl
│ ├── LoopPolymorphic.output
│ ├── LoopPolymorphic.sl
│ ├── LoopPrint.output
│ ├── LoopPrint.sl
│ ├── Mul.output
│ ├── Mul.sl
│ ├── Null.output
│ ├── Null.sl
│ ├── Object.output
│ ├── Object.sl
│ ├── ObjectDyn.output
│ ├── ObjectDyn.sl
│ ├── String.output
│ ├── String.sl
│ ├── Sub.output
│ ├── Sub.sl
│ ├── Sum.output
│ ├── Sum.sl
│ ├── SumCall.output
│ ├── SumCall.sl
│ ├── SumObject.output
│ ├── SumObject.sl
│ ├── SumPrint.output
│ ├── SumPrint.sl
│ ├── TypeOf.output
│ ├── TypeOf.sl
│ └── error
│ ├── InvalidAssignmentInAssignment.output
│ ├── InvalidAssignmentInAssignment.sl
│ ├── InvalidAssignmentInBinOp.output
│ ├── InvalidAssignmentInBinOp.sl
│ ├── InvalidAssignmentInBlock.output
│ ├── InvalidAssignmentInBlock.sl
│ ├── InvalidAssignmentInIfCond.output
│ ├── InvalidAssignmentInIfCond.sl
│ ├── InvalidAssignmentInWhileCond.output
│ ├── InvalidAssignmentInWhileCond.sl
│ ├── InvalidBreak.output
│ ├── InvalidBreak.sl
│ ├── InvalidContinue.output
│ ├── InvalidContinue.sl
│ ├── ParseError01.output
│ ├── ParseError01.sl
│ ├── ParseError02.output
│ ├── ParseError02.sl
│ ├── TypeError01.output
│ ├── TypeError01.sl
│ ├── TypeError02.output
│ ├── TypeError02.sl
│ ├── TypeError03.output
│ ├── TypeError03.sl
│ ├── TypeError04.output
│ ├── TypeError04.sl
│ ├── TypeError05.output
│ ├── TypeError05.sl
│ ├── TypeError06.output
│ ├── TypeError06.sl
│ ├── TypeError07.output
│ ├── TypeError07.sl
│ ├── UndefinedFunction01.output
│ ├── UndefinedFunction01.sl
│ ├── UndefinedFunction02.output
│ ├── UndefinedFunction02.sl
│ ├── UndefinedFunction03.output
│ └── UndefinedFunction03.sl
├── launcher
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── com
│ └── oracle
│ │ └── truffle
│ │ └── sl
│ │ └── launcher
│ │ └── SLMain.java
│ └── module-info.java
├── pom.xml
├── sl
├── standalone
├── README.md
├── pom.xml
└── sl
└── tck
├── pom.xml
└── src
└── main
├── java
├── com
│ └── oracle
│ │ └── truffle
│ │ └── sl
│ │ └── tck
│ │ └── SLTCKLanguageProvider.java
└── module-info.java
└── resources
├── META-INF
└── services
│ └── org.graalvm.polyglot.tck.LanguageProvider
└── com
└── oracle
└── truffle
└── sl
└── tck
└── resources
├── Ackermann.sl
├── Fibonacci.sl
├── InvalidSyntax01.sl
└── InvalidSyntax02.sl
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.cfg
3 | *.iml
4 | target/
5 | graalvm/
6 | .settings/
7 | ./.project
8 | .factorypath
9 | .classpath
10 | .idea/
11 | .project
12 | /bin/
13 | /Coco.jar
14 | component/sl-component.jar
15 | language/dependency-reduced-pom.xml
16 | native/slnative
17 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | This repository contains a snapshot of SimpleLanguage that is updated only after major changes. The development version is part of the Truffle repository: https://github.com/graalvm/truffle
2 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
2 |
3 | The Universal Permissive License (UPL), Version 1.0
4 |
5 | Subject to the condition set forth below, permission is hereby granted to any
6 | person obtaining a copy of this software, associated documentation and/or data
7 | (collectively the "Software"), free of charge and under any and all copyright
8 | rights in the Software, and any and all patent rights owned or freely
9 | licensable by each licensor hereunder covering either (i) the unmodified
10 | Software as contributed to or provided by such licensor, or (ii) the Larger
11 | Works (as defined below), to deal in both
12 |
13 | (a) the Software, and
14 |
15 | (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16 | one is included with the Software each a "Larger Work" to which the Software
17 | is contributed by such licensors),
18 |
19 | without restriction, including without limitation the rights to copy, create
20 | derivative works of, display, perform, and distribute the Software and make,
21 | use, sell, offer for sale, import, export, have made, and have sold the
22 | Software and the Larger Work(s), and to sublicense the foregoing rights on
23 | either these or other terms.
24 |
25 | This license is subject to the following condition:
26 |
27 | The above copyright notice and either this complete permission notice or at a
28 | minimum a reference to the UPL must be included in all copies or substantial
29 | portions of the Software.
30 |
31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 | SOFTWARE.
38 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SimpleLanguage
2 |
3 | A simple demonstration language built using Truffle for GraalVM.
4 |
5 | SimpleLanguage is heavily documented to explain the how and why of writing a
6 | Truffle language. A good way to find out more is to read the source with
7 | comments. Start reading [here](https://github.com/graalvm/simplelanguage/blob/master/language/src/main/java/com/oracle/truffle/sl/SLLanguage.java).
8 | We also like to encourage people to clone the repository and start hacking.
9 |
10 | This repository is licensed under the permissive UPL licence. Fork it to begin
11 | your own Truffle language.
12 |
13 | For instructions on how to get started please refer to [our website](http://www.graalvm.org/docs/graalvm-as-a-platform/implement-language/)
14 |
15 | # Building for a JVM
16 |
17 | Build the project with `mvn package`.
18 | To run simple language using a JDK from JAVA_HOME run `./sl`.
19 |
20 | # Building a Native Image
21 |
22 | Build the project with `mvn package -Pnative`.
23 | To run simple language natively run `./standalone/target/slnative`.
24 |
--------------------------------------------------------------------------------
/ci.jsonnet:
--------------------------------------------------------------------------------
1 | {
2 | local graalvmBuild = {
3 | targets: ['gate'],
4 | timelimit: '00:59:59',
5 | run+: [
6 | ['mvn', 'clean'],
7 | ['mvn', 'package', '-Pnative'],
8 | ['./sl', 'language/tests/Add.sl'],
9 | ['./standalone/target/slnative', 'language/tests/Add.sl'],
10 | ['./generate_parser.sh'],
11 | ['mvn', 'package'],
12 | ['./sl', 'language/tests/Add.sl'],
13 | ]
14 | },
15 |
16 | local graalvm = {
17 | downloads+: {
18 | JAVA_HOME: { name: 'graalvm-community-java24', version: '24.2.0', platformspecific: true },
19 | },
20 | },
21 |
22 | local linux = {
23 | capabilities+: ['linux', 'amd64'],
24 | packages+: {
25 | maven: '==3.3.9',
26 | devtoolset: "==7", # GCC 7.3.1, make 4.2.1, binutils 2.28, valgrind 3.13.0
27 | },
28 | docker: {
29 | image: "buildslave_ol7",
30 | mount_modules: true,
31 | },
32 | },
33 |
34 | local darwin = {
35 | capabilities+: ["darwin", "!darwin_sierra", "!darwin_mojave", "!darwin_catalina", "aarch64"],
36 | packages+: {
37 | maven: '==3.3.9',
38 | },
39 | environment+: {
40 | MACOSX_DEPLOYMENT_TARGET: '10.11',
41 | },
42 | },
43 |
44 | local fixDarwinJavaHome = {
45 | environment+: {
46 | JAVA_HOME: '$JAVA_HOME/Contents/Home'
47 | },
48 | },
49 |
50 | builds: [
51 | graalvmBuild + linux + graalvm + { name: 'linux-graalvm' },
52 |
53 | graalvmBuild + darwin + fixDarwinJavaHome + graalvm + { name: 'darwin-graalvm' },
54 |
55 | # Blocked by the sl script being unable to find maven repo
56 | ],
57 | }
58 |
--------------------------------------------------------------------------------
/generate_parser.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #
3 | # Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
4 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 | #
6 | # The Universal Permissive License (UPL), Version 1.0
7 | #
8 | # Subject to the condition set forth below, permission is hereby granted to any
9 | # person obtaining a copy of this software, associated documentation and/or
10 | # data (collectively the "Software"), free of charge and under any and all
11 | # copyright rights in the Software, and any and all patent rights owned or
12 | # freely licensable by each licensor hereunder covering either (i) the
13 | # unmodified Software as contributed to or provided by such licensor, or (ii)
14 | # the Larger Works (as defined below), to deal in both
15 | #
16 | # (a) the Software, and
17 | #
18 | # (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
19 | # one is included with the Software each a "Larger Work" to which the Software
20 | # is contributed by such licensors),
21 | #
22 | # without restriction, including without limitation the rights to copy, create
23 | # derivative works of, display, perform, and distribute the Software and make,
24 | # use, sell, offer for sale, import, export, have made, and have sold the
25 | # Software and the Larger Work(s), and to sublicense the foregoing rights on
26 | # either these or other terms.
27 | #
28 | # This license is subject to the following condition:
29 | #
30 | # The above copyright notice and either this complete permission notice or at a
31 | # minimum a reference to the UPL must be included in all copies or substantial
32 | # portions of the Software.
33 | #
34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 | # SOFTWARE.
41 | #
42 |
43 | curl -O https://www.antlr.org/download/antlr-4.13.2-complete.jar
44 | $JAVA_HOME/bin/java -cp antlr-4.13.2-complete.jar org.antlr.v4.Tool -package com.oracle.truffle.sl.parser -no-listener -visitor language/src/main/java/com/oracle/truffle/sl/parser/SimpleLanguage.g4
45 |
--------------------------------------------------------------------------------
/language/src/main/java/META-INF/native-image/org.graalvm.truffle/truffle-sl/native-image.properties:
--------------------------------------------------------------------------------
1 | Args = --initialize-at-build-time=com.oracle.truffle.sl,org.antlr.v4 \
2 | -H:MaxRuntimeCompileMethods=250
3 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/SLEvaluateLocalNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl;
42 |
43 | import com.oracle.truffle.api.frame.FrameDescriptor;
44 | import com.oracle.truffle.api.frame.MaterializedFrame;
45 | import com.oracle.truffle.api.frame.VirtualFrame;
46 | import com.oracle.truffle.api.nodes.RootNode;
47 | import com.oracle.truffle.api.strings.TruffleString;
48 |
49 | final class SLEvaluateLocalNode extends RootNode {
50 |
51 | private final TruffleString variable;
52 | private final MaterializedFrame inspectFrame;
53 |
54 | SLEvaluateLocalNode(SLLanguage language, TruffleString variableName, MaterializedFrame frame) {
55 | super(language);
56 | this.variable = variableName;
57 | this.inspectFrame = frame;
58 | }
59 |
60 | @Override
61 | public Object execute(VirtualFrame currentFrame) {
62 | FrameDescriptor frameDescriptor = inspectFrame.getFrameDescriptor();
63 |
64 | for (int i = 0; i < frameDescriptor.getNumberOfSlots(); i++) {
65 | if (variable.equals(frameDescriptor.getSlotName(i))) {
66 | return inspectFrame.getValue(i);
67 | }
68 | }
69 | return null;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/SLFileDetector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl;
42 |
43 | import com.oracle.truffle.api.TruffleFile;
44 | import java.io.IOException;
45 | import java.nio.charset.Charset;
46 |
47 | public final class SLFileDetector implements TruffleFile.FileTypeDetector {
48 |
49 | @Override
50 | public String findMimeType(TruffleFile file) throws IOException {
51 | String name = file.getName();
52 | if (name != null && name.endsWith(".sl")) {
53 | return SLLanguage.MIME_TYPE;
54 | }
55 | return null;
56 | }
57 |
58 | @Override
59 | public Charset findEncoding(TruffleFile file) throws IOException {
60 | return null;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLAddToHostClassPathBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.CompilerDirectives;
44 | import com.oracle.truffle.api.TruffleFile;
45 | import com.oracle.truffle.api.TruffleLanguage;
46 | import com.oracle.truffle.api.dsl.Bind;
47 | import com.oracle.truffle.api.dsl.Cached;
48 | import com.oracle.truffle.api.dsl.Specialization;
49 | import com.oracle.truffle.api.nodes.NodeInfo;
50 | import com.oracle.truffle.api.strings.TruffleString;
51 | import com.oracle.truffle.sl.runtime.SLContext;
52 | import com.oracle.truffle.sl.runtime.SLNull;
53 |
54 | /**
55 | * Builtin function that performs context exit.
56 | */
57 | @NodeInfo(shortName = "addToHostClassPath")
58 | public abstract class SLAddToHostClassPathBuiltin extends SLBuiltinNode {
59 |
60 | @Specialization
61 | protected Object doDefault(TruffleString classPath,
62 | @Cached TruffleString.ToJavaStringNode toJavaStringNode,
63 | @Bind SLContext context) {
64 | addToHostClassPath(context, toJavaStringNode.execute(classPath));
65 | return SLNull.SINGLETON;
66 | }
67 |
68 | @CompilerDirectives.TruffleBoundary
69 | private static void addToHostClassPath(SLContext context, String classPath) {
70 | TruffleLanguage.Env env = context.getEnv();
71 | TruffleFile file = env.getPublicTruffleFile(classPath);
72 | env.addToHostClassPath(file);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLBuiltinNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.GenerateInline;
44 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
45 | import com.oracle.truffle.api.dsl.NodeChild;
46 | import com.oracle.truffle.api.frame.VirtualFrame;
47 | import com.oracle.truffle.api.nodes.Node;
48 | import com.oracle.truffle.sl.runtime.SLContext;
49 | import com.oracle.truffle.sl.runtime.SLFunctionRegistry;
50 |
51 | /**
52 | * Base class for all builtin functions. It contains the Truffle DSL annotation {@link NodeChild}
53 | * that defines the function arguments.
54 | * The builtin functions are registered in {@link SLContext#installBuiltins}. Every builtin node
55 | * subclass is instantiated there, wrapped into a function, and added to the
56 | * {@link SLFunctionRegistry}. This ensures that builtin functions can be called like user-defined
57 | * functions; there is no special function lookup or call node for builtin functions.
58 | */
59 | @GenerateNodeFactory
60 | @GenerateInline(value = false, inherit = true)
61 | public abstract class SLBuiltinNode extends Node {
62 |
63 | public abstract Object execute(VirtualFrame frame, Object... arguments);
64 | }
65 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLDefineFunctionBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
44 | import com.oracle.truffle.api.dsl.Bind;
45 | import com.oracle.truffle.api.dsl.Specialization;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 | import com.oracle.truffle.api.source.Source;
48 | import com.oracle.truffle.api.strings.TruffleString;
49 | import com.oracle.truffle.sl.SLLanguage;
50 | import com.oracle.truffle.sl.runtime.SLContext;
51 |
52 | /**
53 | * Builtin function to define (or redefine) functions. The provided source code is parsed the same
54 | * way as the initial source of the script, so the same syntax applies.
55 | */
56 | @NodeInfo(shortName = "defineFunction")
57 | public abstract class SLDefineFunctionBuiltin extends SLBuiltinNode {
58 |
59 | @TruffleBoundary
60 | @Specialization
61 | public TruffleString defineFunction(TruffleString code, @Bind SLContext context) {
62 | // @formatter:off
63 | Source source = Source.newBuilder(SLLanguage.ID, code.toJavaStringUncached(), "[defineFunction]").
64 | build();
65 | // @formatter:on
66 | /* The same parsing code as for parsing the initial source. */
67 | context.getFunctionRegistry().register(source);
68 |
69 | return code;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLExitBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.sl.runtime.SLContext;
46 | import com.oracle.truffle.sl.runtime.SLNull;
47 |
48 | /**
49 | * Builtin function that performs context exit.
50 | */
51 | @NodeInfo(shortName = "exit")
52 | public abstract class SLExitBuiltin extends SLBuiltinNode {
53 |
54 | @Specialization
55 | protected Object doDefault(long exitCode) {
56 | SLContext.get(this).getEnv().getContext().closeExited(this, (int) exitCode);
57 | return SLNull.SINGLETON;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLGetSizeBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.interop.InteropLibrary;
45 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
46 | import com.oracle.truffle.api.library.CachedLibrary;
47 | import com.oracle.truffle.api.nodes.NodeInfo;
48 | import com.oracle.truffle.sl.SLException;
49 |
50 | /**
51 | * Built-in function that queries the size property of a foreign object. See
52 | * Messages.GET_SIZE.
53 | */
54 | @NodeInfo(shortName = "getSize")
55 | public abstract class SLGetSizeBuiltin extends SLBuiltinNode {
56 |
57 | @Specialization(limit = "3")
58 | public Object getSize(Object obj, @CachedLibrary("obj") InteropLibrary arrays) {
59 | try {
60 | return arrays.getArraySize(obj);
61 | } catch (UnsupportedMessageException e) {
62 | throw SLException.create("Element is not a valid array.", this);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLHasSizeBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.interop.InteropLibrary;
45 | import com.oracle.truffle.api.library.CachedLibrary;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 |
48 | /**
49 | * Built-in function that queries if the foreign object has a size. See
50 | * Messages.HAS_SIZE.
51 | */
52 | @NodeInfo(shortName = "hasSize")
53 | public abstract class SLHasSizeBuiltin extends SLBuiltinNode {
54 |
55 | @Specialization(limit = "3")
56 | public boolean hasSize(Object obj, @CachedLibrary("obj") InteropLibrary arrays) {
57 | return arrays.hasArrayElements(obj);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLImportBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Bind;
44 | import com.oracle.truffle.api.dsl.Cached;
45 | import com.oracle.truffle.api.dsl.Specialization;
46 | import com.oracle.truffle.api.interop.InteropLibrary;
47 | import com.oracle.truffle.api.interop.UnknownIdentifierException;
48 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
49 | import com.oracle.truffle.api.library.CachedLibrary;
50 | import com.oracle.truffle.api.nodes.NodeInfo;
51 | import com.oracle.truffle.api.strings.TruffleString;
52 | import com.oracle.truffle.sl.SLException;
53 | import com.oracle.truffle.sl.runtime.SLContext;
54 | import com.oracle.truffle.sl.runtime.SLNull;
55 |
56 | /**
57 | * Built-in function that goes through to import a symbol from the polyglot bindings.
58 | */
59 | @NodeInfo(shortName = "import")
60 | public abstract class SLImportBuiltin extends SLBuiltinNode {
61 |
62 | @Specialization
63 | public Object importSymbol(TruffleString symbol,
64 | @Cached TruffleString.ToJavaStringNode toJavaStringNode,
65 | @CachedLibrary(limit = "3") InteropLibrary arrays,
66 | @Bind SLContext context) {
67 | try {
68 | return arrays.readMember(context.getPolyglotBindings(), toJavaStringNode.execute(symbol));
69 | } catch (UnsupportedMessageException | UnknownIdentifierException e) {
70 | return SLNull.SINGLETON;
71 | } catch (SecurityException e) {
72 | throw SLException.create("No polyglot access allowed.", this);
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLInNativeImageBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.TruffleOptions;
44 | import com.oracle.truffle.api.dsl.Specialization;
45 | import com.oracle.truffle.api.nodes.NodeInfo;
46 |
47 | /**
48 | * Built-in function that returns true if in a native-image builtin.
49 | */
50 | @NodeInfo(shortName = "inNativeImage")
51 | public abstract class SLInNativeImageBuiltin extends SLBuiltinNode {
52 |
53 | @Specialization
54 | public boolean isExecutable() {
55 | return TruffleOptions.AOT;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLIsExecutableBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.interop.InteropLibrary;
45 | import com.oracle.truffle.api.library.CachedLibrary;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 |
48 | /**
49 | * Built-in function that queries if the foreign object is executable. See
50 | * Messages.IS_EXECUTABLE.
51 | */
52 | @NodeInfo(shortName = "isExecutable")
53 | public abstract class SLIsExecutableBuiltin extends SLBuiltinNode {
54 |
55 | @Specialization(limit = "3")
56 | public boolean isExecutable(Object obj, @CachedLibrary("obj") InteropLibrary executables) {
57 | return executables.isExecutable(obj);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLIsInstanceBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import static com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere;
44 |
45 | import com.oracle.truffle.api.dsl.Specialization;
46 | import com.oracle.truffle.api.interop.InteropLibrary;
47 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
48 | import com.oracle.truffle.api.library.CachedLibrary;
49 | import com.oracle.truffle.api.nodes.NodeInfo;
50 |
51 | /**
52 | * Built-in function that returns true if the given operand is of a given meta-object. Meta-objects
53 | * may be values of the current or a foreign value.
54 | */
55 | @NodeInfo(shortName = "isInstance")
56 | @SuppressWarnings("unused")
57 | public abstract class SLIsInstanceBuiltin extends SLBuiltinNode {
58 |
59 | @Specialization(limit = "3", guards = "metaLib.isMetaObject(metaObject)")
60 | public Object doDefault(Object metaObject, Object value,
61 | @CachedLibrary("metaObject") InteropLibrary metaLib) {
62 | try {
63 | return metaLib.isMetaInstance(metaObject, value);
64 | } catch (UnsupportedMessageException e) {
65 | throw shouldNotReachHere(e);
66 | }
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLIsNullBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.interop.InteropLibrary;
45 | import com.oracle.truffle.api.library.CachedLibrary;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 |
48 | /**
49 | * Built-in function that queries if the foreign object is a null value. See
50 | * Messages.IS_NULL.
51 | */
52 | @NodeInfo(shortName = "isNull")
53 | public abstract class SLIsNullBuiltin extends SLBuiltinNode {
54 |
55 | @Specialization(limit = "3")
56 | public boolean isExecutable(Object obj, @CachedLibrary("obj") InteropLibrary values) {
57 | return values.isNull(obj);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLJavaTypeBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Bind;
44 | import com.oracle.truffle.api.dsl.Specialization;
45 | import com.oracle.truffle.api.interop.InteropLibrary;
46 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
47 | import com.oracle.truffle.api.library.CachedLibrary;
48 | import com.oracle.truffle.api.nodes.NodeInfo;
49 | import com.oracle.truffle.sl.SLException;
50 | import com.oracle.truffle.sl.runtime.SLContext;
51 |
52 | /**
53 | * Builtin that allows to lookup a Java type.
54 | */
55 | @NodeInfo(shortName = "java")
56 | public abstract class SLJavaTypeBuiltin extends SLBuiltinNode {
57 |
58 | @Specialization
59 | public Object doLookup(Object symbolName,
60 | @CachedLibrary(limit = "3") InteropLibrary interop,
61 | @Bind SLContext context) {
62 | try {
63 | /*
64 | * This is the entry point to Java host interoperability. The return value of
65 | * lookupHostSymbol implements the interop contracts. So we can use Java for things that
66 | * are expressible also in SL. Like function calls on objects.
67 | */
68 | return context.getEnv().lookupHostSymbol(interop.asString(symbolName));
69 | } catch (UnsupportedMessageException e) {
70 | throw SLException.create("The java builtin expected a String argument, but a non-string argument was provided.", this);
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLNanoTimeBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 |
46 | /**
47 | * Builtin function that returns the value of a high-resolution time, in nanoseconds.
48 | */
49 | @NodeInfo(shortName = "nanoTime")
50 | public abstract class SLNanoTimeBuiltin extends SLBuiltinNode {
51 |
52 | @Specialization
53 | public long nanoTime() {
54 | return System.nanoTime();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLPrintlnBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
44 | import com.oracle.truffle.api.dsl.Bind;
45 | import com.oracle.truffle.api.dsl.Specialization;
46 | import com.oracle.truffle.api.interop.InteropLibrary;
47 | import com.oracle.truffle.api.library.CachedLibrary;
48 | import com.oracle.truffle.api.nodes.NodeInfo;
49 | import com.oracle.truffle.sl.runtime.SLContext;
50 | import com.oracle.truffle.sl.runtime.SLLanguageView;
51 |
52 | /**
53 | * Builtin function to write a value to the {@link SLContext#getOutput() standard output}. The
54 | * different specialization leverage the typed {@code println} methods available in Java, i.e.,
55 | * primitive values are printed without converting them to a {@link String} first.
56 | *
57 | * Printing involves a lot of Java code, so we need to tell the optimizing system that it should not
58 | * unconditionally inline everything reachable from the println() method. This is done via the
59 | * {@link TruffleBoundary} annotations.
60 | */
61 | @NodeInfo(shortName = "println")
62 | public abstract class SLPrintlnBuiltin extends SLBuiltinNode {
63 |
64 | @Specialization
65 | @TruffleBoundary
66 | public Object println(Object value,
67 | @CachedLibrary(limit = "3") InteropLibrary interop,
68 | @Bind SLContext context) {
69 | context.getOutput().println(interop.toDisplayString(SLLanguageView.forValue(value)));
70 | return value;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLRegisterShutdownHookBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Bind;
44 | import com.oracle.truffle.api.dsl.Specialization;
45 | import com.oracle.truffle.api.nodes.NodeInfo;
46 | import com.oracle.truffle.sl.runtime.SLContext;
47 | import com.oracle.truffle.sl.runtime.SLFunction;
48 | import com.oracle.truffle.sl.runtime.SLNull;
49 |
50 | /**
51 | * Builtin function that registers a function as a shutdown hook. Only no-parameter functions are
52 | * supported.
53 | */
54 | @NodeInfo(shortName = "registerShutdownHook")
55 | public abstract class SLRegisterShutdownHookBuiltin extends SLBuiltinNode {
56 |
57 | @Specialization
58 | protected Object doDefault(SLFunction shutdownHook, @Bind SLContext context) {
59 | context.registerShutdownHook(shutdownHook);
60 | return SLNull.SINGLETON;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/builtins/SLTypeOfBuiltin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.builtins;
42 |
43 | import com.oracle.truffle.api.dsl.Specialization;
44 | import com.oracle.truffle.api.interop.InteropLibrary;
45 | import com.oracle.truffle.api.library.CachedLibrary;
46 | import com.oracle.truffle.api.nodes.ExplodeLoop;
47 | import com.oracle.truffle.api.nodes.NodeInfo;
48 | import com.oracle.truffle.sl.runtime.SLNull;
49 | import com.oracle.truffle.sl.runtime.SLType;
50 |
51 | /**
52 | * Built-in function that returns the type of a guest language value.
53 | */
54 | @NodeInfo(shortName = "typeOf")
55 | @SuppressWarnings("unused")
56 | public abstract class SLTypeOfBuiltin extends SLBuiltinNode {
57 |
58 | /*
59 | * This returns the SL type for a particular operand value.
60 | */
61 | @Specialization(limit = "3")
62 | @ExplodeLoop
63 | public Object doDefault(Object operand,
64 | @CachedLibrary("operand") InteropLibrary interop) {
65 | for (SLType type : SLType.PRECEDENCE) {
66 | if (type.isInstance(operand, interop)) {
67 | return type;
68 | }
69 | }
70 | return SLNull.SINGLETON;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/SLBinaryNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes;
42 |
43 | import com.oracle.truffle.api.dsl.NodeChild;
44 |
45 | /**
46 | * Utility base class for operations that take two arguments (per convention called "left" and
47 | * "right"). For concrete subclasses of this class, the Truffle DSL creates two child fields, and
48 | * the necessary constructors and logic to set them.
49 | */
50 | @NodeChild("leftNode")
51 | @NodeChild("rightNode")
52 | public abstract class SLBinaryNode extends SLExpressionNode {
53 | }
54 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLBreakException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.nodes.ControlFlowException;
44 |
45 | /**
46 | * Exception thrown by the {@link SLBreakNode break statement} and caught by the {@link SLWhileNode
47 | * loop statement}. Since the exception is stateless, i.e., has no instance fields, we can use a
48 | * {@link #SINGLETON} to avoid memory allocation during interpretation.
49 | */
50 | public final class SLBreakException extends ControlFlowException {
51 |
52 | public static final SLBreakException SINGLETON = new SLBreakException();
53 |
54 | private static final long serialVersionUID = -91013036379258890L;
55 |
56 | /* Prevent instantiation from outside. */
57 | private SLBreakException() {
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLBreakNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.frame.VirtualFrame;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.sl.nodes.SLStatementNode;
46 |
47 | /**
48 | * Implementation of the SL break statement. We need to unwind an unknown number of interpreter
49 | * frames that are between this {@link SLBreakNode} and the {@link SLWhileNode} of the loop we are
50 | * breaking out. This is done by throwing an {@link SLBreakException exception} that is caught by
51 | * the {@link SLWhileNode#executeVoid loop node}.
52 | */
53 | @NodeInfo(shortName = "break", description = "The node implementing a break statement")
54 | public final class SLBreakNode extends SLStatementNode {
55 |
56 | @Override
57 | public void executeVoid(VirtualFrame frame) {
58 | throw SLBreakException.SINGLETON;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLContinueException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.nodes.ControlFlowException;
44 |
45 | /**
46 | * Exception thrown by the {@link SLContinueNode continue statement} and caught by the
47 | * {@link SLWhileNode loop statement}. Since the exception is stateless, i.e., has no instance
48 | * fields, we can use a {@link #SINGLETON} to avoid memory allocation during interpretation.
49 | */
50 | public final class SLContinueException extends ControlFlowException {
51 |
52 | public static final SLContinueException SINGLETON = new SLContinueException();
53 |
54 | private static final long serialVersionUID = 5329687983726237188L;
55 |
56 | /* Prevent instantiation from outside. */
57 | private SLContinueException() {
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLContinueNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.frame.VirtualFrame;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.sl.nodes.SLStatementNode;
46 |
47 | /**
48 | * Implementation of the SL continue statement. We need to unwind an unknown number of interpreter
49 | * frames that are between this {@link SLContinueNode} and the {@link SLWhileNode} of the loop we
50 | * are continuing. This is done by throwing an {@link SLContinueException exception} that is caught
51 | * by the {@link SLWhileNode#executeVoid loop node}.
52 | */
53 | @NodeInfo(shortName = "continue", description = "The node implementing a continue statement")
54 | public final class SLContinueNode extends SLStatementNode {
55 |
56 | @Override
57 | public void executeVoid(VirtualFrame frame) {
58 | throw SLContinueException.SINGLETON;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLDebuggerNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.debug.DebuggerTags;
44 | import com.oracle.truffle.api.frame.VirtualFrame;
45 | import com.oracle.truffle.api.instrumentation.Tag;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 | import com.oracle.truffle.sl.nodes.SLStatementNode;
48 |
49 | /**
50 | * Implementation of the SL debugger statement. When under the debugger, execution suspends here.
51 | */
52 | @NodeInfo(shortName = "debugger", description = "The node implementing a debugger statement")
53 | public class SLDebuggerNode extends SLStatementNode {
54 |
55 | @Override
56 | public void executeVoid(VirtualFrame frame) {
57 | // No op.
58 | }
59 |
60 | @Override
61 | public boolean hasTag(Class extends Tag> tag) {
62 | if (tag == DebuggerTags.AlwaysHalt.class) {
63 | return true;
64 | }
65 | return super.hasTag(tag);
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLReturnException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.nodes.ControlFlowException;
44 |
45 | /**
46 | * Exception thrown by the {@link SLReturnNode return statement} and caught by the
47 | * {@link SLFunctionBodyNode function body}. The exception transports the return value in its
48 | * {@link #result} field.
49 | */
50 | @SuppressWarnings("serial")
51 | public final class SLReturnException extends ControlFlowException {
52 |
53 | private static final long serialVersionUID = 4073191346281369231L;
54 |
55 | private final Object result;
56 |
57 | public SLReturnException(Object result) {
58 | this.result = result;
59 | }
60 |
61 | public Object getResult() {
62 | return result;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLReturnNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.frame.VirtualFrame;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
46 | import com.oracle.truffle.sl.nodes.SLStatementNode;
47 | import com.oracle.truffle.sl.runtime.SLNull;
48 |
49 | /**
50 | * Implementation of the SL return statement. We need to unwind an unknown number of interpreter
51 | * frames that are between this {@link SLReturnNode} and the {@link SLFunctionBodyNode} of the
52 | * method we are exiting. This is done by throwing an {@link SLReturnException exception} that is
53 | * caught by the {@link SLFunctionBodyNode#executeGeneric function body}. The exception transports
54 | * the return value.
55 | */
56 | @NodeInfo(shortName = "return", description = "The node implementing a return statement")
57 | public final class SLReturnNode extends SLStatementNode {
58 |
59 | @Child private SLExpressionNode valueNode;
60 |
61 | public SLReturnNode(SLExpressionNode valueNode) {
62 | this.valueNode = valueNode;
63 | }
64 |
65 | @Override
66 | public void executeVoid(VirtualFrame frame) {
67 | Object result;
68 | if (valueNode != null) {
69 | result = valueNode.executeGeneric(frame);
70 | } else {
71 | /*
72 | * Return statement that was not followed by an expression, so return the SL null value.
73 | */
74 | result = SLNull.SINGLETON;
75 | }
76 | throw new SLReturnException(result);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/controlflow/SLWhileNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.controlflow;
42 |
43 | import com.oracle.truffle.api.Truffle;
44 | import com.oracle.truffle.api.frame.VirtualFrame;
45 | import com.oracle.truffle.api.nodes.LoopNode;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
48 | import com.oracle.truffle.sl.nodes.SLStatementNode;
49 |
50 | @NodeInfo(shortName = "while", description = "The node implementing a while loop")
51 | public final class SLWhileNode extends SLStatementNode {
52 |
53 | @Child private LoopNode loopNode;
54 |
55 | public SLWhileNode(SLExpressionNode conditionNode, SLStatementNode bodyNode) {
56 | this.loopNode = Truffle.getRuntime().createLoopNode(new SLWhileRepeatingNode(conditionNode, bodyNode));
57 | }
58 |
59 | @Override
60 | public void executeVoid(VirtualFrame frame) {
61 | loopNode.execute(frame);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLBigIntegerLiteralNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import java.math.BigInteger;
44 |
45 | import com.oracle.truffle.api.frame.VirtualFrame;
46 | import com.oracle.truffle.api.nodes.NodeInfo;
47 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
48 | import com.oracle.truffle.sl.runtime.SLBigInteger;
49 |
50 | /**
51 | * Constant literal for a arbitrary-precision number that exceeds the range of
52 | * {@link SLLongLiteralNode}.
53 | */
54 | @NodeInfo(shortName = "const")
55 | public final class SLBigIntegerLiteralNode extends SLExpressionNode {
56 |
57 | private final SLBigInteger value;
58 |
59 | public SLBigIntegerLiteralNode(BigInteger value) {
60 | this.value = new SLBigInteger(value);
61 | }
62 |
63 | @Override
64 | public SLBigInteger executeGeneric(VirtualFrame frame) {
65 | return value;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import com.oracle.truffle.api.nodes.NodeInfo;
44 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
45 |
46 | /**
47 | * Logical conjunction node with short circuit evaluation.
48 | */
49 | @NodeInfo(shortName = "&&")
50 | public final class SLLogicalAndNode extends SLShortCircuitNode {
51 |
52 | public SLLogicalAndNode(SLExpressionNode left, SLExpressionNode right) {
53 | super(left, right);
54 | }
55 |
56 | /**
57 | * The right value does not need to be evaluated if the left value is already false
58 | * .
59 | */
60 | @Override
61 | protected boolean isEvaluateRight(boolean left) {
62 | return left;
63 | }
64 |
65 | /**
66 | * Only if left and right value are true the result of the logical and is true
. If
67 | * the second parameter is not evaluated, false
is provided.
68 | */
69 | @Override
70 | protected boolean execute(boolean left, boolean right) {
71 | return left && right;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLLogicalNotNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import com.oracle.truffle.api.bytecode.OperationProxy;
44 | import com.oracle.truffle.api.dsl.Bind;
45 | import com.oracle.truffle.api.dsl.Fallback;
46 | import com.oracle.truffle.api.dsl.NodeChild;
47 | import com.oracle.truffle.api.dsl.Specialization;
48 | import com.oracle.truffle.api.nodes.Node;
49 | import com.oracle.truffle.api.nodes.NodeInfo;
50 | import com.oracle.truffle.sl.SLException;
51 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
52 |
53 | /**
54 | * Example of a simple unary node that uses type specialization. See {@link SLAddNode} for
55 | * information on specializations.
56 | */
57 | @NodeChild("valueNode")
58 | @NodeInfo(shortName = "!")
59 | @OperationProxy.Proxyable(allowUncached = true)
60 | public abstract class SLLogicalNotNode extends SLExpressionNode {
61 |
62 | @Specialization
63 | public static boolean doBoolean(boolean value) {
64 | return !value;
65 | }
66 |
67 | @Fallback
68 | public static boolean typeError(Object value, @Bind Node node) {
69 | throw SLException.typeError(node, "!", value);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLLogicalOrNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import com.oracle.truffle.api.nodes.NodeInfo;
44 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
45 |
46 | /**
47 | * Logical disjunction node with short circuit evaluation.
48 | */
49 | @NodeInfo(shortName = "||")
50 | public final class SLLogicalOrNode extends SLShortCircuitNode {
51 |
52 | public SLLogicalOrNode(SLExpressionNode left, SLExpressionNode right) {
53 | super(left, right);
54 | }
55 |
56 | @Override
57 | protected boolean isEvaluateRight(boolean left) {
58 | return !left;
59 | }
60 |
61 | @Override
62 | protected boolean execute(boolean left, boolean right) {
63 | return left || right;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLLongLiteralNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import com.oracle.truffle.api.frame.VirtualFrame;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.api.nodes.UnexpectedResultException;
46 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
47 |
48 | /**
49 | * Constant literal for a primitive {@code long} value. The unboxed value can be returned when the
50 | * parent expects a long value and calls {@link SLLongLiteralNode#executeLong}. In the generic case,
51 | * the primitive value is automatically boxed by Java.
52 | */
53 | @NodeInfo(shortName = "const")
54 | public final class SLLongLiteralNode extends SLExpressionNode {
55 |
56 | private final long value;
57 |
58 | public SLLongLiteralNode(long value) {
59 | this.value = value;
60 | }
61 |
62 | @Override
63 | public long executeLong(VirtualFrame frame) throws UnexpectedResultException {
64 | return value;
65 | }
66 |
67 | @Override
68 | public Object executeGeneric(VirtualFrame frame) {
69 | return value;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLParenExpressionNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import com.oracle.truffle.api.frame.VirtualFrame;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.api.nodes.UnexpectedResultException;
46 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
47 |
48 | /**
49 | * A {@link SLExpressionNode} that represents a parenthesized expression; it simply returns the
50 | * value of the enclosed (child) expression. It is represented separately in the AST for the purpose
51 | * of correct source attribution; this preserves the lexical relationship between the two
52 | * parentheses and allows a tool to describe the expression as distinct from its contents.
53 | */
54 | @NodeInfo(description = "A parenthesized expression")
55 | public class SLParenExpressionNode extends SLExpressionNode {
56 |
57 | @Child private SLExpressionNode expression;
58 |
59 | public SLParenExpressionNode(SLExpressionNode expression) {
60 | this.expression = expression;
61 | }
62 |
63 | @Override
64 | public Object executeGeneric(VirtualFrame frame) {
65 | return expression.executeGeneric(frame);
66 | }
67 |
68 | @Override
69 | public long executeLong(VirtualFrame frame) throws UnexpectedResultException {
70 | return expression.executeLong(frame);
71 | }
72 |
73 | @Override
74 | public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException {
75 | return expression.executeBoolean(frame);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLStringLiteralNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.nodes.expression;
42 |
43 | import com.oracle.truffle.api.frame.VirtualFrame;
44 | import com.oracle.truffle.api.nodes.NodeInfo;
45 | import com.oracle.truffle.api.strings.TruffleString;
46 | import com.oracle.truffle.sl.nodes.SLExpressionNode;
47 |
48 | /**
49 | * Constant literal for a String value.
50 | */
51 | @NodeInfo(shortName = "const")
52 | public final class SLStringLiteralNode extends SLExpressionNode {
53 |
54 | private final TruffleString value;
55 |
56 | public SLStringLiteralNode(TruffleString value) {
57 | this.value = value;
58 | }
59 |
60 | @Override
61 | public TruffleString executeGeneric(VirtualFrame frame) {
62 | return value;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/parser/SimpleLanguage.tokens:
--------------------------------------------------------------------------------
1 | T__0=1
2 | T__1=2
3 | T__2=3
4 | T__3=4
5 | T__4=5
6 | T__5=6
7 | T__6=7
8 | T__7=8
9 | T__8=9
10 | T__9=10
11 | T__10=11
12 | T__11=12
13 | T__12=13
14 | T__13=14
15 | T__14=15
16 | T__15=16
17 | T__16=17
18 | T__17=18
19 | WS=19
20 | COMMENT=20
21 | LINE_COMMENT=21
22 | OP_OR=22
23 | OP_AND=23
24 | OP_COMPARE=24
25 | OP_ADD=25
26 | OP_MUL=26
27 | IDENTIFIER=27
28 | STRING_LITERAL=28
29 | NUMERIC_LITERAL=29
30 | 'function'=1
31 | '('=2
32 | ','=3
33 | ')'=4
34 | '{'=5
35 | '}'=6
36 | 'break'=7
37 | ';'=8
38 | 'continue'=9
39 | 'debugger'=10
40 | 'while'=11
41 | 'if'=12
42 | 'else'=13
43 | 'return'=14
44 | '='=15
45 | '.'=16
46 | '['=17
47 | ']'=18
48 | '||'=22
49 | '&&'=23
50 |
--------------------------------------------------------------------------------
/language/src/main/java/com/oracle/truffle/sl/parser/SimpleLanguageLexer.tokens:
--------------------------------------------------------------------------------
1 | T__0=1
2 | T__1=2
3 | T__2=3
4 | T__3=4
5 | T__4=5
6 | T__5=6
7 | T__6=7
8 | T__7=8
9 | T__8=9
10 | T__9=10
11 | T__10=11
12 | T__11=12
13 | T__12=13
14 | T__13=14
15 | T__14=15
16 | T__15=16
17 | T__16=17
18 | T__17=18
19 | WS=19
20 | COMMENT=20
21 | LINE_COMMENT=21
22 | OP_OR=22
23 | OP_AND=23
24 | OP_COMPARE=24
25 | OP_ADD=25
26 | OP_MUL=26
27 | IDENTIFIER=27
28 | STRING_LITERAL=28
29 | NUMERIC_LITERAL=29
30 | 'function'=1
31 | '('=2
32 | ','=3
33 | ')'=4
34 | '{'=5
35 | '}'=6
36 | 'break'=7
37 | ';'=8
38 | 'continue'=9
39 | 'debugger'=10
40 | 'while'=11
41 | 'if'=12
42 | 'else'=13
43 | 'return'=14
44 | '='=15
45 | '.'=16
46 | '['=17
47 | ']'=18
48 | '||'=22
49 | '&&'=23
50 |
--------------------------------------------------------------------------------
/language/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | module org.graalvm.sl {
42 | requires java.base;
43 | requires java.logging;
44 | requires jdk.unsupported;
45 | requires org.antlr.antlr4.runtime;
46 | requires org.graalvm.polyglot;
47 | requires org.graalvm.truffle;
48 | exports com.oracle.truffle.sl to org.graalvm.sl.test;
49 | exports com.oracle.truffle.sl.runtime to org.graalvm.sl.test;
50 | exports com.oracle.truffle.sl.builtins to org.graalvm.sl.test;
51 | provides com.oracle.truffle.api.provider.TruffleLanguageProvider with
52 | com.oracle.truffle.sl.SLLanguageProvider;
53 | }
54 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLInteropControlFlowTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.graalvm.polyglot.Context;
44 | import org.graalvm.polyglot.Source;
45 | import org.graalvm.polyglot.Value;
46 | import org.junit.After;
47 | import org.junit.Assert;
48 | import org.junit.Before;
49 | import org.junit.Test;
50 |
51 | public class SLInteropControlFlowTest extends AbstractSLTest {
52 | private Context context;
53 |
54 | @Before
55 | public void setUp() {
56 | context = newContextBuilder().build();
57 | }
58 |
59 | @After
60 | public void tearDown() {
61 | context = null;
62 | }
63 |
64 | @Test
65 | public void testWhile() {
66 | final Source src = Source.newBuilder("sl", "function testWhile(a) {while(a) {break;}} function main() {return testWhile;}", "testWhile.sl").buildLiteral();
67 | final Value fnc = context.eval(src);
68 | Assert.assertTrue(fnc.canExecute());
69 | fnc.execute(false);
70 | }
71 |
72 | @Test
73 | public void testIf() {
74 | final Source src = Source.newBuilder("sl", "function testIf(a) {if(a) {return 1;} else {return 0;}} function main() {return testIf;}", "testIf.sl").buildLiteral();
75 | final Value fnc = context.eval(src);
76 | fnc.execute(false);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLInteropOperatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.graalvm.polyglot.Context;
44 | import org.graalvm.polyglot.Source;
45 | import org.graalvm.polyglot.Value;
46 | import org.junit.After;
47 | import org.junit.Assert;
48 | import org.junit.Before;
49 | import org.junit.Test;
50 |
51 | public class SLInteropOperatorTest extends AbstractSLTest {
52 | private Context context;
53 |
54 | @Before
55 | public void setUp() {
56 | context = newContextBuilder().build();
57 | }
58 |
59 | @After
60 | public void tearDown() {
61 | context = null;
62 | }
63 |
64 | @Test
65 | public void testAdd() {
66 | final Source src = Source.newBuilder("sl", "function testAdd(a,b) {return a + b;} function main() {return testAdd;}", "testAdd.sl").buildLiteral();
67 | final Value fnc = context.eval(src);
68 | Assert.assertTrue(fnc.canExecute());
69 | final Value res = fnc.execute(1, 2);
70 | Assert.assertTrue(res.isNumber());
71 | Assert.assertEquals(3, res.asInt());
72 | }
73 |
74 | @Test
75 | public void testSub() {
76 | final Source src = Source.newBuilder("sl", "function testSub(a,b) {return a - b;} function main() {return testSub;}", "testSub.sl").buildLiteral();
77 | final Value fnc = context.eval(src);
78 | final Value res = fnc.execute(1, 2);
79 | Assert.assertTrue(res.isNumber());
80 | Assert.assertEquals(-1, res.asInt());
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLReadPropertyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import static org.junit.Assert.assertNull;
44 |
45 | import org.graalvm.polyglot.Context;
46 | import org.graalvm.polyglot.Value;
47 | import org.junit.After;
48 | import org.junit.Assert;
49 | import org.junit.Before;
50 | import org.junit.Test;
51 |
52 | public class SLReadPropertyTest extends AbstractSLTest {
53 |
54 | private Context ctx;
55 | private Value slObject;
56 |
57 | @Before
58 | public void setUp() {
59 | this.ctx = newContextBuilder("sl").build();
60 | this.slObject = ctx.eval("sl", "function createObject() {\n" +
61 | "obj1 = new();\n" +
62 | "obj1.number = 42;\n" +
63 | "return obj1;\n" +
64 | "}\n" +
65 | "function main() {\n" +
66 | "return createObject;\n" +
67 | "}").execute();
68 | }
69 |
70 | @After
71 | public void tearDown() {
72 | this.ctx.close();
73 | }
74 |
75 | @Test
76 | public void testRead() {
77 | Assert.assertEquals(42, slObject.getMember("number").asInt());
78 | assertNull(slObject.getMember("nonexistent"));
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLTestSuite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import java.lang.annotation.ElementType;
44 | import java.lang.annotation.Retention;
45 | import java.lang.annotation.RetentionPolicy;
46 | import java.lang.annotation.Target;
47 |
48 | @Retention(RetentionPolicy.RUNTIME)
49 | @Target(ElementType.TYPE)
50 | public @interface SLTestSuite {
51 |
52 | /**
53 | * Defines the base path of the test suite. Multiple base paths can be specified. However only
54 | * the first base that exists is used to lookup the test cases.
55 | */
56 | String[] value();
57 |
58 | /**
59 | * A class in the same project (or .jar file) that contains the {@link #value test case
60 | * directory}. If the property is not specified, the class that declares the annotation is used,
61 | * i.e., the test cases must be in the same project as the test class.
62 | */
63 | Class> testCaseDirectory() default SLTestSuite.class;
64 |
65 | /**
66 | * The options passed to {@code Context.Builder} to configure the {@code Context} executing the
67 | * tests. The options are given as an string array containing an option name followed by an
68 | * option value.
69 | *
70 | * @since 20.0.0
71 | */
72 | String[] options() default {};
73 | }
74 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLTestSuiteAST.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.junit.Test;
44 | import org.junit.runner.RunWith;
45 |
46 | @RunWith(SLTestRunner.class)
47 | @SLTestSuite({"tests"})
48 | public class SLTestSuiteAST {
49 |
50 | public static void main(String[] args) throws Exception {
51 | SLTestRunner.runInMain(SLTestSuiteAST.class, args);
52 | }
53 |
54 | /*
55 | * Our "mx unittest" command looks for methods that are annotated with @Test. By just defining
56 | * an empty method, this class gets included and the test suite is properly executed.
57 | */
58 | @Test
59 | public void unittest() {
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLTestSuiteBytecode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.junit.Test;
44 | import org.junit.runner.RunWith;
45 |
46 | @RunWith(SLTestRunner.class)
47 | @SLTestSuite(value = {"tests"}, options = {"sl.UseBytecode", "true"})
48 | public class SLTestSuiteBytecode {
49 |
50 | public static void main(String[] args) throws Exception {
51 | SLTestRunner.runInMain(SLTestSuiteBytecode.class, args);
52 | }
53 |
54 | /*
55 | * Our "mx unittest" command looks for methods that are annotated with @Test. By just defining
56 | * an empty method, this class gets included and the test suite is properly executed.
57 | */
58 | @Test
59 | public void unittest() {
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLTestSuiteBytecodeCached.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.junit.Test;
44 | import org.junit.runner.RunWith;
45 |
46 | @RunWith(SLTestRunner.class)
47 | @SLTestSuite(value = {"tests"}, options = {"sl.UseBytecode", "true", "sl.ForceBytecodeTier", "CACHED"})
48 | public class SLTestSuiteBytecodeCached {
49 |
50 | public static void main(String[] args) throws Exception {
51 | SLTestRunner.runInMain(SLTestSuiteBytecodeCached.class, args);
52 | }
53 |
54 | /*
55 | * Our "mx unittest" command looks for methods that are annotated with @Test. By just defining
56 | * an empty method, this class gets included and the test suite is properly executed.
57 | */
58 | @Test
59 | public void unittest() {
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLTestSuiteBytecodeUncached.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.junit.Test;
44 | import org.junit.runner.RunWith;
45 |
46 | @RunWith(SLTestRunner.class)
47 | @SLTestSuite(value = {"tests"}, options = {"sl.UseBytecode", "true", "sl.ForceBytecodeTier", "UNCACHED"})
48 | public class SLTestSuiteBytecodeUncached {
49 |
50 | public static void main(String[] args) throws Exception {
51 | SLTestRunner.runInMain(SLTestSuiteBytecodeUncached.class, args);
52 | }
53 |
54 | /*
55 | * Our "mx unittest" command looks for methods that are annotated with @Test. By just defining
56 | * an empty method, this class gets included and the test suite is properly executed.
57 | */
58 | @Test
59 | public void unittest() {
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/SLValueSharingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import static org.junit.Assert.assertEquals;
44 | import static org.junit.Assert.assertTrue;
45 |
46 | import org.graalvm.polyglot.Context;
47 | import org.graalvm.polyglot.Value;
48 | import org.junit.Test;
49 |
50 | public class SLValueSharingTest extends AbstractSLTest {
51 |
52 | public static class JavaObject {
53 | public Object sharedField;
54 | }
55 |
56 | @Test
57 | public void testImplicitValueSharing() {
58 | JavaObject obj = new JavaObject();
59 | Context.Builder b = newContextBuilder().allowAllAccess(true);
60 | try (Context c0 = b.build();
61 | Context c1 = b.build()) {
62 |
63 | c0.eval("sl", "function test(obj) { obj.sharedField = new(); }");
64 | c1.eval("sl", "function test(obj) { return obj.sharedField; }");
65 |
66 | c0.getBindings("sl").getMember("test").execute(obj);
67 | Value test1 = c1.getBindings("sl").getMember("test");
68 |
69 | Value v = test1.execute(obj);
70 |
71 | assertTrue(v.hasMembers());
72 | assertEquals(v, c1.asValue(obj.sharedField));
73 | }
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/ToStringOfEvalTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import static org.junit.Assert.assertFalse;
44 | import static org.junit.Assert.assertNotNull;
45 | import static org.junit.Assert.assertTrue;
46 |
47 | import org.graalvm.polyglot.Context;
48 | import org.graalvm.polyglot.Value;
49 | import org.junit.After;
50 | import org.junit.Before;
51 | import org.junit.Test;
52 |
53 | public class ToStringOfEvalTest extends AbstractSLTest {
54 | Context context;
55 |
56 | @Before
57 | public void initialize() {
58 | context = newContextBuilder().build();
59 | }
60 |
61 | @After
62 | public void dispose() {
63 | context.close();
64 | }
65 |
66 | @Test
67 | public void checkToStringOnAFunction() {
68 | context.eval("sl", "function checkName() {}");
69 | Value value1 = context.getBindings("sl").getMember("checkName");
70 | Value value2 = context.getBindings("sl").getMember("checkName");
71 |
72 | assertNotNull("Symbol is not null", value1);
73 | assertNotNull("Symbol is not null either", value2);
74 |
75 | assertFalse("Symbol is not null", value1.isNull());
76 | assertFalse("Symbol is not null either", value2.isNull());
77 |
78 | assertTrue("Contans checkName text: " + value2, value2.toString().contains("checkName"));
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/language/src/test/java/com/oracle/truffle/sl/test/TruffleTestAssumptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | package com.oracle.truffle.sl.test;
42 |
43 | import org.graalvm.polyglot.Engine;
44 | import org.junit.Assume;
45 |
46 | public class TruffleTestAssumptions {
47 | private static final boolean spawnIsolate = "true".equals(System.getProperty("polyglot.engine.SpawnIsolate"));
48 | private static Boolean optimizingRuntimeUsed;
49 |
50 | public static void assumeWeakEncapsulation() {
51 | Assume.assumeFalse(spawnIsolate);
52 | }
53 |
54 | public static boolean isWeakEncapsulation() {
55 | return !spawnIsolate;
56 | }
57 |
58 | public static boolean isOptimizingRuntime() {
59 | Boolean optimizing = optimizingRuntimeUsed;
60 | if (optimizing == null) {
61 | try (Engine e = Engine.create()) {
62 | optimizingRuntimeUsed = optimizing = !e.getImplementationName().equals("Interpreted");
63 | }
64 | }
65 | return optimizing;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/language/src/test/java/module-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | open module org.graalvm.sl.test {
42 | requires java.logging;
43 | requires jdk.unsupported;
44 | requires org.graalvm.polyglot;
45 | requires junit;
46 | requires org.graalvm.truffle;
47 | requires org.graalvm.sl;
48 | exports com.oracle.truffle.sl.test;
49 |
50 | provides com.oracle.truffle.api.provider.TruffleLanguageProvider
51 | with com.oracle.truffle.sl.test.SLParseInContextTestEvalLangProvider;
52 |
53 | provides com.oracle.truffle.api.instrumentation.provider.TruffleInstrumentProvider
54 | with com.oracle.truffle.sl.test.SLInstrumentTestEarlyReturnInstrumentProvider,
55 | com.oracle.truffle.sl.test.SLInstrumentTestEnvironmentHandlerInstrumentProvider,
56 | com.oracle.truffle.sl.test.SLInstrumentTestIncreaseArgOnErrorInstrumentProvider,
57 | com.oracle.truffle.sl.test.SLInstrumentTestNewReplacedInstrumentProvider,
58 | com.oracle.truffle.sl.test.SLInstrumentTestTestRedoIOProvider,
59 | com.oracle.truffle.sl.test.SLSharedCodeSeparatedEnvTestCaptureOutputProvider;
60 | }
61 |
--------------------------------------------------------------------------------
/language/tests/Add.output:
--------------------------------------------------------------------------------
1 | 7
2 | 34
3 | 34
4 | 34
5 | 4000000000003
6 | 3000000000004
7 | 7000000000000
8 |
--------------------------------------------------------------------------------
/language/tests/Add.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println(3 + 4);
8 | println(3 + "4");
9 | println("3" + 4);
10 | println("3" + "4");
11 | println(3 + 4000000000000);
12 | println(3000000000000 + 4);
13 | println(3000000000000 + 4000000000000);
14 | }
15 |
--------------------------------------------------------------------------------
/language/tests/Arithmetic.output:
--------------------------------------------------------------------------------
1 | 5
2 | 1
3 | -3
4 | 14
5 | 11
6 | 5
7 | -3
8 | 1
9 | 18
10 | 11
11 |
--------------------------------------------------------------------------------
/language/tests/Arithmetic.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println(3 + 4 - 2);
8 | println(3 - 4 + 2);
9 | println(3 - 4 - 2);
10 | println(3 * 4 + 2);
11 | println(3 + 4 * 2);
12 | println(3 + (4 - 2));
13 | println(3 - (4 + 2));
14 | println(3 - (4 - 2));
15 | println(3 * (4 + 2));
16 | println(3 + (4 * 2));
17 | }
18 |
--------------------------------------------------------------------------------
/language/tests/Break.output:
--------------------------------------------------------------------------------
1 | 942
2 |
--------------------------------------------------------------------------------
/language/tests/Break.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | i = 0;
8 | while (i < 1000) {
9 | if (i >= 942) {
10 | break;
11 | }
12 | i = i + 1;
13 | }
14 | return i;
15 | }
16 |
--------------------------------------------------------------------------------
/language/tests/Builtins.output:
--------------------------------------------------------------------------------
1 | Hello World!
2 |
--------------------------------------------------------------------------------
/language/tests/Builtins.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println("Hello World!");
8 | nanoTime();
9 | }
10 |
--------------------------------------------------------------------------------
/language/tests/Call.output:
--------------------------------------------------------------------------------
1 | 42
2 | 42
3 | 42
4 | 42
5 | 42
6 | 42
7 | 42
8 | 42
9 |
--------------------------------------------------------------------------------
/language/tests/Call.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function ret(a) { return a; }
7 | function dub(a) { return a * 2; }
8 | function inc(a) { return a + 1; }
9 | function dec(a) { return a - 1; }
10 | function call(f, v) { return f(v); }
11 |
12 | function main() {
13 | println(ret(42));
14 | println(dub(21));
15 | println(inc(41));
16 | println(dec(43));
17 | println(call(ret, 42));
18 | println(call(dub, 21));
19 | println(call(inc, 41));
20 | println(call(dec, 43));
21 | }
22 |
--------------------------------------------------------------------------------
/language/tests/Comparison.output:
--------------------------------------------------------------------------------
1 | <
2 | true
3 | false
4 | false
5 | true
6 | false
7 | true
8 | false
9 | false
10 | <=
11 | true
12 | false
13 | true
14 | true
15 | false
16 | true
17 | false
18 | true
19 | >
20 | false
21 | true
22 | false
23 | false
24 | true
25 | false
26 | true
27 | false
28 | >=
29 | false
30 | true
31 | true
32 | false
33 | true
34 | false
35 | true
36 | true
37 | ==
38 | false
39 | false
40 | true
41 | false
42 | false
43 | false
44 | false
45 | true
46 | !=
47 | true
48 | true
49 | false
50 | true
51 | true
52 | true
53 | true
54 | false
55 |
--------------------------------------------------------------------------------
/language/tests/Comparison.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println("<");
8 | println(4 < 20);
9 | println(40 < 2);
10 | println(4 < 4);
11 | println(4 < 200000000000000000000000000);
12 | println(40000000000000000000000000 < 20);
13 | println(40000000000000000000000000 < 200000000000000000000000000);
14 | println(400000000000000000000000000 < 20000000000000000000000000);
15 | println(40000000000000000000000000 < 40000000000000000000000000);
16 |
17 | println("<=");
18 | println(4 <= 20);
19 | println(40 <= 2);
20 | println(4 <= 4);
21 | println(4 <= 200000000000000000000000000);
22 | println(40000000000000000000000000 <= 20);
23 | println(40000000000000000000000000 <= 200000000000000000000000000);
24 | println(400000000000000000000000000 <= 20000000000000000000000000);
25 | println(40000000000000000000000000 <= 40000000000000000000000000);
26 |
27 | println(">");
28 | println(4 > 20);
29 | println(40 > 2);
30 | println(4 > 4);
31 | println(4 > 200000000000000000000000000);
32 | println(40000000000000000000000000 > 20);
33 | println(40000000000000000000000000 > 200000000000000000000000000);
34 | println(400000000000000000000000000 > 20000000000000000000000000);
35 | println(40000000000000000000000000 > 40000000000000000000000000);
36 |
37 | println(">=");
38 | println(4 >= 20);
39 | println(40 >= 2);
40 | println(4 >= 4);
41 | println(4 >= 200000000000000000000000000);
42 | println(40000000000000000000000000 >= 20);
43 | println(40000000000000000000000000 >= 200000000000000000000000000);
44 | println(400000000000000000000000000 >= 20000000000000000000000000);
45 | println(40000000000000000000000000 >= 40000000000000000000000000);
46 |
47 | println("==");
48 | println(4 == 20);
49 | println(40 == 2);
50 | println(4 == 4);
51 | println(4 == 200000000000000000000000000);
52 | println(40000000000000000000000000 == 20);
53 | println(40000000000000000000000000 == 200000000000000000000000000);
54 | println(400000000000000000000000000 == 20000000000000000000000000);
55 | println(40000000000000000000000000 == 40000000000000000000000000);
56 |
57 | println("!=");
58 | println(4 != 20);
59 | println(40 != 2);
60 | println(4 != 4);
61 | println(4 != 200000000000000000000000000);
62 | println(40000000000000000000000000 != 20);
63 | println(40000000000000000000000000 != 200000000000000000000000000);
64 | println(400000000000000000000000000 != 20000000000000000000000000);
65 | println(40000000000000000000000000 != 40000000000000000000000000);
66 | }
67 |
--------------------------------------------------------------------------------
/language/tests/ControlFlow.output:
--------------------------------------------------------------------------------
1 | 1
2 |
--------------------------------------------------------------------------------
/language/tests/ControlFlow.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function foo() {}
7 | function bar() {}
8 |
9 | function main() {
10 | foo();
11 | if (1 < 2) {
12 | bar();
13 | return 1;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/language/tests/CreateContext.output:
--------------------------------------------------------------------------------
1 | Object
2 | 42
3 |
--------------------------------------------------------------------------------
/language/tests/CreateContext.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | if (inNativeImage()) {
8 | /* no support for host reflection in native-image */
9 | println("Object");
10 | println("42");
11 | } else {
12 | context = java("org.graalvm.polyglot.Context").newBuilder().option("engine.WarnInterpreterOnly", "false").build();
13 | context.eval("sl", "function createObject() { return new(); }");
14 | context.eval("sl", "function getPrimitive() { return 42; }");
15 | innerBindings = context.getBindings("sl");
16 | println(innerBindings.createObject());
17 | println(innerBindings.getPrimitive());
18 | context.close();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/language/tests/DefineFunction.output:
--------------------------------------------------------------------------------
1 | 42
2 | 38
3 |
--------------------------------------------------------------------------------
/language/tests/DefineFunction.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function foo() {
7 | println(test(40, 2));
8 | }
9 |
10 | function main() {
11 | defineFunction("function test(a, b) { return a + b; }");
12 | foo();
13 |
14 | defineFunction("function test(a, b) { return a - b; }");
15 | foo();
16 | }
17 |
--------------------------------------------------------------------------------
/language/tests/Div.output:
--------------------------------------------------------------------------------
1 | 2
2 | 0
3 | 1000000000000
4 | 1
5 |
--------------------------------------------------------------------------------
/language/tests/Div.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println(4 / 2);
8 | println(4 / 4000000000000);
9 | println(3000000000000 / 3);
10 | println(3000000000000 / 3000000000000);
11 | }
12 |
--------------------------------------------------------------------------------
/language/tests/Equal.output:
--------------------------------------------------------------------------------
1 | true
2 | false
3 | true
4 | true
5 | true
6 | false
7 | true
8 |
--------------------------------------------------------------------------------
/language/tests/Equal.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function e(a, b) {
7 | return a == b;
8 | }
9 |
10 | function main() {
11 | println(e(4, 4));
12 | println(e(3, "aaa"));
13 | println(e(4, 4));
14 | println(e("a", "a"));
15 | println(e(1==2, 1==2));
16 | println(e(1==2, 1));
17 | println(e(e, e));
18 | }
19 |
--------------------------------------------------------------------------------
/language/tests/Eval.output:
--------------------------------------------------------------------------------
1 | 16
2 |
--------------------------------------------------------------------------------
/language/tests/Eval.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | eval("sl", "function foo() { return 14 + 2; }");
8 | println(foo());
9 | }
10 |
--------------------------------------------------------------------------------
/language/tests/Fibonacci.output:
--------------------------------------------------------------------------------
1 | 1: 1
2 | 2: 1
3 | 3: 2
4 | 4: 3
5 | 5: 5
6 | 6: 8
7 | 7: 13
8 | 8: 21
9 | 9: 34
10 | 10: 55
11 |
--------------------------------------------------------------------------------
/language/tests/Fibonacci.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function fib(num) {
7 | if (num < 1) {return 0;}
8 | n1 = 0;
9 | n2 = 1;
10 | i = 1;
11 | while (i < num) {
12 | next = n2 + n1;
13 | n1 = n2;
14 | n2 = next;
15 | i = i + 1;
16 | }
17 | return n2;
18 | }
19 |
20 | function main() {
21 | i = 1;
22 | while (i <= 10) {
23 | println(i + ": " + fib(i));
24 | i = i + 1;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/language/tests/FunctionLiteral.output:
--------------------------------------------------------------------------------
1 | 42
2 | 38
3 |
--------------------------------------------------------------------------------
/language/tests/FunctionLiteral.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function add(a, b) {
7 | return a + b;
8 | }
9 |
10 | function sub(a, b) {
11 | return a - b;
12 | }
13 |
14 | function foo(f) {
15 | println(f(40, 2));
16 | }
17 |
18 | function main() {
19 | foo(add);
20 | foo(sub);
21 | }
22 |
--------------------------------------------------------------------------------
/language/tests/HelloEqualsWorld.output:
--------------------------------------------------------------------------------
1 | Initial stack trace:
2 | Frame: root doIt, a=0
3 | Frame: root main, i=0
4 | After 123 assignment:
5 | Frame: root doIt, a=0, hello=123
6 | Frame: root main, i=0
7 | After hello assignment:
8 | Frame: root doIt, a=0, hello=world
9 | Frame: root main, i=0
10 | Initial stack trace:
11 | Frame: root doIt, a=1
12 | Frame: root main, i=1
13 | After 123 assignment:
14 | Frame: root doIt, a=1, hello=123
15 | Frame: root main, i=1
16 | After hello assignment:
17 | Frame: root doIt, a=1, hello=world
18 | Frame: root main, i=1
19 | Initial stack trace:
20 | Frame: root doIt, a=2
21 | Frame: root main, i=2
22 | After 123 assignment:
23 | Frame: root doIt, a=2, hello=123
24 | Frame: root main, i=2
25 | After hello assignment:
26 | Frame: root doIt, a=2, hello=world
27 | Frame: root main, i=2
28 | Initial stack trace:
29 | Frame: root doIt, a=3
30 | Frame: root main, i=3
31 | After 123 assignment:
32 | Frame: root doIt, a=3, hello=123
33 | Frame: root main, i=3
34 | After hello assignment:
35 | Frame: root doIt, a=3, hello=world
36 | Frame: root main, i=3
37 | Initial stack trace:
38 | Frame: root doIt, a=4
39 | Frame: root main, i=4
40 | After 123 assignment:
41 | Frame: root doIt, a=4, hello=123
42 | Frame: root main, i=4
43 | After hello assignment:
44 | Frame: root doIt, a=4, hello=world
45 | Frame: root main, i=4
46 | Initial stack trace:
47 | Frame: root doIt, a=5
48 | Frame: root main, i=5
49 | After 123 assignment:
50 | Frame: root doIt, a=5, hello=123
51 | Frame: root main, i=5
52 | After hello assignment:
53 | Frame: root doIt, a=5, hello=world
54 | Frame: root main, i=5
55 | Initial stack trace:
56 | Frame: root doIt, a=6
57 | Frame: root main, i=6
58 | After 123 assignment:
59 | Frame: root doIt, a=6, hello=123
60 | Frame: root main, i=6
61 | After hello assignment:
62 | Frame: root doIt, a=6, hello=world
63 | Frame: root main, i=6
64 | Initial stack trace:
65 | Frame: root doIt, a=7
66 | Frame: root main, i=7
67 | After 123 assignment:
68 | Frame: root doIt, a=7, hello=123
69 | Frame: root main, i=7
70 | After hello assignment:
71 | Frame: root doIt, a=7, hello=world
72 | Frame: root main, i=7
73 | Initial stack trace:
74 | Frame: root doIt, a=8
75 | Frame: root main, i=8
76 | After 123 assignment:
77 | Frame: root doIt, a=8, hello=123
78 | Frame: root main, i=8
79 | After hello assignment:
80 | Frame: root doIt, a=8, hello=world
81 | Frame: root main, i=8
82 | Initial stack trace:
83 | Frame: root doIt, a=9
84 | Frame: root main, i=9
85 | After 123 assignment:
86 | Frame: root doIt, a=9, hello=123
87 | Frame: root main, i=9
88 | After hello assignment:
89 | Frame: root doIt, a=9, hello=world
90 | Frame: root main, i=9
91 |
--------------------------------------------------------------------------------
/language/tests/HelloEqualsWorld.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function doIt(a) {
7 | println("Initial stack trace:");
8 | println(stacktrace());
9 |
10 | hello = 123;
11 | println("After 123 assignment:");
12 | println(stacktrace());
13 |
14 | helloEqualsWorld();
15 | println("After hello assignment:");
16 | println(stacktrace());
17 |
18 | // readln();
19 | }
20 |
21 | function main() {
22 | i = 0;
23 | while (i < 10) {
24 | doIt(i);
25 | i = i + 1;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/language/tests/HelloWorld.output:
--------------------------------------------------------------------------------
1 | Hello World!
2 |
--------------------------------------------------------------------------------
/language/tests/Inlining.output:
--------------------------------------------------------------------------------
1 | 1260000
2 |
--------------------------------------------------------------------------------
/language/tests/Inlining.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 |
7 | function a() {return 42;}
8 | function b() {return a();}
9 | function c() {return b();}
10 | function d() {return c();}
11 | function e() {return c();}
12 | function f() {return c();}
13 | function g() {return d() + e() + f();}
14 |
15 | function main() {
16 | i = 0;
17 | result = 0;
18 | while (i < 10000) {
19 | result = result + g();
20 | i = i + 1;
21 | }
22 | return result;
23 | }
24 |
--------------------------------------------------------------------------------
/language/tests/IsMetaInstance.output:
--------------------------------------------------------------------------------
1 | true
2 | true
3 | false
4 | false
5 | false
6 | false
7 | false
8 |
9 | false
10 | false
11 | true
12 | false
13 | false
14 | false
15 | false
16 |
17 | false
18 | false
19 | false
20 | true
21 | false
22 | false
23 | false
24 |
25 | false
26 | false
27 | false
28 | false
29 | true
30 | false
31 | false
32 |
33 | false
34 | false
35 | false
36 | false
37 | false
38 | true
39 | false
40 |
41 | false
42 | false
43 | false
44 | false
45 | false
46 | false
47 | true
48 |
49 |
--------------------------------------------------------------------------------
/language/tests/IsMetaInstance.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function printTypes(type) {
7 | println(isInstance(type, 42));
8 | println(isInstance(type, 42000000000000000000000000000000000000000));
9 | println(isInstance(type, "42"));
10 | println(isInstance(type, 42 == 42));
11 | println(isInstance(type, new()));
12 | println(isInstance(type, null));
13 | println(isInstance(type, null()));
14 | println("");
15 | }
16 |
17 | function null() {
18 | }
19 |
20 | function main() {
21 | number = typeOf(42);
22 | string = typeOf("42");
23 | boolean = typeOf(42 == 42);
24 | object = typeOf(new());
25 | f = typeOf(null);
26 | null_type = typeOf(null());
27 |
28 | printTypes(number);
29 | printTypes(string);
30 | printTypes(boolean);
31 | printTypes(object);
32 | printTypes(f);
33 | printTypes(null_type);
34 | }
35 |
--------------------------------------------------------------------------------
/language/tests/LocalTypeChange.output:
--------------------------------------------------------------------------------
1 | abc
2 | 42
3 | 42
4 | 42
5 |
--------------------------------------------------------------------------------
/language/tests/LocalTypeChange.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function recursion(n) {
7 | local = 42;
8 |
9 | if (n > 0) {
10 | recursion(n - 1);
11 | } else {
12 | local = "abc";
13 | }
14 |
15 | println(local);
16 | }
17 |
18 | function main() {
19 | recursion(3);
20 | }
21 |
--------------------------------------------------------------------------------
/language/tests/Logical.output:
--------------------------------------------------------------------------------
1 | left
2 | false
3 | left
4 | false
5 | left
6 | right
7 | false
8 | left
9 | right
10 | true
11 |
12 | left
13 | right
14 | false
15 | left
16 | right
17 | true
18 | left
19 | true
20 | left
21 | true
22 |
--------------------------------------------------------------------------------
/language/tests/Logical.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | t = 10 == 10; // true
8 | f = 10 != 10; // false
9 | println(left(f) && right(f));
10 | println(left(f) && right(t));
11 | println(left(t) && right(f));
12 | println(left(t) && right(t));
13 | println("");
14 | println(left(f) || right(f));
15 | println(left(f) || right(t));
16 | println(left(t) || right(f));
17 | println(left(t) || right(t));
18 | }
19 |
20 | function left(x) {
21 | println("left");
22 | return x;
23 | }
24 |
25 | function right(x) {
26 | println("right");
27 | return x;
28 | }
29 |
--------------------------------------------------------------------------------
/language/tests/Loop.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/Loop.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | i = 0;
8 | while (i < 1000) {
9 | i = i + 1;
10 | }
11 | return i;
12 | }
13 |
--------------------------------------------------------------------------------
/language/tests/LoopCall.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/LoopCall.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function add(a, b) {
7 | return a + b;
8 | }
9 |
10 | function loop(n) {
11 | i = 0;
12 | while (i < n) {
13 | i = add(i, 1);
14 | }
15 | return i;
16 | }
17 |
18 | function main() {
19 | i = 0;
20 | while (i < 20) {
21 | loop(1000);
22 | i = i + 1;
23 | }
24 | println(loop(1000));
25 | }
26 |
--------------------------------------------------------------------------------
/language/tests/LoopInvalidate.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/LoopInvalidate.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function add(a, b) {
7 | return a + b;
8 | }
9 |
10 | function loop(n) {
11 | i = 0;
12 | while (i < n) {
13 | i = add(i, 1);
14 | }
15 | return i;
16 | }
17 |
18 | function main() {
19 | i = 0;
20 | while (i < 20) {
21 | loop(1000);
22 | i = i + 1;
23 | }
24 | add("a", "b");
25 | println(loop(1000));
26 | }
27 |
--------------------------------------------------------------------------------
/language/tests/LoopObject.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/LoopObject.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function loop(n) {
7 | obj = new();
8 | obj.i = 0;
9 | while (obj.i < n) {
10 | obj.i = obj.i + 1;
11 | }
12 | return obj.i;
13 | }
14 |
15 | function main() {
16 | i = 0;
17 | while (i < 20) {
18 | loop(1000);
19 | i = i + 1;
20 | }
21 | println(loop(1000));
22 | }
23 |
--------------------------------------------------------------------------------
/language/tests/LoopObjectDyn.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/LoopObjectDyn.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function loop(n, obj, name) {
7 | obj[name] = 0;
8 | while (obj[name] < n) {
9 | obj[name] = obj[name] + 1;
10 | }
11 | return obj[name];
12 | }
13 |
14 | function main() {
15 | i = 0;
16 | while (i < 20) {
17 | loop(1000, new(), "prop");
18 | i = i + 1;
19 | }
20 | println(loop(1000, new(), "prop"));
21 | }
22 |
--------------------------------------------------------------------------------
/language/tests/LoopPolymorphic.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/LoopPolymorphic.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function add(a, b) {
7 | return a + b;
8 | }
9 |
10 | function loop(n) {
11 | i = 0;
12 | while (i < n) {
13 | i = add(i, 1);
14 | }
15 | return i;
16 | }
17 |
18 | function main() {
19 | add("a", "b");
20 |
21 | i = 0;
22 | while (i < 20) {
23 | loop(1000);
24 | i = i + 1;
25 | }
26 | println(loop(1000));
27 | }
28 |
--------------------------------------------------------------------------------
/language/tests/LoopPrint.output:
--------------------------------------------------------------------------------
1 | 1000
2 |
--------------------------------------------------------------------------------
/language/tests/LoopPrint.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function loop(n) {
7 | i = 0;
8 | while (i < n) {
9 | i = i + 1;
10 | }
11 | return i;
12 | }
13 |
14 | function main() {
15 | i = 0;
16 | while (i < 20) {
17 | loop(1000);
18 | i = i + 1;
19 | }
20 | println(loop(1000));
21 | }
22 |
--------------------------------------------------------------------------------
/language/tests/Mul.output:
--------------------------------------------------------------------------------
1 | 12
2 | 12000000000000
3 | 12000000000000
4 | 12000000000000000000000000
5 |
--------------------------------------------------------------------------------
/language/tests/Mul.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println(3 * 4);
8 | println(3 * 4000000000000);
9 | println(3000000000000 * 4);
10 | println(3000000000000 * 4000000000000);
11 | }
12 |
--------------------------------------------------------------------------------
/language/tests/Null.output:
--------------------------------------------------------------------------------
1 | NULL
2 | true
3 | false
4 | false
5 | true
6 | false
7 | true
8 |
--------------------------------------------------------------------------------
/language/tests/Null.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | /* The easiest way to generate null: a function without a return statement implicitly returns null. */
7 | function null() {
8 | }
9 |
10 | function main() {
11 | println(null());
12 | println(null() == null());
13 | println(null() != null());
14 | println(null() == 42);
15 | println(null() != 42);
16 | println(null() == "42");
17 | println(null() != "42");
18 | }
19 |
--------------------------------------------------------------------------------
/language/tests/Object.output:
--------------------------------------------------------------------------------
1 | 42
2 | 42
3 | why
4 | zzz
5 | zzz
6 | Undefined property: x
7 |
--------------------------------------------------------------------------------
/language/tests/Object.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | obj1 = new();
8 | obj1.x = 42;
9 | println(obj1.x);
10 |
11 | obj2 = new();
12 | obj2.o = obj1;
13 | println(obj2.o.x);
14 | obj2.o.y = "why";
15 | println(obj1.y);
16 |
17 | println(mkobj().z);
18 |
19 | obj3 = new();
20 | obj3.fn = mkobj;
21 | println(obj3.fn().z);
22 |
23 | obj4 = new();
24 | write(obj4, 1);
25 | read(obj4);
26 | write(obj4, 2);
27 | read(obj4);
28 | write(obj4, "three");
29 | read(obj4);
30 |
31 | obj5 = new();
32 | println(obj5.x);
33 | }
34 |
35 | function mkobj() {
36 | newobj = new();
37 | newobj.z = "zzz";
38 | return newobj;
39 | }
40 |
41 | function read(obj) {
42 | return obj.prop;
43 | }
44 |
45 | function write(obj, value) {
46 | return obj.prop = value;
47 | }
48 |
--------------------------------------------------------------------------------
/language/tests/ObjectDyn.output:
--------------------------------------------------------------------------------
1 | 42
2 | 42
3 | why
4 | zzz
5 | zzz
6 | 4
7 | 512
8 | Undefined property: x
9 |
--------------------------------------------------------------------------------
/language/tests/ObjectDyn.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | obj1 = new();
8 | obj1["x"] = 42;
9 | println(obj1["x"]);
10 |
11 | obj2 = new();
12 | obj2["o"] = obj1;
13 | println(obj2["o"]["x"]);
14 | obj2["o"]["y"] = "why";
15 | println(obj1["y"]);
16 |
17 | println(mkobj()["z"]);
18 |
19 | obj3 = new();
20 | obj3["fn"] = mkobj;
21 | println(obj3["fn"]()["z"]);
22 |
23 | obj4 = new();
24 | write(obj4, "prop", 1);
25 | read(obj4, "prop");
26 | write(obj4, "prop", 2);
27 | read(obj4, "prop");
28 | write(obj4, "prop", "three");
29 | read(obj4, "prop");
30 |
31 | obj5 = new();
32 | i = 1;
33 | obj5.prop0 = 1;
34 | while (i < 10) {
35 | write(obj5, "prop" + i, read(obj5, "prop" + (i - 1)) * 2);
36 | i = i + 1;
37 | }
38 | println(obj5.prop2);
39 | println(obj5.prop9);
40 |
41 | obj6 = new();
42 | println(obj6["x"]);
43 | }
44 |
45 | function mkobj() {
46 | newobj = new();
47 | newobj["z"] = "zzz";
48 | return newobj;
49 | }
50 |
51 | function read(obj, name) {
52 | return obj[name];
53 | }
54 |
55 | function write(obj, name, value) {
56 | return obj[name] = value;
57 | }
58 |
--------------------------------------------------------------------------------
/language/tests/String.output:
--------------------------------------------------------------------------------
1 | sNULL
2 | snull
3 | sbar
4 | sfoo
5 | NULLs
6 | NULLs
7 | bars
8 | foos
9 | 2 < 4: true
10 | Type error at String.sl line 14 col 34: operation "<" not defined for Number 2, String "4"
11 |
--------------------------------------------------------------------------------
/language/tests/String.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function null() {
7 | }
8 |
9 | function foo() {
10 | return "bar";
11 | }
12 |
13 | function f(a, b) {
14 | return a + " < " + b + ": " + (a < b);
15 | }
16 |
17 | function main() {
18 | println("s" + null());
19 | println("s" + null);
20 | println("s" + foo());
21 | println("s" + foo);
22 |
23 | println(null() + "s");
24 | println(null() + "s");
25 | println(foo() + "s");
26 | println(foo + "s");
27 |
28 | println(f(2, 4));
29 | println(f(2, "4"));
30 | }
31 |
--------------------------------------------------------------------------------
/language/tests/Sub.output:
--------------------------------------------------------------------------------
1 | -1
2 | -3999999999997
3 | 2999999999996
4 | -1000000000000
5 |
--------------------------------------------------------------------------------
/language/tests/Sub.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println(3 - 4);
8 | println(3 - 4000000000000);
9 | println(3000000000000 - 4);
10 | println(3000000000000 - 4000000000000);
11 | }
12 |
--------------------------------------------------------------------------------
/language/tests/Sum.output:
--------------------------------------------------------------------------------
1 | 50005000
2 |
--------------------------------------------------------------------------------
/language/tests/Sum.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | i = 0;
8 | sum = 0;
9 | while (i <= 10000) {
10 | sum = sum + i;
11 | i = i + 1;
12 | }
13 | return sum;
14 | }
15 |
--------------------------------------------------------------------------------
/language/tests/SumCall.output:
--------------------------------------------------------------------------------
1 | 50005000
2 |
--------------------------------------------------------------------------------
/language/tests/SumCall.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function add(a, b) {
7 | return a + b;
8 | }
9 |
10 | function loop(n) {
11 | i = 0;
12 | sum = 0;
13 | while (i <= n) {
14 | sum = add(sum, i);
15 | i = add(i, 1);
16 | }
17 | return sum;
18 | }
19 |
20 | function main() {
21 | i = 0;
22 | while (i < 20) {
23 | loop(10000);
24 | i = i + 1;
25 | }
26 | println(loop(10000));
27 | }
28 |
--------------------------------------------------------------------------------
/language/tests/SumObject.output:
--------------------------------------------------------------------------------
1 | 50005000
2 |
--------------------------------------------------------------------------------
/language/tests/SumObject.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function loop(n) {
7 | obj = new();
8 | obj.i = 0;
9 | obj.sum = 0;
10 | while (obj.i <= n) {
11 | obj.sum = obj.sum + obj.i;
12 | obj.i = obj.i + 1;
13 | }
14 | return obj.sum;
15 | }
16 |
17 | function main() {
18 | i = 0;
19 | while (i < 20) {
20 | loop(10000);
21 | i = i + 1;
22 | }
23 | println(loop(10000));
24 | }
25 |
--------------------------------------------------------------------------------
/language/tests/SumPrint.output:
--------------------------------------------------------------------------------
1 | 50005000
2 |
--------------------------------------------------------------------------------
/language/tests/SumPrint.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function loop(n) {
7 | i = 0;
8 | sum = 0;
9 | while (i <= n) {
10 | sum = sum + i;
11 | i = i + 1;
12 | }
13 | return sum;
14 | }
15 |
16 | function main() {
17 | i = 0;
18 | while (i < 20) {
19 | loop(10000);
20 | i = i + 1;
21 | }
22 | println(loop(10000));
23 | }
24 |
--------------------------------------------------------------------------------
/language/tests/TypeOf.output:
--------------------------------------------------------------------------------
1 | Number
2 | Number
3 | String
4 | Boolean
5 | Object
6 | Function
7 | NULL
8 |
--------------------------------------------------------------------------------
/language/tests/TypeOf.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | println(typeOf(42));
8 | println(typeOf(42000000000000000000000000000000000000000));
9 | println(typeOf("42"));
10 | println(typeOf(42 == 42));
11 | println(typeOf(new()));
12 | println(typeOf(main));
13 | println(typeOf(null()));
14 | }
15 | function null() {
16 | }
17 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInAssignment.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 7 col 12: invalid assignment target
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInAssignment.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | x = 42 = 42;
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInBinOp.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 11 col 19: invalid assignment target
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInBinOp.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function double(x) {
7 | return 2 * x;
8 | }
9 |
10 | function main() {
11 | 5 + double(2) = 4;
12 | }
13 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInBlock.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 11 col 15: invalid assignment target
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInBlock.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function double(x) {
7 | return 2 * x;
8 | }
9 |
10 | function main() {
11 | double(2) = 4;
12 | }
13 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInIfCond.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 11 col 19: invalid assignment target
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInIfCond.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function double(x) {
7 | return 2 * x;
8 | }
9 |
10 | function main() {
11 | if (double(2) = 4) {
12 | 42;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInWhileCond.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 11 col 22: invalid assignment target
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidAssignmentInWhileCond.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function double(x) {
7 | return 2 * x;
8 | }
9 |
10 | function main() {
11 | while (double(2) = 4) {
12 | 42;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidBreak.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 7 col 3: break used outside of loop
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidBreak.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | break;
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidContinue.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 7 col 3: continue used outside of loop
3 |
--------------------------------------------------------------------------------
/language/tests/error/InvalidContinue.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | continue;
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/ParseError01.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 7 col 10: extraneous input '-' expecting {'(', ';', IDENTIFIER, STRING_LITERAL, NUMERIC_LITERAL}
3 |
--------------------------------------------------------------------------------
/language/tests/error/ParseError01.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | return -1;
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/ParseError02.output:
--------------------------------------------------------------------------------
1 | Error(s) parsing script:
2 | -- line 16 col 11: extraneous input '-' expecting {'(', IDENTIFIER, STRING_LITERAL, NUMERIC_LITERAL}
3 |
--------------------------------------------------------------------------------
/language/tests/error/ParseError02.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function test(n) {
7 | a = 1;
8 | if (a > 0) {
9 | b = 10;
10 | println(b);
11 | } else {
12 | b = 20;
13 | a = 0;
14 | c = 1;
15 | if (b > 0) {
16 | a = -1;
17 | b = -1;
18 | c = -1;
19 | d = -1;
20 | print(d);
21 | }
22 | }
23 | println(b);
24 | println(a);
25 | }
26 | function main() {
27 | test(\"n_n\");
28 | }
29 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError01.output:
--------------------------------------------------------------------------------
1 | Type error at TypeError01.sl line 7 col 3: operation "-" not defined for Number 3, String "4"
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError01.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | 3 - "4";
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError02.output:
--------------------------------------------------------------------------------
1 | Type error at TypeError02.sl line 7 col 7: operation "toBoolean" not defined for String "4"
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError02.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | if ("4") { }
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError03.output:
--------------------------------------------------------------------------------
1 | Type error at TypeError03.sl line 7 col 3: operation "toBoolean" not defined for String "4"
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError03.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | "4" && 4;
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError04.output:
--------------------------------------------------------------------------------
1 | Type error at TypeError04.sl line 7 col 3: operation "toBoolean" not defined for Number 4
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError04.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | (1 > 2) || 4;
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError05.output:
--------------------------------------------------------------------------------
1 | Undefined function: true
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError05.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | f = 1 < 2;
8 | f();
9 | }
10 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError06.output:
--------------------------------------------------------------------------------
1 | Type error: operation "defineFunction" not defined for Number 3
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError06.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | defineFunction(3);
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError07.output:
--------------------------------------------------------------------------------
1 | Type error: operation "defineFunction" not defined for NULL
2 |
--------------------------------------------------------------------------------
/language/tests/error/TypeError07.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | defineFunction();
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/UndefinedFunction01.output:
--------------------------------------------------------------------------------
1 | Undefined function: foo
2 |
--------------------------------------------------------------------------------
/language/tests/error/UndefinedFunction01.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function main() {
7 | foo();
8 | }
9 |
--------------------------------------------------------------------------------
/language/tests/error/UndefinedFunction02.output:
--------------------------------------------------------------------------------
1 | f1
2 | Undefined function: foo
3 |
--------------------------------------------------------------------------------
/language/tests/error/UndefinedFunction02.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function invoke(f) {
7 | f("hello");
8 | }
9 |
10 | function f1() {
11 | println("f1");
12 | }
13 |
14 | function main() {
15 | invoke(f1);
16 | invoke(foo);
17 | }
18 |
--------------------------------------------------------------------------------
/language/tests/error/UndefinedFunction03.output:
--------------------------------------------------------------------------------
1 | f1
2 | f2
3 | f3
4 | f4
5 | f5
6 | Undefined function: foo
7 |
--------------------------------------------------------------------------------
/language/tests/error/UndefinedFunction03.sl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4 | */
5 |
6 | function invoke(f) {
7 | f("hello");
8 | }
9 |
10 | function f1() {
11 | println("f1");
12 | }
13 |
14 | function f2() {
15 | println("f2");
16 | }
17 |
18 | function f3() {
19 | println("f3");
20 | }
21 |
22 | function f4() {
23 | println("f4");
24 | }
25 |
26 | function f5() {
27 | println("f5");
28 | }
29 |
30 | function main() {
31 | invoke(f1);
32 | invoke(f2);
33 | invoke(f3);
34 | invoke(f4);
35 | invoke(f5);
36 | invoke(foo);
37 | }
38 |
--------------------------------------------------------------------------------
/launcher/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * The Universal Permissive License (UPL), Version 1.0
6 | *
7 | * Subject to the condition set forth below, permission is hereby granted to any
8 | * person obtaining a copy of this software, associated documentation and/or
9 | * data (collectively the "Software"), free of charge and under any and all
10 | * copyright rights in the Software, and any and all patent rights owned or
11 | * freely licensable by each licensor hereunder covering either (i) the
12 | * unmodified Software as contributed to or provided by such licensor, or (ii)
13 | * the Larger Works (as defined below), to deal in both
14 | *
15 | * (a) the Software, and
16 | *
17 | * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18 | * one is included with the Software each a "Larger Work" to which the Software
19 | * is contributed by such licensors),
20 | *
21 | * without restriction, including without limitation the rights to copy, create
22 | * derivative works of, display, perform, and distribute the Software and make,
23 | * use, sell, offer for sale, import, export, have made, and have sold the
24 | * Software and the Larger Work(s), and to sublicense the foregoing rights on
25 | * either these or other terms.
26 | *
27 | * This license is subject to the following condition:
28 | *
29 | * The above copyright notice and either this complete permission notice or at a
30 | * minimum a reference to the UPL must be included in all copies or substantial
31 | * portions of the Software.
32 | *
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | * SOFTWARE.
40 | */
41 | open module org.graalvm.sl.launcher {
42 | requires org.graalvm.polyglot;
43 | exports com.oracle.truffle.sl.launcher;
44 | }
45 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
42 |