From 3a811c26c3a511735aa9590ebdc29e7c76d7aec5 Mon Sep 17 00:00:00 2001 From: Kevin Modzelewski Date: Mon, 2 Nov 2015 14:32:02 -0800 Subject: [PATCH 1/4] Add documentation about some structs/classes --- src/codegen/irgen/hooks.cpp | 4 +- src/core/stats.h | 31 ++++++++ src/core/threading.h | 1 + src/core/types.h | 154 ++++++++++++++++++++++++++++-------- src/runtime/types.h | 15 +++- 5 files changed, 167 insertions(+), 38 deletions(-) diff --git a/src/codegen/irgen/hooks.cpp b/src/codegen/irgen/hooks.cpp index 05b5cf454..267e837e0 100644 --- a/src/codegen/irgen/hooks.cpp +++ b/src/codegen/irgen/hooks.cpp @@ -772,11 +772,11 @@ CompiledFunction::CompiledFunction(llvm::Function* func, FunctionSpecialization* ExceptionStyle exception_style, const OSREntryDescriptor* entry_descriptor) : clfunc(NULL), func(func), + effort(effort), + exception_style(exception_style), spec(spec), entry_descriptor(entry_descriptor), code(code), - effort(effort), - exception_style(exception_style), times_called(0), times_speculation_failed(0), location_map(nullptr) { diff --git a/src/core/stats.h b/src/core/stats.h index d82059a11..6eadd59a8 100644 --- a/src/core/stats.h +++ b/src/core/stats.h @@ -26,8 +26,10 @@ namespace pyston { +// Set this to 1 to disable all stats-related operations. Shouldn't usually be necessary. #define DISABLE_STATS 0 +// Enable certain expensive stat collections: #define STAT_ALLOCATIONS (0 && !DISABLE_STATS) #define STAT_ALLOCATION_TYPES (0 && !DISABLE_STATS) #define STAT_CALLATTR_DESCR_ABORTS (0 && !DISABLE_STATS) @@ -53,6 +55,8 @@ namespace pyston { #define STAT_TIMER_NAME(id) _st##id #if !DISABLE_STATS +// The class that stores and manages stats collection. For normal stats collections purposes, +// you shouldn't have to use this class, and will usually want to use StatCounter instead. struct Stats { private: static std::unordered_map* names; @@ -75,6 +79,22 @@ struct Stats { static void endOfInit(); }; +// A helper class for efficient stats collections. Typical usage: +// +// static StatCounter my_stat_counter("my_informative_stat_name"); +// void myFunction() { +// my_stat_counter.log(); +// } +// +// The current convention for stat names is underscore_case, such as `num_cxa_throw`, +// though at some point we'd like to move to a period-delimited convention. +// (Run `./pyston -s` to see the list of current stats we log.) +// For single stats, usually `num_foo` is a decent name. If there are many stats in a +// single category, you can drop the `num_`. +// If a stat name is a prefix of another, the event it is counting should be a superset. +// For instance, `ic_rewrites` counts a superset of the events that `ic_rewrites_aborted` +// counts, which itself is a superset of the events that `ic_rewrites_aborted_assemblyfail` +// counts. struct StatCounter { private: uint64_t* counter; @@ -85,6 +105,11 @@ struct StatCounter { void log(uint64_t count = 1) { *counter += count; } }; +// Similar to StatCounter, but should be allocated as: +// +// static thread_local StatPerThreadCounter my_stat_counter("cool_stat_name"); +// +// This will automatically add the thread id to the stat name. struct StatPerThreadCounter { private: uint64_t* counter = 0; @@ -117,6 +142,9 @@ struct StatPerThreadCounter { #endif #if STAT_TIMERS + +// StatTimers are for a specific type of profiling investigation. Until we make this more usable, +// there probably shouldn't be more changes or uses of this class. class StatTimer { private: static __thread StatTimer* stack; @@ -226,6 +254,8 @@ class StatTimer { static void assertActive() { ASSERT(stack && !stack->isPaused(), ""); } }; + +// Helper class around a StatTimer class ScopedStatTimer { private: StatTimer timer; @@ -237,6 +267,7 @@ class ScopedStatTimer { } ~ScopedStatTimer() { timer.popNonTopLevel(); } }; + #else struct StatTimer { StatTimer(uint64_t*) {} diff --git a/src/core/threading.h b/src/core/threading.h index f422f5f80..6ccab9d01 100644 --- a/src/core/threading.h +++ b/src/core/threading.h @@ -138,6 +138,7 @@ void demoteGL(); +// Helper macro for creating a RAII wrapper around two functions. #define MAKE_REGION(name, start, end) \ class name { \ public: \ diff --git a/src/core/types.h b/src/core/types.h index f81f77b4a..198528cdf 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -41,16 +41,35 @@ namespace pyston { using gc::GCVisitor; +// The "effort" which we will put into compiling a Python function. This applies to the LLVM tier, +// where it can affect things such as the amount of type analysis we do, whether or not to run expensive +// LLVM optimization passes, etc. +// Currently (Nov '15) these are mostly unused, and we only use MAXIMAL. There used to be two other levels +// as well but we stopped using them too. enum class EffortLevel { MODERATE = 2, MAXIMAL = 3, }; +// Pyston supports two ways of implementing Python exceptions: by using return-code-based exceptions ("CAPI" +// style since this is what the CPython C API uses), or our custom C++-based exceptions ("CXX" style). CAPI +// is faster when an exception is thrown, and CXX is faster when an exception is not thrown, so depending on +// the situation it can be beneficial to use one or the other. The JIT will use some light profiling to +// determine when to emit code in one style or the other. +// Many runtime functions support being called in either style, and can get passed one of these enum values +// as a template parameter to switch between them. enum ExceptionStyle { CAPI, CXX, }; +// Much of our runtime supports "rewriting" aka tracing itself. Our tracing JIT requires support from the +// functions to be traced, so our runtime functions will contain checks to see if the tracer is currently +// activated, and then will do additional work. +// When the tracer isn't active, these extra "is the tracer active" checks can become expensive. So when +// the caller knows that the tracer is not active, they can call a special version of the function where +// all of the "is the tracer active" checks are hardcoded to false. This is possible by passing "NOT_REWRITEABLE" +// as a template argument to the called function. enum Rewritable { NOT_REWRITABLE, REWRITABLE, @@ -88,6 +107,8 @@ struct ExceptionSwitchableFunction : public ExceptionSwitchable template R call(Args... args) noexcept(S == CAPI) { return this->template get()(args...); } }; +// CompilerType (and a specific kind of CompilerType, the ConcreteCompilerType) are the way that the LLVM JIT represents +// type information. See src/codegen/compvars.h for more information. class CompilerType; template class ValuedCompilerType; typedef ValuedCompilerType ConcreteCompilerType; @@ -98,6 +119,8 @@ extern ConcreteCompilerType* UNBOXED_INT, *BOXED_INT, *LONG, *UNBOXED_FLOAT, *BO *BOXED_COMPLEX, *FRAME_INFO; extern CompilerType* UNDEF, *INT, *FLOAT, *UNBOXED_SLICE; +// CompilerVariables are the way that the LLVM JIT tracks variables, which are a CompilerType combined with some sort +// of value (the type of value depends on the type of CompilerType). class CompilerVariable; template class ValuedCompilerVariable; typedef ValuedCompilerVariable ConcreteCompilerVariable; @@ -125,6 +148,10 @@ class ScopingAnalysis; class CLFunction; class OSREntryDescriptor; +// Pyston's internal calling convention is to pass around arguments in as unprocessed a form as possible, +// which lets the callee decide how they would like to receive their arguments. In addition to the actual +// argument parameters, functions will often receive an ArgPassSpec struct which specifies the meaning of +// the raw pointer values, such as whether they were positional arguments or keyword arguments, etc. struct ArgPassSpec { bool has_starargs : 1; bool has_kwargs : 1; @@ -196,7 +223,8 @@ struct ParamNames { ParamNames() : takes_param_names(false), vararg_name(NULL), kwarg_name(NULL) {} }; -// Probably overkill to copy this from ArgPassSpec +// Similar to ArgPassSpec, this struct is how functions specify what their parameter signature is. +// (Probably overkill to copy this from ArgPassSpec) struct ParamReceiveSpec { bool takes_varargs : 1; bool takes_kwargs : 1; @@ -228,6 +256,14 @@ struct ParamReceiveSpec { int kwargsIndex() { return num_args + (takes_varargs ? 1 : 0); } }; +// Inline-caches contain fastpath code, and need to know that their fastpath is valid for a particular set +// of arguments. This is usually done with guards: conditional checks that will avoid the fastpath if the +// assumptions failed. This can also be done using invalidation: no checks will be emitted into the generated +// assembly, but instead if the assumption is invalidated, the IC will get erased. +// This is useful for cases where we expect the assumption to overwhelmingly be true, or cases where it +// is not possible to use guards. It is more difficult to use invalidation because it is much easier to +// get it wrong by forgetting to invalidate in all places that are necessary (whereas it is easier to be +// conservative about guarding). class ICInvalidator { private: int64_t cur_version; @@ -259,17 +295,31 @@ class ICInfo; class LocationMap; class JitCodeBlock; +// A specific compilation of a CLFunction. Usually these will be created by the LLVM JIT, which will take a CLFunction +// and some compilation settings, and produce a CompiledFunction +// CompiledFunctions can also be created from raw function pointers, using boxRTFunction. +// A single CLFunction can have multiple CompiledFunctions associated with it, if they have different settings. +// Typically, this will happen due to specialization on the argument types (ie we will generate a separate versions +// of a function that are faster but only apply to specific argument types). struct CompiledFunction { private: public: CLFunction* clfunc; llvm::Function* func; // the llvm IR object + + // Some compilation settings: + EffortLevel effort; + ExceptionStyle exception_style; FunctionSpecialization* spec; + // If this compilation was due to an OSR, `entry_descriptor` contains metadata about the OSR. + // Otherwise this field is NULL. const OSREntryDescriptor* entry_descriptor; // Pointers that were written directly into the code, which the GC should be aware of. std::vector pointers_in_code; + // The function pointer to the generated code. For convenience, it can be accessed + // as one of many different types. union { Box* (*call)(Box*, Box*, Box*, Box**); Box* (*closure_call)(BoxedClosure*, Box*, Box*, Box*, Box**); @@ -283,14 +333,20 @@ struct CompiledFunction { }; int code_size; - EffortLevel effort; - ExceptionStyle exception_style; - + // Some simple profiling stats: int64_t times_called, times_speculation_failed; + + // A list of ICs that depend on various properties of this CompiledFunction. + // These will get invalidated in situations such as: we compiled a higher-effort version of + // this function so we want to get old callsites to use the newer and better version, or + // we noticed that we compiled the function with speculations that kept on failing and + // we want to generate a more conservative version. ICInvalidator dependent_callsites; + // Metadata that lets us find local variables from the C stack fram. LocationMap* location_map; + // List of metadata objects for ICs inside this compilation std::vector ics; CompiledFunction(llvm::Function* func, FunctionSpecialization* spec, void* code, EffortLevel effort, @@ -316,9 +372,12 @@ class BoxedModule; class ScopeInfo; class InternedStringPool; class LivenessAnalysis; + +// Data about a single textual function definition. class SourceInfo { private: BoxedString* fn; // equivalent of code.co_filename + public: BoxedModule* parent_module; ScopingAnalysis* scoping; @@ -354,16 +413,24 @@ class SourceInfo { typedef std::vector FunctionList; struct CallRewriteArgs; + +// A BoxedCode is our implementation of the Python "code" object (such as function.func_code). +// It is implemented as a wrapper around a CLFunction. class BoxedCode; + class CLFunction { +private: + // The Python-level "code" object corresponding to this CLFunction. We store it in the CLFunction + // so that multiple attempts to translate from CLFunction->BoxedCode will always return the same + // BoxedCode object. + // Callers should use getCode() BoxedCode* code_obj; public: int num_args; bool takes_varargs, takes_kwargs; - //ParamReceiveSpec paramspec; - std::unique_ptr source; + std::unique_ptr source; // source can be NULL for functions defined in the C/C++ runtime ParamNames param_names; FunctionList @@ -371,6 +438,7 @@ class CLFunction { CompiledFunction* always_use_version; // if this version is set, always use it (for unboxed cases) std::unordered_map osr_versions; + // Profiling counter: int propagated_cxx_exceptions = 0; // For use by the interpreter/baseline jit: @@ -426,6 +494,9 @@ typedef int64_t i64; const char* getNameOfClass(BoxedClass* cls); std::string getFullNameOfClass(BoxedClass* cls); +std::string getFullTypeName(Box* o); +const char* getTypeName(Box* b); + class Rewriter; class RewriterVar; @@ -491,6 +562,8 @@ inline void internStringMortalInplace(BoxedString*& s) noexcept { PyString_InternInPlace((PyObject**)&s); } +// The data structure definition for hidden-class-based attributes. Consists of a +// pointer to the hidden class object, and a pointer to a variable-size attributes array. struct HCAttrs { public: struct AttrList { @@ -507,12 +580,13 @@ static_assert(sizeof(HCAttrs) == sizeof(struct _hcattrs), ""); class BoxedDict; class BoxedString; -// In Pyston, this is the same type as CPython's PyObject (they are interchangeable, but we -// use Box in Pyston wherever possible as a convention). +// "Box" is the base class of any C++ type that implements a Python type. For example, +// BoxedString is the data structure that implements Python's str type, and BoxedString +// inherits from Box. // -// Other types on Pyston inherit from Box (e.g. BoxedString is a Box). Why is this class not -// polymorphic? Because of C extension support -- having virtual methods would change the layout -// of the object. +// This is the same as CPython's PyObject (and they are interchangeable), with the difference +// since we are in C++ (whereas CPython is in C) we can use C++ inheritance to implement +// Python inheritance, and avoid the raw pointer casts that CPython needs everywhere. class Box { private: BoxedDict** getDictPtr(); @@ -573,6 +647,12 @@ static_assert(offsetof(Box, cls) == offsetof(struct _object, ob_type), ""); // Our default for tp_alloc: extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) noexcept; +// These are some macros for tying the C++ type hiercharchy to the Pyston type hiercharchy. +// Classes that inherit from Box have a special operator new() that takes a class object (as +// a BoxedClass*) since the class is necessary for object allocation. +// To enable expressions such as `new BoxedString()` instead of having to type +// `new (str_cls) BoxedString()` everywhere, we need to tell C++ what the default class is. +// We can do this by putting `DEFAULT_CLASS(str_cls);` anywhere in the definition of BoxedString. #define DEFAULT_CLASS(default_cls) \ void* operator new(size_t size, BoxedClass * cls) __attribute__((visibility("default"))) { \ assert(cls->tp_itemsize == 0); \ @@ -615,6 +695,11 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) #endif +// In the simple cases, we can inline the fast paths of the following methods and improve allocation speed quite a bit: +// - Box::operator new +// - cls->tp_alloc +// - PystonType_GenericAlloc +// - PyObject_Init // The restrictions on when you can use the SIMPLE (ie fast) variant are encoded as // asserts in the 1-arg operator new function: #define DEFAULT_CLASS_SIMPLE(default_cls) \ @@ -623,12 +708,6 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) } \ void* operator new(size_t size) __attribute__((visibility("default"))) { \ ALLOC_STATS(default_cls); \ - /* In the simple cases, we can inline the following methods and simplify things a lot: \ - * - Box::operator new \ - * - cls->tp_alloc \ - * - PystonType_GenericAlloc \ - * - PyObject_Init \ - */ \ assert(default_cls->tp_alloc == PystonType_GenericAlloc); \ assert(default_cls->tp_itemsize == 0); \ assert(default_cls->tp_basicsize == size); \ @@ -650,6 +729,22 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) /* TODO: there should be a way to not have to do this nested inlining by hand */ \ } +// This corresponds to CPython's PyVarObject, for objects with a variable number of "items" that are stored inline. +// For example, strings and tuples store their data in line in the main object allocation, so are BoxVars. Lists, +// since they have a changeable size, store their elements in a separate array, and their main object is a fixed +// size and so aren't BoxVar. +class BoxVar : public Box { +public: + // This field gets initialized in operator new. + Py_ssize_t ob_size; + + BoxVar() {} + + void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))); +}; +static_assert(offsetof(BoxVar, ob_size) == offsetof(struct _varobject, ob_size), ""); + +// This is the variant of DEFAULT_CLASS that applies to BoxVar objects. #define DEFAULT_CLASS_VAR(default_cls, itemsize) \ static_assert(itemsize > 0, ""); \ /* asserts that the class in question is a subclass of BoxVar */ \ @@ -693,21 +788,6 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) return rtn; \ } -// CPython C API compatibility class: -class BoxVar : public Box { -public: - // This field gets initialized in operator new. - Py_ssize_t ob_size; - - BoxVar() {} - - void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))); -}; -static_assert(offsetof(BoxVar, ob_size) == offsetof(struct _varobject, ob_size), ""); - -std::string getFullTypeName(Box* o); -const char* getTypeName(Box* b); - class BoxedClass; // TODO these shouldn't be here @@ -733,6 +813,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR void raiseSyntaxErrorHelper(llvm::StringRef file, llvm::StringRef func, AST* node_at, const char* msg, ...) __attribute__((format(printf, 4, 5))); +// A data structure used for storing information for tracebacks. struct LineInfo { public: int line, column; @@ -742,6 +823,7 @@ struct LineInfo { : line(line), column(column), file(file), func(func) {} }; +// A data structure to simplify passing around all the data about a thrown exception. struct ExcInfo { Box* type, *value, *traceback; @@ -750,7 +832,10 @@ struct ExcInfo { void printExcAndTraceback() const; }; +// Our object that implements Python's "frame" object: class BoxedFrame; + +// Our internal data structure for storing certain information about a stack frame. struct FrameInfo { // Note(kmod): we have a number of fields here that all have independent // initialization rules. We could potentially save time on every function-entry @@ -779,6 +864,7 @@ struct FrameInfo { void gcVisit(GCVisitor* visitor); }; +// callattr() takes a number of flags and arguments, and for performance we pack them into a single register: struct CallattrFlags { bool cls_only : 1; bool null_on_nonexistent : 1; @@ -788,7 +874,7 @@ struct CallattrFlags { }; static_assert(sizeof(CallattrFlags) == sizeof(uint64_t), ""); -// A C++-style way of handling a PyArena* +// A C++-style RAII way of handling a PyArena* class ArenaWrapper { private: PyArena* arena; @@ -803,6 +889,7 @@ class ArenaWrapper { operator PyArena*() const { return arena; } }; +// A C++-style RAII way of handling a FILE* class FileHandle { private: FILE* file; @@ -841,6 +928,7 @@ int binarySearch(T needle, RandomAccessIterator start, RandomAccessIterator end, } } +// We need to override these functions so that our GC can know about them. namespace std { template <> std::pair get_temporary_buffer(std::ptrdiff_t count) noexcept; template <> void return_temporary_buffer(pyston::Box** p); diff --git a/src/runtime/types.h b/src/runtime/types.h index d96576822..f1e4e73eb 100644 --- a/src/runtime/types.h +++ b/src/runtime/types.h @@ -307,6 +307,10 @@ class BoxedClass : public BoxVar { friend void setupThread(); }; +// Corresponds to PyHeapTypeObject. Very similar to BoxedClass, but allocates some extra space for +// structures that otherwise might get allocated statically. For instance, tp_as_number for builtin +// types will usually point to a `static PyNumberMethods` object, but for a heap-allocated class it +// will point to `this->as_number`. class BoxedHeapClass : public BoxedClass { public: PyNumberMethods as_number; @@ -336,6 +340,7 @@ class BoxedHeapClass : public BoxedClass { friend void setupThread(); }; +// Assert that our data structures have the same layout as the C API ones with which they need to be interchangeable. static_assert(sizeof(pyston::Box) == sizeof(struct _object), ""); static_assert(offsetof(pyston::Box, cls) == offsetof(struct _object, ob_type), ""); @@ -675,7 +680,7 @@ class BoxedTuple : public BoxVar { // CPython declares ob_item (their version of elts) to have 1 element. We want to // copy that behavior so that the sizes of the objects match, but we want to also // have a zero-length array in there since we have some extra compiler warnings turned - // on. _elts[1] will throw an error, but elts[1] will not. + // on: _elts[1] will throw an error, but elts[1] will not. union { Box* elts[0]; Box* _elts[1]; @@ -687,6 +692,7 @@ static_assert(offsetof(BoxedTuple, elts) == offsetof(PyTupleObject, ob_item), "" extern BoxedString* characters[UCHAR_MAX + 1]; +// C++ functor objects that implement Python semantics. struct PyHasher { size_t operator()(Box* b) const { if (b->cls == str_cls) { @@ -719,8 +725,11 @@ struct PyLt { // llvm::DenseMap doesn't store the original hash values, choosing to instead // check for equality more often. This is probably a good tradeoff when the keys -// are pointers and comparison is cheap, but we want to make sure that keys with -// different hash values don't get compared. +// are pointers and comparison is cheap, but when the equality function is user-defined +// it can be much faster to avoid Python function invocations by doing some integer +// comparisons. +// This also has a user-visible behavior difference of how many times the hash function +// and equality functions get called. struct BoxAndHash { Box* value; size_t hash; From 6a880f448052988bb079d355b6c772d4b1a9818b Mon Sep 17 00:00:00 2001 From: Kevin Modzelewski Date: Mon, 2 Nov 2015 14:36:12 -0800 Subject: [PATCH 2/4] Move some functions to where I think they make more sense --- src/runtime/classobj.cpp | 1 + src/runtime/objmodel.cpp | 10 ---------- src/runtime/objmodel.h | 6 ------ src/runtime/types.cpp | 10 ++++++++++ src/runtime/types.h | 4 ++++ 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/runtime/classobj.cpp b/src/runtime/classobj.cpp index 6bb42491e..14a6a5d63 100644 --- a/src/runtime/classobj.cpp +++ b/src/runtime/classobj.cpp @@ -18,6 +18,7 @@ #include "capi/typeobject.h" #include "capi/types.h" +#include "codegen/unwinding.h" #include "core/types.h" #include "runtime/objmodel.h" #include "runtime/rewrite_args.h" diff --git a/src/runtime/objmodel.cpp b/src/runtime/objmodel.cpp index 3e9bfd764..99c1b97c6 100644 --- a/src/runtime/objmodel.cpp +++ b/src/runtime/objmodel.cpp @@ -337,10 +337,6 @@ extern "C" Box** unpackIntoArray(Box* obj, int64_t expected_size) { return &elts[0]; } -void dealloc_null(Box* box) { - assert(box->cls->tp_del == NULL); -} - // Analoguous to CPython's implementation of subtype_dealloc, but having a GC // saves us from complications involving "trashcan macros". // @@ -378,12 +374,6 @@ static void subtype_dealloc(Box* self) { } } -// We don't need CPython's version of tp_free since we have GC. -// We still need to set tp_free to something and not a NULL pointer, -// because C extensions might still call tp_free from tp_dealloc. -void default_free(void*) { -} - bool BoxedClass::hasNonDefaultTpDealloc() { // Find nearest base with a different tp_dealloc. BoxedClass* base = this; diff --git a/src/runtime/objmodel.h b/src/runtime/objmodel.h index f5e8711ed..e57b83f27 100644 --- a/src/runtime/objmodel.h +++ b/src/runtime/objmodel.h @@ -42,17 +42,11 @@ void _printStacktrace(); extern "C" Box* deopt(AST_expr* expr, Box* value); -// Finalizer-related -void default_free(void*); -void dealloc_null(Box* box); - // helper function for raising from the runtime: void raiseExcHelper(BoxedClass*, const char* fmt, ...) __attribute__((__noreturn__)) __attribute__((format(printf, 2, 3))); void raiseExcHelper(BoxedClass*, Box* arg) __attribute__((__noreturn__)); -BoxedModule* getCurrentModule(); - // TODO sort this extern "C" bool softspace(Box* b, bool newval); extern "C" void printHelper(Box* dest, Box* var, bool nl); diff --git a/src/runtime/types.cpp b/src/runtime/types.cpp index 4d9270edd..ad240a25d 100644 --- a/src/runtime/types.cpp +++ b/src/runtime/types.cpp @@ -3498,6 +3498,16 @@ extern "C" PyUnicodeObject* _PyUnicode_New(Py_ssize_t length) noexcept { return unicode; } +// We don't need CPython's version of tp_free since we have GC. +// We still need to set tp_free to something and not a NULL pointer, +// because C extensions might still call tp_free from tp_dealloc. +void default_free(void*) { +} + +void dealloc_null(Box* box) { + assert(box->cls->tp_del == NULL); +} + // Normally we don't call the Python tp_ slots that are present to support // CPython's reference-counted garbage collection. static void setTypeGCProxy(BoxedClass* cls) { diff --git a/src/runtime/types.h b/src/runtime/types.h index f1e4e73eb..fb5354158 100644 --- a/src/runtime/types.h +++ b/src/runtime/types.h @@ -181,6 +181,10 @@ void ensureCAPIExceptionSet(); struct ExcInfo; void setCAPIException(const ExcInfo& e); +// Finalizer-related +void default_free(void*); +void dealloc_null(Box* box); + // In Pyston, this is the same type as CPython's PyTypeObject (they are interchangeable, but we // use BoxedClass in Pyston wherever possible as a convention). class BoxedClass : public BoxVar { From c8360f6d1a41226782f671e2bec75b05c419ec04 Mon Sep 17 00:00:00 2001 From: Kevin Modzelewski Date: Mon, 2 Nov 2015 15:07:32 -0800 Subject: [PATCH 3/4] Rename CLFunction->FunctionMetadata and a couple of the other related functions: - addRTFunction is now an overload of FunctionMetadata::addVersion - boxFunctionMetadata is now createFunctionFromMetadata (it doesn't return a box) - createRTFunction was just a wrapper around new FunctionMetadata(), so get rid of it - boxRTFunction is now FunctionMetadata::create "CLFunction" never really made sense as a name, and some of the other related functions didn't make sense either (especially after a couple refactorings happened). Hopefully this makes it less confusing. --- src/codegen/ast_interpreter.cpp | 39 ++-- src/codegen/ast_interpreter.h | 12 +- src/codegen/codegen.cpp | 11 +- src/codegen/compvars.cpp | 13 +- src/codegen/compvars.h | 2 +- src/codegen/irgen.cpp | 2 +- src/codegen/irgen.h | 2 +- src/codegen/irgen/hooks.cpp | 83 +++----- src/codegen/irgen/hooks.h | 2 +- src/codegen/irgen/irgenerator.cpp | 19 +- src/codegen/irgen/irgenerator.h | 10 +- src/codegen/osrentry.h | 6 +- src/codegen/runtime_hooks.cpp | 6 +- src/codegen/runtime_hooks.h | 6 +- src/codegen/unwinding.cpp | 16 +- src/codegen/unwinding.h | 4 +- src/core/types.h | 73 ++++--- src/runtime/bool.cpp | 15 +- src/runtime/builtin_modules/builtins.cpp | 243 ++++++++++++----------- src/runtime/builtin_modules/gc.cpp | 17 +- src/runtime/builtin_modules/pyston.cpp | 14 +- src/runtime/builtin_modules/sys.cpp | 42 ++-- src/runtime/builtin_modules/thread.cpp | 36 ++-- src/runtime/capi.cpp | 5 +- src/runtime/classobj.cpp | 204 +++++++++++-------- src/runtime/code.cpp | 4 +- src/runtime/code.h | 4 +- src/runtime/complex.cpp | 72 ++++--- src/runtime/descr.cpp | 62 +++--- src/runtime/dict.cpp | 94 ++++----- src/runtime/file.cpp | 29 +-- src/runtime/float.cpp | 66 +++--- src/runtime/generator.cpp | 19 +- src/runtime/import.cpp | 54 ++--- src/runtime/inline/link_forcer.cpp | 4 +- src/runtime/inline/xrange.cpp | 44 ++-- src/runtime/int.cpp | 58 +++--- src/runtime/iterobject.cpp | 18 +- src/runtime/list.cpp | 131 ++++++------ src/runtime/long.cpp | 84 ++++---- src/runtime/objmodel.cpp | 24 +-- src/runtime/objmodel.h | 2 +- src/runtime/set.cpp | 97 ++++----- src/runtime/str.cpp | 133 +++++++------ src/runtime/super.cpp | 9 +- src/runtime/traceback.cpp | 3 +- src/runtime/tuple.cpp | 56 +++--- src/runtime/types.cpp | 188 ++++++++++-------- src/runtime/types.h | 24 +-- src/runtime/util.cpp | 2 +- test/unittests/analysis.cpp | 2 +- 51 files changed, 1149 insertions(+), 1016 deletions(-) diff --git a/src/codegen/ast_interpreter.cpp b/src/codegen/ast_interpreter.cpp index 296181150..16c2f63d0 100644 --- a/src/codegen/ast_interpreter.cpp +++ b/src/codegen/ast_interpreter.cpp @@ -66,7 +66,7 @@ extern "C" Box* executeInnerAndSetupFrame(ASTInterpreter& interpreter, CFGBlock* */ class ASTInterpreter { public: - ASTInterpreter(CLFunction* clfunc, Box** vregs); + ASTInterpreter(FunctionMetadata* clfunc, Box** vregs); void initArguments(BoxedClosure* closure, BoxedGenerator* generator, Box* arg1, Box* arg2, Box* arg3, Box** args); @@ -138,7 +138,7 @@ class ASTInterpreter { CFGBlock* next_block, *current_block; AST_stmt* current_inst; - CLFunction* clfunc; + FunctionMetadata* clfunc; SourceInfo* source_info; ScopeInfo* scope_info; PhiAnalysis* phis; @@ -172,7 +172,7 @@ class ASTInterpreter { return globals; } - CLFunction* getCL() { return clfunc; } + FunctionMetadata* getCL() { return clfunc; } FrameInfo* getFrameInfo() { return &frame_info; } BoxedClosure* getPassedClosure() { return passed_closure; } Box** getVRegs() { return vregs; } @@ -227,7 +227,7 @@ void ASTInterpreter::setGlobals(Box* globals) { this->globals = globals; } -ASTInterpreter::ASTInterpreter(CLFunction* clfunc, Box** vregs) +ASTInterpreter::ASTInterpreter(FunctionMetadata* clfunc, Box** vregs) : current_block(0), current_inst(0), clfunc(clfunc), @@ -987,7 +987,7 @@ Value ASTInterpreter::visit_return(AST_Return* node) { } Value ASTInterpreter::createFunction(AST* node, AST_arguments* args, const std::vector& body) { - CLFunction* cl = wrapFunction(node, args, body, source_info); + FunctionMetadata* cl = wrapFunction(node, args, body, source_info); std::vector> defaults; @@ -1060,11 +1060,11 @@ Value ASTInterpreter::createFunction(AST* node, AST_arguments* args, const std:: closure_var = jit->imm(0ul); if (!passed_globals_var) passed_globals_var = jit->imm(0ul); - rtn.var = jit->call(false, (void*)boxCLFunction, jit->imm(cl), closure_var, passed_globals_var, defaults_var, - jit->imm(args->defaults.size())); + rtn.var = jit->call(false, (void*)createFunctionFromMetadata, jit->imm(cl), closure_var, passed_globals_var, + defaults_var, jit->imm(args->defaults.size())); } - rtn.o = boxCLFunction(cl, closure, passed_globals, u.il); + rtn.o = createFunctionFromMetadata(cl, closure, passed_globals, u.il); return rtn; } @@ -1111,12 +1111,13 @@ Value ASTInterpreter::visit_makeClass(AST_MakeClass* mkclass) { closure = created_closure; assert(closure); } - CLFunction* cl = wrapFunction(node, nullptr, node->body, source_info); + FunctionMetadata* cl = wrapFunction(node, nullptr, node->body, source_info); Box* passed_globals = NULL; if (!getCL()->source->scoping->areGlobalsFromModule()) passed_globals = globals; - Box* attrDict = runtimeCall(boxCLFunction(cl, closure, passed_globals, {}), ArgPassSpec(0), 0, 0, 0, 0, 0); + Box* attrDict + = runtimeCall(createFunctionFromMetadata(cl, closure, passed_globals, {}), ArgPassSpec(0), 0, 0, 0, 0, 0); Box* classobj = createUserClass(node->name.getBox(), basesTuple, attrDict); @@ -1698,7 +1699,7 @@ extern "C" Box* executeInnerFromASM(ASTInterpreter& interpreter, CFGBlock* start return ASTInterpreter::executeInner(interpreter, start_block, start_at); } -static int calculateNumVRegs(CLFunction* clfunc) { +static int calculateNumVRegs(FunctionMetadata* clfunc) { SourceInfo* source_info = clfunc->source.get(); CFG* cfg = source_info->cfg; @@ -1720,7 +1721,7 @@ static int calculateNumVRegs(CLFunction* clfunc) { return cfg->sym_vreg_map.size(); } -Box* astInterpretFunction(CLFunction* clfunc, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, +Box* astInterpretFunction(FunctionMetadata* clfunc, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, Box* arg3, Box** args) { UNAVOIDABLE_STAT_TIMER(t0, "us_timer_in_interpreter"); @@ -1813,7 +1814,7 @@ Box* astInterpretFunction(CLFunction* clfunc, Box* closure, Box* generator, Box* return v ? v : None; } -Box* astInterpretFunctionEval(CLFunction* clfunc, Box* globals, Box* boxedLocals) { +Box* astInterpretFunctionEval(FunctionMetadata* clfunc, Box* globals, Box* boxedLocals) { ++clfunc->times_interpreted; Box** vregs = NULL; @@ -1835,10 +1836,10 @@ Box* astInterpretFunctionEval(CLFunction* clfunc, Box* globals, Box* boxedLocals return v ? v : None; } -static Box* astInterpretDeoptInner(CLFunction* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, - FrameStackState frame_state) __attribute__((noinline)); -static Box* astInterpretDeoptInner(CLFunction* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, - FrameStackState frame_state) { +static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, + Box* expr_val, FrameStackState frame_state) __attribute__((noinline)); +static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, + Box* expr_val, FrameStackState frame_state) { assert(clfunc); assert(enclosing_stmt); assert(frame_state.locals); @@ -1931,7 +1932,7 @@ static Box* astInterpretDeoptInner(CLFunction* clfunc, AST_expr* after_expr, AST return v ? v : None; } -Box* astInterpretDeopt(CLFunction* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, +Box* astInterpretDeopt(FunctionMetadata* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, FrameStackState frame_state) { return astInterpretDeoptInner(clfunc, after_expr, enclosing_stmt, expr_val, frame_state); } @@ -1961,7 +1962,7 @@ Box* getGlobalsForInterpretedFrame(void* frame_ptr) { return interpreter->getGlobals(); } -CLFunction* getCLForInterpretedFrame(void* frame_ptr) { +FunctionMetadata* getCLForInterpretedFrame(void* frame_ptr) { ASTInterpreter* interpreter = getInterpreterFromFramePtr(frame_ptr); assert(interpreter); return interpreter->getCL(); diff --git a/src/codegen/ast_interpreter.h b/src/codegen/ast_interpreter.h index 723aa9f46..080b0b0da 100644 --- a/src/codegen/ast_interpreter.h +++ b/src/codegen/ast_interpreter.h @@ -29,7 +29,7 @@ class AST_Jump; class Box; class BoxedClosure; class BoxedDict; -struct CLFunction; +struct FunctionMetadata; struct LineInfo; extern const void* interpreter_instr_addr; @@ -70,15 +70,15 @@ struct Value { Value(Box* o, RewriterVar* var) : o(o), var(var) {} }; -Box* astInterpretFunction(CLFunction* f, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, Box* arg3, - Box** args); -Box* astInterpretFunctionEval(CLFunction* cf, Box* globals, Box* boxedLocals); -Box* astInterpretDeopt(CLFunction* cf, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, +Box* astInterpretFunction(FunctionMetadata* f, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, + Box* arg3, Box** args); +Box* astInterpretFunctionEval(FunctionMetadata* cf, Box* globals, Box* boxedLocals); +Box* astInterpretDeopt(FunctionMetadata* cf, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, FrameStackState frame_state); AST_stmt* getCurrentStatementForInterpretedFrame(void* frame_ptr); Box* getGlobalsForInterpretedFrame(void* frame_ptr); -CLFunction* getCLForInterpretedFrame(void* frame_ptr); +FunctionMetadata* getCLForInterpretedFrame(void* frame_ptr); struct FrameInfo; FrameInfo* getFrameInfoForInterpretedFrame(void* frame_ptr); BoxedClosure* passedClosureForInterpretedFrame(void* frame_ptr); diff --git a/src/codegen/codegen.cpp b/src/codegen/codegen.cpp index fec17ff07..a6dde84d7 100644 --- a/src/codegen/codegen.cpp +++ b/src/codegen/codegen.cpp @@ -38,7 +38,8 @@ namespace pyston { DS_DEFINE_RWLOCK(codegen_rwlock); -CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, std::unique_ptr source) +FunctionMetadata::FunctionMetadata(int num_args, bool takes_varargs, bool takes_kwargs, + std::unique_ptr source) : code_obj(NULL), num_args(num_args), takes_varargs(takes_varargs), @@ -50,7 +51,7 @@ CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, std: internal_callable(NULL, NULL) { } -CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names) +FunctionMetadata::FunctionMetadata(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names) : code_obj(NULL), num_args(num_args), takes_varargs(takes_varargs), @@ -62,16 +63,16 @@ CLFunction::CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, cons internal_callable(NULL, NULL) { } -BoxedCode* CLFunction::getCode() { +BoxedCode* FunctionMetadata::getCode() { if (!code_obj) { code_obj = new BoxedCode(this); - // CLFunctions don't currently participate in GC. They actually never get freed currently. + // FunctionMetadatas don't currently participate in GC. They actually never get freed currently. gc::registerPermanentRoot(code_obj); } return code_obj; } -void CLFunction::addVersion(CompiledFunction* compiled) { +void FunctionMetadata::addVersion(CompiledFunction* compiled) { assert(compiled); assert((compiled->spec != NULL) + (compiled->entry_descriptor != NULL) == 1); assert(compiled->clfunc == NULL); diff --git a/src/codegen/compvars.cpp b/src/codegen/compvars.cpp index 93ea3f245..50e6b38d6 100644 --- a/src/codegen/compvars.cpp +++ b/src/codegen/compvars.cpp @@ -810,9 +810,9 @@ ConcreteCompilerVariable* UnknownType::hasnext(IREmitter& emitter, const OpInfo& return boolFromI1(emitter, rtn_val); } -CompilerVariable* makeFunction(IREmitter& emitter, CLFunction* f, CompilerVariable* closure, llvm::Value* globals, +CompilerVariable* makeFunction(IREmitter& emitter, FunctionMetadata* f, CompilerVariable* closure, llvm::Value* globals, const std::vector& defaults) { - // Unlike the CLFunction*, which can be shared between recompilations, the Box* around it + // Unlike the FunctionMetadata*, which can be shared between recompilations, the Box* around it // should be created anew every time the functiondef is encountered llvm::Value* closure_v; @@ -844,8 +844,9 @@ CompilerVariable* makeFunction(IREmitter& emitter, CLFunction* f, CompilerVariab // We know this function call can't throw, so it's safe to use emitter.getBuilder()->CreateCall() rather than // emitter.createCall(). llvm::Value* boxed = emitter.getBuilder()->CreateCall( - g.funcs.boxCLFunction, std::vector{ embedRelocatablePtr(f, g.llvm_clfunction_type_ptr), closure_v, - globals, scratch, getConstantInt(defaults.size(), g.i64) }); + g.funcs.createFunctionFromMetadata, + std::vector{ embedRelocatablePtr(f, g.llvm_clfunction_type_ptr), closure_v, globals, scratch, + getConstantInt(defaults.size(), g.i64) }); if (convertedClosure) convertedClosure->decvref(emitter); @@ -914,7 +915,7 @@ class AbstractFunctionType : public CompilerType { static CompilerType* fromRT(BoxedFunction* rtfunc, bool stripfirst) { std::vector sigs; - CLFunction* clf = rtfunc->f; + FunctionMetadata* clf = rtfunc->f; assert(!rtfunc->can_change_defaults); @@ -1864,7 +1865,7 @@ class NormalObjectType : public ConcreteCompilerType { // but I don't think we should be running into that case. RELEASE_ASSERT(!rtattr_func->can_change_defaults, "could handle this but unexpected"); - CLFunction* cl = rtattr_func->f; + FunctionMetadata* cl = rtattr_func->f; assert(cl); ParamReceiveSpec paramspec = rtattr_func->getParamspec(); diff --git a/src/codegen/compvars.h b/src/codegen/compvars.h index 794457b6c..7f9a190fc 100644 --- a/src/codegen/compvars.h +++ b/src/codegen/compvars.h @@ -441,7 +441,7 @@ UnboxedSlice extractSlice(CompilerVariable* slice); #if 0 CompilerVariable* makeUnicode(IREmitter& emitter, llvm::StringRef); #endif -CompilerVariable* makeFunction(IREmitter& emitter, CLFunction*, CompilerVariable* closure, llvm::Value* globals, +CompilerVariable* makeFunction(IREmitter& emitter, FunctionMetadata*, CompilerVariable* closure, llvm::Value* globals, const std::vector& defaults); ConcreteCompilerVariable* undefVariable(); CompilerVariable* makeTuple(const std::vector& elts); diff --git a/src/codegen/irgen.cpp b/src/codegen/irgen.cpp index f2ccd1292..8b73c6b2c 100644 --- a/src/codegen/irgen.cpp +++ b/src/codegen/irgen.cpp @@ -974,7 +974,7 @@ static std::string getUniqueFunctionName(std::string nameprefix, EffortLevel eff return os.str(); } -CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames* param_names, +CompiledFunction* doCompile(FunctionMetadata* clfunc, SourceInfo* source, ParamNames* param_names, const OSREntryDescriptor* entry_descriptor, EffortLevel effort, ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix) { Timer _t("in doCompile"); diff --git a/src/codegen/irgen.h b/src/codegen/irgen.h index 58b5b43a0..393de8b8b 100644 --- a/src/codegen/irgen.h +++ b/src/codegen/irgen.h @@ -113,7 +113,7 @@ extern const std::string PASSED_GENERATOR_NAME; InternedString getIsDefinedName(InternedString name, InternedStringPool& interned_strings); bool isIsDefinedName(llvm::StringRef name); -CompiledFunction* doCompile(CLFunction* clfunc, SourceInfo* source, ParamNames* param_names, +CompiledFunction* doCompile(FunctionMetadata* clfunc, SourceInfo* source, ParamNames* param_names, const OSREntryDescriptor* entry_descriptor, EffortLevel effort, ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix); diff --git a/src/codegen/irgen/hooks.cpp b/src/codegen/irgen/hooks.cpp index 267e837e0..f205be5d0 100644 --- a/src/codegen/irgen/hooks.cpp +++ b/src/codegen/irgen/hooks.cpp @@ -197,7 +197,7 @@ static void compileIR(CompiledFunction* cf, EffortLevel effort) { // Compiles a new version of the function with the given signature and adds it to the list; // should only be called after checking to see if the other versions would work. // The codegen_lock needs to be held in W mode before calling this function: -CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, EffortLevel effort, +CompiledFunction* compileFunction(FunctionMetadata* f, FunctionSpecialization* spec, EffortLevel effort, const OSREntryDescriptor* entry_descriptor, bool force_exception_style, ExceptionStyle forced_exception_style) { UNAVOIDABLE_STAT_TIMER(t0, "us_timer_compileFunction"); @@ -310,7 +310,7 @@ CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, E } void compileAndRunModule(AST_Module* m, BoxedModule* bm) { - CLFunction* clfunc; + FunctionMetadata* clfunc; { // scope for limiting the locked region: LOCK_REGION(codegen_rwlock.asWrite()); @@ -332,7 +332,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) { if (!bm->hasattr(builtins_str)) bm->giveAttr(builtins_str, PyModule_GetDict(builtins_module)); - clfunc = new CLFunction(0, false, false, std::move(si)); + clfunc = new FunctionMetadata(0, false, false, std::move(si)); } UNAVOIDABLE_STAT_TIMER(t0, "us_timer_interpreted_module_toplevel"); @@ -340,7 +340,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) { assert(r == None); } -Box* evalOrExec(CLFunction* cl, Box* globals, Box* boxedLocals) { +Box* evalOrExec(FunctionMetadata* cl, Box* globals, Box* boxedLocals) { RELEASE_ASSERT(!cl->source->scoping->areGlobalsFromModule(), ""); assert(globals && (globals->cls == module_cls || globals->cls == dict_cls)); @@ -354,8 +354,8 @@ Box* evalOrExec(CLFunction* cl, Box* globals, Box* boxedLocals) { return astInterpretFunctionEval(cl, globals, boxedLocals); } -static CLFunction* compileForEvalOrExec(AST* source, std::vector body, BoxedString* fn, - PyCompilerFlags* flags) { +static FunctionMetadata* compileForEvalOrExec(AST* source, std::vector body, BoxedString* fn, + PyCompilerFlags* flags) { LOCK_REGION(codegen_rwlock.asWrite()); Timer _t("for evalOrExec()"); @@ -375,7 +375,7 @@ static CLFunction* compileForEvalOrExec(AST* source, std::vector body std::unique_ptr si( new SourceInfo(getCurrentModule(), scoping, future_flags, source, std::move(body), fn)); - CLFunction* cl_f = new CLFunction(0, false, false, std::move(si)); + FunctionMetadata* cl_f = new FunctionMetadata(0, false, false, std::move(si)); return cl_f; } @@ -393,7 +393,7 @@ static AST_Module* parseExec(llvm::StringRef source, FutureFlags future_flags, b return parsedModule; } -static CLFunction* compileExec(AST_Module* parsedModule, BoxedString* fn, PyCompilerFlags* flags) { +static FunctionMetadata* compileExec(AST_Module* parsedModule, BoxedString* fn, PyCompilerFlags* flags) { return compileForEvalOrExec(parsedModule, parsedModule->body, fn, flags); } @@ -420,7 +420,7 @@ static AST_Expression* parseEval(llvm::StringRef source, FutureFlags future_flag return parsedExpr; } -static CLFunction* compileEval(AST_Expression* parsedExpr, BoxedString* fn, PyCompilerFlags* flags) { +static FunctionMetadata* compileEval(AST_Expression* parsedExpr, BoxedString* fn, PyCompilerFlags* flags) { // We need body (list of statements) to compile. // Obtain this by simply making a single statement which contains the expression. AST_Return* stmt = new AST_Return(); @@ -477,7 +477,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) { if (dont_inherit) { future_flags = arg_future_flags; } else { - CLFunction* caller_cl = getTopPythonFunction(); + FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); assert(caller_cl->source != NULL); FutureFlags caller_future_flags = caller_cl->source->future_flags; @@ -512,7 +512,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) { PyCompilerFlags pcf; pcf.cf_flags = future_flags; - CLFunction* cl; + FunctionMetadata* cl; if (type_str->s() == "exec" || type_str->s() == "single") { // TODO: CPython parses execs as Modules if (parsed->type != AST_TYPE::Module) @@ -582,9 +582,9 @@ static Box* evalMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* // cf.cf_flags |= PyCF_SOURCE_IS_UTF8 } - CLFunction* cl; + FunctionMetadata* cl; if (boxedCode->cls == str_cls) { - CLFunction* caller_cl = getTopPythonFunction(); + FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); assert(caller_cl->source != NULL); @@ -601,7 +601,7 @@ static Box* evalMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* } Box* eval(Box* boxedCode, Box* globals, Box* locals) { - CLFunction* caller_cl = getTopPythonFunction(); + FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); assert(caller_cl->source != NULL); FutureFlags caller_future_flags = caller_cl->source->future_flags; @@ -640,14 +640,14 @@ Box* execfile(Box* _fn, Box* globals, Box* locals) { AST_Module* parsed = caching_parse_file(fn->s().data(), /* future_flags = */ 0); assert(parsed); - CLFunction* caller_cl = getTopPythonFunction(); + FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); assert(caller_cl->source != NULL); FutureFlags caller_future_flags = caller_cl->source->future_flags; PyCompilerFlags pcf; pcf.cf_flags = caller_future_flags; - CLFunction* cl = compileForEvalOrExec(parsed, parsed->body, fn, &pcf); + FunctionMetadata* cl = compileForEvalOrExec(parsed, parsed->body, fn, &pcf); assert(cl); return evalOrExec(cl, globals, locals); @@ -675,9 +675,9 @@ Box* execMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* flags) // cf.cf_flags |= PyCF_SOURCE_IS_UTF8 } - CLFunction* cl; + FunctionMetadata* cl; if (boxedCode->cls == str_cls) { - CLFunction* caller_cl = getTopPythonFunction(); + FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); assert(caller_cl->source != NULL); @@ -733,7 +733,7 @@ void CompiledFunction::speculationFailed() { if (this->times_speculation_failed == 4) { // printf("Killing %p because it failed too many speculations\n", this); - CLFunction* cl = this->clfunc; + FunctionMetadata* cl = this->clfunc; assert(cl); assert(this != cl->always_use_version); @@ -812,7 +812,7 @@ ConcreteCompilerType* CompiledFunction::getReturnType() { } /// Reoptimizes the given function version at the new effort level. -/// The cf must be an active version in its parents CLFunction; the given +/// The cf must be an active version in its parents FunctionMetadata; the given /// version will be replaced by the new version, which will be returned. static CompiledFunction* _doReopt(CompiledFunction* cf, EffortLevel new_effort) { LOCK_REGION(codegen_rwlock.asWrite()); @@ -823,7 +823,7 @@ static CompiledFunction* _doReopt(CompiledFunction* cf, EffortLevel new_effort) assert(cf->entry_descriptor == NULL && "We can't reopt an osr-entry compile!"); assert(cf->spec); - CLFunction* clfunc = cf->clfunc; + FunctionMetadata* clfunc = cf->clfunc; assert(clfunc); assert(new_effort > cf->effort); @@ -860,7 +860,7 @@ CompiledFunction* compilePartialFuncInternal(OSRExit* exit) { // if (VERBOSITY("irgen") >= 1) printf("In compilePartialFunc, handling %p\n", exit); - CLFunction* clfunc = exit->entry->clfunc; + FunctionMetadata* clfunc = exit->entry->clfunc; assert(clfunc); CompiledFunction*& new_cf = clfunc->osr_versions[exit->entry]; if (new_cf == NULL) { @@ -904,34 +904,9 @@ extern "C" char* reoptCompiledFunc(CompiledFunction* cf) { return (char*)new_cf->code; } -CLFunction* createRTFunction(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names) { - return new CLFunction(num_args, takes_varargs, takes_kwargs, param_names); -} - -CLFunction* boxRTFunction(void* f, ConcreteCompilerType* rtn_type, int num_args, const ParamNames& param_names, - ExceptionStyle exception_style) { - assert(!param_names.takes_param_names || num_args == param_names.args.size()); - assert(param_names.vararg.str() == ""); - assert(param_names.kwarg.str() == ""); - - return boxRTFunction(f, rtn_type, num_args, false, false, param_names, exception_style); -} - -CLFunction* boxRTFunction(void* f, ConcreteCompilerType* rtn_type, int num_args, bool takes_varargs, bool takes_kwargs, - const ParamNames& param_names, ExceptionStyle exception_style) { - assert(!param_names.takes_param_names || num_args == param_names.args.size()); - assert(takes_varargs || param_names.vararg.str() == ""); - assert(takes_kwargs || param_names.kwarg.str() == ""); - - CLFunction* cl_f = createRTFunction(num_args, takes_varargs, takes_kwargs, param_names); - - addRTFunction(cl_f, f, rtn_type, exception_style); - return cl_f; -} - -void addRTFunction(CLFunction* cl_f, void* f, ConcreteCompilerType* rtn_type, ExceptionStyle exception_style) { - std::vector arg_types(cl_f->numReceivedArgs(), UNKNOWN); - return addRTFunction(cl_f, f, rtn_type, arg_types, exception_style); +void FunctionMetadata::addVersion(void* f, ConcreteCompilerType* rtn_type, ExceptionStyle exception_style) { + std::vector arg_types(numReceivedArgs(), UNKNOWN); + return FunctionMetadata::addVersion(f, rtn_type, arg_types, exception_style); } static ConcreteCompilerType* processType(ConcreteCompilerType* type) { @@ -939,15 +914,15 @@ static ConcreteCompilerType* processType(ConcreteCompilerType* type) { return type; } -void addRTFunction(CLFunction* cl_f, void* f, ConcreteCompilerType* rtn_type, - const std::vector& arg_types, ExceptionStyle exception_style) { - assert(arg_types.size() == cl_f->numReceivedArgs()); +void FunctionMetadata::addVersion(void* f, ConcreteCompilerType* rtn_type, + const std::vector& arg_types, ExceptionStyle exception_style) { + assert(arg_types.size() == numReceivedArgs()); #ifndef NDEBUG for (ConcreteCompilerType* t : arg_types) assert(t); #endif FunctionSpecialization* spec = new FunctionSpecialization(processType(rtn_type), arg_types); - cl_f->addVersion(new CompiledFunction(NULL, spec, f, EffortLevel::MAXIMAL, exception_style, NULL)); + addVersion(new CompiledFunction(NULL, spec, f, EffortLevel::MAXIMAL, exception_style, NULL)); } } diff --git a/src/codegen/irgen/hooks.h b/src/codegen/irgen/hooks.h index 7c61511c8..eb0941a9d 100644 --- a/src/codegen/irgen/hooks.h +++ b/src/codegen/irgen/hooks.h @@ -22,7 +22,7 @@ namespace pyston { struct CompiledFunction; -class CLFunction; +class FunctionMetadata; class OSRExit; class Box; class BoxedDict; diff --git a/src/codegen/irgen/irgenerator.cpp b/src/codegen/irgen/irgenerator.cpp index 36fa22c36..8906e5177 100644 --- a/src/codegen/irgen/irgenerator.cpp +++ b/src/codegen/irgen/irgenerator.cpp @@ -44,7 +44,7 @@ extern "C" void dumpLLVM(void* _v) { v->dump(); } -IRGenState::IRGenState(CLFunction* clfunc, CompiledFunction* cf, SourceInfo* source_info, +IRGenState::IRGenState(FunctionMetadata* clfunc, CompiledFunction* cf, SourceInfo* source_info, std::unique_ptr phis, ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info) : clfunc(clfunc), @@ -1390,7 +1390,7 @@ class IRGeneratorImpl : public IRGenerator { decorators.push_back(evalExpr(d, unw_info)); } - CLFunction* cl = wrapFunction(node, nullptr, node->body, irstate->getSourceInfo()); + FunctionMetadata* cl = wrapFunction(node, nullptr, node->body, irstate->getSourceInfo()); // TODO duplication with _createFunction: CompilerVariable* created_closure = NULL; @@ -1436,7 +1436,7 @@ class IRGeneratorImpl : public IRGenerator { CompilerVariable* _createFunction(AST* node, const UnwindInfo& unw_info, AST_arguments* args, const std::vector& body) { - CLFunction* cl = wrapFunction(node, args, body, irstate->getSourceInfo()); + FunctionMetadata* cl = wrapFunction(node, args, body, irstate->getSourceInfo()); std::vector defaults; for (auto d : args->defaults) { @@ -2950,19 +2950,20 @@ IRGenerator* createIRGenerator(IRGenState* irstate, std::unordered_map& body, SourceInfo* source) { +FunctionMetadata* wrapFunction(AST* node, AST_arguments* args, const std::vector& body, SourceInfo* source) { // Different compilations of the parent scope of a functiondef should lead - // to the same CLFunction* being used: - static std::unordered_map made; + // to the same FunctionMetadata* being used: + static std::unordered_map made; - CLFunction*& cl = made[node]; + FunctionMetadata*& cl = made[node]; if (cl == NULL) { std::unique_ptr si( new SourceInfo(source->parent_module, source->scoping, source->future_flags, node, body, source->getFn())); if (args) - cl = new CLFunction(args->args.size(), args->vararg.s().size(), args->kwarg.s().size(), std::move(si)); + cl = new FunctionMetadata(args->args.size(), args->vararg.s().size(), args->kwarg.s().size(), + std::move(si)); else - cl = new CLFunction(0, false, false, std::move(si)); + cl = new FunctionMetadata(0, false, false, std::move(si)); } return cl; } diff --git a/src/codegen/irgen/irgenerator.h b/src/codegen/irgen/irgenerator.h index 570d5c0c0..2a5da7bd4 100644 --- a/src/codegen/irgen/irgenerator.h +++ b/src/codegen/irgen/irgenerator.h @@ -59,7 +59,7 @@ class IRGenState { private: // Note: due to some not-yet-fixed behavior, cf->clfunc is NULL will only get set to point // to clfunc at the end of irgen. - CLFunction* clfunc; + FunctionMetadata* clfunc; CompiledFunction* cf; SourceInfo* source_info; std::unique_ptr phis; @@ -75,12 +75,12 @@ class IRGenState { int scratch_size; public: - IRGenState(CLFunction* clfunc, CompiledFunction* cf, SourceInfo* source_info, std::unique_ptr phis, - ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info); + IRGenState(FunctionMetadata* clfunc, CompiledFunction* cf, SourceInfo* source_info, + std::unique_ptr phis, ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info); ~IRGenState(); CompiledFunction* getCurFunction() { return cf; } - CLFunction* getCL() { return clfunc; } + FunctionMetadata* getCL() { return clfunc; } ExceptionStyle getExceptionStyle() { return cf->exception_style; } @@ -170,7 +170,7 @@ IREmitter* createIREmitter(IRGenState* irstate, llvm::BasicBlock*& curblock, IRG IRGenerator* createIRGenerator(IRGenState* irstate, std::unordered_map& entry_blocks, CFGBlock* myblock, TypeAnalysis* types); -CLFunction* wrapFunction(AST* node, AST_arguments* args, const std::vector& body, SourceInfo* source); +FunctionMetadata* wrapFunction(AST* node, AST_arguments* args, const std::vector& body, SourceInfo* source); std::vector* getKeywordNameStorage(AST_Call* node); } diff --git a/src/codegen/osrentry.h b/src/codegen/osrentry.h index 9c6f869bb..dbfcb48e4 100644 --- a/src/codegen/osrentry.h +++ b/src/codegen/osrentry.h @@ -31,19 +31,19 @@ struct StackMap; class OSREntryDescriptor { private: - OSREntryDescriptor(CLFunction* clfunc, AST_Jump* backedge, ExceptionStyle exception_style) + OSREntryDescriptor(FunctionMetadata* clfunc, AST_Jump* backedge, ExceptionStyle exception_style) : clfunc(clfunc), backedge(backedge), exception_style(exception_style) { assert(clfunc); } public: - CLFunction* clfunc; + FunctionMetadata* clfunc; AST_Jump* const backedge; ExceptionStyle exception_style; typedef std::map ArgMap; ArgMap args; - static OSREntryDescriptor* create(CLFunction* clfunc, AST_Jump* backedge, ExceptionStyle exception_style) { + static OSREntryDescriptor* create(FunctionMetadata* clfunc, AST_Jump* backedge, ExceptionStyle exception_style) { return new OSREntryDescriptor(clfunc, backedge, exception_style); } }; diff --git a/src/codegen/runtime_hooks.cpp b/src/codegen/runtime_hooks.cpp index daa4a3144..d029bdc2c 100644 --- a/src/codegen/runtime_hooks.cpp +++ b/src/codegen/runtime_hooks.cpp @@ -122,7 +122,7 @@ static llvm::Value* addFunc(void* func, llvm::Type* rtn_type, llvm::Type* arg1, void initGlobalFuncs(GlobalState& g) { g.llvm_opaque_type = llvm::StructType::create(g.context, "opaque"); - g.llvm_clfunction_type_ptr = lookupFunction("boxCLFunction")->arg_begin()->getType(); + g.llvm_clfunction_type_ptr = lookupFunction("createFunctionFromMetadata")->arg_begin()->getType(); g.llvm_module_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedModule")->getPointerTo(); assert(g.llvm_module_type_ptr); g.llvm_bool_type_ptr = lookupFunction("boxBool")->getReturnType(); @@ -181,8 +181,8 @@ void initGlobalFuncs(GlobalState& g) { GET(softspace); - GET(boxCLFunction); - GET(unboxCLFunction); + GET(createFunctionFromMetadata); + GET(getFunctionMetadata); GET(createUserClass); GET(boxInt); GET(unboxInt); diff --git a/src/codegen/runtime_hooks.h b/src/codegen/runtime_hooks.h index 982a6f810..3a6b521a4 100644 --- a/src/codegen/runtime_hooks.h +++ b/src/codegen/runtime_hooks.h @@ -32,9 +32,9 @@ struct GlobalFuncs { llvm::Value* printf, *my_assert, *malloc, *free; - llvm::Value* boxInt, *unboxInt, *boxFloat, *unboxFloat, *boxCLFunction, *unboxCLFunction, *boxInstanceMethod, - *boxBool, *unboxBool, *createTuple, *createDict, *createList, *createSlice, *createUserClass, *createClosure, - *createGenerator, *createSet; + llvm::Value* boxInt, *unboxInt, *boxFloat, *unboxFloat, *createFunctionFromMetadata, *getFunctionMetadata, + *boxInstanceMethod, *boxBool, *unboxBool, *createTuple, *createDict, *createList, *createSlice, + *createUserClass, *createClosure, *createGenerator, *createSet; llvm::Value* getattr, *getattr_capi, *setattr, *delattr, *delitem, *delGlobal, *nonzero, *binop, *compare, *augbinop, *unboxedLen, *getitem, *getitem_capi, *getclsattr, *getGlobal, *setitem, *unaryop, *import, *importFrom, *importStar, *repr, *exceptionMatches, *yield, *getiterHelper, *hasnext, *setGlobal, *apply_slice; diff --git a/src/codegen/unwinding.cpp b/src/codegen/unwinding.cpp index e7a9c68fe..8f1580f74 100644 --- a/src/codegen/unwinding.cpp +++ b/src/codegen/unwinding.cpp @@ -278,7 +278,7 @@ struct PythonFrameId { class PythonFrameIteratorImpl { public: PythonFrameId id; - CLFunction* cl; // always exists + FunctionMetadata* cl; // always exists // These only exist if id.type==COMPILED: CompiledFunction* cf; @@ -289,7 +289,7 @@ class PythonFrameIteratorImpl { PythonFrameIteratorImpl() : regs_valid(0) {} - PythonFrameIteratorImpl(PythonFrameId::FrameType type, uint64_t ip, uint64_t bp, CLFunction* cl, + PythonFrameIteratorImpl(PythonFrameId::FrameType type, uint64_t ip, uint64_t bp, FunctionMetadata* cl, CompiledFunction* cf) : id(PythonFrameId(type, ip, bp)), cl(cl), cf(cf), regs_valid(0) { assert(cl); @@ -301,7 +301,7 @@ class PythonFrameIteratorImpl { return cf; } - CLFunction* getCL() const { + FunctionMetadata* getCL() const { assert(cl); return cl; } @@ -461,7 +461,7 @@ static inline unw_word_t get_cursor_bp(unw_cursor_t* cursor) { // frame information through the PythonFrameIteratorImpl* info arg. bool frameIsPythonFrame(unw_word_t ip, unw_word_t bp, unw_cursor_t* cursor, PythonFrameIteratorImpl* info) { CompiledFunction* cf = getCFForAddress(ip); - CLFunction* cl = cf ? cf->clfunc : NULL; + FunctionMetadata* cl = cf ? cf->clfunc : NULL; bool jitted = cf != NULL; bool interpreted = !jitted && inASTInterpreterExecuteInner(ip); if (interpreted) @@ -797,7 +797,7 @@ void updateFrameExcInfoIfNeeded(ExcInfo* latest) { return; } -CLFunction* getTopPythonFunction() { +FunctionMetadata* getTopPythonFunction() { auto rtn = getTopPythonFrame(); if (!rtn) return NULL; @@ -816,7 +816,7 @@ Box* getGlobalsDict() { } BoxedModule* getCurrentModule() { - CLFunction* clfunc = getTopPythonFunction(); + FunctionMetadata* clfunc = getTopPythonFunction(); if (!clfunc) return NULL; return clfunc->source->parent_module; @@ -941,7 +941,7 @@ Box* PythonFrameIterator::fastLocalsToBoxedLocals() { BoxedClosure* closure; FrameInfo* frame_info; - CLFunction* clfunc = impl->getCL(); + FunctionMetadata* clfunc = impl->getCL(); ScopeInfo* scope_info = clfunc->source->getScopeInfo(); if (scope_info->areLocalsFromModule()) { @@ -1088,7 +1088,7 @@ CompiledFunction* PythonFrameIterator::getCF() { return impl->getCF(); } -CLFunction* PythonFrameIterator::getCL() { +FunctionMetadata* PythonFrameIterator::getCL() { return impl->getCL(); } diff --git a/src/codegen/unwinding.h b/src/codegen/unwinding.h index 1439c7867..8dc001f11 100644 --- a/src/codegen/unwinding.h +++ b/src/codegen/unwinding.h @@ -58,7 +58,7 @@ extern "C" void caughtCapiException(AST_stmt* current_stmt, void* source_info); extern "C" void reraiseCapiExcAsCxx() __attribute__((noreturn)); -CLFunction* getTopPythonFunction(); +FunctionMetadata* getTopPythonFunction(); // debugging/stat helper, returns python filename:linenumber, or "unknown:-1" if it fails std::string getCurrentPythonLine(); @@ -76,7 +76,7 @@ class PythonFrameIterator { public: CompiledFunction* getCF(); - CLFunction* getCL(); + FunctionMetadata* getCL(); FrameInfo* getFrameInfo(); bool exists() { return impl.get() != NULL; } AST_stmt* getCurrentStatement(); diff --git a/src/core/types.h b/src/core/types.h index 198528cdf..a5ef50cb2 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -145,7 +145,7 @@ class PhiAnalysis; class LivenessAnalysis; class ScopingAnalysis; -class CLFunction; +class FunctionMetadata; class OSREntryDescriptor; // Pyston's internal calling convention is to pass around arguments in as unprocessed a form as possible, @@ -295,16 +295,16 @@ class ICInfo; class LocationMap; class JitCodeBlock; -// A specific compilation of a CLFunction. Usually these will be created by the LLVM JIT, which will take a CLFunction +// A specific compilation of a FunctionMetadata. Usually these will be created by the LLVM JIT, which will take a FunctionMetadata // and some compilation settings, and produce a CompiledFunction -// CompiledFunctions can also be created from raw function pointers, using boxRTFunction. -// A single CLFunction can have multiple CompiledFunctions associated with it, if they have different settings. +// CompiledFunctions can also be created from raw function pointers, using FunctionMetadata::create. +// A single FunctionMetadata can have multiple CompiledFunctions associated with it, if they have different settings. // Typically, this will happen due to specialization on the argument types (ie we will generate a separate versions // of a function that are faster but only apply to specific argument types). struct CompiledFunction { private: public: - CLFunction* clfunc; + FunctionMetadata* clfunc; llvm::Function* func; // the llvm IR object // Some compilation settings: @@ -415,13 +415,19 @@ typedef std::vector FunctionList; struct CallRewriteArgs; // A BoxedCode is our implementation of the Python "code" object (such as function.func_code). -// It is implemented as a wrapper around a CLFunction. +// It is implemented as a wrapper around a FunctionMetadata. class BoxedCode; -class CLFunction { +// FunctionMetadata corresponds to metadata about a function definition. If the same 'def foo():' block gets +// executed multiple times, there will only be a single FunctionMetadata, even though multiple function objects +// will get created from it. +// FunctionMetadata objects can also be created to correspond to C/C++ runtime functions, via FunctionMetadata::create. +// +// FunctionMetadata objects also keep track of any machine code that we have available for this function. +class FunctionMetadata { private: - // The Python-level "code" object corresponding to this CLFunction. We store it in the CLFunction - // so that multiple attempts to translate from CLFunction->BoxedCode will always return the same + // The Python-level "code" object corresponding to this FunctionMetadata. We store it in the FunctionMetadata + // so that multiple attempts to translate from FunctionMetadata->BoxedCode will always return the same // BoxedCode object. // Callers should use getCode() BoxedCode* code_obj; @@ -454,37 +460,54 @@ class CLFunction { Box**, const std::vector*> InternalCallable; InternalCallable internal_callable; - CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, std::unique_ptr source); - CLFunction(int num_args, bool takes_varargs, bool takes_kwargs, const ParamNames& param_names); - ~CLFunction(); + FunctionMetadata(int num_args, bool takes_varargs, bool takes_kwargs, std::unique_ptr source); + FunctionMetadata(int num_args, bool takes_varargs, bool takes_kwargs, + const ParamNames& param_names = ParamNames::empty()); + ~FunctionMetadata(); int numReceivedArgs() { return num_args + takes_varargs + takes_kwargs; } BoxedCode* getCode(); - void addVersion(CompiledFunction* compiled); - bool isGenerator() const { if (source) return source->is_generator; return false; } + + // These functions add new compiled "versions" (or, instantiations) of this FunctionMetadata. The first + // form takes a CompiledFunction* directly, and the second forms (meant for use by the C++ runtime) take + // some raw parameters and will create the CompiledFunction behind the scenes. + void addVersion(CompiledFunction* compiled); + void addVersion(void* f, ConcreteCompilerType* rtn_type, ExceptionStyle exception_style = CXX); + void addVersion(void* f, ConcreteCompilerType* rtn_type, const std::vector& arg_types, + ExceptionStyle exception_style = CXX); + + // Helper function, meant for the C++ runtime, which allocates a FunctionMetadata object and calls addVersion + // once to it. + static FunctionMetadata* create(void* f, ConcreteCompilerType* rtn_type, int nargs, bool takes_varargs, + bool takes_kwargs, const ParamNames& param_names = ParamNames::empty(), + ExceptionStyle exception_style = CXX) { + assert(!param_names.takes_param_names || nargs == param_names.args.size()); + assert(takes_varargs || param_names.vararg.str() == ""); + assert(takes_kwargs || param_names.kwarg.str() == ""); + + FunctionMetadata* fmd = new FunctionMetadata(nargs, takes_varargs, takes_kwargs, param_names); + fmd->addVersion(f, rtn_type, exception_style); + return fmd; + } + + static FunctionMetadata* create(void* f, ConcreteCompilerType* rtn_type, int nargs, + const ParamNames& param_names = ParamNames::empty(), + ExceptionStyle exception_style = CXX) { + return create(f, rtn_type, nargs, false, false, param_names, exception_style); + } }; -CLFunction* createRTFunction(int num_args, bool takes_varargs, bool takes_kwargs, - const ParamNames& param_names = ParamNames::empty()); -CLFunction* boxRTFunction(void* f, ConcreteCompilerType* rtn_type, int nargs, bool takes_varargs, bool takes_kwargs, - const ParamNames& param_names = ParamNames::empty(), ExceptionStyle exception_style = CXX); -CLFunction* boxRTFunction(void* f, ConcreteCompilerType* rtn_type, int nargs, - const ParamNames& param_names = ParamNames::empty(), ExceptionStyle exception_style = CXX); -void addRTFunction(CLFunction* cf, void* f, ConcreteCompilerType* rtn_type, ExceptionStyle exception_style = CXX); -void addRTFunction(CLFunction* cf, void* f, ConcreteCompilerType* rtn_type, - const std::vector& arg_types, ExceptionStyle exception_style = CXX); -CLFunction* unboxRTFunction(Box*); // Compiles a new version of the function with the given signature and adds it to the list; // should only be called after checking to see if the other versions would work. -CompiledFunction* compileFunction(CLFunction* f, FunctionSpecialization* spec, EffortLevel effort, +CompiledFunction* compileFunction(FunctionMetadata* f, FunctionSpecialization* spec, EffortLevel effort, const OSREntryDescriptor* entry, bool force_exception_style = false, ExceptionStyle forced_exception_style = CXX); EffortLevel initialEffort(); diff --git a/src/runtime/bool.cpp b/src/runtime/bool.cpp index 1daffd21f..fb2a015f2 100644 --- a/src/runtime/bool.cpp +++ b/src/runtime/bool.cpp @@ -90,15 +90,16 @@ void setupBool() { static PyNumberMethods bool_as_number; bool_cls->tp_as_number = &bool_as_number; - bool_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)boolNonzero, BOXED_BOOL, 1))); - bool_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)boolRepr, STR, 1))); - bool_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)boolHash, BOXED_INT, 1))); + bool_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)boolNonzero, BOXED_BOOL, 1))); + bool_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)boolRepr, STR, 1))); + bool_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)boolHash, BOXED_INT, 1))); - bool_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)boolNew, UNKNOWN, 2, false, false), { None })); + bool_cls->giveAttr("__new__", + new BoxedFunction(FunctionMetadata::create((void*)boolNew, UNKNOWN, 2, false, false), { None })); - bool_cls->giveAttr("__and__", new BoxedFunction(boxRTFunction((void*)boolAnd, BOXED_BOOL, 2))); - bool_cls->giveAttr("__or__", new BoxedFunction(boxRTFunction((void*)boolOr, BOXED_BOOL, 2))); - bool_cls->giveAttr("__xor__", new BoxedFunction(boxRTFunction((void*)boolXor, BOXED_BOOL, 2))); + bool_cls->giveAttr("__and__", new BoxedFunction(FunctionMetadata::create((void*)boolAnd, BOXED_BOOL, 2))); + bool_cls->giveAttr("__or__", new BoxedFunction(FunctionMetadata::create((void*)boolOr, BOXED_BOOL, 2))); + bool_cls->giveAttr("__xor__", new BoxedFunction(FunctionMetadata::create((void*)boolXor, BOXED_BOOL, 2))); bool_cls->freeze(); bool_cls->tp_hash = (hashfunc)bool_hash; diff --git a/src/runtime/builtin_modules/builtins.cpp b/src/runtime/builtin_modules/builtins.cpp index 334cc7b04..5d01d0af4 100644 --- a/src/runtime/builtin_modules/builtins.cpp +++ b/src/runtime/builtin_modules/builtins.cpp @@ -1120,9 +1120,10 @@ static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int cls->giveAttr("__module__", boxString("exceptions")); if (base == object_cls) { - cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)exceptionNew, UNKNOWN, 1, true, true))); - cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)exceptionStr, STR, 1))); - cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)exceptionRepr, STR, 1))); + cls->giveAttr("__new__", + new BoxedFunction(FunctionMetadata::create((void*)exceptionNew, UNKNOWN, 1, true, true))); + cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)exceptionStr, STR, 1))); + cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)exceptionRepr, STR, 1))); } cls->freeze(); @@ -1850,7 +1851,7 @@ void setupBuiltins() { "the `nil' object; Ellipsis represents `...' in slices."); ellipsis_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "ellipsis"); - ellipsis_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)ellipsisRepr, STR, 1))); + ellipsis_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)ellipsisRepr, STR, 1))); Ellipsis = new (ellipsis_cls) Box(); assert(Ellipsis->cls); gc::registerPermanentRoot(Ellipsis); @@ -1860,11 +1861,13 @@ void setupBuiltins() { builtins_module->giveAttr("__debug__", False); - builtins_module->giveAttr("print", new BoxedBuiltinFunctionOrMethod( - boxRTFunction((void*)print, NONE, 0, true, true), "print", print_doc)); + builtins_module->giveAttr( + "print", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)print, NONE, 0, true, true), "print", + print_doc)); notimplemented_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "NotImplementedType"); - notimplemented_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)notimplementedRepr, STR, 1))); + notimplemented_cls->giveAttr("__repr__", + new BoxedFunction(FunctionMetadata::create((void*)notimplementedRepr, STR, 1))); notimplemented_cls->freeze(); NotImplemented = new (notimplemented_cls) Box(); gc::registerPermanentRoot(NotImplemented); @@ -1872,100 +1875,103 @@ void setupBuiltins() { builtins_module->giveAttr("NotImplemented", NotImplemented); builtins_module->giveAttr( - "all", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)all, BOXED_BOOL, 1), "all", all_doc)); + "all", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)all, BOXED_BOOL, 1), "all", all_doc)); builtins_module->giveAttr( - "any", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)any, BOXED_BOOL, 1), "any", any_doc)); + "any", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)any, BOXED_BOOL, 1), "any", any_doc)); - builtins_module->giveAttr( - "apply", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)builtinApply, UNKNOWN, 3, false, false), "apply", - { NULL }, NULL, apply_doc)); + builtins_module->giveAttr("apply", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)builtinApply, UNKNOWN, 3, false, false), + "apply", { NULL }, NULL, apply_doc)); - repr_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)repr, UNKNOWN, 1), "repr", repr_doc); + repr_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)repr, UNKNOWN, 1), "repr", repr_doc); builtins_module->giveAttr("repr", repr_obj); - auto len_func = boxRTFunction((void*)len, UNKNOWN, 1); + auto len_func = FunctionMetadata::create((void*)len, UNKNOWN, 1); len_func->internal_callable.cxx_val = lenCallInternal; len_obj = new BoxedBuiltinFunctionOrMethod(len_func, "len", len_doc); builtins_module->giveAttr("len", len_obj); - hash_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)hash, UNKNOWN, 1), "hash", hash_doc); + hash_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)hash, UNKNOWN, 1), "hash", hash_doc); builtins_module->giveAttr("hash", hash_obj); - abs_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)abs_, UNKNOWN, 1), "abs", abs_doc); + abs_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)abs_, UNKNOWN, 1), "abs", abs_doc); builtins_module->giveAttr("abs", abs_obj); builtins_module->giveAttr( - "bin", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)binFunc, UNKNOWN, 1), "bin", bin_doc)); + "bin", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)binFunc, UNKNOWN, 1), "bin", bin_doc)); builtins_module->giveAttr( - "hex", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)hexFunc, UNKNOWN, 1), "hex", hex_doc)); + "hex", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)hexFunc, UNKNOWN, 1), "hex", hex_doc)); builtins_module->giveAttr( - "oct", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)octFunc, UNKNOWN, 1), "oct", oct_doc)); + "oct", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)octFunc, UNKNOWN, 1), "oct", oct_doc)); - min_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)min, UNKNOWN, 1, true, true), "min", { None }, NULL, - min_doc); + min_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)min, UNKNOWN, 1, true, true), "min", + { None }, NULL, min_doc); builtins_module->giveAttr("min", min_obj); - max_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)max, UNKNOWN, 1, true, true), "max", { None }, NULL, - max_doc); + max_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)max, UNKNOWN, 1, true, true), "max", + { None }, NULL, max_doc); builtins_module->giveAttr("max", max_obj); - builtins_module->giveAttr("next", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)next, UNKNOWN, 2, false, - false, ParamNames::empty(), CAPI), - "next", { NULL }, NULL, next_doc)); + builtins_module->giveAttr( + "next", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)next, UNKNOWN, 2, false, false, ParamNames::empty(), CAPI), "next", + { NULL }, NULL, next_doc)); - builtins_module->giveAttr("sum", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sum, UNKNOWN, 2, false, false), - "sum", { boxInt(0) }, NULL, sum_doc)); + builtins_module->giveAttr( + "sum", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)sum, UNKNOWN, 2, false, false), "sum", + { boxInt(0) }, NULL, sum_doc)); - id_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)id, BOXED_INT, 1), "id", id_doc); + id_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)id, BOXED_INT, 1), "id", id_doc); builtins_module->giveAttr("id", id_obj); - chr_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)chr, STR, 1), "chr", chr_doc); + chr_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)chr, STR, 1), "chr", chr_doc); builtins_module->giveAttr("chr", chr_obj); - builtins_module->giveAttr( - "unichr", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)unichr, UNKNOWN, 1), "unichr", unichr_doc)); - ord_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)ord, BOXED_INT, 1), "ord", ord_doc); + builtins_module->giveAttr("unichr", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)unichr, UNKNOWN, 1), "unichr", unichr_doc)); + ord_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)ord, BOXED_INT, 1), "ord", ord_doc); builtins_module->giveAttr("ord", ord_obj); - trap_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)trap, UNKNOWN, 0), "trap"); + trap_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)trap, UNKNOWN, 0), "trap"); builtins_module->giveAttr("trap", trap_obj); - builtins_module->giveAttr( - "dump", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)pydump, UNKNOWN, 2), "dump", { boxInt(0) })); - builtins_module->giveAttr( - "dumpAddr", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)pydumpAddr, UNKNOWN, 1), "dumpAddr")); + builtins_module->giveAttr("dump", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)pydump, UNKNOWN, 2), "dump", { boxInt(0) })); + builtins_module->giveAttr("dumpAddr", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)pydumpAddr, UNKNOWN, 1), "dumpAddr")); - builtins_module->giveAttr("delattr", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)delattrFunc, NONE, 2), - "delattr", delattr_doc)); + builtins_module->giveAttr("delattr", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)delattrFunc, NONE, 2), + "delattr", delattr_doc)); - auto getattr_func = createRTFunction(3, true, true, ParamNames::empty()); + auto getattr_func = new FunctionMetadata(3, true, true, ParamNames::empty()); getattr_func->internal_callable.capi_val = &getattrFuncInternal; getattr_func->internal_callable.cxx_val = &getattrFuncInternal; builtins_module->giveAttr("getattr", new BoxedBuiltinFunctionOrMethod(getattr_func, "getattr", { NULL }, NULL, getattr_doc)); builtins_module->giveAttr( - "setattr", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)setattrFunc, UNKNOWN, 3, false, false), - "setattr", setattr_doc)); + "setattr", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)setattrFunc, UNKNOWN, 3, false, false), "setattr", setattr_doc)); - auto hasattr_func = createRTFunction(2, false, false); + auto hasattr_func = new FunctionMetadata(2, false, false); hasattr_func->internal_callable.capi_val = &hasattrFuncInternal; hasattr_func->internal_callable.cxx_val = &hasattrFuncInternal; builtins_module->giveAttr("hasattr", new BoxedBuiltinFunctionOrMethod(hasattr_func, "hasattr", hasattr_doc)); - builtins_module->giveAttr("pow", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)powFunc, UNKNOWN, 3, false, false), - "pow", { None }, NULL, pow_doc)); + builtins_module->giveAttr( + "pow", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)powFunc, UNKNOWN, 3, false, false), + "pow", { None }, NULL, pow_doc)); - Box* isinstance_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)isinstance_func, BOXED_BOOL, 2), - "isinstance", isinstance_doc); + Box* isinstance_obj = new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)isinstance_func, BOXED_BOOL, 2), "isinstance", isinstance_doc); builtins_module->giveAttr("isinstance", isinstance_obj); - Box* issubclass_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)issubclass_func, BOXED_BOOL, 2), - "issubclass", issubclass_doc); + Box* issubclass_obj = new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)issubclass_func, BOXED_BOOL, 2), "issubclass", issubclass_doc); builtins_module->giveAttr("issubclass", issubclass_obj); - Box* intern_obj - = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)intern_func, UNKNOWN, 1), "intern", intern_doc); + Box* intern_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)intern_func, UNKNOWN, 1), + "intern", intern_doc); builtins_module->giveAttr("intern", intern_obj); - CLFunction* import_func = boxRTFunction((void*)bltinImport, UNKNOWN, 5, false, false, - ParamNames({ "name", "globals", "locals", "fromlist", "level" }, "", "")); + FunctionMetadata* import_func + = FunctionMetadata::create((void*)bltinImport, UNKNOWN, 5, false, false, + ParamNames({ "name", "globals", "locals", "fromlist", "level" }, "", "")); builtins_module->giveAttr("__import__", new BoxedBuiltinFunctionOrMethod(import_func, "__import__", { None, None, None, new BoxedInt(-1) }, NULL, import_doc)); @@ -1973,84 +1979,91 @@ void setupBuiltins() { enumerate_cls = BoxedClass::create(type_cls, object_cls, &BoxedEnumerate::gcHandler, 0, 0, sizeof(BoxedEnumerate), false, "enumerate"); enumerate_cls->giveAttr( - "__new__", - new BoxedFunction(boxRTFunction((void*)BoxedEnumerate::new_, UNKNOWN, 3, false, false), { boxInt(0) })); - enumerate_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)BoxedEnumerate::iter, typeFromClass(enumerate_cls), 1))); - enumerate_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)BoxedEnumerate::next, BOXED_TUPLE, 1))); + "__new__", new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::new_, UNKNOWN, 3, false, false), + { boxInt(0) })); + enumerate_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::iter, + typeFromClass(enumerate_cls), 1))); + enumerate_cls->giveAttr("next", + new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::next, BOXED_TUPLE, 1))); enumerate_cls->giveAttr("__hasnext__", - new BoxedFunction(boxRTFunction((void*)BoxedEnumerate::hasnext, BOXED_BOOL, 1))); + new BoxedFunction(FunctionMetadata::create((void*)BoxedEnumerate::hasnext, BOXED_BOOL, 1))); enumerate_cls->freeze(); enumerate_cls->tp_iter = PyObject_SelfIter; builtins_module->giveAttr("enumerate", enumerate_cls); - CLFunction* sorted_func = createRTFunction(4, false, false, ParamNames({ "", "cmp", "key", "reverse" }, "", "")); - addRTFunction(sorted_func, (void*)sorted, LIST, { UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }); + FunctionMetadata* sorted_func + = new FunctionMetadata(4, false, false, ParamNames({ "", "cmp", "key", "reverse" }, "", "")); + sorted_func->addVersion((void*)sorted, LIST, { UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }); builtins_module->giveAttr( "sorted", new BoxedBuiltinFunctionOrMethod(sorted_func, "sorted", { None, None, False }, NULL, sorted_doc)); builtins_module->giveAttr("True", True); builtins_module->giveAttr("False", False); - range_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)range, LIST, 3, false, false), "range", + range_obj = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)range, LIST, 3, false, false), "range", { NULL, NULL }, NULL, range_doc); builtins_module->giveAttr("range", range_obj); - auto* round_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)builtinRound, BOXED_FLOAT, 2, false, false), - "round", { boxInt(0) }, NULL, round_doc); + auto* round_obj + = new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)builtinRound, BOXED_FLOAT, 2, false, false), + "round", { boxInt(0) }, NULL, round_doc); builtins_module->giveAttr("round", round_obj); setupXrange(); builtins_module->giveAttr("xrange", xrange_cls); - open_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)open, typeFromClass(file_cls), 3, false, false, - ParamNames({ "name", "mode", "buffering" }, "", "")), - "open", { boxString("r"), boxInt(-1) }, NULL, open_doc); + open_obj = new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)open, typeFromClass(file_cls), 3, false, false, + ParamNames({ "name", "mode", "buffering" }, "", "")), + "open", { boxString("r"), boxInt(-1) }, NULL, open_doc); builtins_module->giveAttr("open", open_obj); - builtins_module->giveAttr("globals", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)globals, UNKNOWN, 0, false, false), - "globals", globals_doc)); builtins_module->giveAttr( - "locals", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)locals, UNKNOWN, 0, false, false), "locals", locals_doc)); - + "globals", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)globals, UNKNOWN, 0, false, false), + "globals", globals_doc)); builtins_module->giveAttr( - "iter", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)builtinIter, UNKNOWN, 2, false, false), "iter", - { NULL }, NULL, iter_doc)); - builtins_module->giveAttr("reversed", new BoxedBuiltinFunctionOrMethod( - boxRTFunction((void*)getreversed, UNKNOWN, 1, false, false), "reversed")); + "locals", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)locals, UNKNOWN, 0, false, false), + "locals", locals_doc)); + builtins_module->giveAttr( - "coerce", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)coerceFunc, UNKNOWN, 2, false, false), "coerce", - coerce_doc)); + "iter", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)builtinIter, UNKNOWN, 2, false, false), + "iter", { NULL }, NULL, iter_doc)); + builtins_module->giveAttr("reversed", + new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)getreversed, UNKNOWN, 1, false, false), "reversed")); builtins_module->giveAttr( - "divmod", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)divmod, UNKNOWN, 2), "divmod", divmod_doc)); + "coerce", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)coerceFunc, UNKNOWN, 2, false, false), "coerce", coerce_doc)); + builtins_module->giveAttr("divmod", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)divmod, UNKNOWN, 2), "divmod", divmod_doc)); - builtins_module->giveAttr("execfile", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)execfile, UNKNOWN, 3, false, false), - "execfile", { NULL, NULL }, NULL, execfile_doc)); + builtins_module->giveAttr("execfile", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)execfile, UNKNOWN, 3, false, false), + "execfile", { NULL, NULL }, NULL, execfile_doc)); - CLFunction* compile_func = createRTFunction( + FunctionMetadata* compile_func = new FunctionMetadata( 5, false, false, ParamNames({ "source", "filename", "mode", "flags", "dont_inherit" }, "", "")); - addRTFunction(compile_func, (void*)compile, UNKNOWN, { UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }); + compile_func->addVersion((void*)compile, UNKNOWN, { UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }); builtins_module->giveAttr("compile", new BoxedBuiltinFunctionOrMethod(compile_func, "compile", { boxInt(0), boxInt(0) }, NULL, compile_doc)); + builtins_module->giveAttr("map", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)map, LIST, 1, true, false), "map", map_doc)); builtins_module->giveAttr( - "map", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)map, LIST, 1, true, false), "map", map_doc)); - builtins_module->giveAttr("reduce", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)reduce, UNKNOWN, 3, false, false), - "reduce", { NULL }, NULL, reduce_doc)); + "reduce", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)reduce, UNKNOWN, 3, false, false), + "reduce", { NULL }, NULL, reduce_doc)); builtins_module->giveAttr( - "filter", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)filter2, UNKNOWN, 2), "filter", filter_doc)); + "filter", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)filter2, UNKNOWN, 2), "filter", filter_doc)); + builtins_module->giveAttr("zip", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)zip, LIST, 0, true, false), "zip", zip_doc)); builtins_module->giveAttr( - "zip", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)zip, LIST, 0, true, false), "zip", zip_doc)); - builtins_module->giveAttr("dir", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)dir, LIST, 1, false, false), - "dir", { NULL }, NULL, dir_doc)); - builtins_module->giveAttr("vars", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)vars, UNKNOWN, 1, false, false), - "vars", { NULL }, NULL, vars_doc)); + "dir", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)dir, LIST, 1, false, false), "dir", + { NULL }, NULL, dir_doc)); + builtins_module->giveAttr( + "vars", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)vars, UNKNOWN, 1, false, false), + "vars", { NULL }, NULL, vars_doc)); builtins_module->giveAttr("object", object_cls); builtins_module->giveAttr("str", str_cls); builtins_module->giveAttr("bytes", str_cls); @@ -2086,21 +2099,23 @@ void setupBuiltins() { PyType_Ready(&PyBuffer_Type); builtins_module->giveAttr("buffer", &PyBuffer_Type); - builtins_module->giveAttr("eval", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)eval, UNKNOWN, 3, false, false), - "eval", { NULL, NULL }, NULL, eval_doc)); - builtins_module->giveAttr("callable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)callable, UNKNOWN, 1), - "callable", callable_doc)); - - builtins_module->giveAttr("raw_input", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)rawInput, UNKNOWN, 1, false, false), - "raw_input", { NULL }, NULL, raw_input_doc)); - builtins_module->giveAttr("input", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)input, UNKNOWN, 1, false, false), - "input", { NULL }, NULL, input_doc)); builtins_module->giveAttr( - "cmp", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)builtinCmp, UNKNOWN, 2), "cmp", cmp_doc)); - builtins_module->giveAttr("format", new BoxedBuiltinFunctionOrMethod( - boxRTFunction((void*)builtinFormat, UNKNOWN, 2), "format", format_doc)); + "eval", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)eval, UNKNOWN, 3, false, false), + "eval", { NULL, NULL }, NULL, eval_doc)); + builtins_module->giveAttr("callable", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)callable, UNKNOWN, 1), + "callable", callable_doc)); + + builtins_module->giveAttr("raw_input", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)rawInput, UNKNOWN, 1, false, false), + "raw_input", { NULL }, NULL, raw_input_doc)); + builtins_module->giveAttr( + "input", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)input, UNKNOWN, 1, false, false), + "input", { NULL }, NULL, input_doc)); + builtins_module->giveAttr("cmp", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)builtinCmp, UNKNOWN, 2), "cmp", cmp_doc)); + builtins_module->giveAttr( + "format", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)builtinFormat, UNKNOWN, 2), "format", + format_doc)); } } diff --git a/src/runtime/builtin_modules/gc.cpp b/src/runtime/builtin_modules/gc.cpp index dc3a3dc40..8fa1e1d0b 100644 --- a/src/runtime/builtin_modules/gc.cpp +++ b/src/runtime/builtin_modules/gc.cpp @@ -61,13 +61,14 @@ PyDoc_STRVAR(gc_collect_doc, "collect() -> n\n" void setupGC() { BoxedModule* gc_module = createModule(boxString("gc")); - gc_module->giveAttr("collect", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)gcCollect, NONE, 0), "collect", - gc_collect_doc)); - gc_module->giveAttr("isenabled", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)isEnabled, BOXED_BOOL, 0), - "isenabled", gc_isenabled_doc)); - gc_module->giveAttr( - "disable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)disable, NONE, 0), "disable", gc_disable_doc)); - gc_module->giveAttr( - "enable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)enable, NONE, 0), "enable", gc_enable_doc)); + gc_module->giveAttr("collect", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)gcCollect, NONE, 0), + "collect", gc_collect_doc)); + gc_module->giveAttr("isenabled", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)isEnabled, BOXED_BOOL, 0), + "isenabled", gc_isenabled_doc)); + gc_module->giveAttr("disable", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)disable, NONE, 0), + "disable", gc_disable_doc)); + gc_module->giveAttr("enable", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)enable, NONE, 0), + "enable", gc_enable_doc)); } } diff --git a/src/runtime/builtin_modules/pyston.cpp b/src/runtime/builtin_modules/pyston.cpp index 80429f129..e6ca5f37a 100644 --- a/src/runtime/builtin_modules/pyston.cpp +++ b/src/runtime/builtin_modules/pyston.cpp @@ -67,13 +67,13 @@ static Box* dumpStats(Box* includeZeros) { void setupPyston() { pyston_module = createModule(boxString("__pyston__")); - pyston_module->giveAttr("setOption", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)setOption, UNKNOWN, 2), "setOption")); + pyston_module->giveAttr("setOption", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)setOption, UNKNOWN, 2), "setOption")); - pyston_module->giveAttr("clearStats", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)clearStats, NONE, 0), "clearStats")); - pyston_module->giveAttr("dumpStats", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)dumpStats, NONE, 1, false, false), - "dumpStats", { False })); + pyston_module->giveAttr("clearStats", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)clearStats, NONE, 0), "clearStats")); + pyston_module->giveAttr( + "dumpStats", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)dumpStats, NONE, 1, false, false), + "dumpStats", { False })); } } diff --git a/src/runtime/builtin_modules/sys.cpp b/src/runtime/builtin_modules/sys.cpp index 38674488c..758c173a6 100644 --- a/src/runtime/builtin_modules/sys.cpp +++ b/src/runtime/builtin_modules/sys.cpp @@ -648,12 +648,15 @@ void setupSys() { sys_module->giveAttr("__stdin__", sys_module->getattr(internStringMortal("stdin"))); sys_module->giveAttr("__stderr__", sys_module->getattr(internStringMortal("stderr"))); - sys_module->giveAttr("exc_info", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExcInfo, BOXED_TUPLE, 0), - "exc_info", exc_info_doc)); - sys_module->giveAttr("exc_clear", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExcClear, NONE, 0), - "exc_clear", exc_clear_doc)); - sys_module->giveAttr("exit", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExit, NONE, 1, false, false), - "exit", { None }, NULL, exit_doc)); + sys_module->giveAttr("exc_info", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)sysExcInfo, BOXED_TUPLE, 0), + "exc_info", exc_info_doc)); + sys_module->giveAttr("exc_clear", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)sysExcClear, NONE, 0), + "exc_clear", exc_clear_doc)); + sys_module->giveAttr( + "exit", new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)sysExit, NONE, 1, false, false), + "exit", { None }, NULL, exit_doc)); sys_module->giveAttr("warnoptions", new BoxedList()); sys_module->giveAttr("py3kwarning", False); @@ -663,19 +666,20 @@ void setupSys() { sys_module->giveAttr("executable", boxString(Py_GetProgramFullPath())); - sys_module->giveAttr("_getframe", - new BoxedFunction(boxRTFunction((void*)sysGetFrame, UNKNOWN, 1, false, false), { NULL })); - sys_module->giveAttr("getdefaultencoding", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetDefaultEncoding, STR, 0), - "getdefaultencoding", getdefaultencoding_doc)); + sys_module->giveAttr( + "_getframe", + new BoxedFunction(FunctionMetadata::create((void*)sysGetFrame, UNKNOWN, 1, false, false), { NULL })); + sys_module->giveAttr("getdefaultencoding", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)sysGetDefaultEncoding, STR, 0), + "getdefaultencoding", getdefaultencoding_doc)); - sys_module->giveAttr("getfilesystemencoding", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetFilesystemEncoding, STR, 0), - "getfilesystemencoding", getfilesystemencoding_doc)); + sys_module->giveAttr("getfilesystemencoding", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)sysGetFilesystemEncoding, STR, 0), + "getfilesystemencoding", getfilesystemencoding_doc)); - sys_module->giveAttr("getrecursionlimit", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetRecursionLimit, UNKNOWN, 0), - "getrecursionlimit", getrecursionlimit_doc)); + sys_module->giveAttr("getrecursionlimit", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)sysGetRecursionLimit, UNKNOWN, 0), + "getrecursionlimit", getrecursionlimit_doc)); sys_module->giveAttr("meta_path", new BoxedList()); sys_module->giveAttr("path_hooks", new BoxedList()); @@ -702,8 +706,8 @@ void setupSys() { sys_flags_cls = new (0) BoxedClass(object_cls, BoxedSysFlags::gcHandler, 0, 0, sizeof(BoxedSysFlags), false, "flags"); - sys_flags_cls->giveAttr("__new__", - new BoxedFunction(boxRTFunction((void*)BoxedSysFlags::__new__, UNKNOWN, 1, true, true))); + sys_flags_cls->giveAttr( + "__new__", new BoxedFunction(FunctionMetadata::create((void*)BoxedSysFlags::__new__, UNKNOWN, 1, true, true))); #define ADD(name) \ sys_flags_cls->giveAttr(STRINGIFY(name), \ new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedSysFlags, name))) diff --git a/src/runtime/builtin_modules/thread.cpp b/src/runtime/builtin_modules/thread.cpp index 45361f8cd..a935245e7 100644 --- a/src/runtime/builtin_modules/thread.cpp +++ b/src/runtime/builtin_modules/thread.cpp @@ -209,17 +209,19 @@ void setupThread() { Box* thread_module = getSysModulesDict()->getOrNull(boxString("thread")); assert(thread_module); - thread_module->giveAttr("start_new_thread", new BoxedBuiltinFunctionOrMethod( - boxRTFunction((void*)startNewThread, BOXED_INT, 3, false, false), - "start_new_thread", { NULL })); - thread_module->giveAttr("allocate_lock", new BoxedBuiltinFunctionOrMethod( - boxRTFunction((void*)allocateLock, UNKNOWN, 0), "allocate_lock")); thread_module->giveAttr( - "get_ident", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)getIdent, BOXED_INT, 0), "get_ident")); + "start_new_thread", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)startNewThread, BOXED_INT, 3, false, false), + "start_new_thread", { NULL })); thread_module->giveAttr( - "stack_size", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)stackSize, BOXED_INT, 0), "stack_size")); - thread_module->giveAttr( - "_count", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)threadCount, BOXED_INT, 0), "_count")); + "allocate_lock", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)allocateLock, UNKNOWN, 0), "allocate_lock")); + thread_module->giveAttr("get_ident", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)getIdent, BOXED_INT, 0), "get_ident")); + thread_module->giveAttr("stack_size", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)stackSize, BOXED_INT, 0), "stack_size")); + thread_module->giveAttr("_count", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)threadCount, BOXED_INT, 0), "_count")); thread_lock_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(BoxedThreadLock), false, "lock"); thread_lock_cls->tp_dealloc = BoxedThreadLock::threadLockDestructor; @@ -227,16 +229,18 @@ void setupThread() { thread_lock_cls->instances_are_nonzero = true; thread_lock_cls->giveAttr("__module__", boxString("thread")); - thread_lock_cls->giveAttr( - "acquire", - new BoxedFunction(boxRTFunction((void*)BoxedThreadLock::acquire, BOXED_BOOL, 2, false, false), { boxInt(1) })); - thread_lock_cls->giveAttr("release", new BoxedFunction(boxRTFunction((void*)BoxedThreadLock::release, NONE, 1))); + thread_lock_cls->giveAttr("acquire", new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::acquire, + BOXED_BOOL, 2, false, false), + { boxInt(1) })); + thread_lock_cls->giveAttr("release", + new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::release, NONE, 1))); thread_lock_cls->giveAttr("acquire_lock", thread_lock_cls->getattr(internStringMortal("acquire"))); thread_lock_cls->giveAttr("release_lock", thread_lock_cls->getattr(internStringMortal("release"))); thread_lock_cls->giveAttr("__enter__", thread_lock_cls->getattr(internStringMortal("acquire"))); - thread_lock_cls->giveAttr("__exit__", new BoxedFunction(boxRTFunction((void*)BoxedThreadLock::exit, NONE, 4))); - thread_lock_cls->giveAttr("locked", - new BoxedFunction(boxRTFunction((void*)BoxedThreadLock::locked, BOXED_BOOL, 1))); + thread_lock_cls->giveAttr("__exit__", + new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::exit, NONE, 4))); + thread_lock_cls->giveAttr( + "locked", new BoxedFunction(FunctionMetadata::create((void*)BoxedThreadLock::locked, BOXED_BOOL, 1))); thread_lock_cls->giveAttr("locked_lock", thread_lock_cls->getattr(internStringMortal("locked"))); thread_lock_cls->freeze(); diff --git a/src/runtime/capi.cpp b/src/runtime/capi.cpp index 5264847e9..ae53d60eb 100644 --- a/src/runtime/capi.cpp +++ b/src/runtime/capi.cpp @@ -1992,9 +1992,10 @@ extern "C" void _Py_FatalError(const char* fmt, const char* function, const char void setupCAPI() { capifunc_cls->giveAttr("__repr__", - new BoxedFunction(boxRTFunction((void*)BoxedCApiFunction::__repr__, UNKNOWN, 1))); + new BoxedFunction(FunctionMetadata::create((void*)BoxedCApiFunction::__repr__, UNKNOWN, 1))); - auto capi_call = new BoxedFunction(boxRTFunction((void*)BoxedCApiFunction::__call__, UNKNOWN, 1, true, true)); + auto capi_call + = new BoxedFunction(FunctionMetadata::create((void*)BoxedCApiFunction::__call__, UNKNOWN, 1, true, true)); capifunc_cls->giveAttr("__call__", capi_call); capifunc_cls->tpp_call.capi_val = BoxedCApiFunction::tppCall; capifunc_cls->tpp_call.cxx_val = BoxedCApiFunction::tppCall; diff --git a/src/runtime/classobj.cpp b/src/runtime/classobj.cpp index 14a6a5d63..6108f88f5 100644 --- a/src/runtime/classobj.cpp +++ b/src/runtime/classobj.cpp @@ -1642,15 +1642,18 @@ void setupClassobj() { instance_cls = BoxedClass::create(type_cls, object_cls, &BoxedInstance::gcHandler, offsetof(BoxedInstance, attrs), offsetof(BoxedInstance, weakreflist), sizeof(BoxedInstance), false, "instance"); - classobj_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)classobjNew, UNKNOWN, 4, false, false))); + classobj_cls->giveAttr("__new__", + new BoxedFunction(FunctionMetadata::create((void*)classobjNew, UNKNOWN, 4, false, false))); - classobj_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)classobjCall, UNKNOWN, 1, true, true))); + classobj_cls->giveAttr("__call__", + new BoxedFunction(FunctionMetadata::create((void*)classobjCall, UNKNOWN, 1, true, true))); classobj_cls->giveAttr("__getattribute__", - new BoxedFunction(boxRTFunction((void*)classobjGetattribute, UNKNOWN, 2))); - classobj_cls->giveAttr("__setattr__", new BoxedFunction(boxRTFunction((void*)classobjSetattr, UNKNOWN, 3))); - classobj_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)classobjStr, STR, 1))); - classobj_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)classobjRepr, STR, 1))); + new BoxedFunction(FunctionMetadata::create((void*)classobjGetattribute, UNKNOWN, 2))); + classobj_cls->giveAttr("__setattr__", + new BoxedFunction(FunctionMetadata::create((void*)classobjSetattr, UNKNOWN, 3))); + classobj_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)classobjStr, STR, 1))); + classobj_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)classobjRepr, STR, 1))); classobj_cls->giveAttr("__dict__", dict_descr); classobj_cls->freeze(); @@ -1665,87 +1668,114 @@ void setupClassobj() { static PyMappingMethods instance_as_mapping; instance_cls->tp_as_mapping = &instance_as_mapping; - instance_cls->giveAttr("__getattribute__", - new BoxedFunction(boxRTFunction((void*)instanceGetattroInternal, UNKNOWN, 2))); - instance_cls->giveAttr("__setattr__", new BoxedFunction(boxRTFunction((void*)instanceSetattr, UNKNOWN, 3))); - instance_cls->giveAttr("__delattr__", new BoxedFunction(boxRTFunction((void*)instanceDelattr, UNKNOWN, 2))); - instance_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)instanceStr, UNKNOWN, 1))); - instance_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)instanceRepr, UNKNOWN, 1))); - instance_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)instanceNonzero, UNKNOWN, 1))); - instance_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)instanceLen, UNKNOWN, 1))); - instance_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)instanceGetitem, UNKNOWN, 2))); - instance_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)instanceSetitem, UNKNOWN, 3))); - instance_cls->giveAttr("__delitem__", new BoxedFunction(boxRTFunction((void*)instanceDelitem, UNKNOWN, 2))); - instance_cls->giveAttr("__getslice__", new BoxedFunction(boxRTFunction((void*)instanceGetslice, UNKNOWN, 3))); - instance_cls->giveAttr("__setslice__", new BoxedFunction(boxRTFunction((void*)instanceSetslice, UNKNOWN, 4))); - instance_cls->giveAttr("__delslice__", new BoxedFunction(boxRTFunction((void*)instanceDelslice, UNKNOWN, 3))); - instance_cls->giveAttr("__cmp__", new BoxedFunction(boxRTFunction((void*)instanceCompare, UNKNOWN, 2))); - instance_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)instanceContains, UNKNOWN, 2))); - instance_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)instanceHash, UNKNOWN, 1))); - instance_cls->giveAttr("__iter__", new BoxedFunction(boxRTFunction((void*)instanceIter, UNKNOWN, 1))); - instance_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)instanceNext, UNKNOWN, 1))); - instance_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)instanceCall, UNKNOWN, 1, true, true))); - instance_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)instanceEq, UNKNOWN, 2))); - instance_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)instanceNe, UNKNOWN, 2))); - instance_cls->giveAttr("__lt__", new BoxedFunction(boxRTFunction((void*)instanceLt, UNKNOWN, 2))); - instance_cls->giveAttr("__le__", new BoxedFunction(boxRTFunction((void*)instanceLe, UNKNOWN, 2))); - instance_cls->giveAttr("__gt__", new BoxedFunction(boxRTFunction((void*)instanceGt, UNKNOWN, 2))); - instance_cls->giveAttr("__ge__", new BoxedFunction(boxRTFunction((void*)instanceGe, UNKNOWN, 2))); - instance_cls->giveAttr("__add__", new BoxedFunction(boxRTFunction((void*)instanceAdd, UNKNOWN, 2))); - instance_cls->giveAttr("__sub__", new BoxedFunction(boxRTFunction((void*)instanceSub, UNKNOWN, 2))); - instance_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)instanceMul, UNKNOWN, 2))); - instance_cls->giveAttr("__floordiv__", new BoxedFunction(boxRTFunction((void*)instanceFloordiv, UNKNOWN, 2))); - instance_cls->giveAttr("__mod__", new BoxedFunction(boxRTFunction((void*)instanceMod, UNKNOWN, 2))); - instance_cls->giveAttr("__divmod__", new BoxedFunction(boxRTFunction((void*)instanceDivMod, UNKNOWN, 2))); - instance_cls->giveAttr("__pow__", new BoxedFunction(boxRTFunction((void*)instancePow, UNKNOWN, 2))); - instance_cls->giveAttr("__lshift__", new BoxedFunction(boxRTFunction((void*)instanceLshift, UNKNOWN, 2))); - instance_cls->giveAttr("__rshift__", new BoxedFunction(boxRTFunction((void*)instanceRshift, UNKNOWN, 2))); - instance_cls->giveAttr("__and__", new BoxedFunction(boxRTFunction((void*)instanceAnd, UNKNOWN, 2))); - instance_cls->giveAttr("__xor__", new BoxedFunction(boxRTFunction((void*)instanceXor, UNKNOWN, 2))); - instance_cls->giveAttr("__or__", new BoxedFunction(boxRTFunction((void*)instanceOr, UNKNOWN, 2))); - instance_cls->giveAttr("__div__", new BoxedFunction(boxRTFunction((void*)instanceDiv, UNKNOWN, 2))); - instance_cls->giveAttr("__truediv__", new BoxedFunction(boxRTFunction((void*)instanceTruediv, UNKNOWN, 2))); - - instance_cls->giveAttr("__radd__", new BoxedFunction(boxRTFunction((void*)instanceRadd, UNKNOWN, 2))); - instance_cls->giveAttr("__rsub__", new BoxedFunction(boxRTFunction((void*)instanceRsub, UNKNOWN, 2))); - instance_cls->giveAttr("__rmul__", new BoxedFunction(boxRTFunction((void*)instanceRmul, UNKNOWN, 2))); - instance_cls->giveAttr("__rdiv__", new BoxedFunction(boxRTFunction((void*)instanceRdiv, UNKNOWN, 2))); - instance_cls->giveAttr("__rtruediv__", new BoxedFunction(boxRTFunction((void*)instanceRtruediv, UNKNOWN, 2))); - instance_cls->giveAttr("__rfloordiv__", new BoxedFunction(boxRTFunction((void*)instanceRfloordiv, UNKNOWN, 2))); - instance_cls->giveAttr("__rmod__", new BoxedFunction(boxRTFunction((void*)instanceRmod, UNKNOWN, 2))); - instance_cls->giveAttr("__rdivmod__", new BoxedFunction(boxRTFunction((void*)instanceRdivmod, UNKNOWN, 2))); - instance_cls->giveAttr("__rpow__", new BoxedFunction(boxRTFunction((void*)instanceRpow, UNKNOWN, 2))); - instance_cls->giveAttr("__rlshift__", new BoxedFunction(boxRTFunction((void*)instanceRlshift, UNKNOWN, 2))); - instance_cls->giveAttr("__rrshift__", new BoxedFunction(boxRTFunction((void*)instanceRrshift, UNKNOWN, 2))); - instance_cls->giveAttr("__rand__", new BoxedFunction(boxRTFunction((void*)instanceRand, UNKNOWN, 2))); - instance_cls->giveAttr("__rxor__", new BoxedFunction(boxRTFunction((void*)instanceRxor, UNKNOWN, 2))); - instance_cls->giveAttr("__ror__", new BoxedFunction(boxRTFunction((void*)instanceRor, UNKNOWN, 2))); - - instance_cls->giveAttr("__iadd__", new BoxedFunction(boxRTFunction((void*)instanceIadd, UNKNOWN, 2))); - instance_cls->giveAttr("__isub__", new BoxedFunction(boxRTFunction((void*)instanceIsub, UNKNOWN, 2))); - instance_cls->giveAttr("__imul__", new BoxedFunction(boxRTFunction((void*)instanceImul, UNKNOWN, 2))); - instance_cls->giveAttr("__idiv__", new BoxedFunction(boxRTFunction((void*)instanceIdiv, UNKNOWN, 2))); - instance_cls->giveAttr("__itruediv__", new BoxedFunction(boxRTFunction((void*)instanceItruediv, UNKNOWN, 2))); - instance_cls->giveAttr("__ifloordiv__", new BoxedFunction(boxRTFunction((void*)instanceIfloordiv, UNKNOWN, 2))); - instance_cls->giveAttr("__imod__", new BoxedFunction(boxRTFunction((void*)instanceImod, UNKNOWN, 2))); - instance_cls->giveAttr("__ipow__", new BoxedFunction(boxRTFunction((void*)instanceIpow, UNKNOWN, 2))); - instance_cls->giveAttr("__ilshift__", new BoxedFunction(boxRTFunction((void*)instanceIlshift, UNKNOWN, 2))); - instance_cls->giveAttr("__irshift__", new BoxedFunction(boxRTFunction((void*)instanceIrshift, UNKNOWN, 2))); - instance_cls->giveAttr("__iand__", new BoxedFunction(boxRTFunction((void*)instanceIand, UNKNOWN, 2))); - instance_cls->giveAttr("__ixor__", new BoxedFunction(boxRTFunction((void*)instanceIxor, UNKNOWN, 2))); - instance_cls->giveAttr("__ior__", new BoxedFunction(boxRTFunction((void*)instanceIor, UNKNOWN, 2))); - - instance_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)instanceNeg, UNKNOWN, 1))); - instance_cls->giveAttr("__pos__", new BoxedFunction(boxRTFunction((void*)instancePos, UNKNOWN, 1))); - instance_cls->giveAttr("__abs__", new BoxedFunction(boxRTFunction((void*)instanceAbs, UNKNOWN, 1))); - instance_cls->giveAttr("__invert__", new BoxedFunction(boxRTFunction((void*)instanceInvert, UNKNOWN, 1))); - instance_cls->giveAttr("__int__", new BoxedFunction(boxRTFunction((void*)instanceInt, UNKNOWN, 1))); - instance_cls->giveAttr("__long__", new BoxedFunction(boxRTFunction((void*)instanceLong, UNKNOWN, 1))); - instance_cls->giveAttr("__float__", new BoxedFunction(boxRTFunction((void*)instanceFloat, UNKNOWN, 1))); - instance_cls->giveAttr("__oct__", new BoxedFunction(boxRTFunction((void*)instanceOct, UNKNOWN, 1))); - instance_cls->giveAttr("__hex__", new BoxedFunction(boxRTFunction((void*)instanceHex, UNKNOWN, 1))); - instance_cls->giveAttr("__coerce__", new BoxedFunction(boxRTFunction((void*)instanceCoerce, UNKNOWN, 2))); - instance_cls->giveAttr("__index__", new BoxedFunction(boxRTFunction((void*)instanceIndex, UNKNOWN, 1))); + instance_cls->giveAttr("__getattribute__", new BoxedFunction(FunctionMetadata::create( + (void*)instanceGetattroInternal, UNKNOWN, 2))); + instance_cls->giveAttr("__setattr__", + new BoxedFunction(FunctionMetadata::create((void*)instanceSetattr, UNKNOWN, 3))); + instance_cls->giveAttr("__delattr__", + new BoxedFunction(FunctionMetadata::create((void*)instanceDelattr, UNKNOWN, 2))); + instance_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)instanceStr, UNKNOWN, 1))); + instance_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)instanceRepr, UNKNOWN, 1))); + instance_cls->giveAttr("__nonzero__", + new BoxedFunction(FunctionMetadata::create((void*)instanceNonzero, UNKNOWN, 1))); + instance_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)instanceLen, UNKNOWN, 1))); + instance_cls->giveAttr("__getitem__", + new BoxedFunction(FunctionMetadata::create((void*)instanceGetitem, UNKNOWN, 2))); + instance_cls->giveAttr("__setitem__", + new BoxedFunction(FunctionMetadata::create((void*)instanceSetitem, UNKNOWN, 3))); + instance_cls->giveAttr("__delitem__", + new BoxedFunction(FunctionMetadata::create((void*)instanceDelitem, UNKNOWN, 2))); + instance_cls->giveAttr("__getslice__", + new BoxedFunction(FunctionMetadata::create((void*)instanceGetslice, UNKNOWN, 3))); + instance_cls->giveAttr("__setslice__", + new BoxedFunction(FunctionMetadata::create((void*)instanceSetslice, UNKNOWN, 4))); + instance_cls->giveAttr("__delslice__", + new BoxedFunction(FunctionMetadata::create((void*)instanceDelslice, UNKNOWN, 3))); + instance_cls->giveAttr("__cmp__", new BoxedFunction(FunctionMetadata::create((void*)instanceCompare, UNKNOWN, 2))); + instance_cls->giveAttr("__contains__", + new BoxedFunction(FunctionMetadata::create((void*)instanceContains, UNKNOWN, 2))); + instance_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)instanceHash, UNKNOWN, 1))); + instance_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)instanceIter, UNKNOWN, 1))); + instance_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)instanceNext, UNKNOWN, 1))); + instance_cls->giveAttr("__call__", + new BoxedFunction(FunctionMetadata::create((void*)instanceCall, UNKNOWN, 1, true, true))); + instance_cls->giveAttr("__eq__", new BoxedFunction(FunctionMetadata::create((void*)instanceEq, UNKNOWN, 2))); + instance_cls->giveAttr("__ne__", new BoxedFunction(FunctionMetadata::create((void*)instanceNe, UNKNOWN, 2))); + instance_cls->giveAttr("__lt__", new BoxedFunction(FunctionMetadata::create((void*)instanceLt, UNKNOWN, 2))); + instance_cls->giveAttr("__le__", new BoxedFunction(FunctionMetadata::create((void*)instanceLe, UNKNOWN, 2))); + instance_cls->giveAttr("__gt__", new BoxedFunction(FunctionMetadata::create((void*)instanceGt, UNKNOWN, 2))); + instance_cls->giveAttr("__ge__", new BoxedFunction(FunctionMetadata::create((void*)instanceGe, UNKNOWN, 2))); + instance_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)instanceAdd, UNKNOWN, 2))); + instance_cls->giveAttr("__sub__", new BoxedFunction(FunctionMetadata::create((void*)instanceSub, UNKNOWN, 2))); + instance_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)instanceMul, UNKNOWN, 2))); + instance_cls->giveAttr("__floordiv__", + new BoxedFunction(FunctionMetadata::create((void*)instanceFloordiv, UNKNOWN, 2))); + instance_cls->giveAttr("__mod__", new BoxedFunction(FunctionMetadata::create((void*)instanceMod, UNKNOWN, 2))); + instance_cls->giveAttr("__divmod__", + new BoxedFunction(FunctionMetadata::create((void*)instanceDivMod, UNKNOWN, 2))); + instance_cls->giveAttr("__pow__", new BoxedFunction(FunctionMetadata::create((void*)instancePow, UNKNOWN, 2))); + instance_cls->giveAttr("__lshift__", + new BoxedFunction(FunctionMetadata::create((void*)instanceLshift, UNKNOWN, 2))); + instance_cls->giveAttr("__rshift__", + new BoxedFunction(FunctionMetadata::create((void*)instanceRshift, UNKNOWN, 2))); + instance_cls->giveAttr("__and__", new BoxedFunction(FunctionMetadata::create((void*)instanceAnd, UNKNOWN, 2))); + instance_cls->giveAttr("__xor__", new BoxedFunction(FunctionMetadata::create((void*)instanceXor, UNKNOWN, 2))); + instance_cls->giveAttr("__or__", new BoxedFunction(FunctionMetadata::create((void*)instanceOr, UNKNOWN, 2))); + instance_cls->giveAttr("__div__", new BoxedFunction(FunctionMetadata::create((void*)instanceDiv, UNKNOWN, 2))); + instance_cls->giveAttr("__truediv__", + new BoxedFunction(FunctionMetadata::create((void*)instanceTruediv, UNKNOWN, 2))); + + instance_cls->giveAttr("__radd__", new BoxedFunction(FunctionMetadata::create((void*)instanceRadd, UNKNOWN, 2))); + instance_cls->giveAttr("__rsub__", new BoxedFunction(FunctionMetadata::create((void*)instanceRsub, UNKNOWN, 2))); + instance_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)instanceRmul, UNKNOWN, 2))); + instance_cls->giveAttr("__rdiv__", new BoxedFunction(FunctionMetadata::create((void*)instanceRdiv, UNKNOWN, 2))); + instance_cls->giveAttr("__rtruediv__", + new BoxedFunction(FunctionMetadata::create((void*)instanceRtruediv, UNKNOWN, 2))); + instance_cls->giveAttr("__rfloordiv__", + new BoxedFunction(FunctionMetadata::create((void*)instanceRfloordiv, UNKNOWN, 2))); + instance_cls->giveAttr("__rmod__", new BoxedFunction(FunctionMetadata::create((void*)instanceRmod, UNKNOWN, 2))); + instance_cls->giveAttr("__rdivmod__", + new BoxedFunction(FunctionMetadata::create((void*)instanceRdivmod, UNKNOWN, 2))); + instance_cls->giveAttr("__rpow__", new BoxedFunction(FunctionMetadata::create((void*)instanceRpow, UNKNOWN, 2))); + instance_cls->giveAttr("__rlshift__", + new BoxedFunction(FunctionMetadata::create((void*)instanceRlshift, UNKNOWN, 2))); + instance_cls->giveAttr("__rrshift__", + new BoxedFunction(FunctionMetadata::create((void*)instanceRrshift, UNKNOWN, 2))); + instance_cls->giveAttr("__rand__", new BoxedFunction(FunctionMetadata::create((void*)instanceRand, UNKNOWN, 2))); + instance_cls->giveAttr("__rxor__", new BoxedFunction(FunctionMetadata::create((void*)instanceRxor, UNKNOWN, 2))); + instance_cls->giveAttr("__ror__", new BoxedFunction(FunctionMetadata::create((void*)instanceRor, UNKNOWN, 2))); + + instance_cls->giveAttr("__iadd__", new BoxedFunction(FunctionMetadata::create((void*)instanceIadd, UNKNOWN, 2))); + instance_cls->giveAttr("__isub__", new BoxedFunction(FunctionMetadata::create((void*)instanceIsub, UNKNOWN, 2))); + instance_cls->giveAttr("__imul__", new BoxedFunction(FunctionMetadata::create((void*)instanceImul, UNKNOWN, 2))); + instance_cls->giveAttr("__idiv__", new BoxedFunction(FunctionMetadata::create((void*)instanceIdiv, UNKNOWN, 2))); + instance_cls->giveAttr("__itruediv__", + new BoxedFunction(FunctionMetadata::create((void*)instanceItruediv, UNKNOWN, 2))); + instance_cls->giveAttr("__ifloordiv__", + new BoxedFunction(FunctionMetadata::create((void*)instanceIfloordiv, UNKNOWN, 2))); + instance_cls->giveAttr("__imod__", new BoxedFunction(FunctionMetadata::create((void*)instanceImod, UNKNOWN, 2))); + instance_cls->giveAttr("__ipow__", new BoxedFunction(FunctionMetadata::create((void*)instanceIpow, UNKNOWN, 2))); + instance_cls->giveAttr("__ilshift__", + new BoxedFunction(FunctionMetadata::create((void*)instanceIlshift, UNKNOWN, 2))); + instance_cls->giveAttr("__irshift__", + new BoxedFunction(FunctionMetadata::create((void*)instanceIrshift, UNKNOWN, 2))); + instance_cls->giveAttr("__iand__", new BoxedFunction(FunctionMetadata::create((void*)instanceIand, UNKNOWN, 2))); + instance_cls->giveAttr("__ixor__", new BoxedFunction(FunctionMetadata::create((void*)instanceIxor, UNKNOWN, 2))); + instance_cls->giveAttr("__ior__", new BoxedFunction(FunctionMetadata::create((void*)instanceIor, UNKNOWN, 2))); + + instance_cls->giveAttr("__neg__", new BoxedFunction(FunctionMetadata::create((void*)instanceNeg, UNKNOWN, 1))); + instance_cls->giveAttr("__pos__", new BoxedFunction(FunctionMetadata::create((void*)instancePos, UNKNOWN, 1))); + instance_cls->giveAttr("__abs__", new BoxedFunction(FunctionMetadata::create((void*)instanceAbs, UNKNOWN, 1))); + instance_cls->giveAttr("__invert__", + new BoxedFunction(FunctionMetadata::create((void*)instanceInvert, UNKNOWN, 1))); + instance_cls->giveAttr("__int__", new BoxedFunction(FunctionMetadata::create((void*)instanceInt, UNKNOWN, 1))); + instance_cls->giveAttr("__long__", new BoxedFunction(FunctionMetadata::create((void*)instanceLong, UNKNOWN, 1))); + instance_cls->giveAttr("__float__", new BoxedFunction(FunctionMetadata::create((void*)instanceFloat, UNKNOWN, 1))); + instance_cls->giveAttr("__oct__", new BoxedFunction(FunctionMetadata::create((void*)instanceOct, UNKNOWN, 1))); + instance_cls->giveAttr("__hex__", new BoxedFunction(FunctionMetadata::create((void*)instanceHex, UNKNOWN, 1))); + instance_cls->giveAttr("__coerce__", + new BoxedFunction(FunctionMetadata::create((void*)instanceCoerce, UNKNOWN, 2))); + instance_cls->giveAttr("__index__", new BoxedFunction(FunctionMetadata::create((void*)instanceIndex, UNKNOWN, 1))); instance_cls->freeze(); instance_cls->tp_getattro = instance_getattro; diff --git a/src/runtime/code.cpp b/src/runtime/code.cpp index 68a4c6a0b..7f13b702f 100644 --- a/src/runtime/code.cpp +++ b/src/runtime/code.cpp @@ -44,7 +44,7 @@ Box* BoxedCode::filename(Box* b, void*) { Box* BoxedCode::firstlineno(Box* b, void*) { RELEASE_ASSERT(b->cls == code_cls, ""); BoxedCode* code = static_cast(b); - CLFunction* cl = code->f; + FunctionMetadata* cl = code->f; if (!cl->source) { // I don't think it really matters what we return here; @@ -100,7 +100,7 @@ Box* codeForFunction(BoxedFunction* f) { return f->f->getCode(); } -CLFunction* clfunctionFromCode(Box* code) { +FunctionMetadata* clfunctionFromCode(Box* code) { assert(code->cls == code_cls); return static_cast(code)->f; } diff --git a/src/runtime/code.h b/src/runtime/code.h index e14654525..3fcd3255c 100644 --- a/src/runtime/code.h +++ b/src/runtime/code.h @@ -23,9 +23,9 @@ namespace pyston { class BoxedCode : public Box { public: - CLFunction* f; + FunctionMetadata* f; - BoxedCode(CLFunction* f) : f(f) {} + BoxedCode(FunctionMetadata* f) : f(f) {} DEFAULT_CLASS(code_cls); diff --git a/src/runtime/complex.cpp b/src/runtime/complex.cpp index 9b196fbc5..b0991f525 100644 --- a/src/runtime/complex.cpp +++ b/src/runtime/complex.cpp @@ -390,11 +390,11 @@ Box* complex_fmt(double r, double i, int precision, char format_code) noexcept { static void _addFunc(const char* name, ConcreteCompilerType* rtn_type, void* complex_func, void* float_func, void* int_func, void* boxed_func) { - CLFunction* cl = createRTFunction(2, false, false); - addRTFunction(cl, complex_func, rtn_type, { BOXED_COMPLEX, BOXED_COMPLEX }); - addRTFunction(cl, float_func, rtn_type, { BOXED_COMPLEX, BOXED_FLOAT }); - addRTFunction(cl, int_func, rtn_type, { BOXED_COMPLEX, BOXED_INT }); - addRTFunction(cl, boxed_func, UNKNOWN, { BOXED_COMPLEX, UNKNOWN }); + FunctionMetadata* cl = new FunctionMetadata(2, false, false); + cl->addVersion(complex_func, rtn_type, { BOXED_COMPLEX, BOXED_COMPLEX }); + cl->addVersion(float_func, rtn_type, { BOXED_COMPLEX, BOXED_FLOAT }); + cl->addVersion(int_func, rtn_type, { BOXED_COMPLEX, BOXED_INT }); + cl->addVersion(boxed_func, UNKNOWN, { BOXED_COMPLEX, UNKNOWN }); complex_cls->giveAttr(name, new BoxedFunction(cl)); } @@ -1229,9 +1229,9 @@ void setupComplex() { static PyNumberMethods complex_as_number; complex_cls->tp_as_number = &complex_as_number; - auto complex_new = boxRTFunction((void*)complexNew, UNKNOWN, 3, false, false, - ParamNames({ "", "real", "imag" }, "", ""), CXX); - addRTFunction(complex_new, (void*)complexNew, UNKNOWN, CAPI); + auto complex_new = FunctionMetadata::create((void*)complexNew, UNKNOWN, 3, false, false, + ParamNames({ "", "real", "imag" }, "", ""), CXX); + complex_new->addVersion((void*)complexNew, UNKNOWN, CAPI); complex_cls->giveAttr("__new__", new BoxedFunction(complex_new, { NULL, NULL })); _addFunc("__add__", BOXED_COMPLEX, (void*)complexAddComplex, (void*)complexAddFloat, (void*)complexAddInt, @@ -1250,31 +1250,37 @@ void setupComplex() { _addFunc("__div__", BOXED_COMPLEX, (void*)complexDivComplex, (void*)complexDivFloat, (void*)complexDivInt, (void*)complexDiv); - complex_cls->giveAttr("__rsub__", new BoxedFunction(boxRTFunction((void*)complexRSub, UNKNOWN, 2))); - complex_cls->giveAttr("__rdiv__", new BoxedFunction(boxRTFunction((void*)complexRDiv, UNKNOWN, 2))); - complex_cls->giveAttr("__pow__", - new BoxedFunction(boxRTFunction((void*)complexPow, UNKNOWN, 3, false, false), { None })); - complex_cls->giveAttr("__mod__", new BoxedFunction(boxRTFunction((void*)complexMod, UNKNOWN, 2))); - complex_cls->giveAttr("__divmod__", new BoxedFunction(boxRTFunction((void*)complexDivmod, BOXED_TUPLE, 2))); - complex_cls->giveAttr("__floordiv__", new BoxedFunction(boxRTFunction((void*)complexFloordiv, UNKNOWN, 2))); - - complex_cls->giveAttr("__truediv__", new BoxedFunction(boxRTFunction((void*)complexDivComplex, BOXED_COMPLEX, 2))); - complex_cls->giveAttr("conjugate", new BoxedFunction(boxRTFunction((void*)complexConjugate, BOXED_COMPLEX, 1))); - complex_cls->giveAttr("__coerce__", new BoxedFunction(boxRTFunction((void*)complexCoerce, UNKNOWN, 2))); - complex_cls->giveAttr("__abs__", new BoxedFunction(boxRTFunction((void*)complexAbs, BOXED_FLOAT, 1))); - complex_cls->giveAttr("__getnewargs__", new BoxedFunction(boxRTFunction((void*)complexGetnewargs, BOXED_TUPLE, 1))); - complex_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)complexNonzero, BOXED_BOOL, 1))); - complex_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)complexEq, UNKNOWN, 2))); - complex_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)complexNe, UNKNOWN, 2))); - complex_cls->giveAttr("__le__", new BoxedFunction(boxRTFunction((void*)complexLe, UNKNOWN, 2))); - complex_cls->giveAttr("__lt__", new BoxedFunction(boxRTFunction((void*)complexLt, UNKNOWN, 2))); - complex_cls->giveAttr("__ge__", new BoxedFunction(boxRTFunction((void*)complexGe, UNKNOWN, 2))); - complex_cls->giveAttr("__gt__", new BoxedFunction(boxRTFunction((void*)complexGt, UNKNOWN, 2))); - complex_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)complexNeg, BOXED_COMPLEX, 1))); - complex_cls->giveAttr("__pos__", new BoxedFunction(boxRTFunction((void*)complexPos, BOXED_COMPLEX, 1))); - complex_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)complexHash, BOXED_INT, 1))); - complex_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)complexStr, STR, 1))); - complex_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)complexRepr, STR, 1))); + complex_cls->giveAttr("__rsub__", new BoxedFunction(FunctionMetadata::create((void*)complexRSub, UNKNOWN, 2))); + complex_cls->giveAttr("__rdiv__", new BoxedFunction(FunctionMetadata::create((void*)complexRDiv, UNKNOWN, 2))); + complex_cls->giveAttr( + "__pow__", new BoxedFunction(FunctionMetadata::create((void*)complexPow, UNKNOWN, 3, false, false), { None })); + complex_cls->giveAttr("__mod__", new BoxedFunction(FunctionMetadata::create((void*)complexMod, UNKNOWN, 2))); + complex_cls->giveAttr("__divmod__", + new BoxedFunction(FunctionMetadata::create((void*)complexDivmod, BOXED_TUPLE, 2))); + complex_cls->giveAttr("__floordiv__", + new BoxedFunction(FunctionMetadata::create((void*)complexFloordiv, UNKNOWN, 2))); + + complex_cls->giveAttr("__truediv__", + new BoxedFunction(FunctionMetadata::create((void*)complexDivComplex, BOXED_COMPLEX, 2))); + complex_cls->giveAttr("conjugate", + new BoxedFunction(FunctionMetadata::create((void*)complexConjugate, BOXED_COMPLEX, 1))); + complex_cls->giveAttr("__coerce__", new BoxedFunction(FunctionMetadata::create((void*)complexCoerce, UNKNOWN, 2))); + complex_cls->giveAttr("__abs__", new BoxedFunction(FunctionMetadata::create((void*)complexAbs, BOXED_FLOAT, 1))); + complex_cls->giveAttr("__getnewargs__", + new BoxedFunction(FunctionMetadata::create((void*)complexGetnewargs, BOXED_TUPLE, 1))); + complex_cls->giveAttr("__nonzero__", + new BoxedFunction(FunctionMetadata::create((void*)complexNonzero, BOXED_BOOL, 1))); + complex_cls->giveAttr("__eq__", new BoxedFunction(FunctionMetadata::create((void*)complexEq, UNKNOWN, 2))); + complex_cls->giveAttr("__ne__", new BoxedFunction(FunctionMetadata::create((void*)complexNe, UNKNOWN, 2))); + complex_cls->giveAttr("__le__", new BoxedFunction(FunctionMetadata::create((void*)complexLe, UNKNOWN, 2))); + complex_cls->giveAttr("__lt__", new BoxedFunction(FunctionMetadata::create((void*)complexLt, UNKNOWN, 2))); + complex_cls->giveAttr("__ge__", new BoxedFunction(FunctionMetadata::create((void*)complexGe, UNKNOWN, 2))); + complex_cls->giveAttr("__gt__", new BoxedFunction(FunctionMetadata::create((void*)complexGt, UNKNOWN, 2))); + complex_cls->giveAttr("__neg__", new BoxedFunction(FunctionMetadata::create((void*)complexNeg, BOXED_COMPLEX, 1))); + complex_cls->giveAttr("__pos__", new BoxedFunction(FunctionMetadata::create((void*)complexPos, BOXED_COMPLEX, 1))); + complex_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)complexHash, BOXED_INT, 1))); + complex_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)complexStr, STR, 1))); + complex_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)complexRepr, STR, 1))); complex_cls->giveAttr("real", new BoxedMemberDescriptor(BoxedMemberDescriptor::DOUBLE, offsetof(BoxedComplex, real))); complex_cls->giveAttr("imag", diff --git a/src/runtime/descr.cpp b/src/runtime/descr.cpp index 110a49337..b7a5ef152 100644 --- a/src/runtime/descr.cpp +++ b/src/runtime/descr.cpp @@ -706,21 +706,22 @@ extern "C" PyObject* PyDescr_NewMethod(PyTypeObject* type, PyMethodDef* method) } void setupDescr() { - member_descriptor_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)memberGet, UNKNOWN, 3))); + member_descriptor_cls->giveAttr("__get__", + new BoxedFunction(FunctionMetadata::create((void*)memberGet, UNKNOWN, 3))); member_descriptor_cls->freeze(); property_cls->instances_are_nonzero = true; - property_cls->giveAttr("__init__", - new BoxedFunction(boxRTFunction((void*)propertyInit, UNKNOWN, 5, false, false, - ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")), - { NULL, NULL, NULL, NULL })); - property_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)propertyGet, UNKNOWN, 3))); - property_cls->giveAttr("__set__", new BoxedFunction(boxRTFunction((void*)propertySet, UNKNOWN, 3))); - property_cls->giveAttr("__delete__", new BoxedFunction(boxRTFunction((void*)propertyDel, UNKNOWN, 2))); - property_cls->giveAttr("getter", new BoxedFunction(boxRTFunction((void*)propertyGetter, UNKNOWN, 2))); - property_cls->giveAttr("setter", new BoxedFunction(boxRTFunction((void*)propertySetter, UNKNOWN, 2))); - property_cls->giveAttr("deleter", new BoxedFunction(boxRTFunction((void*)propertyDeleter, UNKNOWN, 2))); + property_cls->giveAttr("__init__", new BoxedFunction(FunctionMetadata::create( + (void*)propertyInit, UNKNOWN, 5, false, false, + ParamNames({ "", "fget", "fset", "fdel", "doc" }, "", "")), + { NULL, NULL, NULL, NULL })); + property_cls->giveAttr("__get__", new BoxedFunction(FunctionMetadata::create((void*)propertyGet, UNKNOWN, 3))); + property_cls->giveAttr("__set__", new BoxedFunction(FunctionMetadata::create((void*)propertySet, UNKNOWN, 3))); + property_cls->giveAttr("__delete__", new BoxedFunction(FunctionMetadata::create((void*)propertyDel, UNKNOWN, 2))); + property_cls->giveAttr("getter", new BoxedFunction(FunctionMetadata::create((void*)propertyGetter, UNKNOWN, 2))); + property_cls->giveAttr("setter", new BoxedFunction(FunctionMetadata::create((void*)propertySetter, UNKNOWN, 2))); + property_cls->giveAttr("deleter", new BoxedFunction(FunctionMetadata::create((void*)propertyDeleter, UNKNOWN, 2))); property_cls->giveAttr("fget", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_get))); property_cls->giveAttr("fset", @@ -731,50 +732,55 @@ void setupDescr() { new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedProperty, prop_doc))); property_cls->freeze(); - staticmethod_cls->giveAttr("__init__", - new BoxedFunction(boxRTFunction((void*)staticmethodInit, UNKNOWN, 5, false, false), - { None, None, None, None })); staticmethod_cls->giveAttr( - "__get__", new BoxedFunction(boxRTFunction((void*)staticmethodGet, UNKNOWN, 3, false, false), { None })); + "__init__", new BoxedFunction(FunctionMetadata::create((void*)staticmethodInit, UNKNOWN, 5, false, false), + { None, None, None, None })); + staticmethod_cls->giveAttr( + "__get__", + new BoxedFunction(FunctionMetadata::create((void*)staticmethodGet, UNKNOWN, 3, false, false), { None })); staticmethod_cls->freeze(); classmethod_cls->giveAttr( - "__init__", - new BoxedFunction(boxRTFunction((void*)classmethodInit, UNKNOWN, 5, false, false), { None, None, None, None })); + "__init__", new BoxedFunction(FunctionMetadata::create((void*)classmethodInit, UNKNOWN, 5, false, false), + { None, None, None, None })); classmethod_cls->giveAttr( - "__get__", new BoxedFunction(boxRTFunction((void*)classmethodGet, UNKNOWN, 3, false, false), { None })); + "__get__", + new BoxedFunction(FunctionMetadata::create((void*)classmethodGet, UNKNOWN, 3, false, false), { None })); classmethod_cls->freeze(); - method_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)BoxedMethodDescriptor::descr_get, UNKNOWN, 3, - ParamNames::empty(), CAPI))); - CLFunction* method_call_cl = boxRTFunction((void*)BoxedMethodDescriptor::__call__, UNKNOWN, 2, true, true); + method_cls->giveAttr("__get__", new BoxedFunction(FunctionMetadata::create((void*)BoxedMethodDescriptor::descr_get, + UNKNOWN, 3, ParamNames::empty(), CAPI))); + FunctionMetadata* method_call_cl + = FunctionMetadata::create((void*)BoxedMethodDescriptor::__call__, UNKNOWN, 2, true, true); method_cls->giveAttr("__call__", new BoxedFunction(method_call_cl)); method_cls->tpp_call.capi_val = BoxedMethodDescriptor::tppCall; method_cls->tpp_call.cxx_val = BoxedMethodDescriptor::tppCall; method_cls->giveAttr("__doc__", new (pyston_getset_cls) BoxedGetsetDescriptor(methodGetDoc, NULL, NULL)); - method_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)methodRepr, UNKNOWN, 1))); + method_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)methodRepr, UNKNOWN, 1))); method_cls->freeze(); - wrapperdescr_cls->giveAttr( - "__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperDescriptor::__call__, UNKNOWN, 2, true, true))); + wrapperdescr_cls->giveAttr("__call__", new BoxedFunction(FunctionMetadata::create( + (void*)BoxedWrapperDescriptor::__call__, UNKNOWN, 2, true, true))); wrapperdescr_cls->giveAttr("__doc__", new (pyston_getset_cls) BoxedGetsetDescriptor(wrapperdescrGetDoc, NULL, NULL)); wrapperdescr_cls->tp_descr_get = BoxedWrapperDescriptor::descr_get; wrapperdescr_cls->tpp_call.capi_val = BoxedWrapperDescriptor::tppCall; wrapperdescr_cls->tpp_call.cxx_val = BoxedWrapperDescriptor::tppCall; add_operators(wrapperdescr_cls); - wrapperdescr_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)wrapperDescrRepr, UNKNOWN, 1))); + wrapperdescr_cls->giveAttr("__repr__", + new BoxedFunction(FunctionMetadata::create((void*)wrapperDescrRepr, UNKNOWN, 1))); wrapperdescr_cls->freeze(); assert(wrapperdescr_cls->tp_descr_get == BoxedWrapperDescriptor::descr_get); - wrapperobject_cls->giveAttr( - "__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperObject::__call__, UNKNOWN, 1, true, true))); + wrapperobject_cls->giveAttr("__call__", new BoxedFunction(FunctionMetadata::create( + (void*)BoxedWrapperObject::__call__, UNKNOWN, 1, true, true))); wrapperobject_cls->tpp_call.capi_val = BoxedWrapperObject::tppCall; wrapperobject_cls->tpp_call.cxx_val = BoxedWrapperObject::tppCall; wrapperobject_cls->giveAttr("__doc__", new (pyston_getset_cls) BoxedGetsetDescriptor(wrapperobjectGetDoc, NULL, NULL)); - wrapperobject_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)wrapperObjectRepr, UNKNOWN, 1))); + wrapperobject_cls->giveAttr("__repr__", + new BoxedFunction(FunctionMetadata::create((void*)wrapperObjectRepr, UNKNOWN, 1))); wrapperobject_cls->freeze(); } diff --git a/src/runtime/dict.cpp b/src/runtime/dict.cpp index 309dccd32..f9021401f 100644 --- a/src/runtime/dict.cpp +++ b/src/runtime/dict.cpp @@ -810,66 +810,70 @@ void setupDict() { dict_cls->tp_dealloc = &BoxedDict::dealloc; dict_cls->has_safe_tp_dealloc = true; - dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, BOXED_INT, 1))); - dict_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)dictNew, UNKNOWN, 1, true, true))); - dict_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)dictInit, NONE, 1, true, true))); - dict_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)dictRepr, STR, 1))); + dict_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)dictLen, BOXED_INT, 1))); + dict_cls->giveAttr("__new__", new BoxedFunction(FunctionMetadata::create((void*)dictNew, UNKNOWN, 1, true, true))); + dict_cls->giveAttr("__init__", new BoxedFunction(FunctionMetadata::create((void*)dictInit, NONE, 1, true, true))); + dict_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)dictRepr, STR, 1))); - dict_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)dictEq, UNKNOWN, 2))); - dict_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)dictNe, UNKNOWN, 2))); + dict_cls->giveAttr("__eq__", new BoxedFunction(FunctionMetadata::create((void*)dictEq, UNKNOWN, 2))); + dict_cls->giveAttr("__ne__", new BoxedFunction(FunctionMetadata::create((void*)dictNe, UNKNOWN, 2))); - dict_cls->giveAttr("__iter__", - new BoxedFunction(boxRTFunction((void*)dictIterKeys, typeFromClass(dict_iterator_cls), 1))); + dict_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)dictIterKeys, + typeFromClass(dict_iterator_cls), 1))); - dict_cls->giveAttr("update", new BoxedFunction(boxRTFunction((void*)dictUpdate, NONE, 1, true, true))); + dict_cls->giveAttr("update", new BoxedFunction(FunctionMetadata::create((void*)dictUpdate, NONE, 1, true, true))); - dict_cls->giveAttr("clear", new BoxedFunction(boxRTFunction((void*)dictClear, NONE, 1))); - dict_cls->giveAttr("copy", new BoxedFunction(boxRTFunction((void*)dictCopy, DICT, 1))); + dict_cls->giveAttr("clear", new BoxedFunction(FunctionMetadata::create((void*)dictClear, NONE, 1))); + dict_cls->giveAttr("copy", new BoxedFunction(FunctionMetadata::create((void*)dictCopy, DICT, 1))); - dict_cls->giveAttr("has_key", new BoxedFunction(boxRTFunction((void*)dictContains, BOXED_BOOL, 2))); - dict_cls->giveAttr("items", new BoxedFunction(boxRTFunction((void*)dictItems, LIST, 1))); - dict_cls->giveAttr("iteritems", - new BoxedFunction(boxRTFunction((void*)dictIterItems, typeFromClass(dict_iterator_cls), 1))); + dict_cls->giveAttr("has_key", new BoxedFunction(FunctionMetadata::create((void*)dictContains, BOXED_BOOL, 2))); + dict_cls->giveAttr("items", new BoxedFunction(FunctionMetadata::create((void*)dictItems, LIST, 1))); + dict_cls->giveAttr("iteritems", new BoxedFunction(FunctionMetadata::create((void*)dictIterItems, + typeFromClass(dict_iterator_cls), 1))); - dict_cls->giveAttr("values", new BoxedFunction(boxRTFunction((void*)dictValues, LIST, 1))); - dict_cls->giveAttr("itervalues", - new BoxedFunction(boxRTFunction((void*)dictIterValues, typeFromClass(dict_iterator_cls), 1))); + dict_cls->giveAttr("values", new BoxedFunction(FunctionMetadata::create((void*)dictValues, LIST, 1))); + dict_cls->giveAttr("itervalues", new BoxedFunction(FunctionMetadata::create((void*)dictIterValues, + typeFromClass(dict_iterator_cls), 1))); - dict_cls->giveAttr("keys", new BoxedFunction(boxRTFunction((void*)dictKeys, LIST, 1))); + dict_cls->giveAttr("keys", new BoxedFunction(FunctionMetadata::create((void*)dictKeys, LIST, 1))); dict_cls->giveAttr("iterkeys", dict_cls->getattr(internStringMortal("__iter__"))); - dict_cls->giveAttr("pop", new BoxedFunction(boxRTFunction((void*)dictPop, UNKNOWN, 3, false, false), { NULL })); - dict_cls->giveAttr("popitem", new BoxedFunction(boxRTFunction((void*)dictPopitem, BOXED_TUPLE, 1))); + dict_cls->giveAttr("pop", + new BoxedFunction(FunctionMetadata::create((void*)dictPop, UNKNOWN, 3, false, false), { NULL })); + dict_cls->giveAttr("popitem", new BoxedFunction(FunctionMetadata::create((void*)dictPopitem, BOXED_TUPLE, 1))); - auto* fromkeys_func = new BoxedFunction(boxRTFunction((void*)dictFromkeys, DICT, 3, false, false), { None }); + auto* fromkeys_func + = new BoxedFunction(FunctionMetadata::create((void*)dictFromkeys, DICT, 3, false, false), { None }); dict_cls->giveAttr("fromkeys", boxInstanceMethod(dict_cls, fromkeys_func, dict_cls)); - dict_cls->giveAttr("viewkeys", new BoxedFunction(boxRTFunction((void*)dictViewKeys, UNKNOWN, 1))); - dict_cls->giveAttr("viewvalues", new BoxedFunction(boxRTFunction((void*)dictViewValues, UNKNOWN, 1))); - dict_cls->giveAttr("viewitems", new BoxedFunction(boxRTFunction((void*)dictViewItems, UNKNOWN, 1))); + dict_cls->giveAttr("viewkeys", new BoxedFunction(FunctionMetadata::create((void*)dictViewKeys, UNKNOWN, 1))); + dict_cls->giveAttr("viewvalues", new BoxedFunction(FunctionMetadata::create((void*)dictViewValues, UNKNOWN, 1))); + dict_cls->giveAttr("viewitems", new BoxedFunction(FunctionMetadata::create((void*)dictViewItems, UNKNOWN, 1))); - dict_cls->giveAttr("get", new BoxedFunction(boxRTFunction((void*)dictGet, UNKNOWN, 3, false, false), { None })); + dict_cls->giveAttr("get", + new BoxedFunction(FunctionMetadata::create((void*)dictGet, UNKNOWN, 3, false, false), { None })); - dict_cls->giveAttr("setdefault", - new BoxedFunction(boxRTFunction((void*)dictSetdefault, UNKNOWN, 3, false, false), { None })); + dict_cls->giveAttr( + "setdefault", + new BoxedFunction(FunctionMetadata::create((void*)dictSetdefault, UNKNOWN, 3, false, false), { None })); - auto dict_getitem = boxRTFunction((void*)dictGetitem, UNKNOWN, 2, ParamNames::empty(), CXX); - addRTFunction(dict_getitem, (void*)dictGetitem, UNKNOWN, CAPI); + auto dict_getitem = FunctionMetadata::create((void*)dictGetitem, UNKNOWN, 2, ParamNames::empty(), CXX); + dict_getitem->addVersion((void*)dictGetitem, UNKNOWN, CAPI); dict_cls->giveAttr("__getitem__", new BoxedFunction(dict_getitem)); - dict_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)dictSetitem, NONE, 3))); - dict_cls->giveAttr("__delitem__", new BoxedFunction(boxRTFunction((void*)dictDelitem, UNKNOWN, 2))); - dict_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)dictContains, BOXED_BOOL, 2))); + dict_cls->giveAttr("__setitem__", new BoxedFunction(FunctionMetadata::create((void*)dictSetitem, NONE, 3))); + dict_cls->giveAttr("__delitem__", new BoxedFunction(FunctionMetadata::create((void*)dictDelitem, UNKNOWN, 2))); + dict_cls->giveAttr("__contains__", new BoxedFunction(FunctionMetadata::create((void*)dictContains, BOXED_BOOL, 2))); - dict_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)dictNonzero, BOXED_BOOL, 1))); + dict_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)dictNonzero, BOXED_BOOL, 1))); dict_cls->freeze(); - CLFunction* hasnext = boxRTFunction((void*)dictIterHasnextUnboxed, BOOL, 1); - addRTFunction(hasnext, (void*)dictIterHasnext, BOXED_BOOL); + FunctionMetadata* hasnext = FunctionMetadata::create((void*)dictIterHasnextUnboxed, BOOL, 1); + hasnext->addVersion((void*)dictIterHasnext, BOXED_BOOL); dict_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); - dict_iterator_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)dictIterIter, typeFromClass(dict_iterator_cls), 1))); - dict_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)dictIterNext, UNKNOWN, 1))); + dict_iterator_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)dictIterIter, typeFromClass(dict_iterator_cls), 1))); + dict_iterator_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)dictIterNext, UNKNOWN, 1))); dict_iterator_cls->freeze(); dict_iterator_cls->tp_iter = PyObject_SelfIter; dict_iterator_cls->tp_iternext = dictiter_next; @@ -895,14 +899,14 @@ void setupDict() { dict_cls->tp_as_sequence->sq_contains = (objobjproc)PyDict_Contains; - dict_keys_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)dictViewKeysIter, typeFromClass(dict_iterator_cls), 1))); + dict_keys_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)dictViewKeysIter, typeFromClass(dict_iterator_cls), 1))); dict_keys_cls->freeze(); - dict_values_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)dictViewValuesIter, typeFromClass(dict_iterator_cls), 1))); + dict_values_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)dictViewValuesIter, typeFromClass(dict_iterator_cls), 1))); dict_values_cls->freeze(); - dict_items_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)dictViewItemsIter, typeFromClass(dict_iterator_cls), 1))); + dict_items_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)dictViewItemsIter, typeFromClass(dict_iterator_cls), 1))); dict_items_cls->freeze(); } diff --git a/src/runtime/file.cpp b/src/runtime/file.cpp index 0be2269ed..9a1934bde 100644 --- a/src/runtime/file.cpp +++ b/src/runtime/file.cpp @@ -1853,26 +1853,29 @@ void setupFile() { file_cls->tp_dealloc = fileDestructor; file_cls->has_safe_tp_dealloc = true; - file_cls->giveAttr("read", new BoxedFunction(boxRTFunction((void*)fileRead, STR, 2, false, false), { boxInt(-1) })); + file_cls->giveAttr( + "read", new BoxedFunction(FunctionMetadata::create((void*)fileRead, STR, 2, false, false), { boxInt(-1) })); - CLFunction* readline = boxRTFunction((void*)fileReadline1, STR, 1); + FunctionMetadata* readline = FunctionMetadata::create((void*)fileReadline1, STR, 1); file_cls->giveAttr("readline", new BoxedFunction(readline)); - file_cls->giveAttr("flush", new BoxedFunction(boxRTFunction((void*)fileFlush, NONE, 1))); - file_cls->giveAttr("write", new BoxedFunction(boxRTFunction((void*)fileWrite, NONE, 2))); - file_cls->giveAttr("close", new BoxedFunction(boxRTFunction((void*)fileClose, UNKNOWN, 1))); - file_cls->giveAttr("fileno", new BoxedFunction(boxRTFunction((void*)fileFileno, BOXED_INT, 1))); + file_cls->giveAttr("flush", new BoxedFunction(FunctionMetadata::create((void*)fileFlush, NONE, 1))); + file_cls->giveAttr("write", new BoxedFunction(FunctionMetadata::create((void*)fileWrite, NONE, 2))); + file_cls->giveAttr("close", new BoxedFunction(FunctionMetadata::create((void*)fileClose, UNKNOWN, 1))); + file_cls->giveAttr("fileno", new BoxedFunction(FunctionMetadata::create((void*)fileFileno, BOXED_INT, 1))); - file_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)fileRepr, STR, 1))); + file_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)fileRepr, STR, 1))); - file_cls->giveAttr("__enter__", new BoxedFunction(boxRTFunction((void*)fileEnter, typeFromClass(file_cls), 1))); - file_cls->giveAttr("__exit__", new BoxedFunction(boxRTFunction((void*)fileExit, UNKNOWN, 4))); + file_cls->giveAttr("__enter__", + new BoxedFunction(FunctionMetadata::create((void*)fileEnter, typeFromClass(file_cls), 1))); + file_cls->giveAttr("__exit__", new BoxedFunction(FunctionMetadata::create((void*)fileExit, UNKNOWN, 4))); file_cls->giveAttr("__iter__", file_cls->getattr(internStringMortal("__enter__"))); - file_cls->giveAttr("__hasnext__", new BoxedFunction(boxRTFunction((void*)fileIterHasNext, BOXED_BOOL, 1))); - file_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)fileIterNext, STR, 1))); + file_cls->giveAttr("__hasnext__", + new BoxedFunction(FunctionMetadata::create((void*)fileIterHasNext, BOXED_BOOL, 1))); + file_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)fileIterNext, STR, 1))); - file_cls->giveAttr("tell", new BoxedFunction(boxRTFunction((void*)fileTell, UNKNOWN, 1))); + file_cls->giveAttr("tell", new BoxedFunction(FunctionMetadata::create((void*)fileTell, UNKNOWN, 1))); file_cls->giveAttr("softspace", new BoxedMemberDescriptor(BoxedMemberDescriptor::INT, offsetof(BoxedFile, f_softspace), false)); file_cls->giveAttr("name", @@ -1880,7 +1883,7 @@ void setupFile() { file_cls->giveAttr("mode", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedFile, f_mode), true)); - file_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)fileNew, UNKNOWN, 4, false, false), + file_cls->giveAttr("__new__", new BoxedFunction(FunctionMetadata::create((void*)fileNew, UNKNOWN, 4, false, false), { boxString("r"), boxInt(-1) })); for (auto& md : file_methods) { diff --git a/src/runtime/float.cpp b/src/runtime/float.cpp index 04167c695..26e51daff 100644 --- a/src/runtime/float.cpp +++ b/src/runtime/float.cpp @@ -938,10 +938,10 @@ static void _addFunc(const char* name, ConcreteCompilerType* rtn_type, void* flo v_fu.push_back(BOXED_FLOAT); v_fu.push_back(UNKNOWN); - CLFunction* cl = createRTFunction(2, false, false); - addRTFunction(cl, float_func, rtn_type, v_ff); - addRTFunction(cl, int_func, rtn_type, v_fi); - addRTFunction(cl, boxed_func, UNKNOWN, v_fu); + FunctionMetadata* cl = new FunctionMetadata(2, false, false); + cl->addVersion(float_func, rtn_type, v_ff); + cl->addVersion(int_func, rtn_type, v_fi); + cl->addVersion(boxed_func, UNKNOWN, v_fu); float_cls->giveAttr(name, new BoxedFunction(cl)); } @@ -951,10 +951,10 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* std::vector v_fiu{ BOXED_FLOAT, BOXED_INT, UNKNOWN }; std::vector v_fuu{ BOXED_FLOAT, UNKNOWN, UNKNOWN }; - CLFunction* cl = createRTFunction(3, false, false); - addRTFunction(cl, float_func, rtn_type, v_ffu); - addRTFunction(cl, int_func, rtn_type, v_fiu); - addRTFunction(cl, boxed_func, UNKNOWN, v_fuu); + FunctionMetadata* cl = new FunctionMetadata(3, false, false); + cl->addVersion(float_func, rtn_type, v_ffu); + cl->addVersion(int_func, rtn_type, v_fiu); + cl->addVersion(boxed_func, UNKNOWN, v_fuu); float_cls->giveAttr(name, new BoxedFunction(cl, { None })); } @@ -1643,8 +1643,8 @@ void setupFloat() { static PyNumberMethods float_as_number; float_cls->tp_as_number = &float_as_number; - float_cls->giveAttr("__getnewargs__", new BoxedFunction(boxRTFunction((void*)float_getnewargs, UNKNOWN, 1, - ParamNames::empty(), CAPI))); + float_cls->giveAttr("__getnewargs__", new BoxedFunction(FunctionMetadata::create((void*)float_getnewargs, UNKNOWN, + 1, ParamNames::empty(), CAPI))); _addFunc("__add__", BOXED_FLOAT, (void*)floatAddFloat, (void*)floatAddInt, (void*)floatAdd); float_cls->giveAttr("__radd__", float_cls->getattr(internStringMortal("__add__"))); @@ -1663,37 +1663,39 @@ void setupFloat() { _addFunc("__sub__", BOXED_FLOAT, (void*)floatSubFloat, (void*)floatSubInt, (void*)floatSub); _addFunc("__rsub__", BOXED_FLOAT, (void*)floatRSubFloat, (void*)floatRSubInt, (void*)floatRSub); - auto float_new = boxRTFunction((void*)floatNew, UNKNOWN, 2, false, false, ParamNames::empty(), CXX); - addRTFunction(float_new, (void*)floatNew, UNKNOWN, CAPI); + auto float_new = FunctionMetadata::create((void*)floatNew, UNKNOWN, 2, false, false, ParamNames::empty(), CXX); + float_new->addVersion((void*)floatNew, UNKNOWN, CAPI); float_cls->giveAttr("__new__", new BoxedFunction(float_new, { boxFloat(0.0) })); - float_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)floatEq, UNKNOWN, 2))); - float_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)floatNe, UNKNOWN, 2))); - float_cls->giveAttr("__le__", new BoxedFunction(boxRTFunction((void*)floatLe, UNKNOWN, 2))); - float_cls->giveAttr("__lt__", new BoxedFunction(boxRTFunction((void*)floatLt, UNKNOWN, 2))); - float_cls->giveAttr("__ge__", new BoxedFunction(boxRTFunction((void*)floatGe, UNKNOWN, 2))); - float_cls->giveAttr("__gt__", new BoxedFunction(boxRTFunction((void*)floatGt, UNKNOWN, 2))); - float_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)floatNeg, BOXED_FLOAT, 1))); - float_cls->giveAttr("__pos__", new BoxedFunction(boxRTFunction((void*)floatPos, BOXED_FLOAT, 1))); - - CLFunction* nonzero = boxRTFunction((void*)floatNonzeroUnboxed, BOOL, 1); - addRTFunction(nonzero, (void*)floatNonzero, UNKNOWN); + float_cls->giveAttr("__eq__", new BoxedFunction(FunctionMetadata::create((void*)floatEq, UNKNOWN, 2))); + float_cls->giveAttr("__ne__", new BoxedFunction(FunctionMetadata::create((void*)floatNe, UNKNOWN, 2))); + float_cls->giveAttr("__le__", new BoxedFunction(FunctionMetadata::create((void*)floatLe, UNKNOWN, 2))); + float_cls->giveAttr("__lt__", new BoxedFunction(FunctionMetadata::create((void*)floatLt, UNKNOWN, 2))); + float_cls->giveAttr("__ge__", new BoxedFunction(FunctionMetadata::create((void*)floatGe, UNKNOWN, 2))); + float_cls->giveAttr("__gt__", new BoxedFunction(FunctionMetadata::create((void*)floatGt, UNKNOWN, 2))); + float_cls->giveAttr("__neg__", new BoxedFunction(FunctionMetadata::create((void*)floatNeg, BOXED_FLOAT, 1))); + float_cls->giveAttr("__pos__", new BoxedFunction(FunctionMetadata::create((void*)floatPos, BOXED_FLOAT, 1))); + + FunctionMetadata* nonzero = FunctionMetadata::create((void*)floatNonzeroUnboxed, BOOL, 1); + nonzero->addVersion((void*)floatNonzero, UNKNOWN); float_cls->giveAttr("__nonzero__", new BoxedFunction(nonzero)); - // float_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)floatNonzero, NULL, 1))); - float_cls->giveAttr("__float__", new BoxedFunction(boxRTFunction((void*)floatFloat, BOXED_FLOAT, 1))); - float_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)floatStr, STR, 1))); - float_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)floatRepr, STR, 1))); + // float_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)floatNonzero, NULL, 1))); + float_cls->giveAttr("__float__", new BoxedFunction(FunctionMetadata::create((void*)floatFloat, BOXED_FLOAT, 1))); + float_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)floatStr, STR, 1))); + float_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)floatRepr, STR, 1))); - float_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)floatTrunc, UNKNOWN, 1))); - float_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)floatHash, BOXED_INT, 1))); + float_cls->giveAttr("__trunc__", new BoxedFunction(FunctionMetadata::create((void*)floatTrunc, UNKNOWN, 1))); + float_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)floatHash, BOXED_INT, 1))); float_cls->giveAttr("real", new (pyston_getset_cls) BoxedGetsetDescriptor(floatConjugate, NULL, NULL)); float_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(float0, NULL, NULL)); - float_cls->giveAttr("conjugate", new BoxedFunction(boxRTFunction((void*)floatConjugate, BOXED_FLOAT, 1))); + float_cls->giveAttr("conjugate", + new BoxedFunction(FunctionMetadata::create((void*)floatConjugate, BOXED_FLOAT, 1))); - float_cls->giveAttr("__getformat__", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)floatGetFormat, STR, 1), - "__getformat__", floatGetFormatDoc)); + float_cls->giveAttr("__getformat__", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)floatGetFormat, STR, 1), + "__getformat__", floatGetFormatDoc)); for (auto& md : float_methods) { float_cls->giveAttr(md.ml_name, new BoxedMethodDescriptor(&md, float_cls)); diff --git a/src/runtime/generator.cpp b/src/runtime/generator.cpp index a6aa62b0f..1ca7756a0 100644 --- a/src/runtime/generator.cpp +++ b/src/runtime/generator.cpp @@ -482,21 +482,22 @@ void setupGenerator() { sizeof(BoxedGenerator), false, "generator"); generator_cls->tp_dealloc = generatorDestructor; generator_cls->has_safe_tp_dealloc = true; - generator_cls->giveAttr("__iter__", - new BoxedFunction(boxRTFunction((void*)generatorIter, typeFromClass(generator_cls), 1))); + generator_cls->giveAttr( + "__iter__", new BoxedFunction(FunctionMetadata::create((void*)generatorIter, typeFromClass(generator_cls), 1))); - generator_cls->giveAttr("close", new BoxedFunction(boxRTFunction((void*)generatorClose, UNKNOWN, 1))); + generator_cls->giveAttr("close", new BoxedFunction(FunctionMetadata::create((void*)generatorClose, UNKNOWN, 1))); - auto generator_next = boxRTFunction((void*)generatorNext, UNKNOWN, 1, ParamNames::empty(), CXX); - addRTFunction(generator_next, (void*)generatorNext, UNKNOWN, CAPI); + auto generator_next = FunctionMetadata::create((void*)generatorNext, UNKNOWN, 1, ParamNames::empty(), CXX); + generator_next->addVersion((void*)generatorNext, UNKNOWN, CAPI); generator_cls->giveAttr("next", new BoxedFunction(generator_next)); - CLFunction* hasnext = boxRTFunction((void*)generatorHasnextUnboxed, BOOL, 1); - addRTFunction(hasnext, (void*)generatorHasnext, BOXED_BOOL); + FunctionMetadata* hasnext = FunctionMetadata::create((void*)generatorHasnextUnboxed, BOOL, 1); + hasnext->addVersion((void*)generatorHasnext, BOXED_BOOL); generator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); - generator_cls->giveAttr("send", new BoxedFunction(boxRTFunction((void*)generatorSend, UNKNOWN, 2))); - auto gthrow = new BoxedFunction(boxRTFunction((void*)generatorThrow, UNKNOWN, 4, false, false), { NULL, NULL }); + generator_cls->giveAttr("send", new BoxedFunction(FunctionMetadata::create((void*)generatorSend, UNKNOWN, 2))); + auto gthrow + = new BoxedFunction(FunctionMetadata::create((void*)generatorThrow, UNKNOWN, 4, false, false), { NULL, NULL }); generator_cls->giveAttr("throw", gthrow); generator_cls->giveAttr("__name__", new (pyston_getset_cls) BoxedGetsetDescriptor(generatorName, NULL, NULL)); diff --git a/src/runtime/import.cpp b/src/runtime/import.cpp index eb6ac2d76..d7b2ac64c 100644 --- a/src/runtime/import.cpp +++ b/src/runtime/import.cpp @@ -1001,43 +1001,47 @@ void setupImport() { null_importer_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "NullImporter"); null_importer_cls->giveAttr( - "__init__", new BoxedFunction(boxRTFunction((void*)nullImporterInit, NONE, 2, false, false), { None })); - null_importer_cls->giveAttr("find_module", new BoxedBuiltinFunctionOrMethod( - boxRTFunction((void*)nullImporterFindModule, NONE, 2, false, false), - "find_module", { None }, NULL, find_module_doc)); + "__init__", + new BoxedFunction(FunctionMetadata::create((void*)nullImporterInit, NONE, 2, false, false), { None })); + null_importer_cls->giveAttr( + "find_module", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)nullImporterFindModule, NONE, 2, false, false), + "find_module", { None }, NULL, find_module_doc)); null_importer_cls->freeze(); imp_module->giveAttr("NullImporter", null_importer_cls); - CLFunction* find_module_func - = boxRTFunction((void*)impFindModule, UNKNOWN, 2, false, false, ParamNames({ "name", "path" }, "", "")); + FunctionMetadata* find_module_func = FunctionMetadata::create((void*)impFindModule, UNKNOWN, 2, false, false, + ParamNames({ "name", "path" }, "", "")); imp_module->giveAttr("find_module", new BoxedBuiltinFunctionOrMethod(find_module_func, "find_module", { None }, NULL, find_module_doc)); - CLFunction* load_module_func = boxRTFunction((void*)impLoadModule, UNKNOWN, 4, - ParamNames({ "name", "file", "pathname", "description" }, "", "")); + FunctionMetadata* load_module_func = FunctionMetadata::create( + (void*)impLoadModule, UNKNOWN, 4, ParamNames({ "name", "file", "pathname", "description" }, "", "")); imp_module->giveAttr("load_module", new BoxedBuiltinFunctionOrMethod(load_module_func, "load_module", load_module_doc)); - imp_module->giveAttr("load_source", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impLoadSource, UNKNOWN, 3, false, false), - "load_source", { NULL })); + imp_module->giveAttr("load_source", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)impLoadSource, UNKNOWN, 3, false, false), + "load_source", { NULL })); - CLFunction* load_dynamic_func = boxRTFunction((void*)impLoadDynamic, UNKNOWN, 3, false, false, - ParamNames({ "name", "pathname", "file" }, "", "")); + FunctionMetadata* load_dynamic_func = FunctionMetadata::create((void*)impLoadDynamic, UNKNOWN, 3, false, false, + ParamNames({ "name", "pathname", "file" }, "", "")); imp_module->giveAttr("load_dynamic", new BoxedBuiltinFunctionOrMethod(load_dynamic_func, "load_dynamic", { None })); imp_module->giveAttr("get_suffixes", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impGetSuffixes, UNKNOWN, 0), + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)impGetSuffixes, UNKNOWN, 0), "get_suffixes", get_suffixes_doc)); - imp_module->giveAttr("acquire_lock", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impAcquireLock, NONE, 0), - "acquire_lock", acquire_lock_doc)); - imp_module->giveAttr("release_lock", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impReleaseLock, NONE, 0), - "release_lock", release_lock_doc)); - - imp_module->giveAttr("new_module", - new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impNewModule, MODULE, 1), "new_module")); - imp_module->giveAttr( - "is_builtin", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impIsBuiltin, BOXED_INT, 1), "is_builtin")); - imp_module->giveAttr( - "is_frozen", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impIsFrozen, BOXED_BOOL, 1), "is_frozen")); + imp_module->giveAttr("acquire_lock", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)impAcquireLock, NONE, 0), + "acquire_lock", acquire_lock_doc)); + imp_module->giveAttr("release_lock", + new BoxedBuiltinFunctionOrMethod(FunctionMetadata::create((void*)impReleaseLock, NONE, 0), + "release_lock", release_lock_doc)); + + imp_module->giveAttr("new_module", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)impNewModule, MODULE, 1), "new_module")); + imp_module->giveAttr("is_builtin", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)impIsBuiltin, BOXED_INT, 1), "is_builtin")); + imp_module->giveAttr("is_frozen", new BoxedBuiltinFunctionOrMethod( + FunctionMetadata::create((void*)impIsFrozen, BOXED_BOOL, 1), "is_frozen")); } } diff --git a/src/runtime/inline/link_forcer.cpp b/src/runtime/inline/link_forcer.cpp index b0fcd73e5..73e52aa62 100644 --- a/src/runtime/inline/link_forcer.cpp +++ b/src/runtime/inline/link_forcer.cpp @@ -55,8 +55,8 @@ void force() { FORCE(unboxInt); FORCE(boxFloat); FORCE(unboxFloat); - FORCE(boxCLFunction); - FORCE(unboxCLFunction); + FORCE(createFunctionFromMetadata); + FORCE(getFunctionMetadata); FORCE(boxInstanceMethod); FORCE(boxBool); FORCE(boxBoolNegated); diff --git a/src/runtime/inline/xrange.cpp b/src/runtime/inline/xrange.cpp index a2738c947..41b607fe1 100644 --- a/src/runtime/inline/xrange.cpp +++ b/src/runtime/inline/xrange.cpp @@ -250,28 +250,32 @@ void setupXrange() { static PySequenceMethods xrange_as_sequence; xrange_cls->tp_as_sequence = &xrange_as_sequence; - xrange_cls->giveAttr( - "__new__", - new BoxedFunction(boxRTFunction((void*)xrange, typeFromClass(xrange_cls), 4, false, false), { NULL, NULL })); - xrange_cls->giveAttr("__iter__", - new BoxedFunction(boxRTFunction((void*)xrangeIter, typeFromClass(xrange_iterator_cls), 1))); - xrange_cls->giveAttr( - "__reversed__", new BoxedFunction(boxRTFunction((void*)xrangeReversed, typeFromClass(xrange_iterator_cls), 1))); - - xrange_cls->giveAttr("__getitem__", new BoxedFunction(boxRTFunction((void*)xrangeGetitem, BOXED_INT, 2))); - - xrange_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)xrangeLen, BOXED_INT, 1))); - xrange_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)xrangeRepr, STR, 1))); - xrange_cls->giveAttr("__reduce__", new BoxedFunction(boxRTFunction((void*)xrangeReduce, BOXED_TUPLE, 1))); - - CLFunction* hasnext = boxRTFunction((void*)BoxedXrangeIterator::xrangeIteratorHasnextUnboxed, BOOL, 1); - addRTFunction(hasnext, (void*)BoxedXrangeIterator::xrangeIteratorHasnext, BOXED_BOOL); - xrange_iterator_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1))); + xrange_cls->giveAttr("__new__", new BoxedFunction(FunctionMetadata::create((void*)xrange, typeFromClass(xrange_cls), + 4, false, false), + { NULL, NULL })); + xrange_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)xrangeIter, typeFromClass(xrange_iterator_cls), 1))); + xrange_cls->giveAttr("__reversed__", new BoxedFunction(FunctionMetadata::create( + (void*)xrangeReversed, typeFromClass(xrange_iterator_cls), 1))); + + xrange_cls->giveAttr("__getitem__", + new BoxedFunction(FunctionMetadata::create((void*)xrangeGetitem, BOXED_INT, 2))); + + xrange_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)xrangeLen, BOXED_INT, 1))); + xrange_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)xrangeRepr, STR, 1))); + xrange_cls->giveAttr("__reduce__", + new BoxedFunction(FunctionMetadata::create((void*)xrangeReduce, BOXED_TUPLE, 1))); + + FunctionMetadata* hasnext + = FunctionMetadata::create((void*)BoxedXrangeIterator::xrangeIteratorHasnextUnboxed, BOOL, 1); + hasnext->addVersion((void*)BoxedXrangeIterator::xrangeIteratorHasnext, BOXED_BOOL); + xrange_iterator_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1))); xrange_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); - CLFunction* next = boxRTFunction((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, UNBOXED_INT, 1); - addRTFunction(next, (void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT); + FunctionMetadata* next + = FunctionMetadata::create((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, UNBOXED_INT, 1); + next->addVersion((void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT); xrange_iterator_cls->giveAttr("next", new BoxedFunction(next)); // TODO this is pretty hacky, but stuff the iterator cls into xrange to make sure it gets decref'd at the end diff --git a/src/runtime/int.cpp b/src/runtime/int.cpp index e83cab0ac..b42a7cf03 100644 --- a/src/runtime/int.cpp +++ b/src/runtime/int.cpp @@ -694,9 +694,9 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* std::vector v_ifu{ BOXED_INT, BOXED_FLOAT, UNKNOWN }; std::vector v_uuu{ UNKNOWN, UNKNOWN, UNKNOWN }; - CLFunction* cl = createRTFunction(3, false, false); - addRTFunction(cl, float_func, UNKNOWN, v_ifu); - addRTFunction(cl, int_func, UNKNOWN, v_uuu); + FunctionMetadata* cl = new FunctionMetadata(3, false, false); + cl->addVersion(float_func, UNKNOWN, v_ifu); + cl->addVersion(int_func, UNKNOWN, v_uuu); int_cls->giveAttr(name, new BoxedFunction(cl, { None })); } @@ -1085,10 +1085,10 @@ static void _addFuncIntFloatUnknown(const char* name, void* int_func, void* floa v_iu.push_back(UNKNOWN); v_iu.push_back(UNKNOWN); - CLFunction* cl = createRTFunction(2, false, false); - addRTFunction(cl, int_func, UNKNOWN, v_ii); - addRTFunction(cl, float_func, BOXED_FLOAT, v_if); - addRTFunction(cl, boxed_func, UNKNOWN, v_iu); + FunctionMetadata* cl = new FunctionMetadata(2, false, false); + cl->addVersion(int_func, UNKNOWN, v_ii); + cl->addVersion(float_func, BOXED_FLOAT, v_if); + cl->addVersion(boxed_func, UNKNOWN, v_iu); int_cls->giveAttr(name, new BoxedFunction(cl)); } @@ -1100,9 +1100,9 @@ static void _addFuncIntUnknown(const char* name, ConcreteCompilerType* rtn_type, v_iu.push_back(UNKNOWN); v_iu.push_back(UNKNOWN); - CLFunction* cl = createRTFunction(2, false, false); - addRTFunction(cl, int_func, rtn_type, v_ii); - addRTFunction(cl, boxed_func, UNKNOWN, v_iu); + FunctionMetadata* cl = new FunctionMetadata(2, false, false); + cl->addVersion(int_func, rtn_type, v_ii); + cl->addVersion(boxed_func, UNKNOWN, v_iu); int_cls->giveAttr(name, new BoxedFunction(cl)); } @@ -1170,8 +1170,8 @@ void setupInt() { gc::registerPermanentRoot(interned_ints[i]); } - int_cls->giveAttr("__getnewargs__", - new BoxedFunction(boxRTFunction((void*)int_getnewargs, UNKNOWN, 1, ParamNames::empty(), CAPI))); + int_cls->giveAttr("__getnewargs__", new BoxedFunction(FunctionMetadata::create((void*)int_getnewargs, UNKNOWN, 1, + ParamNames::empty(), CAPI))); _addFuncIntFloatUnknown("__add__", (void*)intAddInt, (void*)intAddFloat, (void*)intAdd); _addFuncIntUnknown("__and__", BOXED_INT, (void*)intAndInt, (void*)intAnd); @@ -1190,33 +1190,33 @@ void setupInt() { _addFuncIntUnknown("__lshift__", UNKNOWN, (void*)intLShiftInt, (void*)intLShift); _addFuncIntUnknown("__rshift__", UNKNOWN, (void*)intRShiftInt, (void*)intRShift); - int_cls->giveAttr("__invert__", new BoxedFunction(boxRTFunction((void*)intInvert, BOXED_INT, 1))); - int_cls->giveAttr("__pos__", new BoxedFunction(boxRTFunction((void*)intPos, BOXED_INT, 1))); - int_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)intNeg, UNKNOWN, 1))); - int_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)intNonzero, BOXED_BOOL, 1))); - int_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)intRepr, STR, 1))); + int_cls->giveAttr("__invert__", new BoxedFunction(FunctionMetadata::create((void*)intInvert, BOXED_INT, 1))); + int_cls->giveAttr("__pos__", new BoxedFunction(FunctionMetadata::create((void*)intPos, BOXED_INT, 1))); + int_cls->giveAttr("__neg__", new BoxedFunction(FunctionMetadata::create((void*)intNeg, UNKNOWN, 1))); + int_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)intNonzero, BOXED_BOOL, 1))); + int_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)intRepr, STR, 1))); int_cls->tp_hash = (hashfunc)int_hash; - int_cls->giveAttr("__divmod__", new BoxedFunction(boxRTFunction((void*)intDivmod, UNKNOWN, 2))); + int_cls->giveAttr("__divmod__", new BoxedFunction(FunctionMetadata::create((void*)intDivmod, UNKNOWN, 2))); - int_cls->giveAttr("__bin__", new BoxedFunction(boxRTFunction((void*)intBin, STR, 1))); - int_cls->giveAttr("__hex__", new BoxedFunction(boxRTFunction((void*)intHex, STR, 1))); - int_cls->giveAttr("__oct__", new BoxedFunction(boxRTFunction((void*)intOct, STR, 1))); + int_cls->giveAttr("__bin__", new BoxedFunction(FunctionMetadata::create((void*)intBin, STR, 1))); + int_cls->giveAttr("__hex__", new BoxedFunction(FunctionMetadata::create((void*)intHex, STR, 1))); + int_cls->giveAttr("__oct__", new BoxedFunction(FunctionMetadata::create((void*)intOct, STR, 1))); - int_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)intTrunc, BOXED_INT, 1))); - int_cls->giveAttr("__index__", new BoxedFunction(boxRTFunction((void*)intIndex, BOXED_INT, 1))); - int_cls->giveAttr("__int__", new BoxedFunction(boxRTFunction((void*)intInt, BOXED_INT, 1))); + int_cls->giveAttr("__trunc__", new BoxedFunction(FunctionMetadata::create((void*)intTrunc, BOXED_INT, 1))); + int_cls->giveAttr("__index__", new BoxedFunction(FunctionMetadata::create((void*)intIndex, BOXED_INT, 1))); + int_cls->giveAttr("__int__", new BoxedFunction(FunctionMetadata::create((void*)intInt, BOXED_INT, 1))); - auto int_new - = boxRTFunction((void*)intNew, UNKNOWN, 3, false, false, ParamNames({ "", "x", "base" }, "", ""), CXX); - addRTFunction(int_new, (void*)intNew, UNKNOWN, CAPI); + auto int_new = FunctionMetadata::create((void*)intNew, UNKNOWN, 3, false, false, + ParamNames({ "", "x", "base" }, "", ""), CXX); + int_new->addVersion((void*)intNew, UNKNOWN, CAPI); int_cls->giveAttr("__new__", new BoxedFunction(int_new, { None, NULL })); - int_cls->giveAttr("bit_length", new BoxedFunction(boxRTFunction((void*)intBitLength, BOXED_INT, 1))); + int_cls->giveAttr("bit_length", new BoxedFunction(FunctionMetadata::create((void*)intBitLength, BOXED_INT, 1))); int_cls->giveAttr("real", new (pyston_getset_cls) BoxedGetsetDescriptor(intIntGetset, NULL, NULL)); int_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(int0, NULL, NULL)); - int_cls->giveAttr("conjugate", new BoxedFunction(boxRTFunction((void*)intIntGetset, BOXED_INT, 1))); + int_cls->giveAttr("conjugate", new BoxedFunction(FunctionMetadata::create((void*)intIntGetset, BOXED_INT, 1))); int_cls->giveAttr("numerator", new (pyston_getset_cls) BoxedGetsetDescriptor(intIntGetset, NULL, NULL)); int_cls->giveAttr("denominator", new (pyston_getset_cls) BoxedGetsetDescriptor(int1, NULL, NULL)); diff --git a/src/runtime/iterobject.cpp b/src/runtime/iterobject.cpp index b4f5645b1..eb71d3aef 100644 --- a/src/runtime/iterobject.cpp +++ b/src/runtime/iterobject.cpp @@ -212,9 +212,10 @@ void setupIter() { seqiter_cls = BoxedClass::create(type_cls, object_cls, &BoxedSeqIter::gcHandler, 0, 0, sizeof(BoxedSeqIter), false, "iterator"); - seqiter_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)seqiterNext, UNKNOWN, 1))); - seqiter_cls->giveAttr("__hasnext__", new BoxedFunction(boxRTFunction((void*)seqiterHasnext, BOXED_BOOL, 1))); - seqiter_cls->giveAttr("__iter__", new BoxedFunction(boxRTFunction((void*)seqiterIter, UNKNOWN, 1))); + seqiter_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)seqiterNext, UNKNOWN, 1))); + seqiter_cls->giveAttr("__hasnext__", + new BoxedFunction(FunctionMetadata::create((void*)seqiterHasnext, BOXED_BOOL, 1))); + seqiter_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)seqiterIter, UNKNOWN, 1))); seqiter_cls->freeze(); seqiter_cls->tpp_hasnext = seqiterHasnextUnboxed; @@ -224,9 +225,10 @@ void setupIter() { seqreviter_cls = BoxedClass::create(type_cls, object_cls, &BoxedSeqIter::gcHandler, 0, 0, sizeof(BoxedSeqIter), false, "reversed"); - seqreviter_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)seqiterNext, UNKNOWN, 1))); - seqreviter_cls->giveAttr("__hasnext__", new BoxedFunction(boxRTFunction((void*)seqreviterHasnext, BOXED_BOOL, 1))); - seqreviter_cls->giveAttr("__iter__", new BoxedFunction(boxRTFunction((void*)seqiterIter, UNKNOWN, 1))); + seqreviter_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)seqiterNext, UNKNOWN, 1))); + seqreviter_cls->giveAttr("__hasnext__", + new BoxedFunction(FunctionMetadata::create((void*)seqreviterHasnext, BOXED_BOOL, 1))); + seqreviter_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)seqiterIter, UNKNOWN, 1))); seqreviter_cls->freeze(); seqreviter_cls->tp_iter = PyObject_SelfIter; @@ -235,9 +237,9 @@ void setupIter() { iterwrapper_cls = BoxedClass::create(type_cls, object_cls, &BoxedIterWrapper::gcHandler, 0, 0, sizeof(BoxedIterWrapper), false, "iterwrapper"); - iterwrapper_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)iterwrapperNext, UNKNOWN, 1))); + iterwrapper_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)iterwrapperNext, UNKNOWN, 1))); iterwrapper_cls->giveAttr("__hasnext__", - new BoxedFunction(boxRTFunction((void*)iterwrapperHasnext, BOXED_BOOL, 1))); + new BoxedFunction(FunctionMetadata::create((void*)iterwrapperHasnext, BOXED_BOOL, 1))); iterwrapper_cls->freeze(); iterwrapper_cls->tpp_hasnext = iterwrapperHasnextUnboxed; diff --git a/src/runtime/list.cpp b/src/runtime/list.cpp index d0f8256c4..8e62b97ce 100644 --- a/src/runtime/list.cpp +++ b/src/runtime/list.cpp @@ -1279,79 +1279,80 @@ void setupList() { sizeof(BoxedListIterator), false, "listreverseiterator"); list_iterator_cls->instances_are_nonzero = list_reverse_iterator_cls->instances_are_nonzero = true; - list_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)listLen, BOXED_INT, 1))); - - CLFunction* getitem = createRTFunction(2, false, false); - addRTFunction(getitem, (void*)listGetitemInt, UNKNOWN, std::vector{ LIST, BOXED_INT }); - addRTFunction(getitem, (void*)listGetitemSlice, LIST, std::vector{ LIST, SLICE }, CXX); - addRTFunction(getitem, (void*)listGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, - CXX); - addRTFunction(getitem, (void*)listGetitemSlice, LIST, std::vector{ LIST, SLICE }, - CAPI); - addRTFunction(getitem, (void*)listGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, - CAPI); + list_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)listLen, BOXED_INT, 1))); + + FunctionMetadata* getitem = new FunctionMetadata(2, false, false); + getitem->addVersion((void*)listGetitemInt, UNKNOWN, std::vector{ LIST, BOXED_INT }); + getitem->addVersion((void*)listGetitemSlice, LIST, std::vector{ LIST, SLICE }, CXX); + getitem->addVersion((void*)listGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, CXX); + getitem->addVersion((void*)listGetitemSlice, LIST, std::vector{ LIST, SLICE }, CAPI); + getitem->addVersion((void*)listGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, + CAPI); list_cls->giveAttr("__getitem__", new BoxedFunction(getitem)); - list_cls->giveAttr("__getslice__", new BoxedFunction(boxRTFunction((void*)listGetslice, LIST, 3))); + list_cls->giveAttr("__getslice__", new BoxedFunction(FunctionMetadata::create((void*)listGetslice, LIST, 3))); - CLFunction* setitem = createRTFunction(3, false, false); - addRTFunction(setitem, (void*)listSetitemInt, NONE, std::vector{ LIST, BOXED_INT, UNKNOWN }); - addRTFunction(setitem, (void*)listSetitemSlice, NONE, std::vector{ LIST, SLICE, UNKNOWN }); - addRTFunction(setitem, (void*)listSetitem, NONE, std::vector{ UNKNOWN, UNKNOWN, UNKNOWN }); + FunctionMetadata* setitem = new FunctionMetadata(3, false, false); + setitem->addVersion((void*)listSetitemInt, NONE, std::vector{ LIST, BOXED_INT, UNKNOWN }); + setitem->addVersion((void*)listSetitemSlice, NONE, std::vector{ LIST, SLICE, UNKNOWN }); + setitem->addVersion((void*)listSetitem, NONE, std::vector{ UNKNOWN, UNKNOWN, UNKNOWN }); list_cls->giveAttr("__setitem__", new BoxedFunction(setitem)); - list_cls->giveAttr("__setslice__", new BoxedFunction(boxRTFunction((void*)listSetslice, NONE, 4))); + list_cls->giveAttr("__setslice__", new BoxedFunction(FunctionMetadata::create((void*)listSetslice, NONE, 4))); - CLFunction* delitem = createRTFunction(2, false, false); - addRTFunction(delitem, (void*)listDelitemInt, NONE, std::vector{ LIST, BOXED_INT }); - addRTFunction(delitem, (void*)listDelitemSlice, NONE, std::vector{ LIST, SLICE }); - addRTFunction(delitem, (void*)listDelitem, NONE, std::vector{ UNKNOWN, UNKNOWN }); + FunctionMetadata* delitem = new FunctionMetadata(2, false, false); + delitem->addVersion((void*)listDelitemInt, NONE, std::vector{ LIST, BOXED_INT }); + delitem->addVersion((void*)listDelitemSlice, NONE, std::vector{ LIST, SLICE }); + delitem->addVersion((void*)listDelitem, NONE, std::vector{ UNKNOWN, UNKNOWN }); list_cls->giveAttr("__delitem__", new BoxedFunction(delitem)); - list_cls->giveAttr("__delslice__", new BoxedFunction(boxRTFunction((void*)listDelslice, NONE, 3))); + list_cls->giveAttr("__delslice__", new BoxedFunction(FunctionMetadata::create((void*)listDelslice, NONE, 3))); - list_cls->giveAttr("__iter__", - new BoxedFunction(boxRTFunction((void*)listIter, typeFromClass(list_iterator_cls), 1))); + list_cls->giveAttr( + "__iter__", new BoxedFunction(FunctionMetadata::create((void*)listIter, typeFromClass(list_iterator_cls), 1))); - list_cls->giveAttr("__reversed__", new BoxedFunction(boxRTFunction((void*)listReversed, - typeFromClass(list_reverse_iterator_cls), 1))); + list_cls->giveAttr("__reversed__", new BoxedFunction(FunctionMetadata::create( + (void*)listReversed, typeFromClass(list_reverse_iterator_cls), 1))); - list_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)listEq, UNKNOWN, 2))); - list_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)listNe, UNKNOWN, 2))); - list_cls->giveAttr("__lt__", new BoxedFunction(boxRTFunction((void*)listLt, UNKNOWN, 2))); - list_cls->giveAttr("__le__", new BoxedFunction(boxRTFunction((void*)listLe, UNKNOWN, 2))); - list_cls->giveAttr("__gt__", new BoxedFunction(boxRTFunction((void*)listGt, UNKNOWN, 2))); - list_cls->giveAttr("__ge__", new BoxedFunction(boxRTFunction((void*)listGe, UNKNOWN, 2))); + list_cls->giveAttr("__eq__", new BoxedFunction(FunctionMetadata::create((void*)listEq, UNKNOWN, 2))); + list_cls->giveAttr("__ne__", new BoxedFunction(FunctionMetadata::create((void*)listNe, UNKNOWN, 2))); + list_cls->giveAttr("__lt__", new BoxedFunction(FunctionMetadata::create((void*)listLt, UNKNOWN, 2))); + list_cls->giveAttr("__le__", new BoxedFunction(FunctionMetadata::create((void*)listLe, UNKNOWN, 2))); + list_cls->giveAttr("__gt__", new BoxedFunction(FunctionMetadata::create((void*)listGt, UNKNOWN, 2))); + list_cls->giveAttr("__ge__", new BoxedFunction(FunctionMetadata::create((void*)listGe, UNKNOWN, 2))); - list_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)listRepr, STR, 1))); - list_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)listNonzero, BOXED_BOOL, 1))); + list_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)listRepr, STR, 1))); + list_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)listNonzero, BOXED_BOOL, 1))); - list_cls->giveAttr("pop", new BoxedFunction(boxRTFunction((void*)listPop, UNKNOWN, 2, false, false), { None })); + list_cls->giveAttr("pop", + new BoxedFunction(FunctionMetadata::create((void*)listPop, UNKNOWN, 2, false, false), { None })); - list_cls->giveAttr("append", new BoxedFunction(boxRTFunction((void*)listAppend, NONE, 2))); - list_cls->giveAttr("extend", new BoxedFunction(boxRTFunction((void*)listIAdd, UNKNOWN, 2))); + list_cls->giveAttr("append", new BoxedFunction(FunctionMetadata::create((void*)listAppend, NONE, 2))); + list_cls->giveAttr("extend", new BoxedFunction(FunctionMetadata::create((void*)listIAdd, UNKNOWN, 2))); - list_cls->giveAttr("insert", new BoxedFunction(boxRTFunction((void*)listInsert, NONE, 3))); - list_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)listMul, UNKNOWN, 2))); - list_cls->giveAttr("__rmul__", new BoxedFunction(boxRTFunction((void*)listMul, UNKNOWN, 2))); - list_cls->giveAttr("__imul__", new BoxedFunction(boxRTFunction((void*)listImul, UNKNOWN, 2))); + list_cls->giveAttr("insert", new BoxedFunction(FunctionMetadata::create((void*)listInsert, NONE, 3))); + list_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)listMul, UNKNOWN, 2))); + list_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)listMul, UNKNOWN, 2))); + list_cls->giveAttr("__imul__", new BoxedFunction(FunctionMetadata::create((void*)listImul, UNKNOWN, 2))); - list_cls->giveAttr("__iadd__", new BoxedFunction(boxRTFunction((void*)listIAdd, UNKNOWN, 2))); - list_cls->giveAttr("__add__", new BoxedFunction(boxRTFunction((void*)listAdd, UNKNOWN, 2))); + list_cls->giveAttr("__iadd__", new BoxedFunction(FunctionMetadata::create((void*)listIAdd, UNKNOWN, 2))); + list_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)listAdd, UNKNOWN, 2))); - list_cls->giveAttr("sort", new BoxedFunction(boxRTFunction((void*)listSortFunc, NONE, 4, false, false, - ParamNames({ "", "cmp", "key", "reverse" }, "", "")), - { None, None, False })); - list_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)listContains, BOXED_BOOL, 2))); + list_cls->giveAttr("sort", + new BoxedFunction(FunctionMetadata::create((void*)listSortFunc, NONE, 4, false, false, + ParamNames({ "", "cmp", "key", "reverse" }, "", "")), + { None, None, False })); + list_cls->giveAttr("__contains__", new BoxedFunction(FunctionMetadata::create((void*)listContains, BOXED_BOOL, 2))); - list_cls->giveAttr("__init__", - new BoxedFunction(boxRTFunction((void*)listInit, UNKNOWN, 2, false, false), { NULL })); + list_cls->giveAttr( + "__init__", new BoxedFunction(FunctionMetadata::create((void*)listInit, UNKNOWN, 2, false, false), { NULL })); - list_cls->giveAttr("count", new BoxedFunction(boxRTFunction((void*)listCount, BOXED_INT, 2))); - list_cls->giveAttr("index", - new BoxedFunction(boxRTFunction((void*)listIndex, BOXED_INT, 4, false, false), { NULL, NULL })); - list_cls->giveAttr("remove", new BoxedFunction(boxRTFunction((void*)listRemove, NONE, 2))); - list_cls->giveAttr("reverse", new BoxedFunction(boxRTFunction((void*)listReverse, NONE, 1))); + list_cls->giveAttr("count", new BoxedFunction(FunctionMetadata::create((void*)listCount, BOXED_INT, 2))); + list_cls->giveAttr( + "index", + new BoxedFunction(FunctionMetadata::create((void*)listIndex, BOXED_INT, 4, false, false), { NULL, NULL })); + list_cls->giveAttr("remove", new BoxedFunction(FunctionMetadata::create((void*)listRemove, NONE, 2))); + list_cls->giveAttr("reverse", new BoxedFunction(FunctionMetadata::create((void*)listReverse, NONE, 1))); list_cls->giveAttr("__hash__", None); list_cls->freeze(); @@ -1366,14 +1367,14 @@ void setupList() { list_cls->tp_as_sequence->sq_contains = (objobjproc)list_contains; list_cls->tp_as_sequence->sq_repeat = (ssizeargfunc)list_repeat; - CLFunction* hasnext = boxRTFunction((void*)listiterHasnextUnboxed, BOOL, 1); - addRTFunction(hasnext, (void*)listiterHasnext, BOXED_BOOL); + FunctionMetadata* hasnext = FunctionMetadata::create((void*)listiterHasnextUnboxed, BOOL, 1); + hasnext->addVersion((void*)listiterHasnext, BOXED_BOOL); list_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); - list_iterator_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)listIterIter, typeFromClass(list_iterator_cls), 1))); + list_iterator_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)listIterIter, typeFromClass(list_iterator_cls), 1))); - CLFunction* listiter_next_func = boxRTFunction((void*)listiterNext, UNKNOWN, 1); - addRTFunction(listiter_next_func, (void*)listiterNext, UNKNOWN, CAPI); + FunctionMetadata* listiter_next_func = FunctionMetadata::create((void*)listiterNext, UNKNOWN, 1); + listiter_next_func->addVersion((void*)listiterNext, UNKNOWN, CAPI); list_iterator_cls->giveAttr("next", new BoxedFunction(listiter_next_func)); list_iterator_cls->freeze(); @@ -1383,12 +1384,14 @@ void setupList() { list_reverse_iterator_cls->giveAttr("__name__", boxString("listreverseiterator")); - hasnext = boxRTFunction((void*)listreviterHasnextUnboxed, BOOL, 1); - addRTFunction(hasnext, (void*)listreviterHasnext, BOXED_BOOL); + hasnext = FunctionMetadata::create((void*)listreviterHasnextUnboxed, BOOL, 1); + hasnext->addVersion((void*)listreviterHasnext, BOXED_BOOL); list_reverse_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); list_reverse_iterator_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)listIterIter, typeFromClass(list_reverse_iterator_cls), 1))); - list_reverse_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)listreviterNext, UNKNOWN, 1))); + "__iter__", + new BoxedFunction(FunctionMetadata::create((void*)listIterIter, typeFromClass(list_reverse_iterator_cls), 1))); + list_reverse_iterator_cls->giveAttr( + "next", new BoxedFunction(FunctionMetadata::create((void*)listreviterNext, UNKNOWN, 1))); list_reverse_iterator_cls->freeze(); list_reverse_iterator_cls->tp_iternext = listreviter_next; diff --git a/src/runtime/long.cpp b/src/runtime/long.cpp index 1991e9d33..780c45aeb 100644 --- a/src/runtime/long.cpp +++ b/src/runtime/long.cpp @@ -1278,9 +1278,9 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* std::vector v_lfu{ UNKNOWN, BOXED_FLOAT, UNKNOWN }; std::vector v_uuu{ UNKNOWN, UNKNOWN, UNKNOWN }; - CLFunction* cl = createRTFunction(3, false, false); - addRTFunction(cl, float_func, UNKNOWN, v_lfu); - addRTFunction(cl, long_func, UNKNOWN, v_uuu); + FunctionMetadata* cl = new FunctionMetadata(3, false, false); + cl->addVersion(float_func, UNKNOWN, v_lfu); + cl->addVersion(long_func, UNKNOWN, v_uuu); long_cls->giveAttr(name, new BoxedFunction(cl, { None })); } @@ -1513,69 +1513,69 @@ void setupLong() { mp_set_memory_functions(customised_allocation, customised_realloc, customised_free); _addFuncPow("__pow__", UNKNOWN, (void*)longPowFloat, (void*)longPow); - auto long_new - = boxRTFunction((void*)longNew, UNKNOWN, 3, false, false, ParamNames({ "", "x", "base" }, "", ""), CXX); - addRTFunction(long_new, (void*)longNew, UNKNOWN, CAPI); + auto long_new = FunctionMetadata::create((void*)longNew, UNKNOWN, 3, false, false, + ParamNames({ "", "x", "base" }, "", ""), CXX); + long_new->addVersion((void*)longNew, UNKNOWN, CAPI); long_cls->giveAttr("__new__", new BoxedFunction(long_new, { boxInt(0), NULL })); - long_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)longMul, UNKNOWN, 2))); + long_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)longMul, UNKNOWN, 2))); long_cls->giveAttr("__rmul__", long_cls->getattr(internStringMortal("__mul__"))); - long_cls->giveAttr("__div__", new BoxedFunction(boxRTFunction((void*)longDiv, UNKNOWN, 2))); - long_cls->giveAttr("__rdiv__", new BoxedFunction(boxRTFunction((void*)longRdiv, UNKNOWN, 2))); - long_cls->giveAttr("__floordiv__", new BoxedFunction(boxRTFunction((void*)longFloorDiv, UNKNOWN, 2))); - long_cls->giveAttr("__rfloordiv__", new BoxedFunction(boxRTFunction((void*)longRfloorDiv, UNKNOWN, 2))); - long_cls->giveAttr("__truediv__", new BoxedFunction(boxRTFunction((void*)longTrueDiv, UNKNOWN, 2))); - long_cls->giveAttr("__rtruediv__", new BoxedFunction(boxRTFunction((void*)longRTrueDiv, UNKNOWN, 2))); - long_cls->giveAttr("__mod__", new BoxedFunction(boxRTFunction((void*)longMod, UNKNOWN, 2))); - long_cls->giveAttr("__rmod__", new BoxedFunction(boxRTFunction((void*)longRMod, UNKNOWN, 2))); + long_cls->giveAttr("__div__", new BoxedFunction(FunctionMetadata::create((void*)longDiv, UNKNOWN, 2))); + long_cls->giveAttr("__rdiv__", new BoxedFunction(FunctionMetadata::create((void*)longRdiv, UNKNOWN, 2))); + long_cls->giveAttr("__floordiv__", new BoxedFunction(FunctionMetadata::create((void*)longFloorDiv, UNKNOWN, 2))); + long_cls->giveAttr("__rfloordiv__", new BoxedFunction(FunctionMetadata::create((void*)longRfloorDiv, UNKNOWN, 2))); + long_cls->giveAttr("__truediv__", new BoxedFunction(FunctionMetadata::create((void*)longTrueDiv, UNKNOWN, 2))); + long_cls->giveAttr("__rtruediv__", new BoxedFunction(FunctionMetadata::create((void*)longRTrueDiv, UNKNOWN, 2))); + long_cls->giveAttr("__mod__", new BoxedFunction(FunctionMetadata::create((void*)longMod, UNKNOWN, 2))); + long_cls->giveAttr("__rmod__", new BoxedFunction(FunctionMetadata::create((void*)longRMod, UNKNOWN, 2))); - long_cls->giveAttr("__divmod__", new BoxedFunction(boxRTFunction((void*)longDivmod, UNKNOWN, 2))); + long_cls->giveAttr("__divmod__", new BoxedFunction(FunctionMetadata::create((void*)longDivmod, UNKNOWN, 2))); - long_cls->giveAttr("__sub__", new BoxedFunction(boxRTFunction((void*)longSub, UNKNOWN, 2))); - long_cls->giveAttr("__rsub__", new BoxedFunction(boxRTFunction((void*)longRsub, UNKNOWN, 2))); + long_cls->giveAttr("__sub__", new BoxedFunction(FunctionMetadata::create((void*)longSub, UNKNOWN, 2))); + long_cls->giveAttr("__rsub__", new BoxedFunction(FunctionMetadata::create((void*)longRsub, UNKNOWN, 2))); - long_cls->giveAttr("__add__", new BoxedFunction(boxRTFunction((void*)longAdd, UNKNOWN, 2))); + long_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)longAdd, UNKNOWN, 2))); long_cls->giveAttr("__radd__", long_cls->getattr(internStringMortal("__add__"))); - long_cls->giveAttr("__and__", new BoxedFunction(boxRTFunction((void*)longAnd, UNKNOWN, 2))); + long_cls->giveAttr("__and__", new BoxedFunction(FunctionMetadata::create((void*)longAnd, UNKNOWN, 2))); long_cls->giveAttr("__rand__", long_cls->getattr(internStringMortal("__and__"))); - long_cls->giveAttr("__or__", new BoxedFunction(boxRTFunction((void*)longOr, UNKNOWN, 2))); + long_cls->giveAttr("__or__", new BoxedFunction(FunctionMetadata::create((void*)longOr, UNKNOWN, 2))); long_cls->giveAttr("__ror__", long_cls->getattr(internStringMortal("__or__"))); - long_cls->giveAttr("__xor__", new BoxedFunction(boxRTFunction((void*)longXor, UNKNOWN, 2))); + long_cls->giveAttr("__xor__", new BoxedFunction(FunctionMetadata::create((void*)longXor, UNKNOWN, 2))); long_cls->giveAttr("__rxor__", long_cls->getattr(internStringMortal("__xor__"))); // Note: CPython implements long comparisons using tp_compare long_cls->tp_richcompare = long_richcompare; - long_cls->giveAttr("__lshift__", new BoxedFunction(boxRTFunction((void*)longLshift, UNKNOWN, 2))); - long_cls->giveAttr("__rshift__", new BoxedFunction(boxRTFunction((void*)longRshift, UNKNOWN, 2))); + long_cls->giveAttr("__lshift__", new BoxedFunction(FunctionMetadata::create((void*)longLshift, UNKNOWN, 2))); + long_cls->giveAttr("__rshift__", new BoxedFunction(FunctionMetadata::create((void*)longRshift, UNKNOWN, 2))); - long_cls->giveAttr("__int__", new BoxedFunction(boxRTFunction((void*)longInt, UNKNOWN, 1))); - long_cls->giveAttr("__float__", new BoxedFunction(boxRTFunction((void*)longFloat, UNKNOWN, 1))); - long_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)longRepr, STR, 1))); - long_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)longStr, STR, 1))); - long_cls->giveAttr("__bin__", new BoxedFunction(boxRTFunction((void*)longBin, STR, 1))); - long_cls->giveAttr("__hex__", new BoxedFunction(boxRTFunction((void*)longHex, STR, 1))); - long_cls->giveAttr("__oct__", new BoxedFunction(boxRTFunction((void*)longOct, STR, 1))); + long_cls->giveAttr("__int__", new BoxedFunction(FunctionMetadata::create((void*)longInt, UNKNOWN, 1))); + long_cls->giveAttr("__float__", new BoxedFunction(FunctionMetadata::create((void*)longFloat, UNKNOWN, 1))); + long_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)longRepr, STR, 1))); + long_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)longStr, STR, 1))); + long_cls->giveAttr("__bin__", new BoxedFunction(FunctionMetadata::create((void*)longBin, STR, 1))); + long_cls->giveAttr("__hex__", new BoxedFunction(FunctionMetadata::create((void*)longHex, STR, 1))); + long_cls->giveAttr("__oct__", new BoxedFunction(FunctionMetadata::create((void*)longOct, STR, 1))); - long_cls->giveAttr("__invert__", new BoxedFunction(boxRTFunction((void*)longInvert, UNKNOWN, 1))); - long_cls->giveAttr("__neg__", new BoxedFunction(boxRTFunction((void*)longNeg, UNKNOWN, 1))); - long_cls->giveAttr("__pos__", new BoxedFunction(boxRTFunction((void*)longPos, UNKNOWN, 1))); - long_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)longNonzero, BOXED_BOOL, 1))); - long_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)longHash, BOXED_INT, 1))); + long_cls->giveAttr("__invert__", new BoxedFunction(FunctionMetadata::create((void*)longInvert, UNKNOWN, 1))); + long_cls->giveAttr("__neg__", new BoxedFunction(FunctionMetadata::create((void*)longNeg, UNKNOWN, 1))); + long_cls->giveAttr("__pos__", new BoxedFunction(FunctionMetadata::create((void*)longPos, UNKNOWN, 1))); + long_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)longNonzero, BOXED_BOOL, 1))); + long_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)longHash, BOXED_INT, 1))); - long_cls->giveAttr("__trunc__", new BoxedFunction(boxRTFunction((void*)longTrunc, UNKNOWN, 1))); - long_cls->giveAttr("__index__", new BoxedFunction(boxRTFunction((void*)longIndex, LONG, 1))); + long_cls->giveAttr("__trunc__", new BoxedFunction(FunctionMetadata::create((void*)longTrunc, UNKNOWN, 1))); + long_cls->giveAttr("__index__", new BoxedFunction(FunctionMetadata::create((void*)longIndex, LONG, 1))); - long_cls->giveAttr("bit_length", new BoxedFunction(boxRTFunction((void*)longBitLength, LONG, 1))); + long_cls->giveAttr("bit_length", new BoxedFunction(FunctionMetadata::create((void*)longBitLength, LONG, 1))); long_cls->giveAttr("real", new (pyston_getset_cls) BoxedGetsetDescriptor(longLong, NULL, NULL)); long_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(long0, NULL, NULL)); - long_cls->giveAttr("conjugate", new BoxedFunction(boxRTFunction((void*)longLong, UNKNOWN, 1))); + long_cls->giveAttr("conjugate", new BoxedFunction(FunctionMetadata::create((void*)longLong, UNKNOWN, 1))); long_cls->giveAttr("numerator", new (pyston_getset_cls) BoxedGetsetDescriptor(longLong, NULL, NULL)); long_cls->giveAttr("denominator", new (pyston_getset_cls) BoxedGetsetDescriptor(long1, NULL, NULL)); - long_cls->giveAttr("__getnewargs__", - new BoxedFunction(boxRTFunction((void*)long_getnewargs, UNKNOWN, 1, ParamNames::empty(), CAPI))); + long_cls->giveAttr("__getnewargs__", new BoxedFunction(FunctionMetadata::create((void*)long_getnewargs, UNKNOWN, 1, + ParamNames::empty(), CAPI))); add_operators(long_cls); long_cls->freeze(); diff --git a/src/runtime/objmodel.cpp b/src/runtime/objmodel.cpp index 99c1b97c6..63ed14918 100644 --- a/src/runtime/objmodel.cpp +++ b/src/runtime/objmodel.cpp @@ -3198,7 +3198,7 @@ static inline RewriterVar* getArg(int idx, _CallRewriteArgsBase* rewrite_args) { } static StatCounter slowpath_pickversion("slowpath_pickversion"); -static CompiledFunction* pickVersion(CLFunction* f, ExceptionStyle S, int num_output_args, Box* oarg1, Box* oarg2, +static CompiledFunction* pickVersion(FunctionMetadata* f, ExceptionStyle S, int num_output_args, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs) { LOCK_REGION(codegen_rwlock.asWrite()); @@ -3251,7 +3251,7 @@ static CompiledFunction* pickVersion(CLFunction* f, ExceptionStyle S, int num_ou return NULL; } -static llvm::StringRef getFunctionName(CLFunction* f) { +static llvm::StringRef getFunctionName(FunctionMetadata* f) { if (f->source) return f->source->getName()->s(); else if (f->versions.size()) { @@ -3796,7 +3796,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe #endif slowpath_callfunc.log(); - CLFunction* f = func->f; + FunctionMetadata* f = func->f; ParamReceiveSpec paramspec = func->getParamspec(); if (rewrite_args) { @@ -3983,7 +3983,7 @@ static Box* callChosenCF(CompiledFunction* chosen_cf, BoxedClosure* closure, Box // This function exists for the rewriter: astInterpretFunction takes 9 args, but the rewriter // only supports calling functions with at most 6 since it can currently only pass arguments // in registers. -static Box* astInterpretHelper(CLFunction* f, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, +static Box* astInterpretHelper(FunctionMetadata* f, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box** _args) { Box* arg1 = _args[0]; Box* arg2 = _args[1]; @@ -3993,7 +3993,7 @@ static Box* astInterpretHelper(CLFunction* f, BoxedClosure* closure, BoxedGenera return astInterpretFunction(f, closure, generator, globals, arg1, arg2, arg3, (Box**)args); } -static Box* astInterpretHelperCapi(CLFunction* f, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, +static Box* astInterpretHelperCapi(FunctionMetadata* f, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box** _args) noexcept { try { return astInterpretHelper(f, closure, generator, globals, _args); @@ -4003,8 +4003,8 @@ static Box* astInterpretHelperCapi(CLFunction* f, BoxedClosure* closure, BoxedGe } } -static Box* astInterpretHelper2ArgsCapi(CLFunction* f, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, - Box* arg1, Box* arg2) noexcept { +static Box* astInterpretHelper2ArgsCapi(FunctionMetadata* f, BoxedClosure* closure, BoxedGenerator* generator, + Box* globals, Box* arg1, Box* arg2) noexcept { try { return astInterpretFunction(f, closure, generator, globals, arg1, arg2, NULL, NULL); } catch (ExcInfo e) { @@ -4026,7 +4026,7 @@ static Box* capiCallCxxHelper(Box* (*func_ptr)(void*, void*, void*, void*, void* } template -Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, +Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs) noexcept(S == CAPI) { if (rewritable == NOT_REWRITABLE) { @@ -4168,16 +4168,16 @@ Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_arg } // force instantiation: -template Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, +template Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs); -template Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, +template Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs); -template Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, +template Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs); -template Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, +template Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs); diff --git a/src/runtime/objmodel.h b/src/runtime/objmodel.h index e57b83f27..611d578fe 100644 --- a/src/runtime/objmodel.h +++ b/src/runtime/objmodel.h @@ -193,7 +193,7 @@ Box* processDescriptor(Box* obj, Box* inst, Box* owner); Box* processDescriptorOrNull(Box* obj, Box* inst, Box* owner); template -Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, +Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs) noexcept(S == CAPI); diff --git a/src/runtime/set.cpp b/src/runtime/set.cpp index ad429a894..256c7fd39 100644 --- a/src/runtime/set.cpp +++ b/src/runtime/set.cpp @@ -831,23 +831,25 @@ void setupSet() { set_iterator_cls = BoxedClass::create(type_cls, object_cls, &BoxedSetIterator::gcHandler, 0, 0, sizeof(BoxedSetIterator), false, "setiterator"); - set_iterator_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)setiteratorIter, typeFromClass(set_iterator_cls), 1))); + set_iterator_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)setiteratorIter, typeFromClass(set_iterator_cls), 1))); set_iterator_cls->giveAttr("__hasnext__", - new BoxedFunction(boxRTFunction((void*)setiteratorHasnext, BOXED_BOOL, 1))); - set_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)setiteratorNext, UNKNOWN, 1))); + new BoxedFunction(FunctionMetadata::create((void*)setiteratorHasnext, BOXED_BOOL, 1))); + set_iterator_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)setiteratorNext, UNKNOWN, 1))); set_iterator_cls->giveAttr("__length_hint__", - new BoxedFunction(boxRTFunction((void*)setiteratorLength, BOXED_INT, 1))); + new BoxedFunction(FunctionMetadata::create((void*)setiteratorLength, BOXED_INT, 1))); set_iterator_cls->freeze(); set_iterator_cls->tp_iternext = setiter_next; set_iterator_cls->tp_iter = PyObject_SelfIter; - set_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)setNew, UNKNOWN, 2, false, true), { NULL })); - set_cls->giveAttr("__init__", new BoxedFunction(boxRTFunction((void*)setInit, UNKNOWN, 2, false, true), { NULL })); - frozenset_cls->giveAttr("__new__", - new BoxedFunction(boxRTFunction((void*)frozensetNew, UNKNOWN, 2, false, true), { NULL })); + set_cls->giveAttr("__new__", + new BoxedFunction(FunctionMetadata::create((void*)setNew, UNKNOWN, 2, false, true), { NULL })); + set_cls->giveAttr("__init__", + new BoxedFunction(FunctionMetadata::create((void*)setInit, UNKNOWN, 2, false, true), { NULL })); + frozenset_cls->giveAttr( + "__new__", new BoxedFunction(FunctionMetadata::create((void*)frozensetNew, UNKNOWN, 2, false, true), { NULL })); - Box* set_repr = new BoxedFunction(boxRTFunction((void*)setRepr, STR, 1)); + Box* set_repr = new BoxedFunction(FunctionMetadata::create((void*)setRepr, STR, 1)); set_cls->giveAttr("__repr__", set_repr); set_cls->giveAttr("__str__", set_repr); frozenset_cls->giveAttr("__repr__", set_repr); @@ -869,11 +871,11 @@ void setupSet() { v_fu.push_back(UNKNOWN); auto add = [&](const char* name, void* func) { - auto func_obj = new BoxedFunction(boxRTFunction((void*)func, UNKNOWN, 2, false, false)); + auto func_obj = new BoxedFunction(FunctionMetadata::create((void*)func, UNKNOWN, 2, false, false)); set_cls->giveAttr(name, func_obj); frozenset_cls->giveAttr(name, func_obj); /* - CLFunction* func_obj = boxRTFunction(2, false, false); + FunctionMetadata* func_obj = FunctionMetadata::create(2, false, false); addRTFunction(func_obj, (void*)func, SET, v_ss); addRTFunction(func_obj, (void*)func, SET, v_sf); addRTFunction(func_obj, (void*)func, FROZENSET, v_fs); @@ -893,68 +895,71 @@ void setupSet() { add("__iand__", (void*)setIAnd); - set_cls->giveAttr("__iter__", new BoxedFunction(boxRTFunction((void*)setIter, typeFromClass(set_iterator_cls), 1))); + set_cls->giveAttr("__iter__", + new BoxedFunction(FunctionMetadata::create((void*)setIter, typeFromClass(set_iterator_cls), 1))); frozenset_cls->giveAttr("__iter__", set_cls->getattr(internStringMortal("__iter__"))); - set_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)setLen, BOXED_INT, 1))); + set_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)setLen, BOXED_INT, 1))); frozenset_cls->giveAttr("__len__", set_cls->getattr(internStringMortal("__len__"))); - set_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)setContains, BOXED_BOOL, 2))); + set_cls->giveAttr("__contains__", new BoxedFunction(FunctionMetadata::create((void*)setContains, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__contains__", set_cls->getattr(internStringMortal("__contains__"))); - set_cls->giveAttr("__cmp__", new BoxedFunction(boxRTFunction((void*)setNocmp, NONE, 2))); - frozenset_cls->giveAttr("__cmp__", new BoxedFunction(boxRTFunction((void*)setNocmp, NONE, 2))); - set_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)setEq, BOXED_BOOL, 2))); + set_cls->giveAttr("__cmp__", new BoxedFunction(FunctionMetadata::create((void*)setNocmp, NONE, 2))); + frozenset_cls->giveAttr("__cmp__", new BoxedFunction(FunctionMetadata::create((void*)setNocmp, NONE, 2))); + set_cls->giveAttr("__eq__", new BoxedFunction(FunctionMetadata::create((void*)setEq, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__eq__", set_cls->getattr(internStringMortal("__eq__"))); - set_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)setNe, BOXED_BOOL, 2))); + set_cls->giveAttr("__ne__", new BoxedFunction(FunctionMetadata::create((void*)setNe, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__ne__", set_cls->getattr(internStringMortal("__ne__"))); - set_cls->giveAttr("__le__", new BoxedFunction(boxRTFunction((void*)setLe, BOXED_BOOL, 2))); + set_cls->giveAttr("__le__", new BoxedFunction(FunctionMetadata::create((void*)setLe, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__le__", set_cls->getattr(internStringMortal("__le__"))); - set_cls->giveAttr("__lt__", new BoxedFunction(boxRTFunction((void*)setLt, BOXED_BOOL, 2))); + set_cls->giveAttr("__lt__", new BoxedFunction(FunctionMetadata::create((void*)setLt, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__lt__", set_cls->getattr(internStringMortal("__lt__"))); - set_cls->giveAttr("__ge__", new BoxedFunction(boxRTFunction((void*)setGe, BOXED_BOOL, 2))); + set_cls->giveAttr("__ge__", new BoxedFunction(FunctionMetadata::create((void*)setGe, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__ge__", set_cls->getattr(internStringMortal("__ge__"))); - set_cls->giveAttr("__gt__", new BoxedFunction(boxRTFunction((void*)setGt, BOXED_BOOL, 2))); + set_cls->giveAttr("__gt__", new BoxedFunction(FunctionMetadata::create((void*)setGt, BOXED_BOOL, 2))); frozenset_cls->giveAttr("__gt__", set_cls->getattr(internStringMortal("__gt__"))); - set_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)setNonzero, BOXED_BOOL, 1))); + set_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)setNonzero, BOXED_BOOL, 1))); frozenset_cls->giveAttr("__nonzero__", set_cls->getattr(internStringMortal("__nonzero__"))); - frozenset_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)setHash, BOXED_INT, 1))); + frozenset_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)setHash, BOXED_INT, 1))); set_cls->giveAttr("__hash__", None); - set_cls->giveAttr("add", new BoxedFunction(boxRTFunction((void*)setAdd, NONE, 2))); - set_cls->giveAttr("remove", new BoxedFunction(boxRTFunction((void*)setRemove, NONE, 2))); - set_cls->giveAttr("discard", new BoxedFunction(boxRTFunction((void*)setDiscard, NONE, 2))); + set_cls->giveAttr("add", new BoxedFunction(FunctionMetadata::create((void*)setAdd, NONE, 2))); + set_cls->giveAttr("remove", new BoxedFunction(FunctionMetadata::create((void*)setRemove, NONE, 2))); + set_cls->giveAttr("discard", new BoxedFunction(FunctionMetadata::create((void*)setDiscard, NONE, 2))); - set_cls->giveAttr("clear", new BoxedFunction(boxRTFunction((void*)setClear, NONE, 1))); - set_cls->giveAttr("update", new BoxedFunction(boxRTFunction((void*)setUpdate, NONE, 1, true, false))); - set_cls->giveAttr("union", new BoxedFunction(boxRTFunction((void*)setUnion, UNKNOWN, 1, true, false))); + set_cls->giveAttr("clear", new BoxedFunction(FunctionMetadata::create((void*)setClear, NONE, 1))); + set_cls->giveAttr("update", new BoxedFunction(FunctionMetadata::create((void*)setUpdate, NONE, 1, true, false))); + set_cls->giveAttr("union", new BoxedFunction(FunctionMetadata::create((void*)setUnion, UNKNOWN, 1, true, false))); frozenset_cls->giveAttr("union", set_cls->getattr(internStringMortal("union"))); set_cls->giveAttr("intersection", - new BoxedFunction(boxRTFunction((void*)setIntersection, UNKNOWN, 1, true, false))); + new BoxedFunction(FunctionMetadata::create((void*)setIntersection, UNKNOWN, 1, true, false))); frozenset_cls->giveAttr("intersection", set_cls->getattr(internStringMortal("intersection"))); - set_cls->giveAttr("intersection_update", - new BoxedFunction(boxRTFunction((void*)setIntersectionUpdate, UNKNOWN, 1, true, false))); - set_cls->giveAttr("difference", new BoxedFunction(boxRTFunction((void*)setDifference, UNKNOWN, 1, true, false))); + set_cls->giveAttr("intersection_update", new BoxedFunction(FunctionMetadata::create((void*)setIntersectionUpdate, + UNKNOWN, 1, true, false))); + set_cls->giveAttr("difference", + new BoxedFunction(FunctionMetadata::create((void*)setDifference, UNKNOWN, 1, true, false))); frozenset_cls->giveAttr("difference", set_cls->getattr(internStringMortal("difference"))); set_cls->giveAttr("difference_update", - new BoxedFunction(boxRTFunction((void*)setDifferenceUpdate, UNKNOWN, 1, true, false))); - set_cls->giveAttr("symmetric_difference", - new BoxedFunction(boxRTFunction((void*)setSymmetricDifference, UNKNOWN, 2, false, false))); + new BoxedFunction(FunctionMetadata::create((void*)setDifferenceUpdate, UNKNOWN, 1, true, false))); + set_cls->giveAttr("symmetric_difference", new BoxedFunction(FunctionMetadata::create((void*)setSymmetricDifference, + UNKNOWN, 2, false, false))); frozenset_cls->giveAttr("symmetric_difference", set_cls->getattr(internStringMortal("symmetric_difference"))); - set_cls->giveAttr("symmetric_difference_update", - new BoxedFunction(boxRTFunction((void*)setSymmetricDifferenceUpdate, UNKNOWN, 2, false, false))); - set_cls->giveAttr("issubset", new BoxedFunction(boxRTFunction((void*)setIssubset, UNKNOWN, 2))); + set_cls->giveAttr( + "symmetric_difference_update", + new BoxedFunction(FunctionMetadata::create((void*)setSymmetricDifferenceUpdate, UNKNOWN, 2, false, false))); + set_cls->giveAttr("issubset", new BoxedFunction(FunctionMetadata::create((void*)setIssubset, UNKNOWN, 2))); frozenset_cls->giveAttr("issubset", set_cls->getattr(internStringMortal("issubset"))); - set_cls->giveAttr("issuperset", new BoxedFunction(boxRTFunction((void*)setIssuperset, UNKNOWN, 2))); + set_cls->giveAttr("issuperset", new BoxedFunction(FunctionMetadata::create((void*)setIssuperset, UNKNOWN, 2))); frozenset_cls->giveAttr("issuperset", set_cls->getattr(internStringMortal("issuperset"))); - set_cls->giveAttr("isdisjoint", new BoxedFunction(boxRTFunction((void*)setIsdisjoint, UNKNOWN, 2))); + set_cls->giveAttr("isdisjoint", new BoxedFunction(FunctionMetadata::create((void*)setIsdisjoint, UNKNOWN, 2))); frozenset_cls->giveAttr("isdisjoint", set_cls->getattr(internStringMortal("isdisjoint"))); - set_cls->giveAttr("copy", new BoxedFunction(boxRTFunction((void*)setCopy, UNKNOWN, 1))); - frozenset_cls->giveAttr("copy", new BoxedFunction(boxRTFunction((void*)frozensetCopy, UNKNOWN, 1))); - set_cls->giveAttr("pop", new BoxedFunction(boxRTFunction((void*)setPop, UNKNOWN, 1))); + set_cls->giveAttr("copy", new BoxedFunction(FunctionMetadata::create((void*)setCopy, UNKNOWN, 1))); + frozenset_cls->giveAttr("copy", new BoxedFunction(FunctionMetadata::create((void*)frozensetCopy, UNKNOWN, 1))); + set_cls->giveAttr("pop", new BoxedFunction(FunctionMetadata::create((void*)setPop, UNKNOWN, 1))); for (auto& md : set_methods) { set_cls->giveAttr(md.ml_name, new BoxedMethodDescriptor(&md, set_cls)); diff --git a/src/runtime/str.cpp b/src/runtime/str.cpp index 532546d73..e586dc4dd 100644 --- a/src/runtime/str.cpp +++ b/src/runtime/str.cpp @@ -2798,11 +2798,12 @@ void setupStr() { str_iterator_cls = BoxedClass::create(type_cls, object_cls, &BoxedStringIterator::gcHandler, 0, 0, sizeof(BoxedStringIterator), false, "striterator"); - str_iterator_cls->giveAttr("__hasnext__", - new BoxedFunction(boxRTFunction((void*)BoxedStringIterator::hasnext, BOXED_BOOL, 1))); - str_iterator_cls->giveAttr("__iter__", - new BoxedFunction(boxRTFunction((void*)BoxedStringIterator::iter, UNKNOWN, 1))); - str_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)BoxedStringIterator::next, STR, 1))); + str_iterator_cls->giveAttr( + "__hasnext__", new BoxedFunction(FunctionMetadata::create((void*)BoxedStringIterator::hasnext, BOXED_BOOL, 1))); + str_iterator_cls->giveAttr( + "__iter__", new BoxedFunction(FunctionMetadata::create((void*)BoxedStringIterator::iter, UNKNOWN, 1))); + str_iterator_cls->giveAttr("next", + new BoxedFunction(FunctionMetadata::create((void*)BoxedStringIterator::next, STR, 1))); str_iterator_cls->freeze(); str_iterator_cls->tpp_hasnext = (BoxedClass::pyston_inquiry)BoxedStringIterator::hasnextUnboxed; str_iterator_cls->tp_iternext = BoxedStringIterator::next_capi; @@ -2811,83 +2812,90 @@ void setupStr() { str_cls->tp_as_buffer = &string_as_buffer; str_cls->tp_print = string_print; - str_cls->giveAttr("__getnewargs__", new BoxedFunction(boxRTFunction((void*)string_getnewargs, UNKNOWN, 1, - ParamNames::empty(), CAPI))); - - str_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)strLen, BOXED_INT, 1))); - str_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)str_str, STR, 1))); - str_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)strRepr, STR, 1))); - str_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)strHash, UNKNOWN, 1))); - str_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)strNonzero, BOXED_BOOL, 1))); - - str_cls->giveAttr("isalnum", new BoxedFunction(boxRTFunction((void*)strIsAlnum, BOXED_BOOL, 1))); - str_cls->giveAttr("isalpha", new BoxedFunction(boxRTFunction((void*)strIsAlpha, BOXED_BOOL, 1))); - str_cls->giveAttr("isdigit", new BoxedFunction(boxRTFunction((void*)strIsDigit, BOXED_BOOL, 1))); - str_cls->giveAttr("islower", new BoxedFunction(boxRTFunction((void*)strIsLower, BOXED_BOOL, 1))); - str_cls->giveAttr("isspace", new BoxedFunction(boxRTFunction((void*)strIsSpace, BOXED_BOOL, 1))); - str_cls->giveAttr("istitle", new BoxedFunction(boxRTFunction((void*)strIsTitle, BOXED_BOOL, 1))); - str_cls->giveAttr("isupper", new BoxedFunction(boxRTFunction((void*)strIsUpper, BOXED_BOOL, 1))); - - str_cls->giveAttr("decode", new BoxedFunction(boxRTFunction((void*)strDecode, UNKNOWN, 3, false, false), { 0, 0 })); - str_cls->giveAttr("encode", new BoxedFunction(boxRTFunction((void*)strEncode, UNKNOWN, 3, false, false), { 0, 0 })); - - str_cls->giveAttr("lower", new BoxedFunction(boxRTFunction((void*)strLower, STR, 1))); - str_cls->giveAttr("swapcase", new BoxedFunction(boxRTFunction((void*)strSwapcase, STR, 1))); - str_cls->giveAttr("upper", new BoxedFunction(boxRTFunction((void*)strUpper, STR, 1))); - - str_cls->giveAttr("strip", new BoxedFunction(boxRTFunction((void*)strStrip, UNKNOWN, 2, false, false), { None })); - str_cls->giveAttr("lstrip", new BoxedFunction(boxRTFunction((void*)strLStrip, UNKNOWN, 2, false, false), { None })); - str_cls->giveAttr("rstrip", new BoxedFunction(boxRTFunction((void*)strRStrip, UNKNOWN, 2, false, false), { None })); - - str_cls->giveAttr("capitalize", new BoxedFunction(boxRTFunction((void*)strCapitalize, STR, 1))); - str_cls->giveAttr("title", new BoxedFunction(boxRTFunction((void*)strTitle, STR, 1))); + str_cls->giveAttr("__getnewargs__", new BoxedFunction(FunctionMetadata::create((void*)string_getnewargs, UNKNOWN, 1, + ParamNames::empty(), CAPI))); + + str_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)strLen, BOXED_INT, 1))); + str_cls->giveAttr("__str__", new BoxedFunction(FunctionMetadata::create((void*)str_str, STR, 1))); + str_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)strRepr, STR, 1))); + str_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)strHash, UNKNOWN, 1))); + str_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)strNonzero, BOXED_BOOL, 1))); + + str_cls->giveAttr("isalnum", new BoxedFunction(FunctionMetadata::create((void*)strIsAlnum, BOXED_BOOL, 1))); + str_cls->giveAttr("isalpha", new BoxedFunction(FunctionMetadata::create((void*)strIsAlpha, BOXED_BOOL, 1))); + str_cls->giveAttr("isdigit", new BoxedFunction(FunctionMetadata::create((void*)strIsDigit, BOXED_BOOL, 1))); + str_cls->giveAttr("islower", new BoxedFunction(FunctionMetadata::create((void*)strIsLower, BOXED_BOOL, 1))); + str_cls->giveAttr("isspace", new BoxedFunction(FunctionMetadata::create((void*)strIsSpace, BOXED_BOOL, 1))); + str_cls->giveAttr("istitle", new BoxedFunction(FunctionMetadata::create((void*)strIsTitle, BOXED_BOOL, 1))); + str_cls->giveAttr("isupper", new BoxedFunction(FunctionMetadata::create((void*)strIsUpper, BOXED_BOOL, 1))); + + str_cls->giveAttr( + "decode", new BoxedFunction(FunctionMetadata::create((void*)strDecode, UNKNOWN, 3, false, false), { 0, 0 })); + str_cls->giveAttr( + "encode", new BoxedFunction(FunctionMetadata::create((void*)strEncode, UNKNOWN, 3, false, false), { 0, 0 })); + + str_cls->giveAttr("lower", new BoxedFunction(FunctionMetadata::create((void*)strLower, STR, 1))); + str_cls->giveAttr("swapcase", new BoxedFunction(FunctionMetadata::create((void*)strSwapcase, STR, 1))); + str_cls->giveAttr("upper", new BoxedFunction(FunctionMetadata::create((void*)strUpper, STR, 1))); + + str_cls->giveAttr("strip", + new BoxedFunction(FunctionMetadata::create((void*)strStrip, UNKNOWN, 2, false, false), { None })); + str_cls->giveAttr( + "lstrip", new BoxedFunction(FunctionMetadata::create((void*)strLStrip, UNKNOWN, 2, false, false), { None })); + str_cls->giveAttr( + "rstrip", new BoxedFunction(FunctionMetadata::create((void*)strRStrip, UNKNOWN, 2, false, false), { None })); + + str_cls->giveAttr("capitalize", new BoxedFunction(FunctionMetadata::create((void*)strCapitalize, STR, 1))); + str_cls->giveAttr("title", new BoxedFunction(FunctionMetadata::create((void*)strTitle, STR, 1))); str_cls->giveAttr("translate", - new BoxedFunction(boxRTFunction((void*)strTranslate, STR, 3, false, false), { NULL })); + new BoxedFunction(FunctionMetadata::create((void*)strTranslate, STR, 3, false, false), { NULL })); - str_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)strContains, BOXED_BOOL, 2))); + str_cls->giveAttr("__contains__", new BoxedFunction(FunctionMetadata::create((void*)strContains, BOXED_BOOL, 2))); - str_cls->giveAttr("startswith", - new BoxedFunction(boxRTFunction((void*)strStartswith, BOXED_BOOL, 4, 0, 0), { NULL, NULL })); - str_cls->giveAttr("endswith", - new BoxedFunction(boxRTFunction((void*)strEndswith, BOXED_BOOL, 4, 0, 0), { NULL, NULL })); + str_cls->giveAttr( + "startswith", + new BoxedFunction(FunctionMetadata::create((void*)strStartswith, BOXED_BOOL, 4, 0, 0), { NULL, NULL })); + str_cls->giveAttr("endswith", new BoxedFunction(FunctionMetadata::create((void*)strEndswith, BOXED_BOOL, 4, 0, 0), + { NULL, NULL })); - str_cls->giveAttr("partition", new BoxedFunction(boxRTFunction((void*)strPartition, UNKNOWN, 2))); - str_cls->giveAttr("rpartition", new BoxedFunction(boxRTFunction((void*)strRpartition, UNKNOWN, 2))); + str_cls->giveAttr("partition", new BoxedFunction(FunctionMetadata::create((void*)strPartition, UNKNOWN, 2))); + str_cls->giveAttr("rpartition", new BoxedFunction(FunctionMetadata::create((void*)strRpartition, UNKNOWN, 2))); - str_cls->giveAttr("format", new BoxedFunction(boxRTFunction((void*)strFormat, UNKNOWN, 1, true, true))); + str_cls->giveAttr("format", new BoxedFunction(FunctionMetadata::create((void*)strFormat, UNKNOWN, 1, true, true))); - str_cls->giveAttr("__add__", new BoxedFunction(boxRTFunction((void*)strAdd, UNKNOWN, 2))); - str_cls->giveAttr("__mod__", new BoxedFunction(boxRTFunction((void*)strMod, UNKNOWN, 2))); - str_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)strMul, UNKNOWN, 2))); + str_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)strAdd, UNKNOWN, 2))); + str_cls->giveAttr("__mod__", new BoxedFunction(FunctionMetadata::create((void*)strMod, UNKNOWN, 2))); + str_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)strMul, UNKNOWN, 2))); // TODO not sure if this is right in all cases: - str_cls->giveAttr("__rmul__", new BoxedFunction(boxRTFunction((void*)strMul, UNKNOWN, 2))); + str_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)strMul, UNKNOWN, 2))); str_cls->tp_richcompare = str_richcompare; BoxedString* spaceChar = characters[' ' & UCHAR_MAX]; assert(spaceChar); - str_cls->giveAttr("ljust", - new BoxedFunction(boxRTFunction((void*)strLjust, UNKNOWN, 3, false, false), { spaceChar })); - str_cls->giveAttr("rjust", - new BoxedFunction(boxRTFunction((void*)strRjust, UNKNOWN, 3, false, false), { spaceChar })); - str_cls->giveAttr("center", - new BoxedFunction(boxRTFunction((void*)strCenter, UNKNOWN, 3, false, false), { spaceChar })); - - auto str_getitem = boxRTFunction((void*)strGetitem, STR, 2, ParamNames::empty(), CXX); - addRTFunction(str_getitem, (void*)strGetitem, STR, CAPI); + str_cls->giveAttr( + "ljust", new BoxedFunction(FunctionMetadata::create((void*)strLjust, UNKNOWN, 3, false, false), { spaceChar })); + str_cls->giveAttr( + "rjust", new BoxedFunction(FunctionMetadata::create((void*)strRjust, UNKNOWN, 3, false, false), { spaceChar })); + str_cls->giveAttr("center", new BoxedFunction(FunctionMetadata::create((void*)strCenter, UNKNOWN, 3, false, false), + { spaceChar })); + + auto str_getitem = FunctionMetadata::create((void*)strGetitem, STR, 2, ParamNames::empty(), CXX); + str_getitem->addVersion((void*)strGetitem, STR, CAPI); str_cls->giveAttr("__getitem__", new BoxedFunction(str_getitem)); - str_cls->giveAttr("__getslice__", new BoxedFunction(boxRTFunction((void*)strGetslice, STR, 3))); + str_cls->giveAttr("__getslice__", new BoxedFunction(FunctionMetadata::create((void*)strGetslice, STR, 3))); - str_cls->giveAttr("__iter__", new BoxedFunction(boxRTFunction((void*)strIter, typeFromClass(str_iterator_cls), 1))); + str_cls->giveAttr("__iter__", + new BoxedFunction(FunctionMetadata::create((void*)strIter, typeFromClass(str_iterator_cls), 1))); for (auto& md : string_methods) { str_cls->giveAttr(md.ml_name, new BoxedMethodDescriptor(&md, str_cls)); } - str_cls->giveAttr("__new__", - new BoxedFunction(boxRTFunction((void*)strNew, UNKNOWN, 2, false, false), { EmptyString })); + str_cls->giveAttr("__new__", new BoxedFunction(FunctionMetadata::create((void*)strNew, UNKNOWN, 2, false, false), + { EmptyString })); add_operators(str_cls); str_cls->freeze(); @@ -2903,7 +2911,8 @@ void setupStr() { basestring_cls->giveAttr("__doc__", boxString("Type basestring cannot be instantiated; it is the base for str and unicode.")); - basestring_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)basestringNew, UNKNOWN, 1, true, true))); + basestring_cls->giveAttr("__new__", + new BoxedFunction(FunctionMetadata::create((void*)basestringNew, UNKNOWN, 1, true, true))); basestring_cls->freeze(); } diff --git a/src/runtime/super.cpp b/src/runtime/super.cpp index 43b2be395..6ece43fcc 100644 --- a/src/runtime/super.cpp +++ b/src/runtime/super.cpp @@ -200,11 +200,12 @@ void setupSuper() { super_cls = BoxedClass::create(type_cls, object_cls, &BoxedSuper::gcHandler, 0, 0, sizeof(BoxedSuper), false, "super"); - // super_cls->giveAttr("__getattribute__", new BoxedFunction(boxRTFunction((void*)superGetattribute, UNKNOWN, 2))); - super_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)superRepr, STR, 1))); + // super_cls->giveAttr("__getattribute__", new BoxedFunction(FunctionMetadata::create((void*)superGetattribute, + // UNKNOWN, 2))); + super_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)superRepr, STR, 1))); - super_cls->giveAttr("__init__", - new BoxedFunction(boxRTFunction((void*)superInit, UNKNOWN, 3, false, false), { NULL })); + super_cls->giveAttr( + "__init__", new BoxedFunction(FunctionMetadata::create((void*)superInit, UNKNOWN, 3, false, false), { NULL })); super_cls->giveAttr("__thisclass__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedSuper, type))); diff --git a/src/runtime/traceback.cpp b/src/runtime/traceback.cpp index e8b571407..6985ce51c 100644 --- a/src/runtime/traceback.cpp +++ b/src/runtime/traceback.cpp @@ -123,7 +123,8 @@ void setupTraceback() { traceback_cls = BoxedClass::create(type_cls, object_cls, BoxedTraceback::gcHandler, 0, 0, sizeof(BoxedTraceback), false, "traceback"); - traceback_cls->giveAttr("getLines", new BoxedFunction(boxRTFunction((void*)BoxedTraceback::getLines, UNKNOWN, 1))); + traceback_cls->giveAttr("getLines", + new BoxedFunction(FunctionMetadata::create((void*)BoxedTraceback::getLines, UNKNOWN, 1))); traceback_cls->freeze(); } diff --git a/src/runtime/tuple.cpp b/src/runtime/tuple.cpp index 2ec087f2b..4edd7974d 100644 --- a/src/runtime/tuple.cpp +++ b/src/runtime/tuple.cpp @@ -660,37 +660,39 @@ void setupTuple() { tuple_iterator_cls = BoxedClass::create(type_cls, object_cls, &BoxedTupleIterator::gcHandler, 0, 0, sizeof(BoxedTupleIterator), false, "tuple"); - tuple_cls->giveAttr("__new__", new BoxedFunction(boxRTFunction((void*)tupleNew, UNKNOWN, 1, true, true))); - CLFunction* getitem = createRTFunction(2, 0, 0); - addRTFunction(getitem, (void*)tupleGetitemInt, UNKNOWN, std::vector{ UNKNOWN, BOXED_INT }); - addRTFunction(getitem, (void*)tupleGetitemSlice, UNKNOWN, std::vector{ UNKNOWN, SLICE }); - addRTFunction(getitem, (void*)tupleGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, - CXX); - addRTFunction(getitem, (void*)tupleGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, - CAPI); + tuple_cls->giveAttr("__new__", + new BoxedFunction(FunctionMetadata::create((void*)tupleNew, UNKNOWN, 1, true, true))); + FunctionMetadata* getitem = new FunctionMetadata(2, 0, 0); + getitem->addVersion((void*)tupleGetitemInt, UNKNOWN, std::vector{ UNKNOWN, BOXED_INT }); + getitem->addVersion((void*)tupleGetitemSlice, UNKNOWN, std::vector{ UNKNOWN, SLICE }); + getitem->addVersion((void*)tupleGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, CXX); + getitem->addVersion((void*)tupleGetitem, UNKNOWN, std::vector{ UNKNOWN, UNKNOWN }, + CAPI); tuple_cls->giveAttr("__getitem__", new BoxedFunction(getitem)); - tuple_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)tupleContains, BOXED_BOOL, 2))); - tuple_cls->giveAttr("index", new BoxedFunction(boxRTFunction((void*)tupleIndex, BOXED_INT, 4, false, false), - { boxInt(0), boxInt(std::numeric_limits::max()) })); - tuple_cls->giveAttr("count", new BoxedFunction(boxRTFunction((void*)tupleCount, BOXED_INT, 2))); + tuple_cls->giveAttr("__contains__", + new BoxedFunction(FunctionMetadata::create((void*)tupleContains, BOXED_BOOL, 2))); + tuple_cls->giveAttr("index", + new BoxedFunction(FunctionMetadata::create((void*)tupleIndex, BOXED_INT, 4, false, false), + { boxInt(0), boxInt(std::numeric_limits::max()) })); + tuple_cls->giveAttr("count", new BoxedFunction(FunctionMetadata::create((void*)tupleCount, BOXED_INT, 2))); - tuple_cls->giveAttr("__iter__", - new BoxedFunction(boxRTFunction((void*)tupleIter, typeFromClass(tuple_iterator_cls), 1))); + tuple_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create((void*)tupleIter, + typeFromClass(tuple_iterator_cls), 1))); tuple_cls->tp_richcompare = tuplerichcompare; - tuple_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)tupleNonzero, BOXED_BOOL, 1))); + tuple_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)tupleNonzero, BOXED_BOOL, 1))); - tuple_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)tupleLen, BOXED_INT, 1))); - tuple_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)tupleRepr, STR, 1))); - tuple_cls->giveAttr("__add__", new BoxedFunction(boxRTFunction((void*)tupleAdd, BOXED_TUPLE, 2))); - tuple_cls->giveAttr("__mul__", new BoxedFunction(boxRTFunction((void*)tupleMul, BOXED_TUPLE, 2))); - tuple_cls->giveAttr("__rmul__", new BoxedFunction(boxRTFunction((void*)tupleMul, BOXED_TUPLE, 2))); + tuple_cls->giveAttr("__len__", new BoxedFunction(FunctionMetadata::create((void*)tupleLen, BOXED_INT, 1))); + tuple_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)tupleRepr, STR, 1))); + tuple_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)tupleAdd, BOXED_TUPLE, 2))); + tuple_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, BOXED_TUPLE, 2))); + tuple_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, BOXED_TUPLE, 2))); - tuple_cls->giveAttr("__getnewargs__", new BoxedFunction(boxRTFunction((void*)tuple_getnewargs, UNKNOWN, 1, - ParamNames::empty(), CAPI))); + tuple_cls->giveAttr("__getnewargs__", new BoxedFunction(FunctionMetadata::create((void*)tuple_getnewargs, UNKNOWN, + 1, ParamNames::empty(), CAPI))); tuple_cls->tp_hash = (hashfunc)tuple_hash; tuple_cls->tp_as_sequence->sq_slice = (ssizessizeargfunc)&tupleslice; @@ -704,12 +706,12 @@ void setupTuple() { tuple_cls->tp_as_sequence->sq_repeat = (ssizeargfunc)tuplerepeat; tuple_cls->tp_iter = tupleIter; - CLFunction* hasnext = boxRTFunction((void*)tupleiterHasnextUnboxed, BOOL, 1); - addRTFunction(hasnext, (void*)tupleiterHasnext, BOXED_BOOL); + FunctionMetadata* hasnext = FunctionMetadata::create((void*)tupleiterHasnextUnboxed, BOOL, 1); + hasnext->addVersion((void*)tupleiterHasnext, BOXED_BOOL); tuple_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); - tuple_iterator_cls->giveAttr( - "__iter__", new BoxedFunction(boxRTFunction((void*)tupleIterIter, typeFromClass(tuple_iterator_cls), 1))); - tuple_iterator_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)tupleiterNext, UNKNOWN, 1))); + tuple_iterator_cls->giveAttr("__iter__", new BoxedFunction(FunctionMetadata::create( + (void*)tupleIterIter, typeFromClass(tuple_iterator_cls), 1))); + tuple_iterator_cls->giveAttr("next", new BoxedFunction(FunctionMetadata::create((void*)tupleiterNext, UNKNOWN, 1))); tuple_iterator_cls->freeze(); tuple_iterator_cls->tpp_hasnext = tupleiterHasnextUnboxed; diff --git a/src/runtime/types.cpp b/src/runtime/types.cpp index ad240a25d..40185dcac 100644 --- a/src/runtime/types.cpp +++ b/src/runtime/types.cpp @@ -369,7 +369,7 @@ void Box::gcHandler(GCVisitor* v, Box* b) { } } -extern "C" BoxedFunctionBase::BoxedFunctionBase(CLFunction* f) +extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f) : in_weakreflist(NULL), f(f), closure(NULL), @@ -392,7 +392,7 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(CLFunction* f) } } -extern "C" BoxedFunctionBase::BoxedFunctionBase(CLFunction* f, std::initializer_list defaults, +extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure, Box* globals, bool can_change_defaults) : in_weakreflist(NULL), f(f), @@ -440,11 +440,11 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(CLFunction* f, std::initializer_ } } -BoxedFunction::BoxedFunction(CLFunction* f) : BoxedFunction(f, {}) { +BoxedFunction::BoxedFunction(FunctionMetadata* f) : BoxedFunction(f, {}) { } -BoxedFunction::BoxedFunction(CLFunction* f, std::initializer_list defaults, BoxedClosure* closure, Box* globals, - bool can_change_defaults) +BoxedFunction::BoxedFunction(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure, + Box* globals, bool can_change_defaults) : BoxedFunctionBase(f, defaults, closure, globals, can_change_defaults) { // TODO eventually we want this to assert(f->source), I think, but there are still @@ -482,13 +482,13 @@ void BoxedFunction::gcHandler(GCVisitor* v, Box* b) { v->visit(&f->f->source->parent_module); } -BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(CLFunction* f, const char* name, const char* doc) +BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, const char* doc) : BoxedBuiltinFunctionOrMethod(f, name, {}) { this->doc = doc ? boxString(doc) : None; } -BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(CLFunction* f, const char* name, +BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, std::initializer_list defaults, BoxedClosure* closure, const char* doc) : BoxedFunctionBase(f, defaults, closure) { @@ -599,8 +599,8 @@ void BoxedModule::gcHandler(GCVisitor* v, Box* b) { // This mustn't throw; our IR generator generates calls to it without "invoke" even when there are exception handlers / // finally-blocks in scope. -extern "C" Box* boxCLFunction(CLFunction* f, BoxedClosure* closure, Box* globals, - std::initializer_list defaults) noexcept { +extern "C" Box* createFunctionFromMetadata(FunctionMetadata* f, BoxedClosure* closure, Box* globals, + std::initializer_list defaults) noexcept { STAT_TIMER(t0, "us_timer_boxclfunction", 10); if (closure) @@ -609,7 +609,8 @@ extern "C" Box* boxCLFunction(CLFunction* f, BoxedClosure* closure, Box* globals return new BoxedFunction(f, defaults, closure, globals, /* can_change_defaults = */ true); } -extern "C" CLFunction* unboxCLFunction(Box* b) { +extern "C" FunctionMetadata* getFunctionMetadata(Box* b) { + assert(isSubclass(b->cls, function_cls) || isSubclass(b->cls, builtin_function_or_method_cls)); return static_cast(b)->f; } @@ -2252,11 +2253,6 @@ Box* moduleRepr(BoxedModule* m) { return boxString(os.str()); } -CLFunction* unboxRTFunction(Box* b) { - assert(b->cls == function_cls); - return static_cast(b)->f; -} - class AttrWrapper; class AttrWrapperIter : public Box { private: @@ -3839,12 +3835,14 @@ void setupRuntime() { attrwrapperiter_cls = BoxedClass::create(type_cls, object_cls, &AttrWrapperIter::gcHandler, 0, 0, sizeof(AttrWrapperIter), false, "attrwrapperiter"); - pyston_getset_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)getsetGet, UNKNOWN, 3))); - capi_getset_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)getsetGet, UNKNOWN, 3))); - pyston_getset_cls->giveAttr("__set__", new BoxedFunction(boxRTFunction((void*)getsetSet, UNKNOWN, 3))); - capi_getset_cls->giveAttr("__set__", new BoxedFunction(boxRTFunction((void*)getsetSet, UNKNOWN, 3))); - pyston_getset_cls->giveAttr("__delete__", new BoxedFunction(boxRTFunction((void*)getsetDelete, UNKNOWN, 2))); - capi_getset_cls->giveAttr("__delete__", new BoxedFunction(boxRTFunction((void*)getsetDelete, UNKNOWN, 2))); + pyston_getset_cls->giveAttr("__get__", new BoxedFunction(FunctionMetadata::create((void*)getsetGet, UNKNOWN, 3))); + capi_getset_cls->giveAttr("__get__", new BoxedFunction(FunctionMetadata::create((void*)getsetGet, UNKNOWN, 3))); + pyston_getset_cls->giveAttr("__set__", new BoxedFunction(FunctionMetadata::create((void*)getsetSet, UNKNOWN, 3))); + capi_getset_cls->giveAttr("__set__", new BoxedFunction(FunctionMetadata::create((void*)getsetSet, UNKNOWN, 3))); + pyston_getset_cls->giveAttr("__delete__", + new BoxedFunction(FunctionMetadata::create((void*)getsetDelete, UNKNOWN, 2))); + capi_getset_cls->giveAttr("__delete__", + new BoxedFunction(FunctionMetadata::create((void*)getsetDelete, UNKNOWN, 2))); pyston_getset_cls->freeze(); capi_getset_cls->freeze(); @@ -3852,17 +3850,18 @@ void setupRuntime() { SET = typeFromClass(set_cls); FROZENSET = typeFromClass(frozenset_cls); - object_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)objectRepr, UNKNOWN, 1, false, false))); - object_cls->giveAttr("__subclasshook__", - boxInstanceMethod(object_cls, - new BoxedFunction(boxRTFunction((void*)objectSubclasshook, UNKNOWN, 2)), - object_cls)); + object_cls->giveAttr("__repr__", + new BoxedFunction(FunctionMetadata::create((void*)objectRepr, UNKNOWN, 1, false, false))); + object_cls->giveAttr("__subclasshook__", boxInstanceMethod(object_cls, new BoxedFunction(FunctionMetadata::create( + (void*)objectSubclasshook, UNKNOWN, 2)), + object_cls)); // __setattr__ was already set to a WrapperDescriptor; it'd be nice to set this to a faster BoxedFunction - // object_cls->setattr("__setattr__", new BoxedFunction(boxRTFunction((void*)objectSetattr, UNKNOWN, 3)), NULL); + // object_cls->setattr("__setattr__", new BoxedFunction(FunctionMetadata::create((void*)objectSetattr, UNKNOWN, 3)), + // NULL); // but unfortunately that will set tp_setattro to slot_tp_setattro on object_cls and all already-made subclasses! // Punting on that until needed; hopefully by then we will have better Pyston slots support. - auto typeCallObj = boxRTFunction((void*)typeCall, UNKNOWN, 1, true, true); + auto typeCallObj = FunctionMetadata::create((void*)typeCall, UNKNOWN, 1, true, true); typeCallObj->internal_callable.cxx_val = &typeCallInternal; type_cls->giveAttr("__name__", new (pyston_getset_cls) BoxedGetsetDescriptor(typeName, typeSetName, NULL)); @@ -3870,16 +3869,18 @@ void setupRuntime() { type_cls->giveAttr("__call__", new BoxedFunction(typeCallObj)); type_cls->giveAttr( - "__new__", new BoxedFunction(boxRTFunction((void*)typeNewGeneric, UNKNOWN, 4, false, false), { NULL, NULL })); - type_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)typeRepr, STR, 1))); + "__new__", + new BoxedFunction(FunctionMetadata::create((void*)typeNewGeneric, UNKNOWN, 4, false, false), { NULL, NULL })); + type_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)typeRepr, STR, 1))); type_cls->tp_hash = (hashfunc)_Py_HashPointer; type_cls->giveAttr("__module__", new (pyston_getset_cls) BoxedGetsetDescriptor(typeModule, typeSetModule, NULL)); type_cls->giveAttr("__mro__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedClass, tp_mro))); type_cls->giveAttr("__flags__", new BoxedMemberDescriptor(BoxedMemberDescriptor::LONG, offsetof(BoxedClass, tp_flags))); - type_cls->giveAttr("__subclasses__", new BoxedFunction(boxRTFunction((void*)typeSubclasses, UNKNOWN, 1))); - type_cls->giveAttr("mro", new BoxedFunction(boxRTFunction((void*)typeMro, UNKNOWN, 1))); + type_cls->giveAttr("__subclasses__", + new BoxedFunction(FunctionMetadata::create((void*)typeSubclasses, UNKNOWN, 1))); + type_cls->giveAttr("mro", new BoxedFunction(FunctionMetadata::create((void*)typeMro, UNKNOWN, 1))); type_cls->tp_richcompare = type_richcompare; add_operators(type_cls); type_cls->freeze(); @@ -3887,16 +3888,16 @@ void setupRuntime() { type_cls->tpp_call.capi_val = &typeTppCall; type_cls->tpp_call.cxx_val = &typeTppCall; - none_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)none_repr, STR, 1))); - none_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)noneNonzero, BOXED_BOOL, 1))); + none_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)none_repr, STR, 1))); + none_cls->giveAttr("__nonzero__", new BoxedFunction(FunctionMetadata::create((void*)noneNonzero, BOXED_BOOL, 1))); none_cls->giveAttr("__doc__", None); none_cls->tp_hash = (hashfunc)_Py_HashPointer; none_cls->freeze(); none_cls->tp_repr = none_repr; - module_cls->giveAttr("__init__", - new BoxedFunction(boxRTFunction((void*)moduleInit, UNKNOWN, 3, false, false), { NULL })); - module_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)moduleRepr, STR, 1))); + module_cls->giveAttr( + "__init__", new BoxedFunction(FunctionMetadata::create((void*)moduleInit, UNKNOWN, 3, false, false), { NULL })); + module_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)moduleRepr, STR, 1))); module_cls->giveAttr("__dict__", dict_descr); module_cls->freeze(); @@ -3942,16 +3943,18 @@ void setupRuntime() { function_cls->giveAttr("__dict__", dict_descr); function_cls->giveAttr("__name__", new (pyston_getset_cls) BoxedGetsetDescriptor(funcName, funcSetName, NULL)); - function_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)functionRepr, STR, 1))); + function_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)functionRepr, STR, 1))); function_cls->giveAttr("__module__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedFunction, modname), false)); function_cls->giveAttr( "__doc__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedFunction, doc), false)); function_cls->giveAttr("func_doc", function_cls->getattr(internStringMortal("__doc__"))); function_cls->giveAttr("__globals__", new (pyston_getset_cls) BoxedGetsetDescriptor(functionGlobals, NULL, NULL)); - function_cls->giveAttr("__get__", new BoxedFunction(boxRTFunction((void*)functionGet, UNKNOWN, 3))); - function_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)functionCall, UNKNOWN, 1, true, true))); - function_cls->giveAttr("__nonzero__", new BoxedFunction(boxRTFunction((void*)functionNonzero, BOXED_BOOL, 1))); + function_cls->giveAttr("__get__", new BoxedFunction(FunctionMetadata::create((void*)functionGet, UNKNOWN, 3))); + function_cls->giveAttr("__call__", + new BoxedFunction(FunctionMetadata::create((void*)functionCall, UNKNOWN, 1, true, true))); + function_cls->giveAttr("__nonzero__", + new BoxedFunction(FunctionMetadata::create((void*)functionNonzero, BOXED_BOOL, 1))); function_cls->giveAttr("func_code", new (pyston_getset_cls) BoxedGetsetDescriptor(functionCode, functionSetCode, NULL)); function_cls->giveAttr("__code__", function_cls->getattr(internStringMortal("func_code"))); @@ -3967,10 +3970,11 @@ void setupRuntime() { "__module__", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedBuiltinFunctionOrMethod, modname))); builtin_function_or_method_cls->giveAttr( - "__call__", new BoxedFunction(boxRTFunction((void*)builtinFunctionOrMethodCall, UNKNOWN, 1, true, true))); + "__call__", + new BoxedFunction(FunctionMetadata::create((void*)builtinFunctionOrMethodCall, UNKNOWN, 1, true, true))); builtin_function_or_method_cls->giveAttr( - "__repr__", new BoxedFunction(boxRTFunction((void*)builtinFunctionOrMethodRepr, STR, 1))); + "__repr__", new BoxedFunction(FunctionMetadata::create((void*)builtinFunctionOrMethodRepr, STR, 1))); builtin_function_or_method_cls->giveAttr( "__name__", new (pyston_getset_cls) BoxedGetsetDescriptor(builtinFunctionOrMethodName, NULL, NULL)); builtin_function_or_method_cls->giveAttr( @@ -3979,13 +3983,16 @@ void setupRuntime() { builtin_function_or_method_cls->freeze(); instancemethod_cls->giveAttr( - "__new__", new BoxedFunction(boxRTFunction((void*)instancemethodNew, UNKNOWN, 4, false, false), { NULL })); - instancemethod_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)instancemethodRepr, STR, 1))); - instancemethod_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)instancemethodEq, UNKNOWN, 2))); - instancemethod_cls->giveAttr("__get__", - new BoxedFunction(boxRTFunction((void*)instancemethodGet, UNKNOWN, 3, false, false))); - instancemethod_cls->giveAttr("__call__", - new BoxedFunction(boxRTFunction((void*)instancemethodCall, UNKNOWN, 1, true, true))); + "__new__", + new BoxedFunction(FunctionMetadata::create((void*)instancemethodNew, UNKNOWN, 4, false, false), { NULL })); + instancemethod_cls->giveAttr("__repr__", + new BoxedFunction(FunctionMetadata::create((void*)instancemethodRepr, STR, 1))); + instancemethod_cls->giveAttr("__eq__", + new BoxedFunction(FunctionMetadata::create((void*)instancemethodEq, UNKNOWN, 2))); + instancemethod_cls->giveAttr( + "__get__", new BoxedFunction(FunctionMetadata::create((void*)instancemethodGet, UNKNOWN, 3, false, false))); + instancemethod_cls->giveAttr( + "__call__", new BoxedFunction(FunctionMetadata::create((void*)instancemethodCall, UNKNOWN, 1, true, true))); instancemethod_cls->giveAttr( "im_func", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedInstanceMethod, func))); instancemethod_cls->giveAttr("__func__", instancemethod_cls->getattr(internStringMortal("im_func"))); @@ -3997,12 +4004,13 @@ void setupRuntime() { instancemethod_cls->giveAttr("im_class", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedInstanceMethod, im_class), true)); - slice_cls->giveAttr("__new__", - new BoxedFunction(boxRTFunction((void*)sliceNew, UNKNOWN, 4, false, false), { NULL, None })); - slice_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)sliceRepr, STR, 1))); - slice_cls->giveAttr("__hash__", new BoxedFunction(boxRTFunction((void*)sliceHash, UNKNOWN, 1))); - slice_cls->giveAttr("indices", new BoxedFunction(boxRTFunction((void*)sliceIndices, BOXED_TUPLE, 2))); - slice_cls->giveAttr("__reduce__", new BoxedFunction(boxRTFunction((void*)sliceReduce, BOXED_TUPLE, 1))); + slice_cls->giveAttr( + "__new__", + new BoxedFunction(FunctionMetadata::create((void*)sliceNew, UNKNOWN, 4, false, false), { NULL, None })); + slice_cls->giveAttr("__repr__", new BoxedFunction(FunctionMetadata::create((void*)sliceRepr, STR, 1))); + slice_cls->giveAttr("__hash__", new BoxedFunction(FunctionMetadata::create((void*)sliceHash, UNKNOWN, 1))); + slice_cls->giveAttr("indices", new BoxedFunction(FunctionMetadata::create((void*)sliceIndices, BOXED_TUPLE, 2))); + slice_cls->giveAttr("__reduce__", new BoxedFunction(FunctionMetadata::create((void*)sliceReduce, BOXED_TUPLE, 1))); slice_cls->giveAttr("start", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedSlice, start))); slice_cls->giveAttr("stop", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedSlice, stop))); slice_cls->giveAttr("step", new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT, offsetof(BoxedSlice, step))); @@ -4013,43 +4021,57 @@ void setupRuntime() { attrwrapper_cls->tp_as_mapping = &attrwrapper_as_mapping; static PySequenceMethods attrwrapper_as_sequence; attrwrapper_cls->tp_as_sequence = &attrwrapper_as_sequence; - attrwrapper_cls->giveAttr("__setitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::setitem, UNKNOWN, 3))); + attrwrapper_cls->giveAttr("__setitem__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::setitem, UNKNOWN, 3))); + attrwrapper_cls->giveAttr( + "pop", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::pop, UNKNOWN, 3, false, false), { NULL })); attrwrapper_cls->giveAttr( - "pop", new BoxedFunction(boxRTFunction((void*)AttrWrapper::pop, UNKNOWN, 3, false, false), { NULL })); - attrwrapper_cls->giveAttr("__getitem__", - new BoxedFunction(boxRTFunction((void*)AttrWrapper::getitem, UNKNOWN, 2))); - attrwrapper_cls->giveAttr("__delitem__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::delitem, UNKNOWN, 2))); + "__getitem__", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::getitem, UNKNOWN, 2))); + attrwrapper_cls->giveAttr("__delitem__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::delitem, UNKNOWN, 2))); attrwrapper_cls->giveAttr("setdefault", - new BoxedFunction(boxRTFunction((void*)AttrWrapper::setdefault, UNKNOWN, 3))); + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::setdefault, UNKNOWN, 3))); attrwrapper_cls->giveAttr( - "get", new BoxedFunction(boxRTFunction((void*)AttrWrapper::get, UNKNOWN, 3, false, false), { None })); - attrwrapper_cls->giveAttr("__str__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::str, UNKNOWN, 1))); - attrwrapper_cls->giveAttr("__contains__", - new BoxedFunction(boxRTFunction((void*)AttrWrapper::contains, UNKNOWN, 2))); - attrwrapper_cls->giveAttr("__eq__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::eq, UNKNOWN, 2))); - attrwrapper_cls->giveAttr("__ne__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::ne, UNKNOWN, 2))); - attrwrapper_cls->giveAttr("keys", new BoxedFunction(boxRTFunction((void*)AttrWrapper::keys, LIST, 1))); - attrwrapper_cls->giveAttr("values", new BoxedFunction(boxRTFunction((void*)AttrWrapper::values, LIST, 1))); - attrwrapper_cls->giveAttr("items", new BoxedFunction(boxRTFunction((void*)AttrWrapper::items, LIST, 1))); - attrwrapper_cls->giveAttr("iterkeys", new BoxedFunction(boxRTFunction((void*)AttrWrapper::iterkeys, UNKNOWN, 1))); + "get", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::get, UNKNOWN, 3, false, false), { None })); + attrwrapper_cls->giveAttr("__str__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::str, UNKNOWN, 1))); + attrwrapper_cls->giveAttr( + "__contains__", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::contains, UNKNOWN, 2))); + attrwrapper_cls->giveAttr("__eq__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::eq, UNKNOWN, 2))); + attrwrapper_cls->giveAttr("__ne__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::ne, UNKNOWN, 2))); + attrwrapper_cls->giveAttr("keys", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::keys, LIST, 1))); + attrwrapper_cls->giveAttr("values", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::values, LIST, 1))); + attrwrapper_cls->giveAttr("items", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::items, LIST, 1))); + attrwrapper_cls->giveAttr("iterkeys", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::iterkeys, UNKNOWN, 1))); attrwrapper_cls->giveAttr("itervalues", - new BoxedFunction(boxRTFunction((void*)AttrWrapper::itervalues, UNKNOWN, 1))); - attrwrapper_cls->giveAttr("iteritems", new BoxedFunction(boxRTFunction((void*)AttrWrapper::iteritems, UNKNOWN, 1))); - attrwrapper_cls->giveAttr("copy", new BoxedFunction(boxRTFunction((void*)AttrWrapper::copy, UNKNOWN, 1))); - attrwrapper_cls->giveAttr("clear", new BoxedFunction(boxRTFunction((void*)AttrWrapper::clear, NONE, 1))); - attrwrapper_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::len, BOXED_INT, 1))); - attrwrapper_cls->giveAttr("__iter__", new BoxedFunction(boxRTFunction((void*)AttrWrapper::iter, UNKNOWN, 1))); - attrwrapper_cls->giveAttr("update", - new BoxedFunction(boxRTFunction((void*)AttrWrapper::update, NONE, 1, true, true))); + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::itervalues, UNKNOWN, 1))); + attrwrapper_cls->giveAttr("iteritems", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::iteritems, UNKNOWN, 1))); + attrwrapper_cls->giveAttr("copy", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::copy, UNKNOWN, 1))); + attrwrapper_cls->giveAttr("clear", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::clear, NONE, 1))); + attrwrapper_cls->giveAttr("__len__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::len, BOXED_INT, 1))); + attrwrapper_cls->giveAttr("__iter__", + new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::iter, UNKNOWN, 1))); + attrwrapper_cls->giveAttr( + "update", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::update, NONE, 1, true, true))); attrwrapper_cls->freeze(); attrwrapper_cls->tp_iter = AttrWrapper::iter; attrwrapper_cls->tp_as_mapping->mp_subscript = (binaryfunc)AttrWrapper::getitem; attrwrapper_cls->tp_as_mapping->mp_ass_subscript = (objobjargproc)AttrWrapper::ass_sub; attrwrapper_cls->tp_as_sequence->sq_contains = (objobjproc)AttrWrapper::sq_contains; - attrwrapperiter_cls->giveAttr("__hasnext__", - new BoxedFunction(boxRTFunction((void*)AttrWrapperIter::hasnext, UNKNOWN, 1))); - attrwrapperiter_cls->giveAttr("next", new BoxedFunction(boxRTFunction((void*)AttrWrapperIter::next, UNKNOWN, 1))); + attrwrapperiter_cls->giveAttr( + "__hasnext__", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapperIter::hasnext, UNKNOWN, 1))); + attrwrapperiter_cls->giveAttr( + "next", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapperIter::next, UNKNOWN, 1))); attrwrapperiter_cls->freeze(); attrwrapperiter_cls->tp_iter = PyObject_SelfIter; attrwrapperiter_cls->tp_iternext = AttrWrapperIter::next_capi; diff --git a/src/runtime/types.h b/src/runtime/types.h index fb5354158..3ed978083 100644 --- a/src/runtime/types.h +++ b/src/runtime/types.h @@ -161,9 +161,9 @@ extern "C" Box* decodeUTF8StringPtr(llvm::StringRef s); extern "C" inline void listAppendInternal(Box* self, Box* v) __attribute__((visibility("default"))); extern "C" void listAppendArrayInternal(Box* self, Box** v, int nelts); -extern "C" Box* boxCLFunction(CLFunction* f, BoxedClosure* closure, Box* globals, - std::initializer_list defaults) noexcept; -extern "C" CLFunction* unboxCLFunction(Box* b); +extern "C" Box* createFunctionFromMetadata(FunctionMetadata* f, BoxedClosure* closure, Box* globals, + std::initializer_list defaults) noexcept; +extern "C" FunctionMetadata* getFunctionMetadata(Box* b); extern "C" Box* createUserClass(BoxedString* name, Box* base, Box* attr_dict); extern "C" double unboxFloat(Box* b); extern "C" Box* createDict(); @@ -804,7 +804,7 @@ class BoxedFunctionBase : public Box { public: Box** in_weakreflist; - CLFunction* f; + FunctionMetadata* f; // TODO these should really go in BoxedFunction but it's annoying because they don't get // initializd until after BoxedFunctionBase's constructor is run which means they could have @@ -823,8 +823,8 @@ class BoxedFunctionBase : public Box { BoxedString* name; // __name__ (should be here or in one of the derived classes?) Box* doc; // __doc__ - BoxedFunctionBase(CLFunction* f); - BoxedFunctionBase(CLFunction* f, std::initializer_list defaults, BoxedClosure* closure = NULL, + BoxedFunctionBase(FunctionMetadata* f); + BoxedFunctionBase(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure = NULL, Box* globals = NULL, bool can_change_defaults = false); ParamReceiveSpec getParamspec() { @@ -836,8 +836,8 @@ class BoxedFunction : public BoxedFunctionBase { public: HCAttrs attrs; - BoxedFunction(CLFunction* f); - BoxedFunction(CLFunction* f, std::initializer_list defaults, BoxedClosure* closure = NULL, + BoxedFunction(FunctionMetadata* f); + BoxedFunction(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure = NULL, Box* globals = NULL, bool can_change_defaults = false); DEFAULT_CLASS(function_cls); @@ -847,8 +847,8 @@ class BoxedFunction : public BoxedFunctionBase { class BoxedBuiltinFunctionOrMethod : public BoxedFunctionBase { public: - BoxedBuiltinFunctionOrMethod(CLFunction* f, const char* name, const char* doc = NULL); - BoxedBuiltinFunctionOrMethod(CLFunction* f, const char* name, std::initializer_list defaults, + BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, const char* doc = NULL); + BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, std::initializer_list defaults, BoxedClosure* closure = NULL, const char* doc = NULL); DEFAULT_CLASS(builtin_function_or_method_cls); @@ -1132,8 +1132,8 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) extern Box* dict_descr; Box* codeForFunction(BoxedFunction*); -Box* codeForCLFunction(CLFunction*); -CLFunction* clfunctionFromCode(Box* code); +Box* codeForFunctionMetadata(FunctionMetadata*); +FunctionMetadata* clfunctionFromCode(Box* code); Box* getFrame(int depth); diff --git a/src/runtime/util.cpp b/src/runtime/util.cpp index 4b3ad6d4a..90f9d7f16 100644 --- a/src/runtime/util.cpp +++ b/src/runtime/util.cpp @@ -256,7 +256,7 @@ extern "C" void dumpEx(void* p, int levels) { if (isSubclass(b->cls, function_cls)) { BoxedFunction* f = static_cast(b); - CLFunction* cl = f->f; + FunctionMetadata* cl = f->f; if (cl->source) { printf("User-defined function '%s'\n", cl->source->getName()->c_str()); printf("Defined at %s:%d\n", cl->source->getFn()->c_str(), cl->source->body[0]->lineno); diff --git a/test/unittests/analysis.cpp b/test/unittests/analysis.cpp index d543b59d9..92159fc7a 100644 --- a/test/unittests/analysis.cpp +++ b/test/unittests/analysis.cpp @@ -72,7 +72,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) { ScopeInfo* scope_info = scoping->getScopeInfoForNode(func); std::unique_ptr si(new SourceInfo(createModule(boxString("osr" + std::to_string((is_osr << 1) + i_maybe_undefined)), fn.c_str()), scoping, future_flags, func, func->body, boxString(fn))); - CLFunction* clfunc = new CLFunction(0, false, false, std::move(si)); + FunctionMetadata* clfunc = new FunctionMetadata(0, false, false, std::move(si)); CFG* cfg = computeCFG(clfunc->source.get(), func->body); std::unique_ptr liveness = computeLivenessInfo(cfg); From 6e81dc4f8160f5d64fe02ee943adacce8ad69907 Mon Sep 17 00:00:00 2001 From: Kevin Modzelewski Date: Mon, 2 Nov 2015 23:39:02 +0000 Subject: [PATCH 4/4] Renaming some variables for the new type name --- src/capi/typeobject.cpp | 4 +- src/codegen/ast_interpreter.cpp | 117 +++++++++++++++--------------- src/codegen/ast_interpreter.h | 2 +- src/codegen/codegen.cpp | 4 +- src/codegen/codegen.h | 2 +- src/codegen/compvars.cpp | 26 +++---- src/codegen/irgen.cpp | 4 +- src/codegen/irgen.h | 2 +- src/codegen/irgen/hooks.cpp | 92 +++++++++++------------ src/codegen/irgen/irgenerator.cpp | 28 +++---- src/codegen/irgen/irgenerator.h | 12 +-- src/codegen/osrentry.h | 12 +-- src/codegen/runtime_hooks.cpp | 2 +- src/codegen/unwinding.cpp | 56 +++++++------- src/codegen/unwinding.h | 2 +- src/core/types.h | 2 +- src/runtime/code.cpp | 12 +-- src/runtime/complex.cpp | 12 +-- src/runtime/cxx_unwind.cpp | 2 +- src/runtime/float.cpp | 20 ++--- src/runtime/frame.cpp | 4 +- src/runtime/generator.cpp | 11 +-- src/runtime/int.cpp | 26 +++---- src/runtime/long.cpp | 8 +- src/runtime/objmodel.cpp | 33 ++++----- src/runtime/types.cpp | 70 +++++++++--------- src/runtime/types.h | 14 ++-- src/runtime/util.cpp | 16 ++-- 28 files changed, 297 insertions(+), 298 deletions(-) diff --git a/src/capi/typeobject.cpp b/src/capi/typeobject.cpp index fbf122257..1c7ada75c 100644 --- a/src/capi/typeobject.cpp +++ b/src/capi/typeobject.cpp @@ -1915,8 +1915,8 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce sanity checks. I'll buy the first person to point out a bug in this reasoning a beer. */ } else if (offset == offsetof(BoxedClass, tp_descr_get) && descr->cls == function_cls - && static_cast(descr)->f->always_use_version) { - CompiledFunction* cf = static_cast(descr)->f->always_use_version; + && static_cast(descr)->md->always_use_version) { + CompiledFunction* cf = static_cast(descr)->md->always_use_version; if (cf->exception_style == CXX) { type->tpp_descr_get = (descrgetfunc)cf->code; specific = (void*)slot_tp_tpp_descr_get; diff --git a/src/codegen/ast_interpreter.cpp b/src/codegen/ast_interpreter.cpp index 16c2f63d0..e2f9c3e9d 100644 --- a/src/codegen/ast_interpreter.cpp +++ b/src/codegen/ast_interpreter.cpp @@ -66,7 +66,7 @@ extern "C" Box* executeInnerAndSetupFrame(ASTInterpreter& interpreter, CFGBlock* */ class ASTInterpreter { public: - ASTInterpreter(FunctionMetadata* clfunc, Box** vregs); + ASTInterpreter(FunctionMetadata* md, Box** vregs); void initArguments(BoxedClosure* closure, BoxedGenerator* generator, Box* arg1, Box* arg2, Box* arg3, Box** args); @@ -138,7 +138,7 @@ class ASTInterpreter { CFGBlock* next_block, *current_block; AST_stmt* current_inst; - FunctionMetadata* clfunc; + FunctionMetadata* md; SourceInfo* source_info; ScopeInfo* scope_info; PhiAnalysis* phis; @@ -172,7 +172,7 @@ class ASTInterpreter { return globals; } - FunctionMetadata* getCL() { return clfunc; } + FunctionMetadata* getMD() { return md; } FrameInfo* getFrameInfo() { return &frame_info; } BoxedClosure* getPassedClosure() { return passed_closure; } Box** getVRegs() { return vregs; } @@ -227,11 +227,11 @@ void ASTInterpreter::setGlobals(Box* globals) { this->globals = globals; } -ASTInterpreter::ASTInterpreter(FunctionMetadata* clfunc, Box** vregs) +ASTInterpreter::ASTInterpreter(FunctionMetadata* md, Box** vregs) : current_block(0), current_inst(0), - clfunc(clfunc), - source_info(clfunc->source.get()), + md(md), + source_info(md->source.get()), scope_info(0), phis(NULL), vregs(vregs), @@ -258,7 +258,7 @@ void ASTInterpreter::initArguments(BoxedClosure* _closure, BoxedGenerator* _gene if (scope_info->createsClosure()) created_closure = createClosure(passed_closure, scope_info->getClosureSize()); - const ParamNames& param_names = clfunc->param_names; + const ParamNames& param_names = md->param_names; // make sure the AST_Name nodes are set assert(param_names.args.size() == param_names.arg_names.size()); @@ -286,7 +286,7 @@ void ASTInterpreter::startJITing(CFGBlock* block, int exit_offset) { assert(ENABLE_BASELINEJIT); assert(!jit); - auto& code_blocks = clfunc->code_blocks; + auto& code_blocks = md->code_blocks; JitCodeBlock* code_block = NULL; if (!code_blocks.empty()) code_block = code_blocks[code_blocks.size() - 1].get(); @@ -330,7 +330,7 @@ Box* ASTInterpreter::execJITedBlock(CFGBlock* b) { if (stmt->type != AST_TYPE::Invoke) throw e; - auto source = getCL()->source.get(); + auto source = getMD()->source.get(); stmt->cxx_exception_count++; caughtCxxException(LineInfo(stmt->lineno, stmt->col_offset, source->getFn(), source->getName()), &e); @@ -373,7 +373,7 @@ Box* ASTInterpreter::executeInner(ASTInterpreter& interpreter, CFGBlock* start_b interpreter.next_block = start_block; } - if (ENABLE_BASELINEJIT && interpreter.clfunc->times_interpreted >= REOPT_THRESHOLD_INTERPRETER) + if (ENABLE_BASELINEJIT && interpreter.md->times_interpreted >= REOPT_THRESHOLD_INTERPRETER) interpreter.should_jit = true; while (interpreter.next_block) { @@ -627,7 +627,7 @@ Value ASTInterpreter::visit_jump(AST_Jump* node) { // we may have started JITing because the OSR thresholds got triggered in this case we don't want to jit // additional blocks ouside of the loop if the function is cold. - if (clfunc->times_interpreted < REOPT_THRESHOLD_INTERPRETER) + if (md->times_interpreted < REOPT_THRESHOLD_INTERPRETER) should_jit = false; } @@ -658,8 +658,7 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) { ast_osrs.log(); LivenessAnalysis* liveness = source_info->getLiveness(); - std::unique_ptr phis - = computeRequiredPhis(clfunc->param_names, source_info->cfg, liveness, scope_info); + std::unique_ptr phis = computeRequiredPhis(md->param_names, source_info->cfg, liveness, scope_info); llvm::DenseMap offset_name_map; for (auto&& v : getSymVRegMap()) { @@ -681,7 +680,7 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) { } const OSREntryDescriptor* found_entry = nullptr; - for (auto& p : clfunc->osr_versions) { + for (auto& p : md->osr_versions) { if (p.first->backedge != node) continue; @@ -737,7 +736,7 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) { sorted_symbol_table[source_info->getInternedStrings().get(FRAME_INFO_PTR_NAME)] = (Box*)&frame_info; if (found_entry == nullptr) { - OSREntryDescriptor* entry = OSREntryDescriptor::create(clfunc, node, CXX); + OSREntryDescriptor* entry = OSREntryDescriptor::create(md, node, CXX); for (auto& it : sorted_symbol_table) { if (isIsDefinedName(it.first)) @@ -794,7 +793,7 @@ Value ASTInterpreter::visit_invoke(AST_Invoke* node) { } catch (ExcInfo e) { abortJITing(); - auto source = getCL()->source.get(); + auto source = getMD()->source.get(); node->cxx_exception_count++; caughtCxxException(LineInfo(node->lineno, node->col_offset, source->getFn(), source->getName()), &e); @@ -987,7 +986,7 @@ Value ASTInterpreter::visit_return(AST_Return* node) { } Value ASTInterpreter::createFunction(AST* node, AST_arguments* args, const std::vector& body) { - FunctionMetadata* cl = wrapFunction(node, args, body, source_info); + FunctionMetadata* md = wrapFunction(node, args, body, source_info); std::vector> defaults; @@ -1048,7 +1047,7 @@ Value ASTInterpreter::createFunction(AST* node, AST_arguments* args, const std:: Box* passed_globals = NULL; RewriterVar* passed_globals_var = NULL; - if (!getCL()->source->scoping->areGlobalsFromModule()) { + if (!getMD()->source->scoping->areGlobalsFromModule()) { passed_globals = globals; if (jit) passed_globals_var = jit->getInterp()->getAttr(offsetof(ASTInterpreter, globals)); @@ -1060,11 +1059,11 @@ Value ASTInterpreter::createFunction(AST* node, AST_arguments* args, const std:: closure_var = jit->imm(0ul); if (!passed_globals_var) passed_globals_var = jit->imm(0ul); - rtn.var = jit->call(false, (void*)createFunctionFromMetadata, jit->imm(cl), closure_var, passed_globals_var, + rtn.var = jit->call(false, (void*)createFunctionFromMetadata, jit->imm(md), closure_var, passed_globals_var, defaults_var, jit->imm(args->defaults.size())); } - rtn.o = createFunctionFromMetadata(cl, closure, passed_globals, u.il); + rtn.o = createFunctionFromMetadata(md, closure, passed_globals, u.il); return rtn; } @@ -1111,13 +1110,13 @@ Value ASTInterpreter::visit_makeClass(AST_MakeClass* mkclass) { closure = created_closure; assert(closure); } - FunctionMetadata* cl = wrapFunction(node, nullptr, node->body, source_info); + FunctionMetadata* md = wrapFunction(node, nullptr, node->body, source_info); Box* passed_globals = NULL; - if (!getCL()->source->scoping->areGlobalsFromModule()) + if (!getMD()->source->scoping->areGlobalsFromModule()) passed_globals = globals; Box* attrDict - = runtimeCall(createFunctionFromMetadata(cl, closure, passed_globals, {}), ArgPassSpec(0), 0, 0, 0, 0, 0); + = runtimeCall(createFunctionFromMetadata(md, closure, passed_globals, {}), ArgPassSpec(0), 0, 0, 0, 0, 0); Box* classobj = createUserClass(node->name.getBox(), basesTuple, attrDict); @@ -1699,8 +1698,8 @@ extern "C" Box* executeInnerFromASM(ASTInterpreter& interpreter, CFGBlock* start return ASTInterpreter::executeInner(interpreter, start_block, start_at); } -static int calculateNumVRegs(FunctionMetadata* clfunc) { - SourceInfo* source_info = clfunc->source.get(); +static int calculateNumVRegs(FunctionMetadata* md) { + SourceInfo* source_info = md->source.get(); CFG* cfg = source_info->cfg; @@ -1715,24 +1714,24 @@ static int calculateNumVRegs(FunctionMetadata* clfunc) { cfg = source_info->cfg = computeCFG(source_info, source_info->body); if (!cfg->hasVregsAssigned()) { - ScopeInfo* scope_info = clfunc->source->getScopeInfo(); - cfg->assignVRegs(clfunc->param_names, scope_info); + ScopeInfo* scope_info = md->source->getScopeInfo(); + cfg->assignVRegs(md->param_names, scope_info); } return cfg->sym_vreg_map.size(); } -Box* astInterpretFunction(FunctionMetadata* clfunc, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, +Box* astInterpretFunction(FunctionMetadata* md, Box* closure, Box* generator, Box* globals, Box* arg1, Box* arg2, Box* arg3, Box** args) { UNAVOIDABLE_STAT_TIMER(t0, "us_timer_in_interpreter"); - SourceInfo* source_info = clfunc->source.get(); + SourceInfo* source_info = md->source.get(); assert((!globals) == source_info->scoping->areGlobalsFromModule()); bool can_reopt = ENABLE_REOPT && !FORCE_INTERPRETER; if (unlikely(can_reopt - && (FORCE_OPTIMIZE || !ENABLE_INTERPRETER || clfunc->times_interpreted > REOPT_THRESHOLD_BASELINE))) { - clfunc->times_interpreted = 0; + && (FORCE_OPTIMIZE || !ENABLE_INTERPRETER || md->times_interpreted > REOPT_THRESHOLD_BASELINE))) { + md->times_interpreted = 0; // EffortLevel new_effort = EffortLevel::MODERATE; EffortLevel new_effort = EffortLevel::MAXIMAL; // always use max opt (disabled moderate opt tier) @@ -1740,10 +1739,10 @@ Box* astInterpretFunction(FunctionMetadata* clfunc, Box* closure, Box* generator new_effort = EffortLevel::MAXIMAL; std::vector arg_types; - for (int i = 0; i < clfunc->param_names.totalParameters(); i++) { + for (int i = 0; i < md->param_names.totalParameters(); i++) { Box* arg = getArg(i, arg1, arg2, arg3, args); - assert(arg || i == clfunc->param_names.kwargsIndex()); // only builtin functions can pass NULL args + assert(arg || i == md->param_names.kwargsIndex()); // only builtin functions can pass NULL args // TODO: reenable argument-type specialization arg_types.push_back(UNKNOWN); @@ -1752,9 +1751,9 @@ Box* astInterpretFunction(FunctionMetadata* clfunc, Box* closure, Box* generator FunctionSpecialization* spec = new FunctionSpecialization(UNKNOWN, arg_types); // this also pushes the new CompiledVersion to the back of the version list: - CompiledFunction* optimized = compileFunction(clfunc, spec, new_effort, NULL); + CompiledFunction* optimized = compileFunction(md, spec, new_effort, NULL); - clfunc->dependent_interp_callsites.invalidateAll(); + md->dependent_interp_callsites.invalidateAll(); UNAVOIDABLE_STAT_TIMER(t0, "us_timer_in_jitted_code"); Box* r; @@ -1787,22 +1786,22 @@ Box* astInterpretFunction(FunctionMetadata* clfunc, Box* closure, Box* generator } Box** vregs = NULL; - int num_vregs = calculateNumVRegs(clfunc); + int num_vregs = calculateNumVRegs(md); if (num_vregs > 0) { vregs = (Box**)alloca(sizeof(Box*) * num_vregs); memset(vregs, 0, sizeof(Box*) * num_vregs); } - ++clfunc->times_interpreted; - ASTInterpreter interpreter(clfunc, vregs); + ++md->times_interpreted; + ASTInterpreter interpreter(md, vregs); - ScopeInfo* scope_info = clfunc->source->getScopeInfo(); + ScopeInfo* scope_info = md->source->getScopeInfo(); if (unlikely(scope_info->usesNameLookup())) { interpreter.setBoxedLocals(new BoxedDict()); } - assert((!globals) == clfunc->source->scoping->areGlobalsFromModule()); + assert((!globals) == md->source->scoping->areGlobalsFromModule()); if (globals) { interpreter.setGlobals(globals); } else { @@ -1814,21 +1813,21 @@ Box* astInterpretFunction(FunctionMetadata* clfunc, Box* closure, Box* generator return v ? v : None; } -Box* astInterpretFunctionEval(FunctionMetadata* clfunc, Box* globals, Box* boxedLocals) { - ++clfunc->times_interpreted; +Box* astInterpretFunctionEval(FunctionMetadata* md, Box* globals, Box* boxedLocals) { + ++md->times_interpreted; Box** vregs = NULL; - int num_vregs = calculateNumVRegs(clfunc); + int num_vregs = calculateNumVRegs(md); if (num_vregs > 0) { vregs = (Box**)alloca(sizeof(Box*) * num_vregs); memset(vregs, 0, sizeof(Box*) * num_vregs); } - ASTInterpreter interpreter(clfunc, vregs); + ASTInterpreter interpreter(md, vregs); interpreter.initArguments(NULL, NULL, NULL, NULL, NULL, NULL); interpreter.setBoxedLocals(boxedLocals); - assert(!clfunc->source->scoping->areGlobalsFromModule()); + assert(!md->source->scoping->areGlobalsFromModule()); assert(globals); interpreter.setGlobals(globals); @@ -1836,26 +1835,26 @@ Box* astInterpretFunctionEval(FunctionMetadata* clfunc, Box* globals, Box* boxed return v ? v : None; } -static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, - Box* expr_val, FrameStackState frame_state) __attribute__((noinline)); -static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, - Box* expr_val, FrameStackState frame_state) { - assert(clfunc); +static Box* astInterpretDeoptInner(FunctionMetadata* md, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, + FrameStackState frame_state) __attribute__((noinline)); +static Box* astInterpretDeoptInner(FunctionMetadata* md, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, + FrameStackState frame_state) { + assert(md); assert(enclosing_stmt); assert(frame_state.locals); assert(after_expr); assert(expr_val); - SourceInfo* source_info = clfunc->source.get(); + SourceInfo* source_info = md->source.get(); Box** vregs = NULL; - int num_vregs = calculateNumVRegs(clfunc); + int num_vregs = calculateNumVRegs(md); if (num_vregs > 0) { vregs = (Box**)alloca(sizeof(Box*) * num_vregs); memset(vregs, 0, sizeof(Box*) * num_vregs); } - ASTInterpreter interpreter(clfunc, vregs); + ASTInterpreter interpreter(md, vregs); if (source_info->scoping->areGlobalsFromModule()) interpreter.setGlobals(source_info->parent_module); @@ -1872,7 +1871,7 @@ static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_exp assert(!source_info->scoping->areGlobalsFromModule()); interpreter.setGlobals(p.second); } else { - InternedString interned = clfunc->source->getInternedStrings().get(name); + InternedString interned = md->source->getInternedStrings().get(name); interpreter.addSymbol(interned, p.second, false); } } @@ -1909,7 +1908,7 @@ static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_exp if (start_block == NULL) { // TODO innefficient - for (auto block : clfunc->source->cfg->blocks) { + for (auto block : md->source->cfg->blocks) { int n = block->body.size(); for (int i = 0; i < n; i++) { if (block->body[i] == enclosing_stmt) { @@ -1932,9 +1931,9 @@ static Box* astInterpretDeoptInner(FunctionMetadata* clfunc, AST_expr* after_exp return v ? v : None; } -Box* astInterpretDeopt(FunctionMetadata* clfunc, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, +Box* astInterpretDeopt(FunctionMetadata* md, AST_expr* after_expr, AST_stmt* enclosing_stmt, Box* expr_val, FrameStackState frame_state) { - return astInterpretDeoptInner(clfunc, after_expr, enclosing_stmt, expr_val, frame_state); + return astInterpretDeoptInner(md, after_expr, enclosing_stmt, expr_val, frame_state); } extern "C" void printExprHelper(Box* obj) { @@ -1962,10 +1961,10 @@ Box* getGlobalsForInterpretedFrame(void* frame_ptr) { return interpreter->getGlobals(); } -FunctionMetadata* getCLForInterpretedFrame(void* frame_ptr) { +FunctionMetadata* getMDForInterpretedFrame(void* frame_ptr) { ASTInterpreter* interpreter = getInterpreterFromFramePtr(frame_ptr); assert(interpreter); - return interpreter->getCL(); + return interpreter->getMD(); } FrameInfo* getFrameInfoForInterpretedFrame(void* frame_ptr) { diff --git a/src/codegen/ast_interpreter.h b/src/codegen/ast_interpreter.h index 080b0b0da..915a7db33 100644 --- a/src/codegen/ast_interpreter.h +++ b/src/codegen/ast_interpreter.h @@ -78,7 +78,7 @@ Box* astInterpretDeopt(FunctionMetadata* cf, AST_expr* after_expr, AST_stmt* enc AST_stmt* getCurrentStatementForInterpretedFrame(void* frame_ptr); Box* getGlobalsForInterpretedFrame(void* frame_ptr); -FunctionMetadata* getCLForInterpretedFrame(void* frame_ptr); +FunctionMetadata* getMDForInterpretedFrame(void* frame_ptr); struct FrameInfo; FrameInfo* getFrameInfoForInterpretedFrame(void* frame_ptr); BoxedClosure* passedClosureForInterpretedFrame(void* frame_ptr); diff --git a/src/codegen/codegen.cpp b/src/codegen/codegen.cpp index a6dde84d7..05ee6b0a5 100644 --- a/src/codegen/codegen.cpp +++ b/src/codegen/codegen.cpp @@ -75,9 +75,9 @@ BoxedCode* FunctionMetadata::getCode() { void FunctionMetadata::addVersion(CompiledFunction* compiled) { assert(compiled); assert((compiled->spec != NULL) + (compiled->entry_descriptor != NULL) == 1); - assert(compiled->clfunc == NULL); + assert(compiled->md == NULL); assert(compiled->code); - compiled->clfunc = this; + compiled->md = this; if (compiled->entry_descriptor == NULL) { bool could_have_speculations = (source.get() != NULL); diff --git a/src/codegen/codegen.h b/src/codegen/codegen.h index 75870f6bb..79be0e005 100644 --- a/src/codegen/codegen.h +++ b/src/codegen/codegen.h @@ -74,7 +74,7 @@ struct GlobalState { llvm::Type* llvm_opaque_type; llvm::Type* llvm_boxedstring_type_ptr, *llvm_dict_type_ptr, *llvm_aststmt_type_ptr, *llvm_astexpr_type_ptr; llvm::Type* llvm_frame_info_type; - llvm::Type* llvm_clfunction_type_ptr, *llvm_closure_type_ptr, *llvm_generator_type_ptr; + llvm::Type* llvm_functionmetadata_type_ptr, *llvm_closure_type_ptr, *llvm_generator_type_ptr; llvm::Type* llvm_module_type_ptr, *llvm_bool_type_ptr; llvm::Type* llvm_excinfo_type; llvm::Type* i1, *i8, *i8_ptr, *i32, *i64, *void_, *double_; diff --git a/src/codegen/compvars.cpp b/src/codegen/compvars.cpp index 50e6b38d6..8de7e8f29 100644 --- a/src/codegen/compvars.cpp +++ b/src/codegen/compvars.cpp @@ -845,8 +845,8 @@ CompilerVariable* makeFunction(IREmitter& emitter, FunctionMetadata* f, Compiler // emitter.createCall(). llvm::Value* boxed = emitter.getBuilder()->CreateCall( g.funcs.createFunctionFromMetadata, - std::vector{ embedRelocatablePtr(f, g.llvm_clfunction_type_ptr), closure_v, globals, scratch, - getConstantInt(defaults.size(), g.i64) }); + std::vector{ embedRelocatablePtr(f, g.llvm_functionmetadata_type_ptr), closure_v, globals, + scratch, getConstantInt(defaults.size(), g.i64) }); if (convertedClosure) convertedClosure->decvref(emitter); @@ -915,12 +915,12 @@ class AbstractFunctionType : public CompilerType { static CompilerType* fromRT(BoxedFunction* rtfunc, bool stripfirst) { std::vector sigs; - FunctionMetadata* clf = rtfunc->f; + FunctionMetadata* md = rtfunc->md; assert(!rtfunc->can_change_defaults); - for (int i = 0; i < clf->versions.size(); i++) { - CompiledFunction* cf = clf->versions[i]; + for (int i = 0; i < md->versions.size(); i++) { + CompiledFunction* cf = md->versions[i]; FunctionSpecialization* fspec = cf->spec; @@ -1865,14 +1865,14 @@ class NormalObjectType : public ConcreteCompilerType { // but I don't think we should be running into that case. RELEASE_ASSERT(!rtattr_func->can_change_defaults, "could handle this but unexpected"); - FunctionMetadata* cl = rtattr_func->f; - assert(cl); + FunctionMetadata* md = rtattr_func->md; + assert(md); ParamReceiveSpec paramspec = rtattr_func->getParamspec(); - if (cl->takes_varargs || paramspec.takes_kwargs) + if (md->takes_varargs || paramspec.takes_kwargs) return NULL; - RELEASE_ASSERT(paramspec.num_args == cl->numReceivedArgs(), ""); + RELEASE_ASSERT(paramspec.num_args == md->numReceivedArgs(), ""); RELEASE_ASSERT(args.size() + 1 >= paramspec.num_args - paramspec.num_defaults && args.size() + 1 <= paramspec.num_args, "%d", info.unw_info.current_stmt->lineno); @@ -1881,9 +1881,9 @@ class NormalObjectType : public ConcreteCompilerType { CompiledFunction* best_exception_mismatch = NULL; bool found = false; // TODO have to find the right version.. similar to resolveclfunc? - for (int i = 0; i < cl->versions.size(); i++) { - cf = cl->versions[i]; - assert(cf->spec->arg_types.size() == cl->numReceivedArgs()); + for (int i = 0; i < md->versions.size(); i++) { + cf = md->versions[i]; + assert(cf->spec->arg_types.size() == md->numReceivedArgs()); bool fits = true; for (int j = 0; j < args.size(); j++) { @@ -1915,7 +1915,7 @@ class NormalObjectType : public ConcreteCompilerType { RELEASE_ASSERT(cf->code, ""); std::vector arg_types; - RELEASE_ASSERT(paramspec.num_args == cl->numReceivedArgs(), ""); + RELEASE_ASSERT(paramspec.num_args == md->numReceivedArgs(), ""); for (int i = 0; i < paramspec.num_args; i++) { // TODO support passing unboxed values as arguments assert(cf->spec->arg_types[i]->llvmType() == g.llvm_value_type_ptr); diff --git a/src/codegen/irgen.cpp b/src/codegen/irgen.cpp index 8b73c6b2c..7d034f786 100644 --- a/src/codegen/irgen.cpp +++ b/src/codegen/irgen.cpp @@ -974,7 +974,7 @@ static std::string getUniqueFunctionName(std::string nameprefix, EffortLevel eff return os.str(); } -CompiledFunction* doCompile(FunctionMetadata* clfunc, SourceInfo* source, ParamNames* param_names, +CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names, const OSREntryDescriptor* entry_descriptor, EffortLevel effort, ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix) { Timer _t("in doCompile"); @@ -1093,7 +1093,7 @@ CompiledFunction* doCompile(FunctionMetadata* clfunc, SourceInfo* source, ParamN else phis = computeRequiredPhis(*param_names, source->cfg, liveness, source->getScopeInfo()); - IRGenState irstate(clfunc, cf, source, std::move(phis), param_names, getGCBuilder(), dbg_funcinfo); + IRGenState irstate(md, cf, source, std::move(phis), param_names, getGCBuilder(), dbg_funcinfo); emitBBs(&irstate, types, entry_descriptor, blocks); diff --git a/src/codegen/irgen.h b/src/codegen/irgen.h index 393de8b8b..201108bfb 100644 --- a/src/codegen/irgen.h +++ b/src/codegen/irgen.h @@ -113,7 +113,7 @@ extern const std::string PASSED_GENERATOR_NAME; InternedString getIsDefinedName(InternedString name, InternedStringPool& interned_strings); bool isIsDefinedName(llvm::StringRef name); -CompiledFunction* doCompile(FunctionMetadata* clfunc, SourceInfo* source, ParamNames* param_names, +CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames* param_names, const OSREntryDescriptor* entry_descriptor, EffortLevel effort, ExceptionStyle exception_style, FunctionSpecialization* spec, llvm::StringRef nameprefix); diff --git a/src/codegen/irgen/hooks.cpp b/src/codegen/irgen/hooks.cpp index f205be5d0..08f292f58 100644 --- a/src/codegen/irgen/hooks.cpp +++ b/src/codegen/irgen/hooks.cpp @@ -310,7 +310,7 @@ CompiledFunction* compileFunction(FunctionMetadata* f, FunctionSpecialization* s } void compileAndRunModule(AST_Module* m, BoxedModule* bm) { - FunctionMetadata* clfunc; + FunctionMetadata* md; { // scope for limiting the locked region: LOCK_REGION(codegen_rwlock.asWrite()); @@ -332,26 +332,26 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) { if (!bm->hasattr(builtins_str)) bm->giveAttr(builtins_str, PyModule_GetDict(builtins_module)); - clfunc = new FunctionMetadata(0, false, false, std::move(si)); + md = new FunctionMetadata(0, false, false, std::move(si)); } UNAVOIDABLE_STAT_TIMER(t0, "us_timer_interpreted_module_toplevel"); - Box* r = astInterpretFunction(clfunc, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + Box* r = astInterpretFunction(md, NULL, NULL, NULL, NULL, NULL, NULL, NULL); assert(r == None); } -Box* evalOrExec(FunctionMetadata* cl, Box* globals, Box* boxedLocals) { - RELEASE_ASSERT(!cl->source->scoping->areGlobalsFromModule(), ""); +Box* evalOrExec(FunctionMetadata* md, Box* globals, Box* boxedLocals) { + RELEASE_ASSERT(!md->source->scoping->areGlobalsFromModule(), ""); assert(globals && (globals->cls == module_cls || globals->cls == dict_cls)); - Box* doc_string = cl->source->getDocString(); + Box* doc_string = md->source->getDocString(); if (doc_string != None) { static BoxedString* doc_box = internStringImmortal("__doc__"); setGlobal(boxedLocals, doc_box, doc_string); } - return astInterpretFunctionEval(cl, globals, boxedLocals); + return astInterpretFunctionEval(md, globals, boxedLocals); } static FunctionMetadata* compileForEvalOrExec(AST* source, std::vector body, BoxedString* fn, @@ -375,9 +375,9 @@ static FunctionMetadata* compileForEvalOrExec(AST* source, std::vector si( new SourceInfo(getCurrentModule(), scoping, future_flags, source, std::move(body), fn)); - FunctionMetadata* cl_f = new FunctionMetadata(0, false, false, std::move(si)); - return cl_f; + FunctionMetadata* md = new FunctionMetadata(0, false, false, std::move(si)); + return md; } static AST_Module* parseExec(llvm::StringRef source, FutureFlags future_flags, bool interactive = false) { @@ -512,21 +512,21 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) { PyCompilerFlags pcf; pcf.cf_flags = future_flags; - FunctionMetadata* cl; + FunctionMetadata* md; if (type_str->s() == "exec" || type_str->s() == "single") { // TODO: CPython parses execs as Modules if (parsed->type != AST_TYPE::Module) raiseExcHelper(TypeError, "expected Module node, got %s", boxAst(parsed)->cls->tp_name); - cl = compileExec(static_cast(parsed), filename_str, &pcf); + md = compileExec(static_cast(parsed), filename_str, &pcf); } else if (type_str->s() == "eval") { if (parsed->type != AST_TYPE::Expression) raiseExcHelper(TypeError, "expected Expression node, got %s", boxAst(parsed)->cls->tp_name); - cl = compileEval(static_cast(parsed), filename_str, &pcf); + md = compileEval(static_cast(parsed), filename_str, &pcf); } else { raiseExcHelper(ValueError, "compile() arg 3 must be 'exec', 'eval' or 'single'"); } - return (Box*)cl->getCode(); + return (Box*)md->getCode(); } static void pickGlobalsAndLocals(Box*& globals, Box*& locals) { @@ -582,7 +582,7 @@ static Box* evalMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* // cf.cf_flags |= PyCF_SOURCE_IS_UTF8 } - FunctionMetadata* cl; + FunctionMetadata* md; if (boxedCode->cls == str_cls) { FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); @@ -590,14 +590,14 @@ static Box* evalMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* AST_Expression* parsed = parseEval(static_cast(boxedCode)->s(), caller_cl->source->future_flags); static BoxedString* string_string = internStringImmortal(""); - cl = compileEval(parsed, string_string, flags); + md = compileEval(parsed, string_string, flags); } else if (boxedCode->cls == code_cls) { - cl = clfunctionFromCode(boxedCode); + md = metadataFromCode(boxedCode); } else { abort(); } - return evalOrExec(cl, globals, locals); + return evalOrExec(md, globals, locals); } Box* eval(Box* boxedCode, Box* globals, Box* locals) { @@ -647,10 +647,10 @@ Box* execfile(Box* _fn, Box* globals, Box* locals) { PyCompilerFlags pcf; pcf.cf_flags = caller_future_flags; - FunctionMetadata* cl = compileForEvalOrExec(parsed, parsed->body, fn, &pcf); - assert(cl); + FunctionMetadata* md = compileForEvalOrExec(parsed, parsed->body, fn, &pcf); + assert(md); - return evalOrExec(cl, globals, locals); + return evalOrExec(md, globals, locals); } Box* execMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* flags) { @@ -675,7 +675,7 @@ Box* execMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* flags) // cf.cf_flags |= PyCF_SOURCE_IS_UTF8 } - FunctionMetadata* cl; + FunctionMetadata* md; if (boxedCode->cls == str_cls) { FunctionMetadata* caller_cl = getTopPythonFunction(); assert(caller_cl != NULL); @@ -683,15 +683,15 @@ Box* execMain(Box* boxedCode, Box* globals, Box* locals, PyCompilerFlags* flags) auto parsed = parseExec(static_cast(boxedCode)->s(), caller_cl->source->future_flags); static BoxedString* string_string = internStringImmortal(""); - cl = compileExec(parsed, string_string, flags); + md = compileExec(parsed, string_string, flags); } else if (boxedCode->cls == code_cls) { - cl = clfunctionFromCode(boxedCode); + md = metadataFromCode(boxedCode); } else { abort(); } - assert(cl); + assert(md); - return evalOrExec(cl, globals, locals); + return evalOrExec(md, globals, locals); } Box* exec(Box* boxedCode, Box* globals, Box* locals, FutureFlags caller_future_flags) { @@ -733,14 +733,14 @@ void CompiledFunction::speculationFailed() { if (this->times_speculation_failed == 4) { // printf("Killing %p because it failed too many speculations\n", this); - FunctionMetadata* cl = this->clfunc; - assert(cl); - assert(this != cl->always_use_version); + FunctionMetadata* md = this->md; + assert(md); + assert(this != md->always_use_version); bool found = false; - for (int i = 0; i < clfunc->versions.size(); i++) { - if (clfunc->versions[i] == this) { - clfunc->versions.erase(clfunc->versions.begin() + i); + for (int i = 0; i < md->versions.size(); i++) { + if (md->versions[i] == this) { + md->versions.erase(md->versions.begin() + i); this->dependent_callsites.invalidateAll(); found = true; break; @@ -748,9 +748,9 @@ void CompiledFunction::speculationFailed() { } if (!found) { - for (auto it = clfunc->osr_versions.begin(); it != clfunc->osr_versions.end(); ++it) { + for (auto it = md->osr_versions.begin(); it != md->osr_versions.end(); ++it) { if (it->second == this) { - clfunc->osr_versions.erase(it); + md->osr_versions.erase(it); this->dependent_callsites.invalidateAll(); found = true; break; @@ -759,8 +759,8 @@ void CompiledFunction::speculationFailed() { } if (!found) { - for (int i = 0; i < clfunc->versions.size(); i++) { - printf("%p\n", clfunc->versions[i]); + for (int i = 0; i < md->versions.size(); i++) { + printf("%p\n", md->versions[i]); } } RELEASE_ASSERT(found, ""); @@ -770,7 +770,7 @@ void CompiledFunction::speculationFailed() { std::unordered_set all_compiled_functions; CompiledFunction::CompiledFunction(llvm::Function* func, FunctionSpecialization* spec, void* code, EffortLevel effort, ExceptionStyle exception_style, const OSREntryDescriptor* entry_descriptor) - : clfunc(NULL), + : md(NULL), func(func), effort(effort), exception_style(exception_style), @@ -817,24 +817,24 @@ ConcreteCompilerType* CompiledFunction::getReturnType() { static CompiledFunction* _doReopt(CompiledFunction* cf, EffortLevel new_effort) { LOCK_REGION(codegen_rwlock.asWrite()); - assert(cf->clfunc->versions.size()); + assert(cf->md->versions.size()); assert(cf); assert(cf->entry_descriptor == NULL && "We can't reopt an osr-entry compile!"); assert(cf->spec); - FunctionMetadata* clfunc = cf->clfunc; - assert(clfunc); + FunctionMetadata* md = cf->md; + assert(md); assert(new_effort > cf->effort); - FunctionList& versions = clfunc->versions; + FunctionList& versions = md->versions; for (int i = 0; i < versions.size(); i++) { if (versions[i] == cf) { versions.erase(versions.begin() + i); // this pushes the new CompiledVersion to the back of the version list - CompiledFunction* new_cf = compileFunction(clfunc, cf->spec, new_effort, NULL, true, cf->exception_style); + CompiledFunction* new_cf = compileFunction(md, cf->spec, new_effort, NULL, true, cf->exception_style); cf->dependent_callsites.invalidateAll(); @@ -860,13 +860,13 @@ CompiledFunction* compilePartialFuncInternal(OSRExit* exit) { // if (VERBOSITY("irgen") >= 1) printf("In compilePartialFunc, handling %p\n", exit); - FunctionMetadata* clfunc = exit->entry->clfunc; - assert(clfunc); - CompiledFunction*& new_cf = clfunc->osr_versions[exit->entry]; + FunctionMetadata* md = exit->entry->md; + assert(md); + CompiledFunction*& new_cf = md->osr_versions[exit->entry]; if (new_cf == NULL) { EffortLevel new_effort = EffortLevel::MAXIMAL; CompiledFunction* compiled - = compileFunction(clfunc, NULL, new_effort, exit->entry, true, exit->entry->exception_style); + = compileFunction(md, NULL, new_effort, exit->entry, true, exit->entry->exception_style); assert(compiled == new_cf); stat_osr_compiles.log(); @@ -889,7 +889,7 @@ extern "C" CompiledFunction* reoptCompiledFuncInternal(CompiledFunction* cf) { stat_reopt.log(); assert(cf->effort < EffortLevel::MAXIMAL); - assert(cf->clfunc->versions.size()); + assert(cf->md->versions.size()); EffortLevel new_effort = EffortLevel::MAXIMAL; diff --git a/src/codegen/irgen/irgenerator.cpp b/src/codegen/irgen/irgenerator.cpp index 8906e5177..b494c9a82 100644 --- a/src/codegen/irgen/irgenerator.cpp +++ b/src/codegen/irgen/irgenerator.cpp @@ -44,10 +44,10 @@ extern "C" void dumpLLVM(void* _v) { v->dump(); } -IRGenState::IRGenState(FunctionMetadata* clfunc, CompiledFunction* cf, SourceInfo* source_info, +IRGenState::IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* source_info, std::unique_ptr phis, ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info) - : clfunc(clfunc), + : md(md), cf(cf), source_info(source_info), phis(std::move(phis)), @@ -60,7 +60,7 @@ IRGenState::IRGenState(FunctionMetadata* clfunc, CompiledFunction* cf, SourceInf globals(NULL), scratch_size(0) { assert(cf->func); - assert(!cf->clfunc); // in this case don't need to pass in sourceinfo + assert(!cf->md); // in this case don't need to pass in sourceinfo } IRGenState::~IRGenState() { @@ -1390,7 +1390,7 @@ class IRGeneratorImpl : public IRGenerator { decorators.push_back(evalExpr(d, unw_info)); } - FunctionMetadata* cl = wrapFunction(node, nullptr, node->body, irstate->getSourceInfo()); + FunctionMetadata* md = wrapFunction(node, nullptr, node->body, irstate->getSourceInfo()); // TODO duplication with _createFunction: CompilerVariable* created_closure = NULL; @@ -1409,7 +1409,7 @@ class IRGeneratorImpl : public IRGenerator { // but since the classdef can't create its own closure, shouldn't need to explicitly // create that scope to pass the closure through. assert(irstate->getSourceInfo()->scoping->areGlobalsFromModule()); - CompilerVariable* func = makeFunction(emitter, cl, created_closure, irstate->getGlobalsIfCustom(), {}); + CompilerVariable* func = makeFunction(emitter, md, created_closure, irstate->getGlobalsIfCustom(), {}); CompilerVariable* attr_dict = func->call(emitter, getEmptyOpInfo(unw_info), ArgPassSpec(0), {}, NULL); @@ -1436,7 +1436,7 @@ class IRGeneratorImpl : public IRGenerator { CompilerVariable* _createFunction(AST* node, const UnwindInfo& unw_info, AST_arguments* args, const std::vector& body) { - FunctionMetadata* cl = wrapFunction(node, args, body, irstate->getSourceInfo()); + FunctionMetadata* md = wrapFunction(node, args, body, irstate->getSourceInfo()); std::vector defaults; for (auto d : args->defaults) { @@ -1460,7 +1460,7 @@ class IRGeneratorImpl : public IRGenerator { takes_closure = irstate->getScopeInfoForNode(node)->takesClosure(); } - bool is_generator = cl->source->is_generator; + bool is_generator = md->source->is_generator; if (takes_closure) { if (irstate->getScopeInfo()->createsClosure()) { @@ -1472,7 +1472,7 @@ class IRGeneratorImpl : public IRGenerator { assert(created_closure); } - CompilerVariable* func = makeFunction(emitter, cl, created_closure, irstate->getGlobalsIfCustom(), defaults); + CompilerVariable* func = makeFunction(emitter, md, created_closure, irstate->getGlobalsIfCustom(), defaults); for (auto d : defaults) { d->decvref(emitter); @@ -2125,7 +2125,7 @@ class IRGeneratorImpl : public IRGenerator { // Emitting the actual OSR: emitter.getBuilder()->SetInsertPoint(onramp); - OSREntryDescriptor* entry = OSREntryDescriptor::create(irstate->getCL(), osr_key, irstate->getExceptionStyle()); + OSREntryDescriptor* entry = OSREntryDescriptor::create(irstate->getMD(), osr_key, irstate->getExceptionStyle()); OSRExit* exit = new OSRExit(entry); llvm::Value* partial_func = emitter.getBuilder()->CreateCall(g.funcs.compilePartialFunc, embedRelocatablePtr(exit, g.i8->getPointerTo())); @@ -2955,16 +2955,16 @@ FunctionMetadata* wrapFunction(AST* node, AST_arguments* args, const std::vector // to the same FunctionMetadata* being used: static std::unordered_map made; - FunctionMetadata*& cl = made[node]; - if (cl == NULL) { + FunctionMetadata*& md = made[node]; + if (md == NULL) { std::unique_ptr si( new SourceInfo(source->parent_module, source->scoping, source->future_flags, node, body, source->getFn())); if (args) - cl = new FunctionMetadata(args->args.size(), args->vararg.s().size(), args->kwarg.s().size(), + md = new FunctionMetadata(args->args.size(), args->vararg.s().size(), args->kwarg.s().size(), std::move(si)); else - cl = new FunctionMetadata(0, false, false, std::move(si)); + md = new FunctionMetadata(0, false, false, std::move(si)); } - return cl; + return md; } } diff --git a/src/codegen/irgen/irgenerator.h b/src/codegen/irgen/irgenerator.h index 2a5da7bd4..ae56edbe3 100644 --- a/src/codegen/irgen/irgenerator.h +++ b/src/codegen/irgen/irgenerator.h @@ -57,9 +57,9 @@ extern const std::string PASSED_GLOBALS_NAME; // TODO this probably shouldn't be here class IRGenState { private: - // Note: due to some not-yet-fixed behavior, cf->clfunc is NULL will only get set to point - // to clfunc at the end of irgen. - FunctionMetadata* clfunc; + // Note: due to some not-yet-fixed behavior, cf->md is NULL will only get set to point + // to md at the end of irgen. + FunctionMetadata* md; CompiledFunction* cf; SourceInfo* source_info; std::unique_ptr phis; @@ -75,12 +75,12 @@ class IRGenState { int scratch_size; public: - IRGenState(FunctionMetadata* clfunc, CompiledFunction* cf, SourceInfo* source_info, - std::unique_ptr phis, ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info); + IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* source_info, std::unique_ptr phis, + ParamNames* param_names, GCBuilder* gc, llvm::MDNode* func_dbg_info); ~IRGenState(); CompiledFunction* getCurFunction() { return cf; } - FunctionMetadata* getCL() { return clfunc; } + FunctionMetadata* getMD() { return md; } ExceptionStyle getExceptionStyle() { return cf->exception_style; } diff --git a/src/codegen/osrentry.h b/src/codegen/osrentry.h index dbfcb48e4..c85e33f9e 100644 --- a/src/codegen/osrentry.h +++ b/src/codegen/osrentry.h @@ -31,20 +31,20 @@ struct StackMap; class OSREntryDescriptor { private: - OSREntryDescriptor(FunctionMetadata* clfunc, AST_Jump* backedge, ExceptionStyle exception_style) - : clfunc(clfunc), backedge(backedge), exception_style(exception_style) { - assert(clfunc); + OSREntryDescriptor(FunctionMetadata* md, AST_Jump* backedge, ExceptionStyle exception_style) + : md(md), backedge(backedge), exception_style(exception_style) { + assert(md); } public: - FunctionMetadata* clfunc; + FunctionMetadata* md; AST_Jump* const backedge; ExceptionStyle exception_style; typedef std::map ArgMap; ArgMap args; - static OSREntryDescriptor* create(FunctionMetadata* clfunc, AST_Jump* backedge, ExceptionStyle exception_style) { - return new OSREntryDescriptor(clfunc, backedge, exception_style); + static OSREntryDescriptor* create(FunctionMetadata* md, AST_Jump* backedge, ExceptionStyle exception_style) { + return new OSREntryDescriptor(md, backedge, exception_style); } }; diff --git a/src/codegen/runtime_hooks.cpp b/src/codegen/runtime_hooks.cpp index d029bdc2c..f95648eb5 100644 --- a/src/codegen/runtime_hooks.cpp +++ b/src/codegen/runtime_hooks.cpp @@ -122,7 +122,7 @@ static llvm::Value* addFunc(void* func, llvm::Type* rtn_type, llvm::Type* arg1, void initGlobalFuncs(GlobalState& g) { g.llvm_opaque_type = llvm::StructType::create(g.context, "opaque"); - g.llvm_clfunction_type_ptr = lookupFunction("createFunctionFromMetadata")->arg_begin()->getType(); + g.llvm_functionmetadata_type_ptr = lookupFunction("createFunctionFromMetadata")->arg_begin()->getType(); g.llvm_module_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedModule")->getPointerTo(); assert(g.llvm_module_type_ptr); g.llvm_bool_type_ptr = lookupFunction("boxBool")->getReturnType(); diff --git a/src/codegen/unwinding.cpp b/src/codegen/unwinding.cpp index 8f1580f74..1ddc7b7af 100644 --- a/src/codegen/unwinding.cpp +++ b/src/codegen/unwinding.cpp @@ -278,7 +278,7 @@ struct PythonFrameId { class PythonFrameIteratorImpl { public: PythonFrameId id; - FunctionMetadata* cl; // always exists + FunctionMetadata* md; // always exists // These only exist if id.type==COMPILED: CompiledFunction* cf; @@ -289,10 +289,10 @@ class PythonFrameIteratorImpl { PythonFrameIteratorImpl() : regs_valid(0) {} - PythonFrameIteratorImpl(PythonFrameId::FrameType type, uint64_t ip, uint64_t bp, FunctionMetadata* cl, + PythonFrameIteratorImpl(PythonFrameId::FrameType type, uint64_t ip, uint64_t bp, FunctionMetadata* md, CompiledFunction* cf) - : id(PythonFrameId(type, ip, bp)), cl(cl), cf(cf), regs_valid(0) { - assert(cl); + : id(PythonFrameId(type, ip, bp)), md(md), cf(cf), regs_valid(0) { + assert(md); assert((type == PythonFrameId::COMPILED) == (cf != NULL)); } @@ -301,9 +301,9 @@ class PythonFrameIteratorImpl { return cf; } - FunctionMetadata* getCL() const { - assert(cl); - return cl; + FunctionMetadata* getMD() const { + assert(md); + return md; } uint64_t readLocation(const StackMap::Record::Location& loc) { @@ -366,8 +366,8 @@ class PythonFrameIteratorImpl { Box* getGlobals() { if (id.type == PythonFrameId::COMPILED) { CompiledFunction* cf = getCF(); - if (cf->clfunc->source->scoping->areGlobalsFromModule()) - return cf->clfunc->source->parent_module; + if (cf->md->source->scoping->areGlobalsFromModule()) + return cf->md->source->parent_module; auto locations = findLocations(PASSED_GLOBALS_NAME); assert(locations.size() == 1); Box* r = (Box*)readLocation(locations[0]); @@ -461,16 +461,16 @@ static inline unw_word_t get_cursor_bp(unw_cursor_t* cursor) { // frame information through the PythonFrameIteratorImpl* info arg. bool frameIsPythonFrame(unw_word_t ip, unw_word_t bp, unw_cursor_t* cursor, PythonFrameIteratorImpl* info) { CompiledFunction* cf = getCFForAddress(ip); - FunctionMetadata* cl = cf ? cf->clfunc : NULL; + FunctionMetadata* md = cf ? cf->md : NULL; bool jitted = cf != NULL; bool interpreted = !jitted && inASTInterpreterExecuteInner(ip); if (interpreted) - cl = getCLForInterpretedFrame((void*)bp); + md = getMDForInterpretedFrame((void*)bp); if (!jitted && !interpreted) return false; - *info = PythonFrameIteratorImpl(jitted ? PythonFrameId::COMPILED : PythonFrameId::INTERPRETED, ip, bp, cl, cf); + *info = PythonFrameIteratorImpl(jitted ? PythonFrameId::COMPILED : PythonFrameId::INTERPRETED, ip, bp, md, cf); if (jitted) { // Try getting all the callee-save registers, and save the ones we were able to get. // Some of them may be inaccessible, I think because they weren't defined by that @@ -493,10 +493,10 @@ bool frameIsPythonFrame(unw_word_t ip, unw_word_t bp, unw_cursor_t* cursor, Pyth static const LineInfo lineInfoForFrame(PythonFrameIteratorImpl* frame_it) { AST_stmt* current_stmt = frame_it->getCurrentStatement(); - auto* cl = frame_it->getCL(); - assert(cl); + auto* md = frame_it->getMD(); + assert(md); - auto source = cl->source.get(); + auto source = md->source.get(); return LineInfo(current_stmt->lineno, current_stmt->col_offset, source->getFn(), source->getName()); } @@ -564,7 +564,7 @@ class PythonUnwindSession : public Box { PythonFrameIteratorImpl frame_iter; bool found_frame = pystack_extractor.handleCFrame(cursor, &frame_iter); if (found_frame) { - frame_iter.getCL()->propagated_cxx_exceptions++; + frame_iter.getMD()->propagated_cxx_exceptions++; if (exceptionAtLineCheck()) { // TODO: shouldn't fetch this multiple times? @@ -801,7 +801,7 @@ FunctionMetadata* getTopPythonFunction() { auto rtn = getTopPythonFrame(); if (!rtn) return NULL; - return getTopPythonFrame()->getCL(); + return getTopPythonFrame()->getMD(); } Box* getGlobals() { @@ -816,10 +816,10 @@ Box* getGlobalsDict() { } BoxedModule* getCurrentModule() { - FunctionMetadata* clfunc = getTopPythonFunction(); - if (!clfunc) + FunctionMetadata* md = getTopPythonFunction(); + if (!md) return NULL; - return clfunc->source->parent_module; + return md->source->parent_module; } PythonFrameIterator getPythonFrame(int depth) { @@ -941,14 +941,14 @@ Box* PythonFrameIterator::fastLocalsToBoxedLocals() { BoxedClosure* closure; FrameInfo* frame_info; - FunctionMetadata* clfunc = impl->getCL(); - ScopeInfo* scope_info = clfunc->source->getScopeInfo(); + FunctionMetadata* md = impl->getMD(); + ScopeInfo* scope_info = md->source->getScopeInfo(); if (scope_info->areLocalsFromModule()) { // TODO we should cache this in frame_info->locals or something so that locals() // (and globals() too) will always return the same dict - RELEASE_ASSERT(clfunc->source->scoping->areGlobalsFromModule(), ""); - return clfunc->source->parent_module->getAttrWrapper(); + RELEASE_ASSERT(md->source->scoping->areGlobalsFromModule(), ""); + return md->source->parent_module->getAttrWrapper(); } if (impl->getId().type == PythonFrameId::COMPILED) { @@ -1088,8 +1088,8 @@ CompiledFunction* PythonFrameIterator::getCF() { return impl->getCF(); } -FunctionMetadata* PythonFrameIterator::getCL() { - return impl->getCL(); +FunctionMetadata* PythonFrameIterator::getMD() { + return impl->getMD(); } Box* PythonFrameIterator::getGlobalsDict() { @@ -1142,8 +1142,8 @@ std::string getCurrentPythonLine() { if (frame_iter.get()) { std::ostringstream stream; - auto* clfunc = frame_iter->getCL(); - auto source = clfunc->source.get(); + auto* md = frame_iter->getMD(); + auto source = md->source.get(); auto current_stmt = frame_iter->getCurrentStatement(); diff --git a/src/codegen/unwinding.h b/src/codegen/unwinding.h index 8dc001f11..207b38b75 100644 --- a/src/codegen/unwinding.h +++ b/src/codegen/unwinding.h @@ -76,7 +76,7 @@ class PythonFrameIterator { public: CompiledFunction* getCF(); - FunctionMetadata* getCL(); + FunctionMetadata* getMD(); FrameInfo* getFrameInfo(); bool exists() { return impl.get() != NULL; } AST_stmt* getCurrentStatement(); diff --git a/src/core/types.h b/src/core/types.h index a5ef50cb2..33641621f 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -304,7 +304,7 @@ class JitCodeBlock; struct CompiledFunction { private: public: - FunctionMetadata* clfunc; + FunctionMetadata* md; llvm::Function* func; // the llvm IR object // Some compilation settings: diff --git a/src/runtime/code.cpp b/src/runtime/code.cpp index 7f13b702f..3e8cda64a 100644 --- a/src/runtime/code.cpp +++ b/src/runtime/code.cpp @@ -44,18 +44,18 @@ Box* BoxedCode::filename(Box* b, void*) { Box* BoxedCode::firstlineno(Box* b, void*) { RELEASE_ASSERT(b->cls == code_cls, ""); BoxedCode* code = static_cast(b); - FunctionMetadata* cl = code->f; + FunctionMetadata* md = code->f; - if (!cl->source) { + if (!md->source) { // I don't think it really matters what we return here; // in CPython, builtin functions don't have code objects. return boxInt(-1); } - if (cl->source->ast->lineno == (uint32_t)-1) + if (md->source->ast->lineno == (uint32_t)-1) return boxInt(-1); - return boxInt(cl->source->ast->lineno); + return boxInt(md->source->ast->lineno); } Box* BoxedCode::argcount(Box* b, void*) { @@ -97,10 +97,10 @@ Box* BoxedCode::flags(Box* b, void*) { } Box* codeForFunction(BoxedFunction* f) { - return f->f->getCode(); + return f->md->getCode(); } -FunctionMetadata* clfunctionFromCode(Box* code) { +FunctionMetadata* metadataFromCode(Box* code) { assert(code->cls == code_cls); return static_cast(code)->f; } diff --git a/src/runtime/complex.cpp b/src/runtime/complex.cpp index b0991f525..7af32b814 100644 --- a/src/runtime/complex.cpp +++ b/src/runtime/complex.cpp @@ -390,12 +390,12 @@ Box* complex_fmt(double r, double i, int precision, char format_code) noexcept { static void _addFunc(const char* name, ConcreteCompilerType* rtn_type, void* complex_func, void* float_func, void* int_func, void* boxed_func) { - FunctionMetadata* cl = new FunctionMetadata(2, false, false); - cl->addVersion(complex_func, rtn_type, { BOXED_COMPLEX, BOXED_COMPLEX }); - cl->addVersion(float_func, rtn_type, { BOXED_COMPLEX, BOXED_FLOAT }); - cl->addVersion(int_func, rtn_type, { BOXED_COMPLEX, BOXED_INT }); - cl->addVersion(boxed_func, UNKNOWN, { BOXED_COMPLEX, UNKNOWN }); - complex_cls->giveAttr(name, new BoxedFunction(cl)); + FunctionMetadata* md = new FunctionMetadata(2, false, false); + md->addVersion(complex_func, rtn_type, { BOXED_COMPLEX, BOXED_COMPLEX }); + md->addVersion(float_func, rtn_type, { BOXED_COMPLEX, BOXED_FLOAT }); + md->addVersion(int_func, rtn_type, { BOXED_COMPLEX, BOXED_INT }); + md->addVersion(boxed_func, UNKNOWN, { BOXED_COMPLEX, UNKNOWN }); + complex_cls->giveAttr(name, new BoxedFunction(md)); } static Py_complex c_1 = { 1., 0. }; diff --git a/src/runtime/cxx_unwind.cpp b/src/runtime/cxx_unwind.cpp index 2a5e1aa65..ffa8a3acd 100644 --- a/src/runtime/cxx_unwind.cpp +++ b/src/runtime/cxx_unwind.cpp @@ -358,7 +358,7 @@ static void print_frame(unw_cursor_t* cursor, const unw_proc_info_t* pip) { } if (frame_type == INTERPRETED && cf && cur_stmt) { - auto source = cf->clfunc->source.get(); + auto source = cf->md->source.get(); // FIXME: dup'ed from lineInfoForFrame LineInfo line(cur_stmt->lineno, cur_stmt->col_offset, source->getFn(), source->getName()); printf(" File \"%s\", line %d, in %s\n", line.file->c_str(), line.line, line.func->c_str()); diff --git a/src/runtime/float.cpp b/src/runtime/float.cpp index 26e51daff..d8116cb18 100644 --- a/src/runtime/float.cpp +++ b/src/runtime/float.cpp @@ -938,11 +938,11 @@ static void _addFunc(const char* name, ConcreteCompilerType* rtn_type, void* flo v_fu.push_back(BOXED_FLOAT); v_fu.push_back(UNKNOWN); - FunctionMetadata* cl = new FunctionMetadata(2, false, false); - cl->addVersion(float_func, rtn_type, v_ff); - cl->addVersion(int_func, rtn_type, v_fi); - cl->addVersion(boxed_func, UNKNOWN, v_fu); - float_cls->giveAttr(name, new BoxedFunction(cl)); + FunctionMetadata* md = new FunctionMetadata(2, false, false); + md->addVersion(float_func, rtn_type, v_ff); + md->addVersion(int_func, rtn_type, v_fi); + md->addVersion(boxed_func, UNKNOWN, v_fu); + float_cls->giveAttr(name, new BoxedFunction(md)); } static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* float_func, void* int_func, @@ -951,11 +951,11 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* std::vector v_fiu{ BOXED_FLOAT, BOXED_INT, UNKNOWN }; std::vector v_fuu{ BOXED_FLOAT, UNKNOWN, UNKNOWN }; - FunctionMetadata* cl = new FunctionMetadata(3, false, false); - cl->addVersion(float_func, rtn_type, v_ffu); - cl->addVersion(int_func, rtn_type, v_fiu); - cl->addVersion(boxed_func, UNKNOWN, v_fuu); - float_cls->giveAttr(name, new BoxedFunction(cl, { None })); + FunctionMetadata* md = new FunctionMetadata(3, false, false); + md->addVersion(float_func, rtn_type, v_ffu); + md->addVersion(int_func, rtn_type, v_fiu); + md->addVersion(boxed_func, UNKNOWN, v_fuu); + float_cls->giveAttr(name, new BoxedFunction(md, { None })); } static Box* floatConjugate(Box* b, void*) { diff --git a/src/runtime/frame.cpp b/src/runtime/frame.cpp index cad0e3497..2cc21e61a 100644 --- a/src/runtime/frame.cpp +++ b/src/runtime/frame.cpp @@ -130,11 +130,11 @@ class BoxedFrame : public Box { static Box* boxFrame(PythonFrameIterator it) { FrameInfo* fi = it.getFrameInfo(); if (fi->frame_obj == NULL) { - auto cl = it.getCL(); + auto md = it.getMD(); Box* globals = it.getGlobalsDict(); BoxedFrame* f = fi->frame_obj = new BoxedFrame(std::move(it)); f->_globals = globals; - f->_code = (Box*)cl->getCode(); + f->_code = (Box*)md->getCode(); } return fi->frame_obj; diff --git a/src/runtime/generator.cpp b/src/runtime/generator.cpp index 1ca7756a0..b8df82b0a 100644 --- a/src/runtime/generator.cpp +++ b/src/runtime/generator.cpp @@ -97,8 +97,9 @@ void generatorEntry(BoxedGenerator* g) { BoxedFunctionBase* func = g->function; Box** args = g->args ? &g->args->elts[0] : nullptr; - callCLFunc(func->f, nullptr, func->f->numReceivedArgs(), func->closure, - g, func->globals, g->arg1, g->arg2, g->arg3, args); + callCLFunc(func->md, nullptr, func->md->numReceivedArgs(), + func->closure, g, func->globals, g->arg1, g->arg2, g->arg3, + args); } catch (ExcInfo e) { // unhandled exception: propagate the exception to the caller g->exception = e; @@ -354,7 +355,7 @@ extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1 #endif { - int numArgs = function->f->numReceivedArgs(); + int numArgs = function->md->numReceivedArgs(); if (numArgs > 3) { numArgs -= 3; this->args = new (numArgs) GCdArray(); @@ -428,7 +429,7 @@ void BoxedGenerator::gcHandler(GCVisitor* v, Box* b) { BoxedGenerator* g = (BoxedGenerator*)b; v->visit(&g->function); - int num_args = g->function->f->numReceivedArgs(); + int num_args = g->function->md->numReceivedArgs(); if (num_args >= 1) v->visit(&g->arg1); if (num_args >= 2) @@ -467,7 +468,7 @@ Box* generatorName(Box* _self, void* context) { assert(isSubclass(_self->cls, generator_cls)); BoxedGenerator* self = static_cast(_self); - return self->function->f->source->getName(); + return self->function->md->source->getName(); } void generatorDestructor(Box* b) { diff --git a/src/runtime/int.cpp b/src/runtime/int.cpp index b42a7cf03..a39afc89d 100644 --- a/src/runtime/int.cpp +++ b/src/runtime/int.cpp @@ -694,10 +694,10 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* std::vector v_ifu{ BOXED_INT, BOXED_FLOAT, UNKNOWN }; std::vector v_uuu{ UNKNOWN, UNKNOWN, UNKNOWN }; - FunctionMetadata* cl = new FunctionMetadata(3, false, false); - cl->addVersion(float_func, UNKNOWN, v_ifu); - cl->addVersion(int_func, UNKNOWN, v_uuu); - int_cls->giveAttr(name, new BoxedFunction(cl, { None })); + FunctionMetadata* md = new FunctionMetadata(3, false, false); + md->addVersion(float_func, UNKNOWN, v_ifu); + md->addVersion(int_func, UNKNOWN, v_uuu); + int_cls->giveAttr(name, new BoxedFunction(md, { None })); } extern "C" Box* intPowLong(BoxedInt* lhs, BoxedLong* rhs, Box* mod) { @@ -1085,11 +1085,11 @@ static void _addFuncIntFloatUnknown(const char* name, void* int_func, void* floa v_iu.push_back(UNKNOWN); v_iu.push_back(UNKNOWN); - FunctionMetadata* cl = new FunctionMetadata(2, false, false); - cl->addVersion(int_func, UNKNOWN, v_ii); - cl->addVersion(float_func, BOXED_FLOAT, v_if); - cl->addVersion(boxed_func, UNKNOWN, v_iu); - int_cls->giveAttr(name, new BoxedFunction(cl)); + FunctionMetadata* md = new FunctionMetadata(2, false, false); + md->addVersion(int_func, UNKNOWN, v_ii); + md->addVersion(float_func, BOXED_FLOAT, v_if); + md->addVersion(boxed_func, UNKNOWN, v_iu); + int_cls->giveAttr(name, new BoxedFunction(md)); } static void _addFuncIntUnknown(const char* name, ConcreteCompilerType* rtn_type, void* int_func, void* boxed_func) { @@ -1100,10 +1100,10 @@ static void _addFuncIntUnknown(const char* name, ConcreteCompilerType* rtn_type, v_iu.push_back(UNKNOWN); v_iu.push_back(UNKNOWN); - FunctionMetadata* cl = new FunctionMetadata(2, false, false); - cl->addVersion(int_func, rtn_type, v_ii); - cl->addVersion(boxed_func, UNKNOWN, v_iu); - int_cls->giveAttr(name, new BoxedFunction(cl)); + FunctionMetadata* md = new FunctionMetadata(2, false, false); + md->addVersion(int_func, rtn_type, v_ii); + md->addVersion(boxed_func, UNKNOWN, v_iu); + int_cls->giveAttr(name, new BoxedFunction(md)); } static Box* intIntGetset(Box* b, void*) { diff --git a/src/runtime/long.cpp b/src/runtime/long.cpp index 780c45aeb..a95041b95 100644 --- a/src/runtime/long.cpp +++ b/src/runtime/long.cpp @@ -1278,10 +1278,10 @@ static void _addFuncPow(const char* name, ConcreteCompilerType* rtn_type, void* std::vector v_lfu{ UNKNOWN, BOXED_FLOAT, UNKNOWN }; std::vector v_uuu{ UNKNOWN, UNKNOWN, UNKNOWN }; - FunctionMetadata* cl = new FunctionMetadata(3, false, false); - cl->addVersion(float_func, UNKNOWN, v_lfu); - cl->addVersion(long_func, UNKNOWN, v_uuu); - long_cls->giveAttr(name, new BoxedFunction(cl, { None })); + FunctionMetadata* md = new FunctionMetadata(3, false, false); + md->addVersion(float_func, UNKNOWN, v_lfu); + md->addVersion(long_func, UNKNOWN, v_uuu); + long_cls->giveAttr(name, new BoxedFunction(md, { None })); } extern "C" Box* longPowFloat(BoxedLong* lhs, BoxedFloat* rhs) { diff --git a/src/runtime/objmodel.cpp b/src/runtime/objmodel.cpp index 63ed14918..5cc4cbcfe 100644 --- a/src/runtime/objmodel.cpp +++ b/src/runtime/objmodel.cpp @@ -138,7 +138,7 @@ extern "C" Box* deopt(AST_expr* expr, Box* value) { deopt_state.frame_state.frame_info->exc.value = NULL; } - return astInterpretDeopt(deopt_state.cf->clfunc, expr, deopt_state.current_stmt, value, deopt_state.frame_state); + return astInterpretDeopt(deopt_state.cf->md, expr, deopt_state.current_stmt, value, deopt_state.frame_state); } extern "C" bool softspace(Box* b, bool newval) { @@ -3796,7 +3796,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe #endif slowpath_callfunc.log(); - FunctionMetadata* f = func->f; + FunctionMetadata* md = func->md; ParamReceiveSpec paramspec = func->getParamspec(); if (rewrite_args) { @@ -3827,8 +3827,8 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe } try { - auto func_name_cb = [f]() { return getFunctionName(f).data(); }; - rearrangeArgumentsInternal(paramspec, &f->param_names, func_name_cb, + auto func_name_cb = [md]() { return getFunctionName(md).data(); }; + rearrangeArgumentsInternal(paramspec, &md->param_names, func_name_cb, paramspec.num_defaults ? func->defaults->elts : NULL, rewrite_args, rewrite_success, argspec, arg1, arg2, arg3, args, oargs, keyword_names); } catch (ExcInfo e) { @@ -3863,7 +3863,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe // from a rewrite. #if 0 char buf[80]; - snprintf(buf, sizeof(buf), "zzz_aborted_%d_args_%d_%d_%d_%d_params_%d_%d_%d_%d", f->isGenerator(), + snprintf(buf, sizeof(buf), "zzz_aborted_%d_args_%d_%d_%d_%d_params_%d_%d_%d_%d", md->isGenerator(), argspec.num_args, argspec.num_keywords, argspec.has_starargs, argspec.has_kwargs, paramspec.num_args, paramspec.num_defaults, paramspec.takes_varargs, paramspec.takes_kwargs); uint64_t* counter = Stats::getStatCounter(buf); @@ -3914,7 +3914,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe // special handling for generators: // the call to function containing a yield should just create a new generator object. Box* res; - if (f->isGenerator()) { + if (md->isGenerator()) { // TODO: we might not have a lot to gain by rewriting into createGenerator, but we could at least // rewrite up to the call to it: res = createGenerator(func, arg1, arg2, arg3, oargs); @@ -3930,7 +3930,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe rewrite_args->out_success = true; } } else { - res = callCLFunc(f, rewrite_args, num_output_args, closure, NULL, func->globals, arg1, arg2, + res = callCLFunc(md, rewrite_args, num_output_args, closure, NULL, func->globals, arg1, arg2, arg3, oargs); } @@ -3956,8 +3956,7 @@ static Box* callChosenCF(CompiledFunction* chosen_cf, BoxedClosure* closure, Box } } - assert((globals == NULL) - == (!chosen_cf->clfunc->source || chosen_cf->clfunc->source->scoping->areGlobalsFromModule())); + assert((globals == NULL) == (!chosen_cf->md->source || chosen_cf->md->source->scoping->areGlobalsFromModule())); Box* maybe_args[3]; int nmaybe_args = 0; @@ -4026,7 +4025,7 @@ static Box* capiCallCxxHelper(Box* (*func_ptr)(void*, void*, void*, void*, void* } template -Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, +Box* callCLFunc(FunctionMetadata* md, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs) noexcept(S == CAPI) { if (rewritable == NOT_REWRITABLE) { @@ -4034,17 +4033,17 @@ Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_outp rewrite_args = NULL; } - CompiledFunction* chosen_cf = pickVersion(f, S, num_output_args, oarg1, oarg2, oarg3, oargs); + CompiledFunction* chosen_cf = pickVersion(md, S, num_output_args, oarg1, oarg2, oarg3, oargs); if (!chosen_cf) { if (rewrite_args) { RewriterVar::SmallVector arg_vec; - rewrite_args->rewriter->addDependenceOn(f->dependent_interp_callsites); + rewrite_args->rewriter->addDependenceOn(md->dependent_interp_callsites); // TODO this kind of embedded reference needs to be tracked by the GC somehow? // Or maybe it's ok, since we've guarded on the function object? - arg_vec.push_back(rewrite_args->rewriter->loadConst((intptr_t)f, Location::forArg(0))); + arg_vec.push_back(rewrite_args->rewriter->loadConst((intptr_t)md, Location::forArg(0))); arg_vec.push_back(rewrite_args->rewriter->loadConst((intptr_t)closure, Location::forArg(1))); arg_vec.push_back(rewrite_args->rewriter->loadConst((intptr_t)generator, Location::forArg(2))); arg_vec.push_back(rewrite_args->rewriter->loadConst((intptr_t)globals, Location::forArg(3))); @@ -4085,13 +4084,13 @@ Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_outp if (S == CAPI) { try { - return astInterpretFunction(f, closure, generator, globals, oarg1, oarg2, oarg3, oargs); + return astInterpretFunction(md, closure, generator, globals, oarg1, oarg2, oarg3, oargs); } catch (ExcInfo e) { setCAPIException(e); return NULL; } } else { - return astInterpretFunction(f, closure, generator, globals, oarg1, oarg2, oarg3, oargs); + return astInterpretFunction(md, closure, generator, globals, oarg1, oarg2, oarg3, oargs); } } @@ -4147,7 +4146,7 @@ Box* callCLFunc(FunctionMetadata* f, CallRewriteArgs* rewrite_args, int num_outp // we duplicate the call to callChosenCf here so we can // distinguish lexically between calls that target jitted python // code and calls that target to builtins. - if (f->source) { + if (md->source) { UNAVOIDABLE_STAT_TIMER(t0, "us_timer_in_jitted_code"); r = callChosenCF(chosen_cf, closure, generator, globals, oarg1, oarg2, oarg3, oargs); } else { @@ -4309,7 +4308,7 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec ar // Some functions are sufficiently important that we want them to be able to patchpoint themselves; // they can do this by setting the "internal_callable" field: - auto callable = f->f->internal_callable.get(); + auto callable = f->md->internal_callable.get(); if (callable == NULL) { callable = callFunc; } diff --git a/src/runtime/types.cpp b/src/runtime/types.cpp index 40185dcac..2182c9db4 100644 --- a/src/runtime/types.cpp +++ b/src/runtime/types.cpp @@ -369,9 +369,9 @@ void Box::gcHandler(GCVisitor* v, Box* b) { } } -extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f) +extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* md) : in_weakreflist(NULL), - f(f), + md(md), closure(NULL), defaults(NULL), can_change_defaults(false), @@ -379,23 +379,23 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f) name(NULL), doc(NULL) { - if (f->source) { - assert(f->source->scoping->areGlobalsFromModule()); - Box* globals_for_name = f->source->parent_module; + if (md->source) { + assert(md->source->scoping->areGlobalsFromModule()); + Box* globals_for_name = md->source->parent_module; static BoxedString* name_str = internStringImmortal("__name__"); this->modname = globals_for_name->getattr(name_str); - this->doc = f->source->getDocString(); + this->doc = md->source->getDocString(); } else { this->modname = PyString_InternFromString("__builtin__"); this->doc = None; } } -extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f, std::initializer_list defaults, +extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* md, std::initializer_list defaults, BoxedClosure* closure, Box* globals, bool can_change_defaults) : in_weakreflist(NULL), - f(f), + md(md), closure(closure), globals(globals), defaults(NULL), @@ -403,7 +403,7 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f, std::initia modname(NULL), name(NULL), doc(NULL) { - assert((!globals) == (!f->source || f->source->scoping->areGlobalsFromModule())); + assert((!globals) == (!md->source || md->source->scoping->areGlobalsFromModule())); if (defaults.size()) { // HAX copy+modify the BoxedTuple constructor so that we can put NULLs into the tuple. @@ -418,11 +418,11 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f, std::initia } } - if (f->source) { + if (md->source) { Box* globals_for_name = globals; if (!globals_for_name) { - assert(f->source->scoping->areGlobalsFromModule()); - globals_for_name = f->source->parent_module; + assert(md->source->scoping->areGlobalsFromModule()); + globals_for_name = md->source->parent_module; } static BoxedString* name_str = internStringImmortal("__name__"); @@ -433,25 +433,25 @@ extern "C" BoxedFunctionBase::BoxedFunctionBase(FunctionMetadata* f, std::initia } // It's ok for modname to be NULL - this->doc = f->source->getDocString(); + this->doc = md->source->getDocString(); } else { this->modname = PyString_InternFromString("__builtin__"); this->doc = None; } } -BoxedFunction::BoxedFunction(FunctionMetadata* f) : BoxedFunction(f, {}) { +BoxedFunction::BoxedFunction(FunctionMetadata* md) : BoxedFunction(md, {}) { } -BoxedFunction::BoxedFunction(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure, +BoxedFunction::BoxedFunction(FunctionMetadata* md, std::initializer_list defaults, BoxedClosure* closure, Box* globals, bool can_change_defaults) - : BoxedFunctionBase(f, defaults, closure, globals, can_change_defaults) { + : BoxedFunctionBase(md, defaults, closure, globals, can_change_defaults) { // TODO eventually we want this to assert(f->source), I think, but there are still // some builtin functions that are BoxedFunctions but really ought to be a type that // we don't have yet. - if (f->source) { - this->name = static_cast(f->source->getName()); + if (md->source) { + this->name = static_cast(md->source->getName()); } } @@ -478,20 +478,20 @@ void BoxedFunction::gcHandler(GCVisitor* v, Box* b) { v->visit(&f->defaults); - if (f->f && f->f->source && f->f->source->parent_module) - v->visit(&f->f->source->parent_module); + if (f->md && f->md->source && f->md->source->parent_module) + v->visit(&f->md->source->parent_module); } -BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, const char* doc) - : BoxedBuiltinFunctionOrMethod(f, name, {}) { +BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* md, const char* name, const char* doc) + : BoxedBuiltinFunctionOrMethod(md, name, {}) { this->doc = doc ? boxString(doc) : None; } -BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, +BoxedBuiltinFunctionOrMethod::BoxedBuiltinFunctionOrMethod(FunctionMetadata* md, const char* name, std::initializer_list defaults, BoxedClosure* closure, const char* doc) - : BoxedFunctionBase(f, defaults, closure) { + : BoxedFunctionBase(md, defaults, closure) { assert(name); this->name = static_cast(boxString(name)); @@ -599,19 +599,19 @@ void BoxedModule::gcHandler(GCVisitor* v, Box* b) { // This mustn't throw; our IR generator generates calls to it without "invoke" even when there are exception handlers / // finally-blocks in scope. -extern "C" Box* createFunctionFromMetadata(FunctionMetadata* f, BoxedClosure* closure, Box* globals, +extern "C" Box* createFunctionFromMetadata(FunctionMetadata* md, BoxedClosure* closure, Box* globals, std::initializer_list defaults) noexcept { - STAT_TIMER(t0, "us_timer_boxclfunction", 10); + STAT_TIMER(t0, "us_timer_createfunctionfrommetadata", 10); if (closure) assert(closure->cls == closure_cls); - return new BoxedFunction(f, defaults, closure, globals, /* can_change_defaults = */ true); + return new BoxedFunction(md, defaults, closure, globals, /* can_change_defaults = */ true); } extern "C" FunctionMetadata* getFunctionMetadata(Box* b) { assert(isSubclass(b->cls, function_cls) || isSubclass(b->cls, builtin_function_or_method_cls)); - return static_cast(b)->f; + return static_cast(b)->md; } static PyObject* cpython_type_call(PyTypeObject* type, PyObject* args, PyObject* kwds) noexcept { @@ -1737,12 +1737,12 @@ static void functionSetCode(Box* self, Box* v, void*) { BoxedFunction* func = static_cast(self); BoxedCode* code = static_cast(v); - RELEASE_ASSERT(func->f->source && code->f->source, "__code__ can only be set on python functions"); + RELEASE_ASSERT(func->md->source && code->f->source, "__code__ can only be set on python functions"); - RELEASE_ASSERT(!func->f->internal_callable.get() && !func->f->internal_callable.get(), + RELEASE_ASSERT(!func->md->internal_callable.get() && !func->md->internal_callable.get(), "this could cause invalidation issues"); - func->f = code->f; + func->md = code->f; func->dependent_ics.invalidateAll(); } @@ -1761,14 +1761,14 @@ static Box* functionGlobals(Box* self, void*) { assert(self->cls == function_cls); BoxedFunction* func = static_cast(self); if (func->globals) { - assert(!func->f->source || !func->f->source->scoping->areGlobalsFromModule()); + assert(!func->md->source || !func->md->source->scoping->areGlobalsFromModule()); return func->globals; } - assert(func->f->source); - assert(func->f->source->scoping->areGlobalsFromModule()); + assert(func->md->source); + assert(func->md->source->scoping->areGlobalsFromModule()); static BoxedString* dict_str = internStringImmortal("__dict__"); - return getattr(func->f->source->parent_module, dict_str); + return getattr(func->md->source->parent_module, dict_str); } static void functionSetDefaults(Box* b, Box* v, void*) { diff --git a/src/runtime/types.h b/src/runtime/types.h index 3ed978083..af7de5bd2 100644 --- a/src/runtime/types.h +++ b/src/runtime/types.h @@ -804,7 +804,7 @@ class BoxedFunctionBase : public Box { public: Box** in_weakreflist; - FunctionMetadata* f; + FunctionMetadata* md; // TODO these should really go in BoxedFunction but it's annoying because they don't get // initializd until after BoxedFunctionBase's constructor is run which means they could have @@ -823,12 +823,12 @@ class BoxedFunctionBase : public Box { BoxedString* name; // __name__ (should be here or in one of the derived classes?) Box* doc; // __doc__ - BoxedFunctionBase(FunctionMetadata* f); - BoxedFunctionBase(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure = NULL, + BoxedFunctionBase(FunctionMetadata* md); + BoxedFunctionBase(FunctionMetadata* md, std::initializer_list defaults, BoxedClosure* closure = NULL, Box* globals = NULL, bool can_change_defaults = false); ParamReceiveSpec getParamspec() { - return ParamReceiveSpec(f->num_args, defaults ? defaults->size() : 0, f->takes_varargs, f->takes_kwargs); + return ParamReceiveSpec(md->num_args, defaults ? defaults->size() : 0, md->takes_varargs, md->takes_kwargs); } }; @@ -836,8 +836,8 @@ class BoxedFunction : public BoxedFunctionBase { public: HCAttrs attrs; - BoxedFunction(FunctionMetadata* f); - BoxedFunction(FunctionMetadata* f, std::initializer_list defaults, BoxedClosure* closure = NULL, + BoxedFunction(FunctionMetadata* md); + BoxedFunction(FunctionMetadata* md, std::initializer_list defaults, BoxedClosure* closure = NULL, Box* globals = NULL, bool can_change_defaults = false); DEFAULT_CLASS(function_cls); @@ -1133,7 +1133,7 @@ extern Box* dict_descr; Box* codeForFunction(BoxedFunction*); Box* codeForFunctionMetadata(FunctionMetadata*); -FunctionMetadata* clfunctionFromCode(Box* code); +FunctionMetadata* metadataFromCode(Box* code); Box* getFrame(int depth); diff --git a/src/runtime/util.cpp b/src/runtime/util.cpp index 90f9d7f16..050c498d4 100644 --- a/src/runtime/util.cpp +++ b/src/runtime/util.cpp @@ -256,20 +256,20 @@ extern "C" void dumpEx(void* p, int levels) { if (isSubclass(b->cls, function_cls)) { BoxedFunction* f = static_cast(b); - FunctionMetadata* cl = f->f; - if (cl->source) { - printf("User-defined function '%s'\n", cl->source->getName()->c_str()); - printf("Defined at %s:%d\n", cl->source->getFn()->c_str(), cl->source->body[0]->lineno); + FunctionMetadata* md = f->md; + if (md->source) { + printf("User-defined function '%s'\n", md->source->getName()->c_str()); + printf("Defined at %s:%d\n", md->source->getFn()->c_str(), md->source->body[0]->lineno); - if (cl->source->cfg && levels > 0) { - cl->source->cfg->print(); + if (md->source->cfg && levels > 0) { + md->source->cfg->print(); } } else { printf("A builtin function\n"); } - printf("Has %ld function versions\n", cl->versions.size()); - for (CompiledFunction* cf : cl->versions) { + printf("Has %ld function versions\n", md->versions.size()); + for (CompiledFunction* cf : md->versions) { bool got_name; if (cf->exception_style == CXX) printf("CXX style: ");