| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef VMLOOKUP_H |
| 21 |
#define VMLOOKUP_H |
| 22 |
|
| 23 |
#include "t3std.h" |
| 24 |
#include "vmtype.h" |
| 25 |
#include "vmglob.h" |
| 26 |
#include "vmobj.h" |
| 27 |
#include "vmundo.h" |
| 28 |
#include "vmcoll.h" |
| 29 |
#include "vmiter.h" |
| 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 |
#define VMLOOKUP_VALUE_SIZE (VMB_DATAHOLDER + VMB_DATAHOLDER + VMB_UINT2) |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
struct vm_lookup_val |
| 88 |
{ |
| 89 |
|
| 90 |
vm_val_t key; |
| 91 |
|
| 92 |
|
| 93 |
vm_val_t val; |
| 94 |
|
| 95 |
|
| 96 |
vm_lookup_val *nxt; |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
struct vm_lookup_ext |
| 104 |
{ |
| 105 |
|
| 106 |
static vm_lookup_ext *alloc_ext(VMG_ class CVmObjLookupTable *self, |
| 107 |
uint bucket_cnt, uint value_cnt); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
void init_ext(); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
static vm_lookup_ext *expand_ext(VMG_ class CVmObjLookupTable *self, |
| 124 |
vm_lookup_ext *old_ext, |
| 125 |
uint new_value_cnt); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
void copy_ext_from(vm_lookup_ext *old_ext); |
| 136 |
|
| 137 |
|
| 138 |
vm_lookup_val *alloc_val_entry() |
| 139 |
{ |
| 140 |
|
| 141 |
if (first_free == 0) |
| 142 |
return 0; |
| 143 |
|
| 144 |
|
| 145 |
vm_lookup_val *entry = first_free; |
| 146 |
|
| 147 |
|
| 148 |
first_free = first_free->nxt; |
| 149 |
|
| 150 |
|
| 151 |
return entry; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
void add_val(uint hash, const vm_val_t *key, const vm_val_t *val) |
| 159 |
{ |
| 160 |
|
| 161 |
vm_lookup_val *entry = alloc_val_entry(); |
| 162 |
|
| 163 |
|
| 164 |
entry->key = *key; |
| 165 |
entry->val = *val; |
| 166 |
|
| 167 |
|
| 168 |
entry->nxt = buckets[hash]; |
| 169 |
buckets[hash] = entry; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
vm_lookup_val *idx_to_val(uint idx) const |
| 179 |
{ |
| 180 |
vm_lookup_val *pool; |
| 181 |
|
| 182 |
|
| 183 |
pool = (vm_lookup_val *)(void *)&buckets[bucket_cnt]; |
| 184 |
|
| 185 |
|
| 186 |
return &pool[idx]; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
uint val_to_idx(vm_lookup_val *val) const |
| 191 |
{ |
| 192 |
return (val - idx_to_val(0)); |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
vm_lookup_val *img_idx_to_val(uint idx) const |
| 201 |
{ |
| 202 |
if (idx == 0) |
| 203 |
return 0; |
| 204 |
else |
| 205 |
return idx_to_val(idx - 1); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
uint val_to_img_idx(vm_lookup_val *val) |
| 210 |
{ |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
if (val == 0) |
| 216 |
return 0; |
| 217 |
else |
| 218 |
return (val - idx_to_val(0)) + 1; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
uint bucket_cnt; |
| 223 |
uint value_cnt; |
| 224 |
|
| 225 |
|
| 226 |
vm_lookup_val *first_free; |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
vm_val_t default_value; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
vm_lookup_val *buckets[1]; |
| 239 |
}; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
enum lookuptab_undo_action |
| 247 |
{ |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
LOOKUPTAB_UNDO_NULL, |
| 253 |
|
| 254 |
|
| 255 |
LOOKUPTAB_UNDO_ADD, |
| 256 |
|
| 257 |
|
| 258 |
LOOKUPTAB_UNDO_DEL, |
| 259 |
|
| 260 |
|
| 261 |
LOOKUPTAB_UNDO_MOD, |
| 262 |
|
| 263 |
|
| 264 |
LOOKUPTAB_UNDO_DEFVAL |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
class CVmObjLookupTable: public CVmObjCollection |
| 274 |
{ |
| 275 |
friend class CVmObjIterLookupTable; |
| 276 |
friend class CVmMetaclassLookupTable; |
| 277 |
friend class CVmObjWeakRefLookupTable; |
| 278 |
|
| 279 |
public: |
| 280 |
|
| 281 |
static class CVmMetaclass *metaclass_reg_; |
| 282 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 283 |
|
| 284 |
|
| 285 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 286 |
{ |
| 287 |
|
| 288 |
return (meta == metaclass_reg_ |
| 289 |
|| CVmObjCollection::is_of_metaclass(meta)); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
static int is_lookup_table_obj(VMG_ vm_obj_id_t obj) |
| 294 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 295 |
|
| 296 |
|
| 297 |
static vm_obj_id_t create(VMG_ int in_root_set, |
| 298 |
uint bucket_count, uint init_capacity); |
| 299 |
|
| 300 |
|
| 301 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 302 |
uint argc); |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 309 |
const uchar **pc_ptr, uint *argc, |
| 310 |
vm_prop_id_t prop) |
| 311 |
{ |
| 312 |
return CVmObjCollection:: |
| 313 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
virtual void reserve_const_data(VMG_ class CVmConstMapper *mapper, |
| 318 |
vm_obj_id_t self) |
| 319 |
{ |
| 320 |
|
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
virtual void convert_to_const_data(VMG_ class CVmConstMapper *mapper, |
| 325 |
vm_obj_id_t self); |
| 326 |
|
| 327 |
|
| 328 |
void notify_delete(VMG_ int in_root_set); |
| 329 |
|
| 330 |
|
| 331 |
void set_prop(VMG_ class CVmUndo *undo, |
| 332 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 333 |
|
| 334 |
|
| 335 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 336 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
void notify_new_savept() { } |
| 343 |
|
| 344 |
|
| 345 |
void apply_undo(VMG_ struct CVmUndoRecord *rec); |
| 346 |
|
| 347 |
|
| 348 |
void discard_undo(VMG_ struct CVmUndoRecord *); |
| 349 |
|
| 350 |
|
| 351 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *rec); |
| 352 |
|
| 353 |
|
| 354 |
void mark_refs(VMG_ uint); |
| 355 |
|
| 356 |
|
| 357 |
void remove_stale_weak_refs(VMG0_) { } |
| 358 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 359 |
|
| 360 |
|
| 361 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 362 |
|
| 363 |
|
| 364 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 365 |
const char *ptr, size_t siz); |
| 366 |
|
| 367 |
|
| 368 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 369 |
|
| 370 |
|
| 371 |
void save_to_file(VMG_ class CVmFile *fp); |
| 372 |
|
| 373 |
|
| 374 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 375 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
int is_changed_since_load() const { return TRUE; } |
| 383 |
|
| 384 |
|
| 385 |
int index_check(VMG_ vm_val_t *result, const vm_val_t *index_val); |
| 386 |
|
| 387 |
|
| 388 |
int index_val_q(VMG_ vm_val_t *result, |
| 389 |
vm_obj_id_t self, |
| 390 |
const vm_val_t *index_val); |
| 391 |
|
| 392 |
|
| 393 |
int set_index_val_q(VMG_ vm_val_t *new_container, |
| 394 |
vm_obj_id_t self, |
| 395 |
const vm_val_t *index_val, |
| 396 |
const vm_val_t *new_val); |
| 397 |
|
| 398 |
|
| 399 |
void add_entry(VMG_ const vm_val_t *key, const vm_val_t *val); |
| 400 |
|
| 401 |
|
| 402 |
void set_or_add_entry(VMG_ const vm_val_t *key, const vm_val_t *val); |
| 403 |
|
| 404 |
|
| 405 |
void keys_to_list(VMG_ vm_val_t *lst, |
| 406 |
int (*filter)(VMG_ const vm_val_t *, const vm_val_t *) |
| 407 |
= 0) |
| 408 |
{ make_list(vmg_ lst, TRUE, filter); } |
| 409 |
void vals_to_list(VMG_ vm_val_t *lst, |
| 410 |
int (*filter)(VMG_ const vm_val_t *, const vm_val_t *) |
| 411 |
= 0) |
| 412 |
{ make_list(vmg_ lst, FALSE, filter); } |
| 413 |
|
| 414 |
|
| 415 |
void for_each(VMG_ void (*cb)(VMG_ const vm_val_t *key, |
| 416 |
const vm_val_t *val, void *ctx), void *ctx); |
| 417 |
|
| 418 |
|
| 419 |
void get_default_val(vm_val_t *val); |
| 420 |
|
| 421 |
protected: |
| 422 |
|
| 423 |
static void get_constructor_args(VMG_ uint argc, |
| 424 |
size_t *bucket_count, |
| 425 |
size_t *init_capacity, |
| 426 |
vm_val_t *src_obj); |
| 427 |
|
| 428 |
|
| 429 |
void populate_from_list(VMG_ const vm_val_t *src_obj); |
| 430 |
|
| 431 |
|
| 432 |
void load_image_data(VMG_ const char *ptr, size_t siz); |
| 433 |
|
| 434 |
|
| 435 |
vm_obj_id_t create_copy(VMG0_); |
| 436 |
|
| 437 |
|
| 438 |
void add_entry_undo(VMG_ vm_obj_id_t self, |
| 439 |
const vm_val_t *key, const vm_val_t *val); |
| 440 |
|
| 441 |
|
| 442 |
void del_entry(VMG_ const vm_val_t *key); |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
void unlink_entry(VMG_ vm_lookup_val *entry, uint hashval, |
| 452 |
vm_lookup_val *prv_entry); |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
void mod_entry(VMG_ const vm_val_t *key, const vm_val_t *val); |
| 459 |
|
| 460 |
|
| 461 |
vm_lookup_val *find_entry(VMG_ const vm_val_t *key, |
| 462 |
uint *hashval_p, vm_lookup_val **prv_entry_p); |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
void expand_if_needed(VMG0_); |
| 469 |
|
| 470 |
|
| 471 |
vm_lookup_val *alloc_new_entry(VMG0_); |
| 472 |
|
| 473 |
|
| 474 |
uint calc_key_hash(VMG_ const vm_val_t *key); |
| 475 |
|
| 476 |
|
| 477 |
vm_lookup_ext *get_ext() const { return (vm_lookup_ext *)ext_; } |
| 478 |
|
| 479 |
|
| 480 |
uint get_bucket_count() const { return get_ext()->bucket_cnt; } |
| 481 |
|
| 482 |
|
| 483 |
uint get_entry_count() const { return get_ext()->value_cnt; } |
| 484 |
|
| 485 |
|
| 486 |
vm_lookup_val *get_first_free() const { return get_ext()->first_free; } |
| 487 |
void set_first_free(vm_lookup_val *p) { get_ext()->first_free = p; } |
| 488 |
|
| 489 |
|
| 490 |
vm_lookup_val **get_bucket(uint hash) const |
| 491 |
{ return &get_ext()->buckets[hash]; } |
| 492 |
|
| 493 |
|
| 494 |
void set_bucket(uint hash, vm_lookup_val *p) |
| 495 |
{ get_ext()->buckets[hash] = p; } |
| 496 |
|
| 497 |
|
| 498 |
void set_entry_val_undo(VMG_ vm_obj_id_t self, |
| 499 |
vm_lookup_val *entry, const vm_val_t *val); |
| 500 |
|
| 501 |
|
| 502 |
virtual void new_iterator(VMG_ vm_val_t *retval, |
| 503 |
const vm_val_t *self_val); |
| 504 |
|
| 505 |
|
| 506 |
virtual void new_live_iterator(VMG_ vm_val_t *retval, |
| 507 |
const vm_val_t *self_val); |
| 508 |
|
| 509 |
|
| 510 |
CVmObjLookupTable() { ext_ = 0; } |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
CVmObjLookupTable(VMG_ size_t hash_count, size_t entry_count); |
| 520 |
|
| 521 |
|
| 522 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 523 |
|
| 524 |
|
| 525 |
int getp_remove_entry(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 526 |
|
| 527 |
|
| 528 |
int getp_key_present(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 529 |
|
| 530 |
|
| 531 |
int getp_apply_all(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 532 |
|
| 533 |
|
| 534 |
int getp_for_each(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 535 |
|
| 536 |
|
| 537 |
int getp_for_each_assoc(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 538 |
|
| 539 |
|
| 540 |
int for_each_gen(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc, |
| 541 |
int pass_key_to_cb, struct vm_rcdesc *rc); |
| 542 |
|
| 543 |
|
| 544 |
int getp_count_buckets(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 545 |
|
| 546 |
|
| 547 |
int getp_count_entries(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 548 |
|
| 549 |
|
| 550 |
int getp_keys_to_list(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 551 |
|
| 552 |
|
| 553 |
int getp_vals_to_list(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 554 |
|
| 555 |
|
| 556 |
int getp_get_def_val(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 557 |
|
| 558 |
|
| 559 |
int getp_set_def_val(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 560 |
|
| 561 |
|
| 562 |
int getp_make_list(VMG_ vm_obj_id_t self, |
| 563 |
vm_val_t *retval, uint *argc, int store_keys); |
| 564 |
|
| 565 |
|
| 566 |
int getp_nthKey(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 567 |
|
| 568 |
|
| 569 |
int getp_nthVal(VMG_ vm_obj_id_t self, vm_val_t *val, uint *argc); |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
void get_nth_ele(VMG_ vm_val_t *key, vm_val_t *val, |
| 577 |
vm_obj_id_t self, long idx); |
| 578 |
|
| 579 |
|
| 580 |
void make_list(VMG_ vm_val_t *retval, int store_keys, |
| 581 |
int (*filter)(VMG_ const vm_val_t *, const vm_val_t *)); |
| 582 |
|
| 583 |
|
| 584 |
void add_undo_rec(VMG_ vm_obj_id_t self, |
| 585 |
enum lookuptab_undo_action action, |
| 586 |
const vm_val_t *key, |
| 587 |
const vm_val_t *old_entry_val); |
| 588 |
|
| 589 |
|
| 590 |
static int (CVmObjLookupTable::*func_table_[])(VMG_ vm_obj_id_t self, |
| 591 |
vm_val_t *retval, uint *argc); |
| 592 |
}; |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
class CVmObjWeakRefLookupTable: public CVmObjLookupTable |
| 600 |
{ |
| 601 |
friend class CVmMetaclassWeakRefLookupTable; |
| 602 |
|
| 603 |
public: |
| 604 |
|
| 605 |
static class CVmMetaclass *metaclass_reg_; |
| 606 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 607 |
|
| 608 |
|
| 609 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 610 |
{ |
| 611 |
|
| 612 |
return (meta == metaclass_reg_ |
| 613 |
|| CVmObjLookupTable::is_of_metaclass(meta)); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
static vm_obj_id_t create(VMG_ int in_root_set, |
| 618 |
uint bucket_count, uint init_capacity); |
| 619 |
|
| 620 |
|
| 621 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 622 |
uint argc); |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 629 |
const uchar **pc_ptr, uint *argc, |
| 630 |
vm_prop_id_t prop) |
| 631 |
{ |
| 632 |
return CVmObjLookupTable:: |
| 633 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
void mark_refs(VMG_ uint); |
| 638 |
|
| 639 |
|
| 640 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *rec); |
| 641 |
|
| 642 |
|
| 643 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *rec); |
| 644 |
|
| 645 |
|
| 646 |
void remove_stale_weak_refs(VMG0_); |
| 647 |
|
| 648 |
protected: |
| 649 |
|
| 650 |
CVmObjWeakRefLookupTable() { ext_ = 0; } |
| 651 |
|
| 652 |
|
| 653 |
CVmObjWeakRefLookupTable(VMG_ size_t hash_count, size_t entry_count) |
| 654 |
: CVmObjLookupTable(vmg_ hash_count, entry_count) { } |
| 655 |
}; |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
class CVmMetaclassLookupTable: public CVmMetaclass |
| 662 |
{ |
| 663 |
public: |
| 664 |
|
| 665 |
const char *get_meta_name() const { return "lookuptable/030003"; } |
| 666 |
|
| 667 |
|
| 668 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 669 |
{ |
| 670 |
new (vmg_ id) CVmObjLookupTable(); |
| 671 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 676 |
{ |
| 677 |
new (vmg_ id) CVmObjLookupTable(); |
| 678 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 683 |
{ return CVmObjLookupTable::create_from_stack(vmg_ pc_ptr, argc); } |
| 684 |
|
| 685 |
|
| 686 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 687 |
const uchar **pc_ptr, uint *argc, |
| 688 |
vm_prop_id_t prop) |
| 689 |
{ |
| 690 |
return CVmObjLookupTable:: |
| 691 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
CVmMetaclass *get_supermeta_reg() const |
| 696 |
{ return CVmObjCollection::metaclass_reg_; } |
| 697 |
}; |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
class CVmMetaclassWeakRefLookupTable: public CVmMetaclass |
| 703 |
{ |
| 704 |
public: |
| 705 |
|
| 706 |
const char *get_meta_name() const { return "weakreflookuptable/030001"; } |
| 707 |
|
| 708 |
|
| 709 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 710 |
{ new (vmg_ id) CVmObjWeakRefLookupTable(); } |
| 711 |
|
| 712 |
|
| 713 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 714 |
{ new (vmg_ id) CVmObjWeakRefLookupTable(); } |
| 715 |
|
| 716 |
|
| 717 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 718 |
{ return CVmObjWeakRefLookupTable:: |
| 719 |
create_from_stack(vmg_ pc_ptr, argc); } |
| 720 |
|
| 721 |
|
| 722 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 723 |
const uchar **pc_ptr, uint *argc, |
| 724 |
vm_prop_id_t prop) |
| 725 |
{ |
| 726 |
return CVmObjWeakRefLookupTable:: |
| 727 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
CVmMetaclass *get_supermeta_reg() const |
| 732 |
{ return CVmObjLookupTable::metaclass_reg_; } |
| 733 |
}; |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
#define VMOBJITERLOOKUPTABLE_EXT_SIZE (VMB_DATAHOLDER + 2 + 2) |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
#define VMOBJITERLOOKUPTABLE_UNDO 0x0001 |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
class CVmObjIterLookupTable: public CVmObjIter |
| 771 |
{ |
| 772 |
friend class CVmMetaclassIterLookupTable; |
| 773 |
|
| 774 |
public: |
| 775 |
|
| 776 |
static class CVmMetaclass *metaclass_reg_; |
| 777 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 778 |
|
| 779 |
|
| 780 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 781 |
{ |
| 782 |
|
| 783 |
return (meta == metaclass_reg_ |
| 784 |
|| CVmObjIter::is_of_metaclass(meta)); |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 792 |
const uchar **pc_ptr, uint *argc, |
| 793 |
vm_prop_id_t prop) |
| 794 |
{ |
| 795 |
return CVmObjIter::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
static vm_obj_id_t create_for_coll(VMG_ const vm_val_t *coll); |
| 803 |
|
| 804 |
|
| 805 |
void notify_delete(VMG_ int in_root_set); |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
void notify_new_savept() |
| 812 |
{ set_flags(get_flags() & ~VMOBJITERLOOKUPTABLE_UNDO); } |
| 813 |
|
| 814 |
|
| 815 |
void apply_undo(VMG_ struct CVmUndoRecord *rec); |
| 816 |
|
| 817 |
|
| 818 |
void mark_refs(VMG_ uint state); |
| 819 |
|
| 820 |
|
| 821 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 822 |
|
| 823 |
|
| 824 |
void remove_stale_weak_refs(VMG0_) { } |
| 825 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 826 |
|
| 827 |
|
| 828 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 829 |
|
| 830 |
|
| 831 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 832 |
const char *ptr, size_t siz); |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
int is_changed_since_load() const { return TRUE; } |
| 839 |
|
| 840 |
|
| 841 |
void save_to_file(VMG_ class CVmFile *fp); |
| 842 |
|
| 843 |
|
| 844 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 845 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 846 |
|
| 847 |
|
| 848 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 849 |
|
| 850 |
|
| 851 |
virtual void convert_to_const_data(VMG_ class CVmConstMapper *mapper, |
| 852 |
vm_obj_id_t self); |
| 853 |
|
| 854 |
protected: |
| 855 |
|
| 856 |
CVmObjIterLookupTable() { ext_ = 0; } |
| 857 |
|
| 858 |
|
| 859 |
CVmObjIterLookupTable(VMG_ const vm_val_t *coll); |
| 860 |
|
| 861 |
|
| 862 |
uint find_first_valid_entry(VMG_ uint entry) const; |
| 863 |
|
| 864 |
|
| 865 |
virtual int getp_get_next(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 866 |
uint *argc); |
| 867 |
|
| 868 |
|
| 869 |
virtual int getp_is_next_avail(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 870 |
uint *argc); |
| 871 |
|
| 872 |
|
| 873 |
virtual int getp_reset_iter(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 874 |
uint *argc); |
| 875 |
|
| 876 |
|
| 877 |
virtual int getp_get_cur_key(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 878 |
uint *argc); |
| 879 |
|
| 880 |
|
| 881 |
virtual int getp_get_cur_val(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 882 |
uint *argc); |
| 883 |
|
| 884 |
|
| 885 |
void get_cur_entry(VMG_ vm_val_t *valp, vm_val_t *keyp) const; |
| 886 |
|
| 887 |
|
| 888 |
void get_coll_val(vm_val_t *val) const { vmb_get_dh(ext_, val); } |
| 889 |
|
| 890 |
|
| 891 |
long get_entry_index() const |
| 892 |
{ return osrp2(ext_ + VMB_DATAHOLDER); } |
| 893 |
void set_entry_index(uint idx) |
| 894 |
{ oswp2(ext_ + VMB_DATAHOLDER, idx); } |
| 895 |
|
| 896 |
|
| 897 |
void set_entry_index_undo(VMG_ vm_obj_id_t self, uint entry); |
| 898 |
|
| 899 |
|
| 900 |
uint get_flags() const |
| 901 |
{ return osrp2(ext_ + VMB_DATAHOLDER + 2); } |
| 902 |
void set_flags(uint flags) const |
| 903 |
{ oswp2(ext_ + VMB_DATAHOLDER + 2, flags); } |
| 904 |
}; |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
class CVmMetaclassIterLookupTable: public CVmMetaclass |
| 910 |
{ |
| 911 |
public: |
| 912 |
|
| 913 |
const char *get_meta_name() const |
| 914 |
{ return "lookuptable-iterator/030000"; } |
| 915 |
|
| 916 |
|
| 917 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 918 |
{ |
| 919 |
new (vmg_ id) CVmObjIterLookupTable(); |
| 920 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 925 |
{ |
| 926 |
new (vmg_ id) CVmObjIterLookupTable(); |
| 927 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 932 |
{ |
| 933 |
err_throw(VMERR_BAD_DYNAMIC_NEW); |
| 934 |
AFTER_ERR_THROW(return VM_INVALID_OBJ;) |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 939 |
const uchar **pc_ptr, uint *argc, |
| 940 |
vm_prop_id_t prop) |
| 941 |
{ |
| 942 |
return CVmObjIterLookupTable:: |
| 943 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 944 |
} |
| 945 |
}; |
| 946 |
|
| 947 |
|
| 948 |
#endif |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
VM_REGISTER_METACLASS(CVmObjLookupTable) |
| 954 |
VM_REGISTER_METACLASS(CVmObjWeakRefLookupTable) |
| 955 |
VM_REGISTER_METACLASS(CVmObjIterLookupTable) |
| 956 |
|