Skip to content

Commit 8ce3de7

Browse files
committed
Formatting, adding license and hacking calling RegexEngine.
1 parent 12d584f commit 8ce3de7

File tree

7 files changed

+88
-45
lines changed

7 files changed

+88
-45
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public abstract static class TruffleImportStar extends PythonBuiltinNode {
343343
public Object run(String path, String modulename) {
344344
return run(path, getCore().lookupBuiltinModule(modulename));
345345
}
346-
346+
347347
@Specialization
348348
public Object run(PString path, String modulename) {
349349
return run(path.getValue(), getCore().lookupBuiltinModule(modulename));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ Object call(TruffleObject callable, Object[] arguments,
262262
@Cached("create()") BranchProfile typeError,
263263
@Cached("createExecute()") Node invokeNode) {
264264
try {
265+
// TODO This is a hack. The right solution would be to fix it
266+
// in com.oracle.truffle.regex.RegexEngine.RegexEngineMessageResolution.RegexEngineExecuteNode
267+
// where is only check whether the argumen is instance of String.
268+
// PString should be there unboxed.
269+
for (int i = 0; i < arguments.length; i++) {
270+
if (arguments[i] instanceof PString) {
271+
arguments[i] = ((PString) arguments[i]).getValue();
272+
}
273+
}
265274
return ForeignAccess.sendExecute(invokeNode, callable, arguments);
266275
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
267276
typeError.enter();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/LazyString.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
11
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
2+
* Copyright (c) 2017, 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.
540
*/
641
package com.oracle.graal.python.builtins.objects.str;
742

@@ -12,10 +47,10 @@
1247
import com.oracle.truffle.api.profiles.ConditionProfile;
1348

1449
public class LazyString implements CharSequence {
15-
50+
1651
protected static int MinLazyStringLength = PythonOptions.getMinLazyStringLength();
1752
protected static boolean UseLazyStrings = PythonOptions.useLazyString();
18-
53+
1954
public static int length(CharSequence cs, ConditionProfile profile1, ConditionProfile profile2) {
2055
if (profile1.profile(cs instanceof String)) {
2156
return ((String) cs).length();
@@ -24,12 +59,12 @@ public static int length(CharSequence cs, ConditionProfile profile1, ConditionPr
2459
}
2560
return lengthIntl(cs);
2661
}
27-
62+
2863
@TruffleBoundary
2964
private static int lengthIntl(CharSequence cs) {
3065
return cs.length();
3166
}
32-
67+
3368
@TruffleBoundary
3469
public static CharSequence create(CharSequence left, CharSequence right) {
3570
assert PGuards.isString(left);
@@ -92,11 +127,11 @@ public static CharSequence createCheckedShort(CharSequence left, CharSequence ri
92127
}
93128
return new LazyString(left, right, length);
94129
}
95-
130+
96131
private CharSequence left;
97132
private CharSequence right;
98133
private final int length;
99-
134+
100135
private LazyString(CharSequence left, CharSequence right, int length) {
101136
assert left.length() > 0 && right.length() > 0 && length == left.length() + right.length();
102137
this.left = left;
@@ -107,12 +142,12 @@ private LazyString(CharSequence left, CharSequence right, int length) {
107142
private LazyString(CharSequence left, CharSequence right) {
108143
this(left, right, left.length() + right.length());
109144
}
110-
145+
111146
@Override
112147
public int length() {
113148
return length;
114149
}
115-
150+
116151
@Override
117152
public String toString() {
118153
if (!isFlat()) {
@@ -211,5 +246,5 @@ public boolean endsWith(String prefix) {
211246
@TruffleBoundary
212247
public byte[] getBytes() {
213248
return toString().getBytes();
214-
}
249+
}
215250
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/PString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public PString(PythonClass clazz, CharSequence value) {
4343
public String getValue() {
4444
return value.toString();
4545
}
46-
46+
4747
public CharSequence getCharSequence() {
4848
return value;
4949
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,68 +313,68 @@ PNotImplemented doGeneric(Object self, Object other) {
313313
@Builtin(name = __ADD__, fixedNumOfArguments = 2)
314314
@GenerateNodeFactory
315315
public abstract static class AddNode extends PythonBinaryBuiltinNode {
316-
316+
317317
protected final ConditionProfile leftProfile1 = ConditionProfile.createBinaryProfile();
318318
protected final ConditionProfile leftProfile2 = ConditionProfile.createBinaryProfile();
319319
protected final ConditionProfile rightProfile1 = ConditionProfile.createBinaryProfile();
320320
protected final ConditionProfile rightProfile2 = ConditionProfile.createBinaryProfile();
321-
322-
@Specialization (guards="!concatGuard(self, other)")
321+
322+
@Specialization(guards = "!concatGuard(self, other)")
323323
String doSSSimple(String self, String other) {
324324
if (LazyString.length(self, leftProfile1, leftProfile2) == 0) {
325325
return other;
326326
}
327327
return self;
328328
}
329-
330-
@Specialization (guards="!concatGuard(self, other.getCharSequence())")
329+
330+
@Specialization(guards = "!concatGuard(self, other.getCharSequence())")
331331
Object doSSSimple(String self, PString other) {
332332
if (LazyString.length(self, leftProfile1, leftProfile2) == 0) {
333333
return other;
334334
}
335335
return self;
336336
}
337-
338-
@Specialization (guards="!concatGuard(self.getCharSequence(), other)")
337+
338+
@Specialization(guards = "!concatGuard(self.getCharSequence(), other)")
339339
Object doSSSimple(PString self, String other) {
340340
if (LazyString.length(self.getCharSequence(), leftProfile1, leftProfile2) == 0) {
341341
return other;
342342
}
343343
return self;
344344
}
345-
346-
@Specialization (guards="!concatGuard(self.getCharSequence(), self.getCharSequence())")
345+
346+
@Specialization(guards = "!concatGuard(self.getCharSequence(), self.getCharSequence())")
347347
PString doSSSimple(PString self, PString other) {
348348
if (LazyString.length(self.getCharSequence(), leftProfile1, leftProfile2) == 0) {
349349
return other;
350350
}
351351
return self;
352352
}
353-
354-
@Specialization (guards="concatGuard(self.getCharSequence(), other)")
353+
354+
@Specialization(guards = "concatGuard(self.getCharSequence(), other)")
355355
Object doSS(PString self, String other,
356-
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
356+
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
357357
return doIt(self.getCharSequence(), other, shortStringAppend);
358358
}
359-
360-
@Specialization (guards="concatGuard(self, other)")
359+
360+
@Specialization(guards = "concatGuard(self, other)")
361361
Object doSS(String self, String other,
362-
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
362+
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
363363
return doIt(self, other, shortStringAppend);
364364
}
365-
366-
@Specialization (guards="concatGuard(self, other.getCharSequence())")
365+
366+
@Specialization(guards = "concatGuard(self, other.getCharSequence())")
367367
Object doSS(String self, PString other,
368-
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
368+
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
369369
return doIt(self, other.getCharSequence(), shortStringAppend);
370370
}
371-
372-
@Specialization (guards="concatGuard(self.getCharSequence(), other.getCharSequence())")
371+
372+
@Specialization(guards = "concatGuard(self.getCharSequence(), other.getCharSequence())")
373373
Object doSS(PString self, PString other,
374-
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
374+
@Cached("createBinaryProfile()") ConditionProfile shortStringAppend) {
375375
return doIt(self.getCharSequence(), other.getCharSequence(), shortStringAppend);
376376
}
377-
377+
378378
private Object doIt(CharSequence left, CharSequence right, ConditionProfile shortStringAppend) {
379379
if (LazyString.UseLazyStrings) {
380380
int leftLength = LazyString.length(left, leftProfile1, leftProfile2);
@@ -390,7 +390,7 @@ private Object doIt(CharSequence left, CharSequence right, ConditionProfile shor
390390
}
391391
return stringConcat(left, right);
392392
}
393-
393+
394394
@TruffleBoundary
395395
private static String stringConcat(CharSequence left, CharSequence right) {
396396
return left.toString() + right.toString();
@@ -400,7 +400,7 @@ private static String stringConcat(CharSequence left, CharSequence right) {
400400
String doSO(@SuppressWarnings("unused") String self, Object other) {
401401
throw raise(TypeError, "Can't convert '%p' object to str implicitly", other);
402402
}
403-
403+
404404
@Specialization(guards = "!isString(other)")
405405
String doSO(@SuppressWarnings("unused") PString self, Object other) {
406406
throw raise(TypeError, "Can't convert '%p' object to str implicitly", other);
@@ -411,7 +411,7 @@ String doSO(@SuppressWarnings("unused") PString self, Object other) {
411411
PNotImplemented doGeneric(Object self, Object other) {
412412
return PNotImplemented.NOT_IMPLEMENTED;
413413
}
414-
414+
415415
protected boolean concatGuard(CharSequence left, CharSequence right) {
416416
int leftLength = LazyString.length(left, leftProfile1, leftProfile2);
417417
int rightLength = LazyString.length(right, rightProfile1, rightProfile2);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ private PythonOptions() {
9090

9191
@Option(category = OptionCategory.DEBUG, help = "Turn on verbose mode") //
9292
public static final OptionKey<Boolean> VerboseFlag = new OptionKey<>(false);
93-
93+
9494
@Option(category = OptionCategory.EXPERT, help = "Switch on/off using lazy strings for performance reasons. Default true.") //
9595
public static final OptionKey<Boolean> LazyStrings = new OptionKey<>(true);
96-
96+
9797
@Option(category = OptionCategory.DEBUG, help = "Minimal size of string, when lazy strings are used. Default 20") //
9898
public static final OptionKey<Integer> MinLazyStringLength = new OptionKey<>(20);
99-
10099

101100
public static OptionDescriptors createDescriptors() {
102101
return new PythonOptionsOptionDescriptors();
@@ -125,11 +124,11 @@ public static int getCallSiteInlineCacheMaxDepth() {
125124
public static int getVariableArgumentInlineCacheLimit() {
126125
return getOption(PythonLanguage.getContextRef().get(), VariableArgumentInlineCacheLimit);
127126
}
128-
127+
129128
public static boolean useLazyString() {
130129
return getOption(PythonLanguage.getContextRef().get(), LazyStrings);
131130
}
132-
131+
133132
public static int getMinLazyStringLength() {
134133
return getOption(PythonLanguage.getContextRef().get(), MinLazyStringLength);
135134
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public PString createString(String string) {
248248
public PString createString(PythonClass cls, String string) {
249249
return trace(new PString(cls, string));
250250
}
251-
251+
252252
public PString createString(CharSequence string) {
253253
return trace(new PString(lookupClass(PythonBuiltinClassType.PString), string));
254254
}

0 commit comments

Comments
 (0)