Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
* Copyright (c) 2015, Regents of the University of California
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.oracle.graal.python;
import static com.oracle.graal.python.builtins.PythonOS.PLATFORM_WIN32;
import static com.oracle.graal.python.builtins.PythonOS.getPythonOS;
import static com.oracle.graal.python.nodes.StringLiterals.J_PY_EXTENSION;
import static com.oracle.graal.python.nodes.StringLiterals.T_PY_EXTENSION;
import static com.oracle.graal.python.nodes.truffle.TruffleStringMigrationHelpers.isJavaString;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.InvalidPathException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import org.graalvm.home.Version;
import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionKey;
import org.graalvm.options.OptionValues;
import com.oracle.graal.python.builtins.Python3Core;
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins;
import com.oracle.graal.python.builtins.objects.PNone;
import com.oracle.graal.python.builtins.objects.PNotImplemented;
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
import com.oracle.graal.python.builtins.objects.ellipsis.PEllipsis;
import com.oracle.graal.python.builtins.objects.frame.PFrame;
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
import com.oracle.graal.python.builtins.objects.function.PArguments;
import com.oracle.graal.python.builtins.objects.object.PythonObject;
import com.oracle.graal.python.builtins.objects.type.MroShape;
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
import com.oracle.graal.python.compiler.CodeUnit;
import com.oracle.graal.python.compiler.CompilationUnit;
import com.oracle.graal.python.compiler.Compiler;
import com.oracle.graal.python.compiler.RaisePythonExceptionErrorCallback;
import com.oracle.graal.python.nodes.HiddenAttributes;
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
import com.oracle.graal.python.nodes.call.CallNode;
import com.oracle.graal.python.nodes.call.GenericInvokeNode;
import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler;
import com.oracle.graal.python.nodes.frame.GetFrameLocalsNode;
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
import com.oracle.graal.python.pegparser.FutureFeature;
import com.oracle.graal.python.pegparser.InputType;
import com.oracle.graal.python.pegparser.NodeFactory;
import com.oracle.graal.python.pegparser.Parser;
import com.oracle.graal.python.pegparser.sst.ArgTy;
import com.oracle.graal.python.pegparser.sst.ArgumentsTy;
import com.oracle.graal.python.pegparser.sst.ModTy;
import com.oracle.graal.python.pegparser.sst.StmtTy;
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.PException;
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.graal.python.util.Function;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.graal.python.util.Supplier;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ContextThreadLocal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleLogger;
import com.oracle.truffle.api.debug.DebuggerTags;
import com.oracle.truffle.api.dsl.Idempotent;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.ProvidedTags;
import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.ExecutableNode;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.object.HiddenKey;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.Source.SourceBuilder;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.strings.TruffleString;
@TruffleLanguage.Registration(id = PythonLanguage.ID, //
name = PythonLanguage.NAME, //
implementationName = PythonLanguage.IMPLEMENTATION_NAME, //
version = PythonLanguage.VERSION, //
characterMimeTypes = {PythonLanguage.MIME_TYPE,
"text/x-python-\0\u0000-eval", "text/x-python-\0\u0000-compile", "text/x-python-\1\u0000-eval", "text/x-python-\1\u0000-compile", "text/x-python-\2\u0000-eval",
"text/x-python-\2\u0000-compile", "text/x-python-\0\u0100-eval", "text/x-python-\0\u0100-compile", "text/x-python-\1\u0100-eval", "text/x-python-\1\u0100-compile",
"text/x-python-\2\u0100-eval", "text/x-python-\2\u0100-compile", "text/x-python-\0\u0040-eval", "text/x-python-\0\u0040-compile", "text/x-python-\1\u0040-eval",
"text/x-python-\1\u0040-compile", "text/x-python-\2\u0040-eval", "text/x-python-\2\u0040-compile", "text/x-python-\0\u0140-eval", "text/x-python-\0\u0140-compile",
"text/x-python-\1\u0140-eval", "text/x-python-\1\u0140-compile", "text/x-python-\2\u0140-eval", "text/x-python-\2\u0140-compile"}, //
byteMimeTypes = {PythonLanguage.MIME_TYPE_BYTECODE}, //
defaultMimeType = PythonLanguage.MIME_TYPE, //
dependentLanguages = {"nfi", "llvm"}, //
interactive = true, internal = false, //
contextPolicy = TruffleLanguage.ContextPolicy.SHARED, //
fileTypeDetectors = PythonFileDetector.class, //
website = "https://www.graalvm.org/python/")
@ProvidedTags({
StandardTags.CallTag.class,
StandardTags.StatementTag.class,
StandardTags.RootTag.class,
StandardTags.RootBodyTag.class,
StandardTags.TryBlockTag.class,
StandardTags.ExpressionTag.class,
StandardTags.ReadVariableTag.class,
StandardTags.WriteVariableTag.class,
DebuggerTags.AlwaysHalt.class
})
public final class PythonLanguage extends TruffleLanguage {
public static final String J_GRAALPYTHON_ID = "graalpy";
public static final TruffleString T_GRAALPYTHON_ID = tsLiteral(J_GRAALPYTHON_ID);
public static final String ID = "python";
public static final String NAME = "Python";
public static final String IMPLEMENTATION_NAME = "GraalPy";
public static final int MAJOR = 3;
public static final int MINOR = 10;
public static final int MICRO = 8;
public static final int RELEASE_LEVEL_ALPHA = 0xA;
public static final int RELEASE_LEVEL_BETA = 0xB;
public static final int RELEASE_LEVEL_GAMMA = 0xC;
public static final int RELEASE_LEVEL_FINAL = 0xF;
public static final int RELEASE_LEVEL = RELEASE_LEVEL_ALPHA;
public static final TruffleString RELEASE_LEVEL_STRING;
public static final String FROZEN_FILENAME_PREFIX = " ::= "text/x-python-" "-" kind
// ::= "compile" | "eval"
// ::= "\0" | "\1" | "\2"
// ::= "\u0040" | "\u0100" | "\u0140" | "\u0000"
// where 0100 implies annotations, and 0040 implies barry_as_flufl
static final String MIME_PREFIX = MIME_TYPE + "-";
static final int OPT_FLAGS_LEN = 2; // 1 char is optlevel, 1 char is flags
static final String MIME_KIND_COMPILE = "compile";
static final String MIME_KIND_EVAL = "eval";
// Since flags are greater than the highest unicode codepoint, we shift them into more
// reasonable values in the mime type. 4 hex digits
static final int MIME_FLAG_SHIFTBY = 4 * 4;
// a dash follows after the opt flag pair
static final int MIME_KIND_START = MIME_PREFIX.length() + OPT_FLAGS_LEN + 1;
private static boolean mimeTypesComplete(ArrayList mimeJavaStrings) {
ArrayList mimeTypes = new ArrayList<>();
FutureFeature[] all = FutureFeature.values();
for (int flagset = 0; flagset < (1 << all.length); ++flagset) {
int flags = 0;
for (int i = 0; i < all.length; ++i) {
if ((flagset & (1 << i)) != 0) {
flags |= all[i].flagValue;
}
}
for (int opt = 0; opt <= 2; opt++) {
for (String typ : new String[]{MIME_KIND_EVAL, MIME_KIND_COMPILE}) {
mimeTypes.add(MIME_PREFIX + optFlagsToMime(opt, flags) + "-" + typ);
mimeJavaStrings.add(String.format("\"%s\\%d\\u%04x-%s\"", MIME_PREFIX, opt, flags >> MIME_FLAG_SHIFTBY, typ));
}
}
}
HashSet currentMimeTypes = new HashSet<>(List.of(PythonLanguage.class.getAnnotation(Registration.class).characterMimeTypes()));
return currentMimeTypes.containsAll(mimeTypes);
}
static {
ArrayList mimeJavaStrings = new ArrayList<>();
assert mimeTypesComplete(mimeJavaStrings) : "Expected all of {" + String.join(", ", mimeJavaStrings) + "} in the PythonLanguage characterMimeTypes";
}
public static final String MIME_TYPE_BYTECODE = "application/x-python-bytecode";
public static final TruffleString[] T_DEFAULT_PYTHON_EXTENSIONS = new TruffleString[]{T_PY_EXTENSION, tsLiteral(".pyc")};
private static final TruffleLogger LOGGER = TruffleLogger.getLogger(ID, PythonLanguage.class);
private static final LanguageReference REFERENCE = LanguageReference.create(PythonLanguage.class);
/**
* This assumption will be valid if no context set a trace or profile function at any point.
* Calling sys.settrace(None) or sys.setprofile(None) will not invalidate it
*/
public final Assumption noTracingOrProfilingAssumption = Assumption.create("No tracing function was set");
@CompilationFinal private boolean singleContext = true;
@Idempotent
public boolean isSingleContext() {
return singleContext;
}
/**
* This assumption will be valid if all contexts are single-threaded. Hence, it will be
* invalidated as soon as at least one context has been initialized for multi-threading.
*/
public final Assumption singleThreadedAssumption = Truffle.getRuntime().createAssumption("Only a single thread is active");
/**
* A thread-safe map to retrieve (and cache) singleton instances of call targets, e.g., for
* Arithmetic operations, wrappers, named cext functions, etc. This reduces the number of call
* targets and allows AST sharing across contexts. The key in this map is either a single value
* or a list of values.
*/
private final ConcurrentHashMap