123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- #ifndef VIRTUALMATH_VALUE_H
- #define VIRTUALMATH_VALUE_H
- #include "__macro.h"
- // 标准错误信息定义
- #define INSTANCE_ERROR(class) L"Instance error when calling func, call non-"#class" "#class" method"
- #define VALUE_ERROR(value, acc) L###value" value is not a "#acc" (may be modified by an external program)"
- #define ONLY_ACC(var, value) L###var" only accepts "#value
- #define ERROR_INIT(class) L###class" get wrong initialization parameters"
- #define MANY_ARG L"Too many parameters"
- #define FEW_ARG L"Too few parameters"
- #define CUL_ERROR(opt) L###opt" operation gets incorrect value"
- #define OBJ_NOTSUPPORT(opt) L"Object does not support "#opt" operation"
- #define RETURN_ERROR(func, type) L###func" func should return "#type" type data"
- #define KEY_INTERRUPT L"KeyInterrupt"
- typedef struct Argument Argument;
- typedef struct Inter Inter;
- typedef struct VarList VarList;
- typedef enum ResultType ResultType;
- typedef enum BaseErrorType BaseErrorType;
- typedef struct Value Value;
- typedef struct LinkValue LinkValue;
- typedef struct Result Result;
- typedef struct Error Error;
- typedef struct Inherit Inherit;
- typedef struct Package Package;
- typedef enum ResultType (*OfficialFunction)(O_FUNC);
- typedef void (*Registered)(R_FUNC);
- enum ValueAuthority {
- auto_aut,
- public_aut,
- protect_aut,
- private_aut
- };
- enum ValueType {
- V_none=0,
- V_num=1,
- V_str=2,
- V_func=3,
- V_list=4,
- V_dict=5,
- V_class=6,
- V_obj=7,
- V_bool=8,
- V_ell=9,
- V_file=10,
- V_lib=11,
- };
- struct Number {
- vnum num;
- };
- struct String {
- wchar_t *str;
- };
- struct Function{
- enum {
- c_func,
- vm_func,
- f_func,
- } type;
- struct Statement *function;
- struct Parameter *pt;
- OfficialFunction of;
- void (*ffunc)(); // ffi导入的func
- struct {
- enum FunctionPtType {
- free_, // 不包含任何隐式传递的参数
- static_, // 不包含self参数
- object_static_, // self参数不允许class
- class_static_, // self参数允许一切,但转换为类
- all_static_, // self参数允许一切
- cls_static_, // 使用function自带的cls作为参数
- object_free_, // 同object_static_但不包含func参数
- class_free_, // 同object_static_但不包含func参数
- all_free_, // 允许class或者object
- cls_free_, // 使用function自带的cls作为参数
- } pt_type;
- LinkValue *cls;
- bool run; // 是否为即时调用
- } function_data;
- };
- struct List {
- enum ListType {
- L_tuple,
- L_list,
- } type;
- struct LinkValue **list;
- vnum size;
- };
- struct Dict {
- struct HashTable *dict;
- vnum size;
- };
- struct Bool{
- bool bool_;
- };
- struct Lib{
- void *handle;
- };
- struct File{
- FILE *file;
- char *path; // 文件路径
- char *mode; // 模式
- bool is_std;
- };
- struct Value{
- enum ValueType type;
- struct {
- struct VarList *var;
- struct VarList *out_var;
- struct Inherit *inherit;
- } object;
- union data {
- struct Number num;
- struct String str;
- struct Function function;
- struct List list;
- struct Dict dict;
- struct Bool bool_;
- struct File file;
- struct Lib lib;
- } data;
- struct Value *gc_next;
- struct Value *gc_last;
- struct GCStatus gc_status;
- };
- struct LinkValue {
- enum ValueAuthority aut;
- struct Value *value;
- struct LinkValue *belong;
- struct LinkValue *gc_next;
- struct LinkValue *gc_last;
- struct GCStatus gc_status;
- };
- struct Result {
- enum ResultType {
- R_not = 1, // 无返回值
- R_func=2, // 函数返回值
- R_opt=3, // 表达式返回值
- R_error=4, // 错误
- R_break=5,
- R_continue=6,
- R_rego=7,
- R_restart=8,
- R_goto=9,
- R_yield=10,
- } type;
- wchar_t *label;
- struct LinkValue *value;
- struct Error *error;
- vnum times;
- struct Statement *node;
- bool is_yield; // 执行的函数是否为生成器
- };
- struct Error {
- wchar_t *type;
- wchar_t *messgae;
- char *file;
- fline line;
- struct Error *next;
- };
- struct Inherit {
- struct LinkValue *value;
- struct Inherit *next;
- };
- struct Package {
- struct Value *package;
- char *name; // split dir的name
- char *md5; // md5地址
- struct Package *next;
- };
- enum BaseErrorType{
- E_BaseException,
- E_Exception,
- E_TypeException,
- E_ArgumentException,
- E_PermissionsException,
- E_GotoException,
- E_ResultException,
- E_NameExceptiom,
- E_AssertException,
- E_KeyException,
- E_IndexException,
- E_StrideException,
- E_StopIterException,
- E_SuperException,
- E_ImportException,
- E_IncludeException,
- E_SystemException,
- E_KeyInterrupt,
- E_QuitException,
- };
- Value *makeObject(Inter *inter, VarList *object, VarList *out_var, Inherit *inherit);
- void freeValue(Value **Value);
- LinkValue *makeLinkValue(Value *value, LinkValue *belong, Inter *inter);
- void freeLinkValue(LinkValue **value);
- LinkValue *copyLinkValue(LinkValue *value, Inter *inter);
- Value *useNoneValue(Inter *inter, Result *result);
- Value *makeBoolValue(bool bool_num, fline line, char *file, FUNC_NT);
- Value *makePassValue(fline line, char *file, FUNC_NT);
- Value *makeNumberValue(vnum num, fline line, char *file, FUNC_NT);
- Value *makeStringValue(wchar_t *str, fline line, char *file, FUNC_NT);
- Value *makeVMFunctionValue(struct Statement *st, struct Parameter *pt, FUNC_NT);
- Value *makeCFunctionValue(OfficialFunction of, fline line, char *file, FUNC_NT);
- LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFunction function_new, OfficialFunction function_init, LinkValue *belong, VarList *var_list, Inter *inter);
- Value *makeFFunctionValue(void (*ffunc)(), fline line, char *file, FUNC_NT);
- Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father);
- Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type, FUNC_NT);
- Value *makeDictValue(Argument *arg, bool new_hash, fline line, char *file, FUNC_NT);
- void setResultCore(Result *ru);
- void setResult(Result *ru, Inter *inter);
- void setResultBase(Result *ru, Inter *inter);
- void setResultErrorSt(BaseErrorType type, wchar_t *error_message, bool new, FUNC);
- void setResultError(BaseErrorType type, wchar_t *error_message, fline line, char *file, bool new, FUNC_NT);
- void setResultOperationNone(Result *ru, Inter *inter, LinkValue *belong);
- void setResultOperation(Result *ru, LinkValue *value);
- void setResultOperationBase(Result *ru, LinkValue *value);
- void freeResult(Result *ru);
- Package *makePackage(Value *value, char *md5, char *name, Package *base);
- void freePackage(Package *base);
- Value *checkPackage(Package *base, char *md5, char *name);
- Error *makeError(wchar_t *type, wchar_t *message, fline line, char *file);
- void freeError(Result *base);
- Error *connectError(Error *new, Error *base);
- void printError(Result *result, Inter *inter, bool free);
- void printValue(Value *value, FILE *debug, bool print_father, bool print_in);
- void printLinkValue(LinkValue *value, char *first, char *last, FILE *debug);
- bool isType(Value *value, enum ValueType type);
- Inherit *makeInherit(LinkValue *value);
- Inherit *copyInherit(Inherit *value);
- Inherit *freeInherit(Inherit *value);
- Inherit *connectInherit(Inherit *base, Inherit *back);
- Inherit *connectSafeInherit(Inherit *base, Inherit *back);
- bool checkAttribution(Value *self, Value *father);
- Inherit *getInheritFromValueCore(LinkValue *num_father);
- bool callDel(Value *object_value, Result *result, Inter *inter, VarList *var_list);
- bool needDel(Value *object_value, Inter *inter);
- #endif //VIRTUALMATH_VALUE_H
|