| 1 | #charset "us-ascii" |
| 2 | #pragma once |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1999, 2006 Michael J. Roberts |
| 6 | * |
| 7 | * This file is part of TADS 3 |
| 8 | * |
| 9 | * This header defines the t3vm intrinsic function set. These functions |
| 10 | * provide access to basic features of the Virtual Machine. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * include the LookupTable intrinsic class, since t3GetGlobalSymbols() |
| 15 | * returns an instance of this class |
| 16 | */ |
| 17 | #include "lookup.h" |
| 18 | |
| 19 | |
| 20 | /* |
| 21 | * T3 intrinsic function set definition |
| 22 | */ |
| 23 | intrinsic 't3vm/010006' |
| 24 | { |
| 25 | /* |
| 26 | * Explicitly run garbage collection. |
| 27 | */ |
| 28 | t3RunGC(); |
| 29 | |
| 30 | /* |
| 31 | * Set the default output function or method. The return value is the |
| 32 | * old function pointer or method, depending on which one is being set |
| 33 | * with this call. (If 'val' is a function pointer, the return value |
| 34 | * will be the old function; if 'val' is a property ID, the return |
| 35 | * value is the old method.) |
| 36 | * |
| 37 | * The special values T3SetSayNoFunc and T3SetSayNoMethod can be passed |
| 38 | * to the function to remove any existing function or method, |
| 39 | * respectively, and are returned when appropriate to indicate that |
| 40 | * there was no previous setting. |
| 41 | */ |
| 42 | t3SetSay(val); |
| 43 | |
| 44 | /* |
| 45 | * Get the VM version number. Returns the version number as an integer |
| 46 | * value, with the major version in the high-order 16 bits, the minor |
| 47 | * version number in the next 8 bits, and the patch number ("point |
| 48 | * release" number) in the low-order 8 bits. For example, version |
| 49 | * 3.0.10 is encoded as 0x0003000A. |
| 50 | */ |
| 51 | t3GetVMVsn(); |
| 52 | |
| 53 | /* |
| 54 | * Get the VM identifier string. This returns the version number as a |
| 55 | * string, as in '3.0.10'. |
| 56 | */ |
| 57 | t3GetVMID(); |
| 58 | |
| 59 | /* |
| 60 | * Get the VM banner string. This returns a string with the name of |
| 61 | * the VM, the version number, and a copyright string, in a format |
| 62 | * suitable for displaying to the user to identify the VM executable. |
| 63 | */ |
| 64 | t3GetVMBanner(); |
| 65 | |
| 66 | /* |
| 67 | * Get the preinitialization mode flag. This returns true if the VM is |
| 68 | * running as part of the compiler's pre-initialization phase, nil if |
| 69 | * it's running as a normal interpreter. |
| 70 | */ |
| 71 | t3GetVMPreinitMode(); |
| 72 | |
| 73 | /* |
| 74 | * Debugger trace operations. This provides access to the interactive |
| 75 | * debugger subsystem, if the VM is running under a debugger. The |
| 76 | * 'mode' argument determines what the function does and what the |
| 77 | * additional arguments, if any, are for: |
| 78 | * |
| 79 | * T3DebugCheck - checks to see if an interactive debugger is present. |
| 80 | * No additional arguments; returns true if a debugger is present, nil |
| 81 | * if not. |
| 82 | * |
| 83 | * T3DebugBreak - breaks into the interactive debugger, pausing |
| 84 | * execution at the current code location so that the user can inspect |
| 85 | * the current machine state and determine how to proceed. No |
| 86 | * additional arguments; after the user proceeds with execution, the |
| 87 | * function returns true to indicate that a debugger is present. If no |
| 88 | * debugger is present, the function simply returns nil, and has no |
| 89 | * other effect. |
| 90 | * |
| 91 | * T3DebugLog - writes a message to the debug log. The second argument |
| 92 | * is a string with the text of the message to write. When running |
| 93 | * under an interactive debugger, the log is usually displayed as a |
| 94 | * window in the UI, or something similar. When running in a regular |
| 95 | * interpreter, the log is stored as a text file called tadslog.txt, in |
| 96 | * a directory location that varies by system. When a log file is |
| 97 | * used, the system automatically adds a timestamp to each message. |
| 98 | */ |
| 99 | t3DebugTrace(mode, ...); |
| 100 | |
| 101 | /* |
| 102 | * Get the global symbol table or the global macro table. |
| 103 | * |
| 104 | * 'which' specifies which table to retrieve: |
| 105 | * |
| 106 | *. T3GlobalSymbols - return the global symbol table |
| 107 | *. T3PreprocMacros - return the preprocessor macro table |
| 108 | * |
| 109 | * If 'which' is omitted, the global symbol table is returned by |
| 110 | * default. |
| 111 | * |
| 112 | * If the requested symbol table is available, this returns a |
| 113 | * LookupTable object; otherwise, it returns nil. |
| 114 | * |
| 115 | * The symbol tables are available under two conditions. First, while |
| 116 | * pre-initialization is running during the program build (compiling) |
| 117 | * process, regardless of the debug/release mode being used for |
| 118 | * compilation. Second, during normal "t3run" execution, but only when |
| 119 | * the program has been compiled for debugging. When you compile in |
| 120 | * release mode, the compiler omits the debugging symbols from the .t3 |
| 121 | * image file to save space, so the symbol tables won't be available |
| 122 | * when running a release build under the interpreter. |
| 123 | * |
| 124 | * If you want to access the symbol tables under normal execution |
| 125 | * (i.e., after preinit) in a release build, you can do it, but it |
| 126 | * requires an extra manual step. The trick is to call this function |
| 127 | * during preinit, when the symbol tables are definitely available |
| 128 | * regardless of the debug/release mode, and then save a reference to |
| 129 | * each desired table in an object property. This will ensure that the |
| 130 | * final image file saved after preinit completes includes the tables, |
| 131 | * because the object property reference ensures that the garbage |
| 132 | * collector won't delete them. Now, you *still* can't access the |
| 133 | * tables again at run-time by calling t3GetGlobalSymbols(), but you |
| 134 | * can instead get the same information from your saved object |
| 135 | * property. |
| 136 | */ |
| 137 | t3GetGlobalSymbols(which?); |
| 138 | |
| 139 | /* |
| 140 | * Allocate a new property. Returns a new property not yet used |
| 141 | * anywhere in the program. Note that property ID's are a somewhat |
| 142 | * limited resource - only approximately 65,000 total are available, |
| 143 | * including all of the properties that the program defines |
| 144 | * statically. |
| 145 | */ |
| 146 | t3AllocProp(); |
| 147 | |
| 148 | /* |
| 149 | * Get a stack trace. This returns a list of T3StackInfo objects. |
| 150 | * Each object represents a nesting level in the call stack. The first |
| 151 | * element in the list represents the currently active level (i.e., the |
| 152 | * level that called this function), the second element represents the |
| 153 | * caller of the first element, and so on. |
| 154 | * |
| 155 | * If 'level' is an integer, we'll return a single T3StackInfo object |
| 156 | * giving the context at the given stack level - 1 is the active level, |
| 157 | * 2 is its caller, and so on, so 'level' would simply be the index in |
| 158 | * the returned list when this argument is omitted. If 'level' is |
| 159 | * omitted or nil, we return a list of T3StackInfo objects giving the |
| 160 | * entire stack trace. |
| 161 | * |
| 162 | * If 'flags' is specified, it's a combination of T3GetStackXxx flags |
| 163 | * specifying additional options. If this isn't included, the default |
| 164 | * is 0 (i.e., all flags turned off). |
| 165 | */ |
| 166 | t3GetStackTrace(level?, flags?); |
| 167 | |
| 168 | /* |
| 169 | * Get a named argument. This searches for the specified named |
| 170 | * argument, and returns the value of the argument if it's defined. |
| 171 | * |
| 172 | * 'name' is a string giving the name of the argument to search for. |
| 173 | * This must exactly match the name of an argument passed by a caller |
| 174 | * with the "name: value" syntax. The match is case-sensitive. |
| 175 | * |
| 176 | * 'defval' is an optional default value to return if the argument |
| 177 | * doesn't exist. If 'deval' is specified, and the argument doesn't |
| 178 | * exist, the function returns 'defval'. If 'defval' is omitted, and |
| 179 | * the argument doesn't exist, the function throws an error. |
| 180 | */ |
| 181 | t3GetNamedArg(name, defval?); |
| 182 | |
| 183 | /* |
| 184 | * Get a list of all named arguments currently in effect. This returns |
| 185 | * a list of strings, where each string is the name of a named argument |
| 186 | * that's currently active. |
| 187 | */ |
| 188 | t3GetNamedArgList(); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /* |
| 193 | * t3DebugTrace() mode flags |
| 194 | */ |
| 195 | |
| 196 | /* check to see if the debugger is present */ |
| 197 | #define T3DebugCheck 1 |
| 198 | |
| 199 | /* break into the debugger */ |
| 200 | #define T3DebugBreak 2 |
| 201 | |
| 202 | /* log a message to the system/debug log */ |
| 203 | #define T3DebugLog 3 |
| 204 | |
| 205 | /* |
| 206 | * t3SetSay() special values. These can be passed in lieu of a function |
| 207 | * pointer or property ID when the caller wants to remove any existing |
| 208 | * function or method rather than install a new one. |
| 209 | */ |
| 210 | #define T3SetSayNoFunc 1 |
| 211 | #define T3SetSayNoMethod 2 |
| 212 | |
| 213 | /* |
| 214 | * t3GetGlobalSymbols 'which' flag. One of these values can be specified |
| 215 | * as the function argument to specify which type of table is to be |
| 216 | * retrieved. |
| 217 | */ |
| 218 | #define T3GlobalSymbols 1 |
| 219 | #define T3PreprocMacros 2 |
| 220 | |
| 221 | /* |
| 222 | * t3GetStackTrace flags. These can be combined with the bitwise '|' |
| 223 | * operator. |
| 224 | */ |
| 225 | #define T3GetStackLocals 0x0001 |
| 226 | #define T3GetStackDesc 0x0002 |
| 227 | |
| 228 | /* |
| 229 | * Macro information flags. |
| 230 | */ |
| 231 | #define T3MacroHasArgs 0x0001 |
| 232 | #define T3MacroHasVarargs 0x0002 |
| 233 |