| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#ifndef VMFREF_H |
| 37 |
#define VMFREF_H |
| 38 |
|
| 39 |
#include <stdlib.h> |
| 40 |
#include "vmtype.h" |
| 41 |
#include "vmobj.h" |
| 42 |
#include "vmglob.h" |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
struct vm_framedesc_ext |
| 49 |
{ |
| 50 |
|
| 51 |
vm_obj_id_t fref; |
| 52 |
|
| 53 |
|
| 54 |
int frame_idx; |
| 55 |
|
| 56 |
|
| 57 |
uint ret_ofs; |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
struct vm_frameref_ext |
| 64 |
{ |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
vm_val_t *fp; |
| 72 |
|
| 73 |
|
| 74 |
vm_val_t entry; |
| 75 |
|
| 76 |
|
| 77 |
const uchar *entryp; |
| 78 |
|
| 79 |
|
| 80 |
int nlocals; |
| 81 |
int nparams; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
vm_val_t self; |
| 89 |
vm_obj_id_t defobj; |
| 90 |
vm_obj_id_t targobj; |
| 91 |
vm_prop_id_t targprop; |
| 92 |
vm_val_t invokee; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
vm_val_t vars[1]; |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
class CVmObjFrameDesc: public CVmObject |
| 118 |
{ |
| 119 |
friend class CVmMetaclassFrameDesc; |
| 120 |
|
| 121 |
public: |
| 122 |
|
| 123 |
static class CVmMetaclass *metaclass_reg_; |
| 124 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 125 |
|
| 126 |
|
| 127 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 128 |
{ |
| 129 |
|
| 130 |
return (meta == metaclass_reg_ |
| 131 |
|| CVmObject::is_of_metaclass(meta)); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
static int is_framedesc_obj(VMG_ vm_obj_id_t obj) |
| 136 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 137 |
|
| 138 |
|
| 139 |
vm_obj_id_t get_frame_ref_id() const { return get_ext()->fref; } |
| 140 |
class CVmObjFrameRef *get_frame_ref(VMG0_) const |
| 141 |
{ return (class CVmObjFrameRef *)vm_objp(vmg_ get_frame_ref_id()); } |
| 142 |
|
| 143 |
|
| 144 |
int find_local(VMG_ const vm_val_t *nval, class CVmDbgFrameSymPtr *symp); |
| 145 |
int find_local(VMG_ const textchar_t *sym, size_t len, |
| 146 |
class CVmDbgFrameSymPtr *symp); |
| 147 |
|
| 148 |
|
| 149 |
int get_local_val(VMG_ vm_val_t *result, const vm_val_t *name); |
| 150 |
|
| 151 |
|
| 152 |
int set_local_val(VMG_ const vm_val_t *name, const vm_val_t *new_val); |
| 153 |
|
| 154 |
|
| 155 |
static vm_obj_id_t create(VMG_ vm_obj_id_t fref, int frame_idx, |
| 156 |
uint ret_ofs); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 163 |
const uchar **pc_ptr, uint *argc, |
| 164 |
vm_prop_id_t prop) |
| 165 |
{ return CVmObject::call_stat_prop(vmg_ result, pc_ptr, argc, prop); } |
| 166 |
|
| 167 |
|
| 168 |
void set_prop(VMG_ class CVmUndo *, |
| 169 |
vm_obj_id_t, vm_prop_id_t, const vm_val_t *) |
| 170 |
{ |
| 171 |
|
| 172 |
err_throw(VMERR_INVALID_SETPROP); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 177 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
virtual int index_val_q(VMG_ vm_val_t *result, |
| 182 |
vm_obj_id_t self, |
| 183 |
const vm_val_t *index_val); |
| 184 |
|
| 185 |
|
| 186 |
virtual int set_index_val_q(VMG_ vm_val_t *new_container, |
| 187 |
vm_obj_id_t self, |
| 188 |
const vm_val_t *index_val, |
| 189 |
const vm_val_t *new_val); |
| 190 |
|
| 191 |
|
| 192 |
void notify_delete(VMG_ int in_root_set); |
| 193 |
|
| 194 |
|
| 195 |
void notify_new_savept() { } |
| 196 |
void apply_undo(VMG_ struct CVmUndoRecord *) { } |
| 197 |
|
| 198 |
|
| 199 |
void mark_refs(VMG_ uint); |
| 200 |
|
| 201 |
|
| 202 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 203 |
|
| 204 |
|
| 205 |
void remove_stale_weak_refs(VMG0_) { } |
| 206 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 207 |
|
| 208 |
|
| 209 |
void load_from_image(VMG_ vm_obj_id_t, const char *, size_t); |
| 210 |
void reload_from_image(VMG_ vm_obj_id_t, const char *, size_t); |
| 211 |
ulong rebuild_image(VMG_ char *, ulong); |
| 212 |
|
| 213 |
|
| 214 |
int is_changed_since_load() const { return FALSE; } |
| 215 |
|
| 216 |
|
| 217 |
void save_to_file(VMG_ class CVmFile *fp); |
| 218 |
void restore_from_file(VMG_ vm_obj_id_t self, class CVmFile *fp, |
| 219 |
class CVmObjFixup *fixups); |
| 220 |
|
| 221 |
protected: |
| 222 |
|
| 223 |
CVmObjFrameDesc() { ext_ = 0; } |
| 224 |
CVmObjFrameDesc(VMG_ vm_obj_id_t fref, int frame_idx, uint ret_ofs); |
| 225 |
|
| 226 |
|
| 227 |
vm_framedesc_ext *alloc_ext(VMG_ vm_obj_id_t fref, |
| 228 |
int frame_idx, uint ret_ofs); |
| 229 |
|
| 230 |
|
| 231 |
vm_framedesc_ext *get_ext() const { return (vm_framedesc_ext *)ext_; } |
| 232 |
|
| 233 |
|
| 234 |
void load_image_data(VMG_ vm_obj_id_t self, |
| 235 |
const char *ptr, size_t siz); |
| 236 |
|
| 237 |
|
| 238 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 239 |
|
| 240 |
|
| 241 |
virtual int getp_is_active(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 242 |
uint *argc); |
| 243 |
|
| 244 |
|
| 245 |
virtual int getp_get_self(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 246 |
uint *argc); |
| 247 |
|
| 248 |
|
| 249 |
virtual int getp_get_defobj(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 250 |
uint *argc); |
| 251 |
|
| 252 |
|
| 253 |
virtual int getp_get_targobj(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 254 |
uint *argc); |
| 255 |
|
| 256 |
|
| 257 |
virtual int getp_get_targprop(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 258 |
uint *argc); |
| 259 |
|
| 260 |
|
| 261 |
virtual int getp_get_vars(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 262 |
uint *argc); |
| 263 |
|
| 264 |
|
| 265 |
virtual int getp_get_invokee(VMG_ vm_obj_id_t self, vm_val_t *retval, |
| 266 |
uint *argc); |
| 267 |
|
| 268 |
|
| 269 |
static int (CVmObjFrameDesc::*func_table_[]) |
| 270 |
(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 271 |
}; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
class CVmObjFrameRef: public CVmObject |
| 278 |
{ |
| 279 |
friend class CVmMetaclassFrameRef; |
| 280 |
friend class CVmObjFrameDesc; |
| 281 |
|
| 282 |
public: |
| 283 |
|
| 284 |
static class CVmMetaclass *metaclass_reg_; |
| 285 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 286 |
|
| 287 |
|
| 288 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 289 |
{ |
| 290 |
|
| 291 |
return (meta == metaclass_reg_ |
| 292 |
|| CVmObject::is_of_metaclass(meta)); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
static int is_frameref_obj(VMG_ vm_obj_id_t obj) |
| 297 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 298 |
|
| 299 |
|
| 300 |
static vm_obj_id_t create(VMG_ vm_val_t *fp, const uchar *entry); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
void inval_frame(VMG0_); |
| 307 |
|
| 308 |
|
| 309 |
int is_active() { return get_ext()->fp != 0; } |
| 310 |
|
| 311 |
|
| 312 |
void get_self(VMG_ vm_val_t *result); |
| 313 |
|
| 314 |
|
| 315 |
void get_defobj(VMG_ vm_val_t *result); |
| 316 |
|
| 317 |
|
| 318 |
void get_targobj(VMG_ vm_val_t *result); |
| 319 |
|
| 320 |
|
| 321 |
void get_targprop(VMG_ vm_val_t *result); |
| 322 |
|
| 323 |
|
| 324 |
void get_invokee(VMG_ vm_val_t *result); |
| 325 |
|
| 326 |
|
| 327 |
void create_loadctx_obj(VMG_ vm_val_t *result); |
| 328 |
|
| 329 |
|
| 330 |
void get_local_val(VMG_ vm_val_t *result, |
| 331 |
const class CVmDbgFrameSymPtr *sym); |
| 332 |
|
| 333 |
|
| 334 |
void set_local_val(VMG_ const CVmDbgFrameSymPtr *sym, |
| 335 |
const vm_val_t *new_val); |
| 336 |
|
| 337 |
|
| 338 |
int get_var_frame_index(const CVmDbgFrameSymPtr *symp); |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 345 |
const uchar **pc_ptr, uint *argc, |
| 346 |
vm_prop_id_t prop) |
| 347 |
{ return CVmObject::call_stat_prop(vmg_ result, pc_ptr, argc, prop); } |
| 348 |
|
| 349 |
|
| 350 |
void set_prop(VMG_ class CVmUndo *, |
| 351 |
vm_obj_id_t, vm_prop_id_t, const vm_val_t *) |
| 352 |
{ |
| 353 |
|
| 354 |
err_throw(VMERR_INVALID_SETPROP); |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
virtual int index_val_q(VMG_ vm_val_t *result, |
| 359 |
vm_obj_id_t self, |
| 360 |
const vm_val_t *index_val); |
| 361 |
|
| 362 |
|
| 363 |
virtual int set_index_val_q(VMG_ vm_val_t *new_container, |
| 364 |
vm_obj_id_t self, |
| 365 |
const vm_val_t *index_val, |
| 366 |
const vm_val_t *new_val); |
| 367 |
|
| 368 |
|
| 369 |
void notify_delete(VMG_ int in_root_set); |
| 370 |
|
| 371 |
|
| 372 |
void notify_new_savept() { } |
| 373 |
void apply_undo(VMG_ struct CVmUndoRecord *) { } |
| 374 |
|
| 375 |
|
| 376 |
void mark_refs(VMG_ uint); |
| 377 |
|
| 378 |
|
| 379 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 380 |
|
| 381 |
|
| 382 |
void remove_stale_weak_refs(VMG0_) { } |
| 383 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 384 |
|
| 385 |
|
| 386 |
void load_from_image(VMG_ vm_obj_id_t, const char *, size_t); |
| 387 |
void reload_from_image(VMG_ vm_obj_id_t, const char *, size_t); |
| 388 |
ulong rebuild_image(VMG_ char *, ulong); |
| 389 |
|
| 390 |
|
| 391 |
int is_changed_since_load() const { return FALSE; } |
| 392 |
|
| 393 |
|
| 394 |
void save_to_file(VMG_ class CVmFile *fp); |
| 395 |
void restore_from_file(VMG_ vm_obj_id_t self, class CVmFile *fp, |
| 396 |
class CVmObjFixup *fixups); |
| 397 |
|
| 398 |
|
| 399 |
void post_load_init(VMG_ vm_obj_id_t self); |
| 400 |
|
| 401 |
protected: |
| 402 |
|
| 403 |
CVmObjFrameRef() { ext_ = 0; } |
| 404 |
CVmObjFrameRef(VMG_ vm_val_t *fp, const uchar *entry); |
| 405 |
|
| 406 |
|
| 407 |
vm_frameref_ext *alloc_ext(VMG_ int nlocals, int nparams); |
| 408 |
|
| 409 |
|
| 410 |
vm_frameref_ext *get_ext() const { return (vm_frameref_ext *)ext_; } |
| 411 |
|
| 412 |
|
| 413 |
void make_snapshot(VMG0_); |
| 414 |
|
| 415 |
|
| 416 |
void load_image_data(VMG_ vm_obj_id_t self, |
| 417 |
const char *ptr, size_t siz); |
| 418 |
}; |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
class CVmMetaclassFrameDesc: public CVmMetaclass |
| 426 |
{ |
| 427 |
public: |
| 428 |
|
| 429 |
const char *get_meta_name() const { return "stack-frame-desc/030000"; } |
| 430 |
|
| 431 |
|
| 432 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 433 |
{ |
| 434 |
new (vmg_ id) CVmObjFrameDesc(); |
| 435 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 440 |
{ |
| 441 |
new (vmg_ id) CVmObjFrameDesc(); |
| 442 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 447 |
{ |
| 448 |
err_throw(VMERR_BAD_DYNAMIC_NEW); |
| 449 |
AFTER_ERR_THROW(return VM_INVALID_OBJ;) |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 454 |
const uchar **pc_ptr, uint *argc, |
| 455 |
vm_prop_id_t prop) |
| 456 |
{ |
| 457 |
return CVmObjFrameDesc::call_stat_prop( |
| 458 |
vmg_ result, pc_ptr, argc, prop); |
| 459 |
} |
| 460 |
}; |
| 461 |
|
| 462 |
class CVmMetaclassFrameRef: public CVmMetaclass |
| 463 |
{ |
| 464 |
public: |
| 465 |
|
| 466 |
const char *get_meta_name() const { return "stack-frame-ref/030000"; } |
| 467 |
|
| 468 |
|
| 469 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 470 |
{ |
| 471 |
new (vmg_ id) CVmObjFrameRef(); |
| 472 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 477 |
{ |
| 478 |
new (vmg_ id) CVmObjFrameRef(); |
| 479 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 484 |
{ |
| 485 |
err_throw(VMERR_BAD_DYNAMIC_NEW); |
| 486 |
AFTER_ERR_THROW(return VM_INVALID_OBJ;) |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 491 |
const uchar **pc_ptr, uint *argc, |
| 492 |
vm_prop_id_t prop) |
| 493 |
{ |
| 494 |
return CVmObjFrameRef::call_stat_prop( |
| 495 |
vmg_ result, pc_ptr, argc, prop); |
| 496 |
} |
| 497 |
}; |
| 498 |
|
| 499 |
#endif |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
VM_REGISTER_METACLASS(CVmObjFrameRef) |
| 505 |
VM_REGISTER_METACLASS(CVmObjFrameDesc) |