Skip to content

Commit 857e813

Browse files
authored
Merge pull request #73 from boris-spas/sl_update_vm-1.0.0-rc15
RC15 update.
2 parents 11872fb + 3af8d75 commit 857e813

File tree

68 files changed

+1639
-1855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1639
-1855
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jdk:
1010
- openjdk11
1111

1212
env:
13-
- GRAALVM_VERSION="1.0.0-rc14"
13+
- GRAALVM_VERSION="1.0.0-rc15"
1414
- GRAALVM_VERSION="NONE" SL_BUILD_NATIVE="false"
1515

1616
matrix:
1717
exclude:
18-
- env: GRAALVM_VERSION="1.0.0-rc14"
18+
- env: GRAALVM_VERSION="1.0.0-rc15"
1919
jdk: openjdk11
2020
- jdk: openjdk9
2121
os: linux

component/make_component.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ mkdir -p "$COMPONENT_DIR/META-INF"
2424
{
2525
echo "Bundle-Name: Simple Language";
2626
echo "Bundle-Symbolic-Name: com.oracle.truffle.sl";
27-
echo "Bundle-Version: 1.0.0-rc14";
28-
echo 'Bundle-RequireCapability: org.graalvm; filter:="(&(graalvm_version=1.0.0-rc14)(os_arch=amd64))"';
27+
echo "Bundle-Version: 1.0.0-rc15";
28+
echo 'Bundle-RequireCapability: org.graalvm; filter:="(&(graalvm_version=1.0.0-rc15)(os_arch=amd64))"';
2929
echo "x-GraalVM-Polyglot-Part: True"
3030
} > "$COMPONENT_DIR/META-INF/MANIFEST.MF"
3131

component/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.oracle</groupId>
55
<artifactId>simplelanguage-graalvm-component</artifactId>
6-
<version>1.0.0-rc14-SNAPSHOT</version>
6+
<version>1.0.0-rc15-SNAPSHOT</version>
77
<properties>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
99
<m2e.apt.activation>jdt_apt</m2e.apt.activation>

language/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.oracle</groupId>
66
<artifactId>simplelanguage-parent</artifactId>
7-
<version>1.0.0-rc14-SNAPSHOT</version>
7+
<version>1.0.0-rc15-SNAPSHOT</version>
88
</parent>
99
<artifactId>simplelanguage</artifactId>
1010
<build>

language/src/main/java/com/oracle/truffle/sl/SLException.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@
4242

4343
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4444
import com.oracle.truffle.api.TruffleException;
45+
import com.oracle.truffle.api.interop.InteropLibrary;
4546
import com.oracle.truffle.api.nodes.Node;
4647
import com.oracle.truffle.api.nodes.NodeInfo;
4748
import com.oracle.truffle.api.source.SourceSection;
48-
import com.oracle.truffle.sl.runtime.SLBigNumber;
4949
import com.oracle.truffle.sl.runtime.SLContext;
50-
import com.oracle.truffle.sl.runtime.SLFunction;
51-
import com.oracle.truffle.sl.runtime.SLNull;
5250

5351
/**
5452
* SL does not need a sophisticated error checking and reporting mechanism, so all unexpected
@@ -108,21 +106,18 @@ public static SLException typeError(Node operation, Object... values) {
108106
Object value = values[i];
109107
result.append(sep);
110108
sep = ", ";
111-
if (value instanceof Long || value instanceof SLBigNumber) {
112-
result.append("Number ").append(value);
113-
} else if (value instanceof Boolean) {
114-
result.append("Boolean ").append(value);
115-
} else if (value instanceof String) {
116-
result.append("String \"").append(value).append("\"");
117-
} else if (value instanceof SLFunction) {
118-
result.append("Function ").append(value);
119-
} else if (value == SLNull.SINGLETON) {
120-
result.append("NULL");
121-
} else if (value == null) {
122-
// value is not evaluated because of short circuit evaluation
123-
result.append("ANY");
109+
if (value == null || InteropLibrary.getFactory().getUncached().isNull(value)) {
110+
result.append(SLLanguage.toString(value));
124111
} else {
125-
result.append(value);
112+
result.append(SLLanguage.getMetaObject(value));
113+
result.append(" ");
114+
if (InteropLibrary.getFactory().getUncached().isString(value)) {
115+
result.append("\"");
116+
}
117+
result.append(SLLanguage.toString(value));
118+
if (InteropLibrary.getFactory().getUncached().isString(value)) {
119+
result.append("\"");
120+
}
126121
}
127122
}
128123
return new SLException(result.toString(), operation);

language/src/main/java/com/oracle/truffle/sl/SLFileDetector.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,16 +40,23 @@
4040
*/
4141
package com.oracle.truffle.sl;
4242

43+
import com.oracle.truffle.api.TruffleFile;
4344
import java.io.IOException;
44-
import java.nio.file.Path;
45-
import java.nio.file.spi.FileTypeDetector;
45+
import java.nio.charset.Charset;
46+
47+
public final class SLFileDetector implements TruffleFile.FileTypeDetector {
4648

47-
public final class SLFileDetector extends FileTypeDetector {
4849
@Override
49-
public String probeContentType(Path path) throws IOException {
50-
if (path.toString().endsWith(".sl")) {
50+
public String findMimeType(TruffleFile file) throws IOException {
51+
String name = file.getName();
52+
if (name != null && name.endsWith(".sl")) {
5153
return SLLanguage.MIME_TYPE;
5254
}
5355
return null;
5456
}
57+
58+
@Override
59+
public Charset findEncoding(TruffleFile file) throws IOException {
60+
return null;
61+
}
5562
}

language/src/main/java/com/oracle/truffle/sl/SLLanguage.java

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
4848
import java.util.NoSuchElementException;
4949

5050
import com.oracle.truffle.api.CallTarget;
51+
import com.oracle.truffle.api.CompilerDirectives;
5152
import com.oracle.truffle.api.RootCallTarget;
5253
import com.oracle.truffle.api.Scope;
5354
import com.oracle.truffle.api.Truffle;
@@ -58,7 +59,9 @@
5859
import com.oracle.truffle.api.frame.Frame;
5960
import com.oracle.truffle.api.instrumentation.ProvidedTags;
6061
import com.oracle.truffle.api.instrumentation.StandardTags;
62+
import com.oracle.truffle.api.interop.InteropLibrary;
6163
import com.oracle.truffle.api.interop.TruffleObject;
64+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
6265
import com.oracle.truffle.api.nodes.Node;
6366
import com.oracle.truffle.api.nodes.RootNode;
6467
import com.oracle.truffle.api.object.DynamicObject;
@@ -72,12 +75,6 @@
7275
import com.oracle.truffle.sl.builtins.SLStackTraceBuiltin;
7376
import com.oracle.truffle.sl.nodes.SLEvalRootNode;
7477
import com.oracle.truffle.sl.nodes.SLTypes;
75-
import com.oracle.truffle.sl.nodes.access.SLReadPropertyCacheNode;
76-
import com.oracle.truffle.sl.nodes.access.SLReadPropertyNode;
77-
import com.oracle.truffle.sl.nodes.access.SLWritePropertyCacheNode;
78-
import com.oracle.truffle.sl.nodes.access.SLWritePropertyNode;
79-
import com.oracle.truffle.sl.nodes.call.SLDispatchNode;
80-
import com.oracle.truffle.sl.nodes.call.SLInvokeNode;
8178
import com.oracle.truffle.sl.nodes.controlflow.SLBlockNode;
8279
import com.oracle.truffle.sl.nodes.controlflow.SLBreakNode;
8380
import com.oracle.truffle.sl.nodes.controlflow.SLContinueNode;
@@ -90,13 +87,16 @@
9087
import com.oracle.truffle.sl.nodes.expression.SLDivNode;
9188
import com.oracle.truffle.sl.nodes.expression.SLEqualNode;
9289
import com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode;
90+
import com.oracle.truffle.sl.nodes.expression.SLInvokeNode;
9391
import com.oracle.truffle.sl.nodes.expression.SLLessOrEqualNode;
9492
import com.oracle.truffle.sl.nodes.expression.SLLessThanNode;
9593
import com.oracle.truffle.sl.nodes.expression.SLLogicalAndNode;
9694
import com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode;
9795
import com.oracle.truffle.sl.nodes.expression.SLMulNode;
96+
import com.oracle.truffle.sl.nodes.expression.SLReadPropertyNode;
9897
import com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode;
9998
import com.oracle.truffle.sl.nodes.expression.SLSubNode;
99+
import com.oracle.truffle.sl.nodes.expression.SLWritePropertyNode;
100100
import com.oracle.truffle.sl.nodes.local.SLLexicalScope;
101101
import com.oracle.truffle.sl.nodes.local.SLReadLocalVariableNode;
102102
import com.oracle.truffle.sl.nodes.local.SLWriteLocalVariableNode;
@@ -190,7 +190,7 @@
190190
* variables.
191191
* </ul>
192192
*/
193-
@TruffleLanguage.Registration(id = SLLanguage.ID, name = "SL", defaultMimeType = SLLanguage.MIME_TYPE, characterMimeTypes = SLLanguage.MIME_TYPE, contextPolicy = ContextPolicy.SHARED)
193+
@TruffleLanguage.Registration(id = SLLanguage.ID, name = "SL", defaultMimeType = SLLanguage.MIME_TYPE, characterMimeTypes = SLLanguage.MIME_TYPE, contextPolicy = ContextPolicy.SHARED, fileTypeDetectors = SLFileDetector.class)
194194
@ProvidedTags({StandardTags.CallTag.class, StandardTags.StatementTag.class, StandardTags.RootTag.class, StandardTags.ExpressionTag.class, DebuggerTags.AlwaysHalt.class})
195195
public final class SLLanguage extends TruffleLanguage<SLContext> {
196196
public static volatile int counter;
@@ -267,57 +267,91 @@ protected Object findExportedSymbol(SLContext context, String globalName, boolea
267267

268268
@Override
269269
protected boolean isVisible(SLContext context, Object value) {
270-
return value != SLNull.SINGLETON;
270+
return !InteropLibrary.getFactory().getUncached(value).isNull(value);
271271
}
272272

273273
@Override
274274
protected boolean isObjectOfLanguage(Object object) {
275275
if (!(object instanceof TruffleObject)) {
276276
return false;
277+
} else if (object instanceof SLBigNumber || object instanceof SLFunction || object instanceof SLNull) {
278+
return true;
279+
} else if (SLContext.isSLObject(object)) {
280+
return true;
281+
} else {
282+
return false;
277283
}
278-
TruffleObject truffleObject = (TruffleObject) object;
279-
return truffleObject instanceof SLFunction || truffleObject instanceof SLBigNumber || SLContext.isSLObject(truffleObject);
280284
}
281285

282286
@Override
283287
protected String toString(SLContext context, Object value) {
284-
if (value == SLNull.SINGLETON) {
285-
return "NULL";
286-
}
287-
if (value instanceof SLBigNumber) {
288-
return super.toString(context, ((SLBigNumber) value).getValue());
289-
}
290-
if (value instanceof Long) {
291-
return Long.toString((Long) value);
288+
return toString(value);
289+
}
290+
291+
public static String toString(Object value) {
292+
try {
293+
if (value == null) {
294+
return "ANY";
295+
}
296+
InteropLibrary interop = InteropLibrary.getFactory().getUncached(value);
297+
if (interop.fitsInLong(value)) {
298+
return Long.toString(interop.asLong(value));
299+
} else if (interop.isBoolean(value)) {
300+
return Boolean.toString(interop.asBoolean(value));
301+
} else if (interop.isString(value)) {
302+
return interop.asString(value);
303+
} else if (interop.isNull(value)) {
304+
return "NULL";
305+
} else if (interop.isExecutable(value)) {
306+
if (value instanceof SLFunction) {
307+
return ((SLFunction) value).getName();
308+
} else {
309+
return "Function";
310+
}
311+
} else if (interop.hasMembers(value)) {
312+
return "Object";
313+
} else if (value instanceof SLBigNumber) {
314+
return value.toString();
315+
} else {
316+
return "Unsupported";
317+
}
318+
} catch (UnsupportedMessageException e) {
319+
CompilerDirectives.transferToInterpreter();
320+
throw new AssertionError();
292321
}
293-
return super.toString(context, value);
294322
}
295323

296324
@Override
297325
protected Object findMetaObject(SLContext context, Object value) {
298-
if (value instanceof Number || value instanceof SLBigNumber) {
299-
return "Number";
326+
return getMetaObject(value);
327+
}
328+
329+
public static String getMetaObject(Object value) {
330+
if (value == null) {
331+
return "ANY";
300332
}
301-
if (value instanceof Boolean) {
333+
InteropLibrary interop = InteropLibrary.getFactory().getUncached(value);
334+
if (interop.isNumber(value) || value instanceof SLBigNumber) {
335+
return "Number";
336+
} else if (interop.isBoolean(value)) {
302337
return "Boolean";
303-
}
304-
if (value instanceof String) {
338+
} else if (interop.isString(value)) {
305339
return "String";
306-
}
307-
if (value == SLNull.SINGLETON) {
308-
return "Null";
309-
}
310-
if (value instanceof SLFunction) {
340+
} else if (interop.isNull(value)) {
341+
return "NULL";
342+
} else if (interop.isExecutable(value)) {
311343
return "Function";
344+
} else if (interop.hasMembers(value)) {
345+
return "Object";
346+
} else {
347+
return "Unsupported";
312348
}
313-
return "Object";
314349
}
315350

316351
@Override
317352
protected SourceSection findSourceLocation(SLContext context, Object value) {
318353
if (value instanceof SLFunction) {
319-
SLFunction f = (SLFunction) value;
320-
return f.getCallTarget().getRootNode().getSourceSection();
354+
return ((SLFunction) value).getDeclaredLocation();
321355
}
322356
return null;
323357
}

language/src/main/java/com/oracle/truffle/sl/builtins/SLBuiltinNode.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.oracle.truffle.api.frame.VirtualFrame;
4747
import com.oracle.truffle.api.nodes.UnexpectedResultException;
4848
import com.oracle.truffle.sl.SLException;
49-
import com.oracle.truffle.sl.SLLanguage;
5049
import com.oracle.truffle.sl.nodes.SLExpressionNode;
5150
import com.oracle.truffle.sl.runtime.SLContext;
5251
import com.oracle.truffle.sl.runtime.SLFunctionRegistry;
@@ -63,10 +62,6 @@
6362
@GenerateNodeFactory
6463
public abstract class SLBuiltinNode extends SLExpressionNode {
6564

66-
public final SLContext getContext() {
67-
return getRootNode().getLanguage(SLLanguage.class).getContextReference().get();
68-
}
69-
7065
@Override
7166
public final Object executeGeneric(VirtualFrame frame) {
7267
try {

language/src/main/java/com/oracle/truffle/sl/builtins/SLDefineFunctionBuiltin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
package com.oracle.truffle.sl.builtins;
4242

4343
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
44+
import com.oracle.truffle.api.dsl.CachedContext;
4445
import com.oracle.truffle.api.dsl.Specialization;
4546
import com.oracle.truffle.api.nodes.NodeInfo;
4647
import com.oracle.truffle.api.source.Source;
4748
import com.oracle.truffle.sl.SLLanguage;
49+
import com.oracle.truffle.sl.runtime.SLContext;
4850

4951
/**
5052
* Builtin function to define (or redefine) functions. The provided source code is parsed the same
@@ -55,13 +57,13 @@ public abstract class SLDefineFunctionBuiltin extends SLBuiltinNode {
5557

5658
@TruffleBoundary
5759
@Specialization
58-
public String defineFunction(String code) {
60+
public String defineFunction(String code, @CachedContext(SLLanguage.class) SLContext context) {
5961
// @formatter:off
6062
Source source = Source.newBuilder(SLLanguage.ID, code, "[defineFunction]").
6163
build();
6264
// @formatter:on
6365
/* The same parsing code as for parsing the initial source. */
64-
getContext().getFunctionRegistry().register(source);
66+
context.getFunctionRegistry().register(source);
6567

6668
return code;
6769
}

language/src/main/java/com/oracle/truffle/sl/builtins/SLEvalBuiltin.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
import com.oracle.truffle.api.CallTarget;
4444
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4545
import com.oracle.truffle.api.dsl.Cached;
46+
import com.oracle.truffle.api.dsl.CachedContext;
4647
import com.oracle.truffle.api.dsl.Specialization;
4748
import com.oracle.truffle.api.nodes.DirectCallNode;
4849
import com.oracle.truffle.api.nodes.NodeInfo;
4950
import com.oracle.truffle.api.source.Source;
5051
import com.oracle.truffle.sl.SLLanguage;
52+
import com.oracle.truffle.sl.runtime.SLContext;
5153

5254
/**
5355
* Builtin function to evaluate source code in any supported language.
@@ -64,19 +66,20 @@ public abstract class SLEvalBuiltin extends SLBuiltinNode {
6466
public Object evalCached(String id, String code,
6567
@Cached("id") String cachedId,
6668
@Cached("code") String cachedCode,
67-
@Cached("create(parse(id, code))") DirectCallNode callNode) {
69+
@CachedContext(SLLanguage.class) SLContext context,
70+
@Cached("create(parse(id, code, context))") DirectCallNode callNode) {
6871
return callNode.call(new Object[]{});
6972
}
7073

7174
@TruffleBoundary
7275
@Specialization(replaces = "evalCached")
73-
public Object evalUncached(String id, String code) {
74-
return parse(id, code).call();
76+
public Object evalUncached(String id, String code, @CachedContext(SLLanguage.class) SLContext context) {
77+
return parse(id, code, context).call();
7578
}
7679

77-
protected CallTarget parse(String id, String code) {
80+
protected CallTarget parse(String id, String code, SLContext context) {
7881
final Source source = Source.newBuilder(id, code, "(eval)").build();
79-
return getContext().parse(source);
82+
return context.parse(source);
8083
}
8184

8285
/* Work around findbugs warning in generate code. */

0 commit comments

Comments
 (0)