index Zimbu documentation

MODULE Z @public

summary

     

Items built into the compiler.

CLASS  Pos @public  Class that stores the line/column position in a file.
ENUM  FinishReason @public  Argument to Finish(): why it was called.
 
string  lang @public  The language currently being generated: "C" or "JS"
bool  exiting @public  Set to TRUE when exiting the program.
 
pos() Z.Pos @public  Return the current position in the code.
callerPos() Z.Pos @public  Return the code position of the calling method.
backtrace() list<Z.Pos> @public  Return the stack backtrace, the list of code positions that brought us to the current position.
backtraceString() string @public  Return the stack backtrace as a string.
backtrace(skip) list<Z.Pos> @public  Return the stack backtrace, just like backtrace(), but skip the first skip entries.
have(feature) bool @public  Return TRUE when feature is supported.
usedInJs(method) @public  Registers a method that is called in Javascript.
 

members (alphabetically)

     

bool exiting @public

     

Set to TRUE when exiting the program.

Useful in a Finish method.

Example:

 IF $done || Z.exiting
   $cleanup()
 }

string lang @public

     

The language currently being generated: "C" or "JS"

For example, to generate code for JavaScript only:

 GENERATE_IF Z.lang == "JS"
 >>>
   javascript code
 <<<
 }

FUNC backtrace() list<Z.Pos> @public

     

Return the stack backtrace, the list of code positions that brought us to the current position.

The position where Z.backtrace() is invoked is the first position, index zero in the list. The last position is a call from Main().

Each position has the $text member set to the method name it is inside of.

When Z.have("backtrace") is FALSE then NIL is returned. When used in a method with backtrace=no a compilation error is produced.

Not yet available for Javascript, NIL is returned.

Example:

 FOR p IN Z.backtrace()
   IO.print("\(p): \(p.text)")
 }
Which is what Z.backtraceString() returns.

FUNC backtrace(int skip) list<Z.Pos> @public

     

Return the stack backtrace, just like backtrace(), but skip the first skip entries.

To omit the position this function is called use Z.backtrace(1).

FUNC backtraceString() string @public

     

Return the stack backtrace as a string.

Example:

 IO.print(Z.backtraceString())
This concatenates the result of Z.backtrace(), separated by line breaks.

Alternatively, use LOG.reportStack()

FUNC callerPos() Z.Pos @public

     

Return the code position of the calling method.

When Z.have("backtrace") is FALSE then NIL is returned.

Not yet available for Javascript, NIL is returned. Example:

 PROC getAtIndex(int idx)
   if idx < 0
     THROW NEW("idx invalid", Z.callerPos())
   }
 }

FUNC have(string feature) bool @public

     

Return TRUE when feature is supported.

Known features are:

"backtrace" - Wether stack backtrace is available

"resolve" - Wether IO.resolve() is available

"fork" - Wether fork() is available

"sigaction" - Wether sigaction() is available

"portable" - Whether compiling with --portable

"keepunused" - Whether compiling with --keepunused

"managed" - Whether memory is being managed

"mswindows" - Whether running on MS-Windows

"ctx" - Whether the CTX library is used.

Example:

 GENERATE_IF Z.have("resolve")
   fname = IO.resolve(fname)
 }

FUNC pos() Z.Pos @public

     

Return the current position in the code.

This is generated at compile time.

Example:

 THROW NEW("something wrong here", Z.pos())

PROC usedInJs(dyn method) @public

     

Registers a method that is called in Javascript.

This is only useful if the method is not called from Zimbu code. E.g., when a library containing Javascript calls the method.

license

      Copyright 2010 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0