| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef VMANONFN_H |
| 23 |
#define VMANONFN_H |
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
#include "vmtype.h" |
| 27 |
#include "vmobj.h" |
| 28 |
#include "vmvec.h" |
| 29 |
#include "vmglob.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class CVmObjAnonFn: public CVmObjVector |
| 35 |
{ |
| 36 |
friend class CVmMetaclassAnonFn; |
| 37 |
|
| 38 |
public: |
| 39 |
|
| 40 |
static class CVmMetaclass *metaclass_reg_; |
| 41 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 42 |
|
| 43 |
|
| 44 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 45 |
{ |
| 46 |
|
| 47 |
return (meta == metaclass_reg_ |
| 48 |
|| CVmObjVector::is_of_metaclass(meta)); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
static int is_anonfn_obj(VMG_ vm_obj_id_t obj) |
| 53 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 54 |
|
| 55 |
|
| 56 |
int is_listlike(VMG_ vm_obj_id_t) { return FALSE; } |
| 57 |
|
| 58 |
|
| 59 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 60 |
uint argc); |
| 61 |
|
| 62 |
|
| 63 |
int get_invoker(VMG_ vm_val_t *val); |
| 64 |
|
| 65 |
|
| 66 |
int equals(VMG_ vm_obj_id_t self, const vm_val_t *val, int) const |
| 67 |
{ |
| 68 |
|
| 69 |
return (val->typ == VM_OBJ && val->val.obj == self); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
uint calc_hash(VMG_ vm_obj_id_t self, int) const |
| 74 |
{ |
| 75 |
|
| 76 |
return (uint)(((ulong)self & 0xffff) |
| 77 |
^ (((ulong)self & 0xffff0000) >> 16)); |
| 78 |
} |
| 79 |
|
| 80 |
protected: |
| 81 |
|
| 82 |
CVmObjAnonFn() { ext_ = 0; } |
| 83 |
|
| 84 |
|
| 85 |
CVmObjAnonFn(VMG_ size_t cnt) |
| 86 |
: CVmObjVector(vmg_ cnt) |
| 87 |
{ |
| 88 |
|
| 89 |
set_element_count(cnt); |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
class CVmMetaclassAnonFn: public CVmMetaclass |
| 99 |
{ |
| 100 |
public: |
| 101 |
|
| 102 |
const char *get_meta_name() const { return "anon-func-ptr/030000"; } |
| 103 |
|
| 104 |
|
| 105 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 106 |
{ |
| 107 |
new (vmg_ id) CVmObjAnonFn(); |
| 108 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 113 |
{ |
| 114 |
new (vmg_ id) CVmObjAnonFn(); |
| 115 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 120 |
{ return CVmObjAnonFn::create_from_stack(vmg_ pc_ptr, argc); } |
| 121 |
|
| 122 |
|
| 123 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 124 |
const uchar **pc_ptr, uint *argc, |
| 125 |
vm_prop_id_t prop) |
| 126 |
{ |
| 127 |
|
| 128 |
return CVmObjVector::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
CVmMetaclass *get_supermeta_reg() const |
| 133 |
{ return CVmObjVector::metaclass_reg_; } |
| 134 |
}; |
| 135 |
|
| 136 |
#endif |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
VM_REGISTER_METACLASS(CVmObjAnonFn) |
| 142 |
|
| 143 |
|