Extend native class API to support full AerScript declarations
Build / AerScript (push) Successful in 18s
Build / AerScript (push) Successful in 18s
This commit is contained in:
+57
-1
@@ -546,19 +546,31 @@ typedef struct ph7_type_def {
|
||||
const char *zClass; /* Required only for PH7_TYPE_NAMED; self is allowed. */
|
||||
int bArray; /* Zero or one: the language's T[] annotation. */
|
||||
} ph7_type_def;
|
||||
/* Evaluators use ph7_result_* and return PH7_OK, PH7_ABORT or PH7_EXCEPTION.
|
||||
* They run at the same evaluation point as the corresponding source expression. */
|
||||
typedef int (*ph7_initializer_func)(ph7_context *);
|
||||
typedef struct ph7_field_def {
|
||||
const char *zName;
|
||||
ph7_type_def sType;
|
||||
const ph7_value *pInitial;
|
||||
unsigned int iFlags;
|
||||
ph7_initializer_func xInitial;
|
||||
void *pInitialData;
|
||||
} ph7_field_def;
|
||||
typedef struct ph7_constant_def {
|
||||
const char *zName;
|
||||
const ph7_value *pValue;
|
||||
unsigned int iFlags;
|
||||
ph7_initializer_func xInitial;
|
||||
void *pInitialData;
|
||||
} ph7_constant_def;
|
||||
typedef struct ph7_param_def {
|
||||
const char *zName; /* Exact lowercase this/parent are reserved, even for static methods. */
|
||||
const char *zName; /* Explicit parameters shadow implicit this/parent bindings. */
|
||||
ph7_type_def sType;
|
||||
unsigned int iFlags;
|
||||
const ph7_value *pDefault;
|
||||
ph7_initializer_func xDefault;
|
||||
void *pDefaultData;
|
||||
} ph7_param_def;
|
||||
typedef struct ph7_method_def {
|
||||
const char *zName;
|
||||
@@ -570,6 +582,8 @@ typedef struct ph7_method_def {
|
||||
unsigned int iFlags;
|
||||
} ph7_method_def;
|
||||
typedef struct ph7_class_def {
|
||||
unsigned int nSize; /* sizeof(ph7_class_def), checked before any later field */
|
||||
unsigned int nVersion; /* PH7_CLASS_DEF_VERSION; covers all nested record layouts */
|
||||
const char *zName;
|
||||
const ph7_field_def *aField;
|
||||
unsigned int nField;
|
||||
@@ -577,13 +591,55 @@ typedef struct ph7_class_def {
|
||||
unsigned int nConstant;
|
||||
const ph7_method_def *aMethod;
|
||||
unsigned int nMethod;
|
||||
unsigned int iFlags;
|
||||
const char *const *azBase;
|
||||
unsigned int nBase;
|
||||
const char *const *azInterface;
|
||||
unsigned int nInterface;
|
||||
/* Optional declaration order: indices into fields followed by constants.
|
||||
* NULL/0 keeps the default: all fields, then all constants. Otherwise
|
||||
* supply every index exactly once, in source declaration order. */
|
||||
const unsigned int *aMemberOrder;
|
||||
unsigned int nMemberOrder;
|
||||
} ph7_class_def;
|
||||
#define PH7_CLASS_DEF_VERSION 2
|
||||
#define PH7_MEMBER_STATIC 0x01
|
||||
#define PH7_MEMBER_VIRTUAL 0x04
|
||||
#define PH7_MEMBER_FINAL 0x08
|
||||
#define PH7_MEMBER_PUBLIC 0x10
|
||||
#define PH7_MEMBER_PROTECTED 0x20
|
||||
#define PH7_MEMBER_PRIVATE 0x40
|
||||
#define PH7_PARAM_REF 0x01
|
||||
#define PH7_DECL_FINAL 0x01
|
||||
#define PH7_DECL_INTERFACE 0x02
|
||||
#define PH7_DECL_VIRTUAL 0x04
|
||||
/* Return an exception object using ph7_result_value(), then this status. */
|
||||
#define PH7_EXCEPTION (-255)
|
||||
PH7_APIEXPORT int ph7_create_class(ph7_vm *pVm, const ph7_class_def *pDef);
|
||||
/* Borrowed receiver, valid only during this callback; NULL for static calls. */
|
||||
PH7_APIEXPORT ph7_value *ph7_context_this(ph7_context *pCtx);
|
||||
/* Indexed operations reacquire moving VM storage on every call. argv contains
|
||||
* by-value snapshots; use these operations for immediate reference semantics. */
|
||||
PH7_APIEXPORT int ph7_context_arg_value(ph7_context *pCtx, unsigned int nArg, ph7_value *pOut);
|
||||
PH7_APIEXPORT int ph7_context_arg_store(ph7_context *pCtx, unsigned int nArg, ph7_value *pValue);
|
||||
/* A forwarding handle is borrowed until this callback returns. Calls reacquire
|
||||
* its live indexed binding; ordinary value setters still mutate only its copy. */
|
||||
PH7_APIEXPORT int ph7_context_arg_bind(ph7_context *pCtx, unsigned int nArg, ph7_value *pOut);
|
||||
/* pObject selects instance storage; otherwise zClass selects static/constant
|
||||
* storage. Access is checked in the callback's declaring language scope. */
|
||||
PH7_APIEXPORT int ph7_context_attr_value(ph7_context *pCtx, ph7_value *pObject,
|
||||
const char *zClass, const char *zName, ph7_value *pOut);
|
||||
PH7_APIEXPORT int ph7_context_attr_store(ph7_context *pCtx, ph7_value *pObject,
|
||||
const char *zClass, const char *zName, ph7_value *pValue);
|
||||
PH7_APIEXPORT int ph7_context_call(ph7_context *pCtx, ph7_value *pCallable,
|
||||
int nArg, ph7_value **apArg, ph7_value *pResult);
|
||||
PH7_APIEXPORT int ph7_context_parent(ph7_context *pCtx, const char *zMethod,
|
||||
int nArg, ph7_value **apArg, ph7_value *pResult);
|
||||
PH7_APIEXPORT int ph7_context_var_value(ph7_context *pCtx, const char *zName, ph7_value *pOut);
|
||||
PH7_APIEXPORT int ph7_context_var_store(ph7_context *pCtx, const char *zName, ph7_value *pValue);
|
||||
/* Legacy scalar conversion APIs cannot return an exception status. Query this
|
||||
* before further native side effects; returning it propagates the completion. */
|
||||
PH7_APIEXPORT int ph7_context_status(ph7_context *pCtx);
|
||||
PH7_APIEXPORT int ph7_create_function(ph7_vm *pVm, const char *zName, int (*xFunc)(ph7_context *, int, ph7_value **), void *pUserData);
|
||||
PH7_APIEXPORT int ph7_delete_function(ph7_vm *pVm, const char *zName);
|
||||
PH7_APIEXPORT int ph7_create_constant(ph7_vm *pVm, const char *zName, void (*xExpand)(ph7_value *, void *), void *pUserData);
|
||||
|
||||
Reference in New Issue
Block a user