| 1 |
#if defined( FINCH_DEBUG_COMPILE ) |
| 2 |
#error entering fi_util.t... |
| 3 |
#endif |
| 4 |
|
| 5 |
#if !defined( FINCH_UTILITY_LIBRARY ) |
| 6 |
|
| 7 |
#include "tads.h" |
| 8 |
#include "t3.h" |
| 9 |
#include "lookup.h" |
| 10 |
|
| 11 |
modify TadsObject |
| 12 |
_name = nil |
| 13 |
|
| 14 |
_init_TadsObject() {} |
| 15 |
|
| 16 |
construct() { |
| 17 |
_init_(); |
| 18 |
} |
| 19 |
|
| 20 |
_init_( [args] ) { |
| 21 |
if (self == TadsObject) return; |
| 22 |
|
| 23 |
local obj = (args.length > 0 ? args[1] : self); |
| 24 |
|
| 25 |
local lst = getSuperclassList(); |
| 26 |
foreach (local c in lst) |
| 27 |
c._init_( obj ); |
| 28 |
|
| 29 |
callDefinedMethod( obj, '_init_' + self._name ); |
| 30 |
} |
| 31 |
; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
FinchUtility: PreinitObject |
| 38 |
globalSymbols = nil |
| 39 |
|
| 40 |
storeGlobalSymbols = true |
| 41 |
|
| 42 |
execute() { |
| 43 |
globalSymbols = t3GetGlobalSymbols(); |
| 44 |
|
| 45 |
t3DebugTrace( T3DebugBreak ); |
| 46 |
|
| 47 |
globalSymbols.forEach( |
| 48 |
{ tok, obj : |
| 49 |
dataType( obj ) == TypeObject && |
| 50 |
obj.ofKind( TadsObject ) |
| 51 |
? obj._name = tok |
| 52 |
: nil |
| 53 |
} |
| 54 |
); |
| 55 |
|
| 56 |
for (local o = firstObj(); o; o = nextObj( o )) { |
| 57 |
if (o.ofKind( TadsObject)) { |
| 58 |
o._init_(); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
getGlobalSymbols() { |
| 69 |
return FinchUtility.globalSymbols; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
callMethod( obj, meth, [params] ) { |
| 89 |
|
| 90 |
|
| 91 |
local prop = (getGlobalSymbols())[ meth ]; |
| 92 |
|
| 93 |
|
| 94 |
if (prop == nil) |
| 95 |
throw new NoSuchSymbolException( meth ); |
| 96 |
|
| 97 |
|
| 98 |
else if (dataType( prop ) != TypeProp) |
| 99 |
throw new NoSuchMethodException( meth ); |
| 100 |
|
| 101 |
else { |
| 102 |
try { |
| 103 |
return obj.(prop)( params... ); |
| 104 |
} |
| 105 |
catch (Exception e) { |
| 106 |
throw new InvocationTargetException( obj, meth, e ); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
callDefinedMethod( obj, meth, [params] ) { |
| 129 |
|
| 130 |
|
| 131 |
local prop = (getGlobalSymbols())[ meth ]; |
| 132 |
|
| 133 |
|
| 134 |
if (prop == nil) return nil; |
| 135 |
|
| 136 |
|
| 137 |
if (!obj.propDefined( prop )) return nil; |
| 138 |
|
| 139 |
|
| 140 |
else if (dataType( prop ) != TypeProp) |
| 141 |
throw new NoSuchMethodException( meth ); |
| 142 |
|
| 143 |
else { |
| 144 |
try { |
| 145 |
return obj.(prop)( params... ); |
| 146 |
} |
| 147 |
catch (Exception e) { |
| 148 |
throw new InvocationTargetException( obj, meth, e ); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
createGlobalProperty( str ) { |
| 160 |
|
| 161 |
|
| 162 |
local prop = t3AllocProp(); |
| 163 |
|
| 164 |
|
| 165 |
(getGlobalSymbols())[ str ] = prop; |
| 166 |
|
| 167 |
|
| 168 |
return prop; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
class InvocationTargetException: Exception |
| 176 |
location = nil |
| 177 |
position = nil |
| 178 |
datum = nil |
| 179 |
|
| 180 |
construct( obj, meth, e ) { |
| 181 |
location = obj; |
| 182 |
position = meth; |
| 183 |
datum = e; |
| 184 |
} |
| 185 |
|
| 186 |
getMessage() { |
| 187 |
"InvocationTargetException: the method << position >> |
| 188 |
on the object << location._name >> threw the following |
| 189 |
exception: << datum.getMessage() >>. "; |
| 190 |
} |
| 191 |
; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
class NoSuchMethodException: Exception |
| 198 |
position = nil |
| 199 |
|
| 200 |
construct( meth ) { |
| 201 |
position = meth; |
| 202 |
} |
| 203 |
|
| 204 |
getMessage() { |
| 205 |
"NoSuchMethodException: the symbol << position >> |
| 206 |
does not correspond to a property address."; |
| 207 |
} |
| 208 |
; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
class NoSuchSymbolException: Exception |
| 215 |
position = nil |
| 216 |
|
| 217 |
construct( sym ) { |
| 218 |
position = sym; |
| 219 |
} |
| 220 |
|
| 221 |
getMessage() { |
| 222 |
"NoSuchSymbolException: the symbol << position >> |
| 223 |
does not exist in the global symbols table."; |
| 224 |
} |
| 225 |
; |
| 226 |
|
| 227 |
#endif |
| 228 |
|