1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#pragma once
#include "Compiler/ValueArray.h"
#include "Compiler/Type.h"
#include "Core/Variant.h"
namespace storm {
STORM_PKG(core.lang);
// Create the Fn type.
Type *createFn(Str *name, ValueArray *params);
/**
* Type for function pointers.
*/
class FnType : public Type {
STORM_CLASS;
public:
// Create.
STORM_CTOR FnType(Str *name, ValueArray *params);
// Get the result type of this function. Convenience for examining the first parameter manually.
Value STORM_FN result();
// Get the parameters of this function. Convenience for examining the parameters manually.
Array<Value> *STORM_FN parameters();
// Get a thunk that can be used to call constructors of object-types.
const void *ctorThunk();
// Information to a constructor call. Note, used from ASM.
class CtorInfo : public Object {
STORM_CLASS;
public:
CtorInfo(Type *type, code::Ref ctor)
: type(type), ctor(ctor.source()) {}
Type *type;
code::RefSource *ctor;
};
protected:
// Load.
virtual Bool STORM_FN loadAll();
private:
// Generate the code for calling the function.
CodeGen *CODECALL callCode();
// Generate code returned by 'rawCall'.
CodeGen *CODECALL rawCallCode();
// Create the contents of 'rawCall'.
code::RefSource *createRawCall();
// Thunk used for function calls.
code::RefSource *thunk;
// Code used by 'rawCall'.
code::RefSource *rawCall;
// Thunk for calling constructors. Generated on demand.
code::Binary *ctorThunkBinary;
};
// Find the function type.
FnType *STORM_FN fnType(Array<Value> *params) ON(Compiler);
// Create a function pointer to a function.
FnBase *STORM_FN pointer(Function *target) ON(Compiler);
// Create a function pointer to a function. Binds `thisPtr` to the first parameter.
FnBase *STORM_FN pointer(Function *target, Object *thisPtr) ON(Compiler);
// Create a function pointer to a function. Binds `thisPtr` to the first parameter.
FnBase *STORM_FN pointer(Function *target, TObject *thisPtr) ON(Compiler);
// Dynamic calls to functions by using Variants. Checks the types of parameters before
// performing the call.
Variant STORM_FN dynamicCall(Function *function, Array<Variant> *params) ON(Compiler);
// Low-level functionality required by generated machine code.
void CODECALL fnCallRaw(FnBase *b, void *output, os::CallThunk thunk, void **params, size_t first, CloneEnv **env);
// Low-level creation from generated code. Used from Basic Storm to create pointers to member functions.
FnBase *CODECALL fnCreateRaw(Type *type, code::RefSource *to, Thread *thread, RootObject *thisPtr, Bool memberFn);
}
|