Intrinsic Functions: "t3vm" Function Set

The "t3vm" function set provides access to internal operations in the VM.  This function set is provided by all T3 VM implementations and all host applications.

 

t3AllocProp() – allocates a new property ID value, which is a property not previously used by any object in the program.  Note that property ID's are a somewhat limited resource: only about 65,000 can be allocated, including those defined statically in the program.

 

t3DebugTrace(mode, …) – debugger interface.  The mode parameter indicates the function to be performed.  Any arguments after mode are specific to the mode.  The valid mode values are:

 

 

If this function is called with any other values for the mode argument, it simply ignores any additional arguments and returns nil; this allows for compatible extensions to the function in the future by the addition of new mode values.

 

t3GetGlobalSymbols() – returns a LookupTable object populated with all of the program's global compile-time symbols.  The symbol table is available during pre-initialization (i.e., when t3GetVMPreinitMode() returns true), and during normal execution when the program was compiled for debugging; at all other times, the symbol table is not available, and this function returns nil.  For more information, see Reflection.

 

t3GetStackTrace() - returns information on the current call stack.  This function returns a list of T3StackInfo objects; each object in the list represents one level, or "frame," of the stack trace.  A frame is the data structure that the virtual machine establishes each time the program invokes a method or function; the frame contains information on the function or object method invoked, and the actual parameters (i.e., the argument values).

 

The first T3StackInfo object in the list represents the current function or method - that is, the code that invoked t3GetStackTrace().  The second element of the list represents the current code's caller, the third element represents the second element's caller, and so on.

 

T3StackInfo is an ordinary class defined in the standard run-time library.  This class defines the following properties:

 

·           srcInfo_ - the source code location for the next execution point in the frame, or nil if source information is not available.  Source information is available only if the program was compiled for debugging, but is never available for system routines.  The source information is given as a list of two elements:  the first element is a string giving the name of a source file, and the second is an integer giving the line number in the source file.  Note that srcInfo_ indicates the location of the next instruction that will be executed when control returns to the frame, so this will frequently indicate the next source code statement after the one that actually invoked the next more nested frame.

 

In addition, the class defines the following method:

 

 

t3GetVMBanner() – returns the T3 VM banner string, which is a string identifying the VM, its version number, and its copyright information.  This string is suitable for displaying as a start-up banner.

 

t3GetVMID() – returns the T3 VM identification string.  This is a short string identifying the particular VM implementation; each different implementation has a unique identifier.  Mike Roberts's T3 VM implementation has the identifying string 'mjr-T3'.

 

Note that the VM identification string identifies the VM itself, not the host application environment.

 

t3GetVMPreinitMode() – returns true if the VM is operating in pre-initialization mode, nil if the VM is operating in normal execution mode.

 

t3GetVMVsn() – get the T3 VM version number.  This returns an integer value; the high-order 16 bits of the value give the major version number of the VM; the next 8 bits give the minor version number; and the low-order 8 bits give the patch release number.  So, if V is the return value of this function,

 

 

t3RunGC() – explicitly runs the garbage collector.  Since the garbage collector runs automatically from time to time, it is never necessary to call this function explicitly.  However, if the programmer identifies a particular point at which a large number of objects have suddenly become unreachable, and when a large number of objects are likely to be allocated soon, it might be advantageous to run the garbage collector explicitly so that it can optimize memory.  It might also be desirable to run garbage collection explicitly when a natural user-interface pause is about to occur anyway, since this would take advantage of the natural pause to hide any delay that would occur running the collector.  No return value.

 

t3SetSay(val) – set the default output function or method to the given value:

 

o          There is a valid "self" object (i.e., a method is being executed, not a stand-alone function).

o          A default display method has been defined with t3SetSay().

o          The current "self" object defines or inherits the default display  method.

If these conditions aren't all true, the VM uses the default display function instead.

 

This return value gives the previous default output function or method.  If val is a property pointer or the special value T3SetSayNoMethod, the return value is the old default output method; otherwise, the return value is the old default output function.  The special values T3SetSayNoFunc and T3SetSayNoMethod can also be returned, indicating that there was no previous function or method, respectively.  The return value allows the caller to save and later restore the setting being changed, which is useful when the caller just wants to change the setting temporarily while running a particular block of code.