| 1 | /* $Header$ */cxx . . $ `<file>/tads3/vmanonfn.h`/ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2000, 2002 Michael J. Roberts. All Rights Reserved. |
| 5 | * |
| 6 | * Please see the accompanying license file, LICENSE.TXT, for information |
| 7 | * on using and copying this software. |
| 8 | */ |
| 9 | /* |
| 10 | Name |
| 11 | vmanonfn.h - anonymous function metaclass |
| 12 | Function |
| 13 | The anonymous function metaclass is a subclass of the Vector metaclass |
| 14 | that provides encapsulation of an anonymous function and the context it |
| 15 | shares with its enclosing scope. |
| 16 | Notes |
| 17 | |
| 18 | Modified |
| 19 | 03/21/00 MJRoberts - Creation |
| 20 | */ |
| 21 | |
| 22 | #ifndef VMANONFN_Hcxx . . $ `tads3/vmanonfn.h:23:9`! |
| 23 | #define VMANONFN_Hcxx . . $ `tads3/vmanonfn.h:23:9`! |
| 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include "vmtype.h"cxx . . $ `<file>/tads3/vmtype.h`/ |
| 27 | #include "vmobj.h"cxx . . $ `<file>/tads3/vmobj.h`/ |
| 28 | #include "vmvec.h"cxx . . $ `<file>/tads3/vmvec.h`/ |
| 29 | #include "vmglob.h"cxx . . $ `<file>/tads3/vmglob.h`/ |
| 30 | |
| 31 | /* |
| 32 | * Anonymous Function Metaclass |
| 33 | */ |
| 34 | class CVmObjAnonFncxx . . $ CVmObjAnonFn#: public CVmObjVectorcxx . . $ CVmObjVector# |
| 35 | { |
| 36 | friend class CVmMetaclassAnonFncxx . . $ CVmMetaclassAnonFn#; |
| 37 | |
| 38 | public: |
| 39 | /* metaclass registration object */ |
| 40 | static class CVmMetaclasscxx . . $ CVmMetaclass# *metaclass_reg_cxx . . $ CVmObjAnonFn#metaclass_reg_.; |
| 41 | class CVmMetaclasscxx . . $ CVmMetaclass# *get_metaclass_regcxx . . $ CVmObjAnonFn#get_metaclass_reg(7084458cee891608).() const { return metaclass_reg_cxx . . $ CVmObjAnonFn#metaclass_reg_.; } |
| 42 | |
| 43 | /* am I of the given metaclass? */ |
| 44 | virtual int is_of_metaclasscxx . . $ CVmObjAnonFn#is_of_metaclass(2c084004089a0e56).(class CVmMetaclasscxx . . $ CVmMetaclass# *meta) const |
| 45 | { |
| 46 | /* try my own metaclass and my base class */ |
| 47 | return (meta == metaclass_reg_cxx . . $ CVmObjAnonFn#metaclass_reg_. |
| 48 | || CVmObjVectorcxx . . $ CVmObjVector#::is_of_metaclasscxx . . $ CVmObjVector#is_of_metaclass(2c084004089a0e56).(meta)); |
| 49 | } |
| 50 | |
| 51 | /* is the given object an anonymous function object? */ |
| 52 | static int is_anonfn_objcxx . . $ CVmObjAnonFn#is_anonfn_obj(4c679297bf94b9eb).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_obj_id_tcxx . . $ vm_obj_id_t# obj) |
| 53 | { return vm_objpcxx . . $ vm_objp(dd7eb3d24f616cda).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! obj)->is_of_metaclasscxx . . $ CVmObject#is_of_metaclass(2c084004089a0e56).(metaclass_reg_cxx . . $ CVmObjAnonFn#metaclass_reg_.); } |
| 54 | |
| 55 | /* we don't look like a list to user code */ |
| 56 | int is_listlikecxx . . $ CVmObjAnonFn#is_listlike(4c679297bf94b9eb).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_obj_id_tcxx . . $ vm_obj_id_t#) { return FALSEcxx . . $ `tads3/t3std.h:336:10`!; } |
| 57 | |
| 58 | /* create dynamically using stack arguments */ |
| 59 | static vm_obj_id_tcxx . . $ vm_obj_id_t# create_from_stackcxx . . $ CVmObjAnonFn#create_from_stack(5e224231d728ecee).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! const ucharcxx . . $ uchar# **pc_ptr, |
| 60 | uintcxx . . $ uint# argc); |
| 61 | |
| 62 | /* invoke */ |
| 63 | int get_invokercxx . . $ CVmObjAnonFn#get_invoker(2eaff8624f178fb3).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_val_tcxx . . $ vm_val_t# *val); |
| 64 | |
| 65 | /* check for equality - compare strictly by reference */ |
| 66 | int equalscxx . . $ CVmObjAnonFn#equals(ba92f6c7be345e4).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_obj_id_tcxx . . $ vm_obj_id_t# self, const vm_val_tcxx . . $ vm_val_t# *val, int) const |
| 67 | { |
| 68 | /* return true if the other value is a reference to this object */ |
| 69 | return (val->typcxx . . $ vm_val_t#typ. == VM_OBJcxx . . $ VM_OBJ. && val->valcxx . . $ vm_val_t#val..objcxx . . $ vm_val_t#$anonymous_type_0#obj. == self); |
| 70 | } |
| 71 | |
| 72 | /* calculate a hash value */ |
| 73 | uintcxx . . $ uint# calc_hashcxx . . $ CVmObjAnonFn#calc_hash(e99c713d50db71c7).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_obj_id_tcxx . . $ vm_obj_id_t# self, int) const |
| 74 | { |
| 75 | /* we compare by reference, so hash by object ID */ |
| 76 | return (uintcxx . . $ uint#)(((ulongcxx . . $ ulong#)self & 0xffff) |
| 77 | ^ (((ulongcxx . . $ ulong#)self & 0xffff0000) >> 16)); |
| 78 | } |
| 79 | |
| 80 | protected: |
| 81 | /* create an empty object */ |
| 82 | CVmObjAnonFncxx . . $ CVmObjAnonFn#CVmObjAnonFn(49f6e7a06ebc5aa8).() { ext_cxx . . $ CVmObject#ext_. = 0; } |
| 83 | |
| 84 | /* create with the given number of elements */ |
| 85 | CVmObjAnonFncxx . . $ CVmObjAnonFn#CVmObjAnonFn(2c44cd906ae4e829).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! size_t cnt) |
| 86 | : CVmObjVectorcxx . . $ CVmObjVector#CVmObjVector(2c44cd906ae4e829).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! cnt) |
| 87 | { |
| 88 | /* set to our full initial size */ |
| 89 | set_element_countcxx . . $ CVmObjVector#set_element_count(2c44cd906ae4e829).(cnt); |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | /* ------------------------------------------------------------------------ */ |
| 95 | /* |
| 96 | * Registration table objects |
| 97 | */ |
| 98 | class CVmMetaclassAnonFncxx . . $ CVmMetaclassAnonFn#: public CVmMetaclasscxx . . $ CVmMetaclass# |
| 99 | { |
| 100 | public: |
| 101 | /* get the global name */ |
| 102 | const char *get_meta_namecxx . . $ CVmMetaclassAnonFn#get_meta_name(a9f41ea0e82d88cf).() const { return "anon-func-ptr/030000"; } |
| 103 | |
| 104 | /* create from image file */ |
| 105 | void create_for_image_loadcxx . . $ CVmMetaclassAnonFn#create_for_image_load(cb2f890c2fdad230).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_obj_id_tcxx . . $ vm_obj_id_t# id) |
| 106 | { |
| 107 | new (vmg_cxx . . $ `tads3/vmglob.h:351:9`! id) CVmObjAnonFncxx . . $ CVmObjAnonFn#(); |
| 108 | G_obj_tablecxx . . $ `tads3/vmglob.h:570:9`!->set_obj_gc_characteristicscxx . . $ CVmObjTable#set_obj_gc_characteristics(681e6771ec7c8417).(id, TRUEcxx . . $ `tads3/t3std.h:333:10`!, FALSEcxx . . $ `tads3/t3std.h:336:10`!); |
| 109 | } |
| 110 | |
| 111 | /* create from restoring from saved state */ |
| 112 | void create_for_restorecxx . . $ CVmMetaclassAnonFn#create_for_restore(cb2f890c2fdad230).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_obj_id_tcxx . . $ vm_obj_id_t# id) |
| 113 | { |
| 114 | new (vmg_cxx . . $ `tads3/vmglob.h:351:9`! id) CVmObjAnonFncxx . . $ CVmObjAnonFn#(); |
| 115 | G_obj_tablecxx . . $ `tads3/vmglob.h:570:9`!->set_obj_gc_characteristicscxx . . $ CVmObjTable#set_obj_gc_characteristics(681e6771ec7c8417).(id, TRUEcxx . . $ `tads3/t3std.h:333:10`!, FALSEcxx . . $ `tads3/t3std.h:336:10`!); |
| 116 | } |
| 117 | |
| 118 | /* create dynamically using stack arguments */ |
| 119 | vm_obj_id_tcxx . . $ vm_obj_id_t# create_from_stackcxx . . $ CVmMetaclassAnonFn#create_from_stack(5e224231d728ecee).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! const ucharcxx . . $ uchar# **pc_ptr, uintcxx . . $ uint# argc) |
| 120 | { return CVmObjAnonFncxx . . $ CVmObjAnonFn#::create_from_stackcxx . . $ CVmObjAnonFn#create_from_stack(5e224231d728ecee).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! pc_ptr, argc); } |
| 121 | |
| 122 | /* call a static property */ |
| 123 | int call_stat_propcxx . . $ CVmMetaclassAnonFn#call_stat_prop(bbc7e10853f951a0).(VMG_cxx . . $ `tads3/vmglob.h:349:9`! vm_val_tcxx . . $ vm_val_t# *result, |
| 124 | const ucharcxx . . $ uchar# **pc_ptr, uintcxx . . $ uint# *argc, |
| 125 | vm_prop_id_tcxx . . $ vm_prop_id_t# prop) |
| 126 | { |
| 127 | /* fall back directly on the vector static property evaluator */ |
| 128 | return CVmObjVectorcxx . . $ CVmObjVector#::call_stat_propcxx . . $ CVmObjVector#call_stat_prop(bbc7e10853f951a0).(vmg_cxx . . $ `tads3/vmglob.h:351:9`! result, pc_ptr, argc, prop); |
| 129 | } |
| 130 | |
| 131 | /* I'm a Vector subclass */ |
| 132 | CVmMetaclasscxx . . $ CVmMetaclass# *get_supermeta_regcxx . . $ CVmMetaclassAnonFn#get_supermeta_reg(7084458cee891608).() const |
| 133 | { return CVmObjVectorcxx . . $ CVmObjVector#::metaclass_reg_cxx . . $ CVmObjVector#metaclass_reg_.; } |
| 134 | }; |
| 135 | |
| 136 | #endif /* VMANONFN_H */ |
| 137 | |
| 138 | /* |
| 139 | * Register the class |
| 140 | */ |
| 141 | VM_REGISTER_METACLASScxx . . $ `tads3/vmobj.h:53:10`!(CVmObjAnonFn) |
| 142 | |
| 143 |