| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef VMITER_H |
| 21 |
#define VMITER_H |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include "vmtype.h" |
| 25 |
#include "vmobj.h" |
| 26 |
#include "vmglob.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class CVmObjIter: public CVmObject |
| 33 |
{ |
| 34 |
friend class CVmMetaclassIter; |
| 35 |
|
| 36 |
public: |
| 37 |
|
| 38 |
static class CVmMetaclass *metaclass_reg_; |
| 39 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 40 |
|
| 41 |
|
| 42 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 43 |
{ |
| 44 |
|
| 45 |
return (meta == metaclass_reg_ |
| 46 |
|| CVmObject::is_of_metaclass(meta)); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 54 |
const uchar **pc_ptr, uint *argc, |
| 55 |
vm_prop_id_t prop) |
| 56 |
{ return CVmObject::call_stat_prop(vmg_ result, pc_ptr, argc, prop); } |
| 57 |
|
| 58 |
|
| 59 |
void set_prop(VMG_ class CVmUndo *, |
| 60 |
vm_obj_id_t, vm_prop_id_t, const vm_val_t *) |
| 61 |
{ |
| 62 |
|
| 63 |
err_throw(VMERR_INVALID_SETPROP); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 68 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 69 |
|
| 70 |
protected: |
| 71 |
|
| 72 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 73 |
|
| 74 |
|
| 75 |
virtual int getp_get_next(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 76 |
uint *argc) = 0; |
| 77 |
|
| 78 |
|
| 79 |
virtual int getp_is_next_avail(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 80 |
uint *argc) = 0; |
| 81 |
|
| 82 |
|
| 83 |
virtual int getp_reset_iter(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 84 |
uint *argc) = 0; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
virtual int getp_get_cur_key(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 89 |
uint *argc) = 0; |
| 90 |
|
| 91 |
|
| 92 |
virtual int getp_get_cur_val(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 93 |
uint *argc) = 0; |
| 94 |
|
| 95 |
|
| 96 |
static int (CVmObjIter::*func_table_[])(VMG_ vm_obj_id_t self, |
| 97 |
vm_val_t *retval, uint *argc); |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
#define VMOBJITERIDX_EXT_SIZE (VMB_DATAHOLDER + 16) |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
#define VMOBJITERIDX_UNDO 0x0001 |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
class CVmObjIterIdx: public CVmObjIter |
| 140 |
{ |
| 141 |
friend class CVmMetaclassIterIdx; |
| 142 |
|
| 143 |
public: |
| 144 |
|
| 145 |
static class CVmMetaclass *metaclass_reg_; |
| 146 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 147 |
|
| 148 |
|
| 149 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 150 |
{ |
| 151 |
|
| 152 |
return (meta == metaclass_reg_ |
| 153 |
|| CVmObjIter::is_of_metaclass(meta)); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 161 |
const uchar **pc_ptr, uint *argc, |
| 162 |
vm_prop_id_t prop) |
| 163 |
{ |
| 164 |
return CVmObjIter::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static vm_obj_id_t create_for_coll(VMG_ const vm_val_t *coll, |
| 173 |
long first_valid_index, |
| 174 |
long last_valid_index); |
| 175 |
|
| 176 |
|
| 177 |
void notify_delete(VMG_ int in_root_set); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
void notify_new_savept() |
| 185 |
{ set_flags(get_flags() & ~VMOBJITERIDX_UNDO); } |
| 186 |
|
| 187 |
|
| 188 |
void apply_undo(VMG_ struct CVmUndoRecord *rec); |
| 189 |
|
| 190 |
|
| 191 |
void mark_refs(VMG_ uint state); |
| 192 |
|
| 193 |
|
| 194 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 195 |
|
| 196 |
|
| 197 |
void remove_stale_weak_refs(VMG0_) { } |
| 198 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 199 |
|
| 200 |
|
| 201 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 202 |
|
| 203 |
|
| 204 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 205 |
const char *ptr, size_t siz); |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
int is_changed_since_load() const { return TRUE; } |
| 212 |
|
| 213 |
|
| 214 |
void save_to_file(VMG_ class CVmFile *fp); |
| 215 |
|
| 216 |
|
| 217 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 218 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 219 |
|
| 220 |
|
| 221 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 222 |
|
| 223 |
|
| 224 |
virtual void convert_to_const_data(VMG_ class CVmConstMapper *mapper, |
| 225 |
vm_obj_id_t self); |
| 226 |
|
| 227 |
|
| 228 |
virtual int iter_next(VMG_ vm_obj_id_t self, vm_val_t *val); |
| 229 |
|
| 230 |
protected: |
| 231 |
|
| 232 |
CVmObjIterIdx() { ext_ = 0; } |
| 233 |
|
| 234 |
|
| 235 |
CVmObjIterIdx(VMG_ const vm_val_t *coll, long first_valid_index, |
| 236 |
long last_valid_index); |
| 237 |
|
| 238 |
|
| 239 |
void get_indexed_val(VMG_ long idx, vm_val_t *retval); |
| 240 |
|
| 241 |
|
| 242 |
virtual int getp_get_next(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 243 |
uint *argc); |
| 244 |
|
| 245 |
|
| 246 |
virtual int getp_is_next_avail(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 247 |
uint *argc); |
| 248 |
|
| 249 |
|
| 250 |
virtual int getp_reset_iter(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 251 |
uint *argc); |
| 252 |
|
| 253 |
|
| 254 |
virtual int getp_get_cur_key(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 255 |
uint *argc); |
| 256 |
|
| 257 |
|
| 258 |
virtual int getp_get_cur_val(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 259 |
uint *argc); |
| 260 |
|
| 261 |
|
| 262 |
void get_coll_val(vm_val_t *val) { vmb_get_dh(ext_, val); } |
| 263 |
|
| 264 |
|
| 265 |
long get_cur_index() const |
| 266 |
{ return t3rp4u(ext_ + VMB_DATAHOLDER); } |
| 267 |
void set_cur_index_no_undo(long idx) |
| 268 |
{ oswp4(ext_ + VMB_DATAHOLDER, idx); } |
| 269 |
|
| 270 |
|
| 271 |
void set_cur_index(VMG_ vm_obj_id_t self, long idx); |
| 272 |
|
| 273 |
|
| 274 |
long get_first_valid() const |
| 275 |
{ return t3rp4u(ext_ + VMB_DATAHOLDER + 4); } |
| 276 |
long get_last_valid() const |
| 277 |
{ return t3rp4u(ext_ + VMB_DATAHOLDER + 8); } |
| 278 |
|
| 279 |
|
| 280 |
void set_first_valid(long idx) const |
| 281 |
{ oswp4(ext_ + VMB_DATAHOLDER + 4, idx); } |
| 282 |
void set_last_valid(long idx) const |
| 283 |
{ oswp4(ext_ + VMB_DATAHOLDER + 8, idx); } |
| 284 |
|
| 285 |
|
| 286 |
unsigned long get_flags() const |
| 287 |
{ return t3rp4u(ext_ + VMB_DATAHOLDER + 12); } |
| 288 |
void set_flags(unsigned long flags) const |
| 289 |
{ oswp4(ext_ + VMB_DATAHOLDER + 12, flags); } |
| 290 |
}; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
class CVmMetaclassIter: public CVmMetaclass |
| 298 |
{ |
| 299 |
public: |
| 300 |
|
| 301 |
const char *get_meta_name() const { return "iterator/030001"; } |
| 302 |
|
| 303 |
|
| 304 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 305 |
{ err_throw(VMERR_BAD_STATIC_NEW); } |
| 306 |
|
| 307 |
|
| 308 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 309 |
{ err_throw(VMERR_BAD_STATIC_NEW); } |
| 310 |
|
| 311 |
|
| 312 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 313 |
{ |
| 314 |
err_throw(VMERR_BAD_DYNAMIC_NEW); |
| 315 |
AFTER_ERR_THROW(return VM_INVALID_OBJ;) |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 320 |
const uchar **pc_ptr, uint *argc, |
| 321 |
vm_prop_id_t prop) |
| 322 |
{ |
| 323 |
return CVmObjIter::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 324 |
} |
| 325 |
}; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
class CVmMetaclassIterIdx: public CVmMetaclass |
| 331 |
{ |
| 332 |
public: |
| 333 |
|
| 334 |
const char *get_meta_name() const { return "indexed-iterator/030000"; } |
| 335 |
|
| 336 |
|
| 337 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 338 |
{ |
| 339 |
new (vmg_ id) CVmObjIterIdx(); |
| 340 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 345 |
{ |
| 346 |
new (vmg_ id) CVmObjIterIdx(); |
| 347 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 352 |
{ |
| 353 |
err_throw(VMERR_BAD_DYNAMIC_NEW); |
| 354 |
AFTER_ERR_THROW(return VM_INVALID_OBJ;) |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 359 |
const uchar **pc_ptr, uint *argc, |
| 360 |
vm_prop_id_t prop) |
| 361 |
{ |
| 362 |
return CVmObjIterIdx::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 363 |
} |
| 364 |
}; |
| 365 |
|
| 366 |
#endif |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
VM_REGISTER_METACLASS(CVmObjIter) |
| 372 |
VM_REGISTER_METACLASS(CVmObjIterIdx) |
| 373 |
|