Tools
Tools
Tools
Version 3.05
airbit
m Mobile Shell, Programming Tools, Version 3.05
Written by Lukas Knecht
www.m-shell.net
Document AB-M-TOO-869
The information contained herein is the property of airbit AG and shall neither be
reproduced in whole or in part without prior written approval from airbit AG. All rights
are reserved, whether the whole or part of the material is concerned, specifically those of
translation, reprinting, reuse of illustration, broadcasting, reproduction by photocopying
machine or similar means and storage in data banks. airbit AG reserves the right to make
changes, without notice, to the contents contained herein and shall not be responsible for
any damages (including consequential) caused by reliance on the material as presented.
Typeset in Switzerland.
c 2010 airbit AG Contents
Contents
1 Introduction 3
2 Debugging Support 5
2.1 Module debug: Runtime Debugging . . . . . . . . . . . 5
2.1.1 Module, Class, Function and Variable Indices . . . 6
2.1.2 Code Positions and Frames . . . . . . . . . . . . . 7
2.1.3 Example . . . . . . . . . . . . . . . . . . . . . . . 7
3 Generating Documentation 19
3.1 Item Descriptions . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Module mdoc: Documentation Generator . . . . . . . . . 20
4 Scanning m Sources 21
4.1 Module mscanner: Source Scanner . . . . . . . . . . . . 21
Index 23
1. Introduction
This manual describes the programming tools available in m. The tools
are a collection of m modules which aid in developing m applications
and module libraries.
The following tools are currently available:
2. Debugging Support
The m debugging support consist of three parts:
7. Check the process state, and check for runtime errors with
debug.state (p. 14).
9. Examine the variable values and types with debug.vglobal (p. 15)
and debug.vlocal (p. 16).
2.1.3 Example
Assume the following (not particulary useful) script SampleScript:
use ui
const DEFAULTMUL=20
class C
p
function init(p=..DEFAULTMUL)
this.p=p
end
function mul(n)
return n*p
end
end
function fact(n)
if n>1 then
res=n*fact(n-1)
else
res=1
end;
return res
end
c:C=C(13)
n=ui.query("n","Debuggable",10)
print "n=" + n
print "fact=" + c.mul(fact(n))
print "fact2=" + c.mul("a")
debug.breakp
• function breakp(process,mod,pos,enabled=true)→ Number
Enables (if enabled=true) or disables (if enabled=false) the break-
point in module mod at code position pos in the debuggable process.
Execution will pause if an enabled breakpoint is reached.
Returns the real position where the breakpoint was enabled or disabled
(breakpoints can only be set at the beginning of statements).
Throws ErrNotFound if the code position does not exist. Throws
ErrInUse if process is executing.
debug.close
• function close(process)→ null
Closes the debuggable process. Its state changes to debug.died.
debug.ccount
• function ccount(process,mod=-1,cls=-1)→ Number
Returns the number of code units (or the maximum index + 1):
mod cls Count returned
<0 Number of modules.
>=0 <0 Number of classes in module mod.
>=0 0 Number of functions in module mod.
>=0 >0 Number of functions in class cls in module mod.
debug.cindex
• function cindex(process,name,mod=-1,cls=-1)→ Number
Returns the index of a code unit with name name:
mod cls Index returned
<0 Index of module.
>=0 <0 Index of class in module mod.
>=0 0 Index of function in module mod.
>=0 >0 Index of function in class cls in module mod.
debug.cinfo
• function cinfo(process,mod,cls=-1,func=-1)→ Array
Returns information about a code unit:
cls func Information returned
<0 About module mod.
>0 <0 About class cls in module mod.
0 >=0 About function func in module mod.
>0 >=0 About function func in class cls in module mod.
The information is returned as an array with the following fields:
debug.compile
• function compile(process)→ null|Array
Compile the debuggable process. Returns null if successful, an array
with the following fields if an error occured:
Key Meaning Type
msg Error message String
file Source file path with error String
pos Position in source file Number
Throws ErrInUse if process is not stopped.
debug.fcount
• function fcount(process)→ Number
Return the number of frames (nested function calls) of the debuggable
process.
Throws ErrNotReady if process has not been started. Throws ErrInUse
if process is executing.
debug.go
• function go(process,mode=debug.run,arg="")→ null
Continues execution the debuggable process (or starts it), either until a
breakpoint is hit, or the condition implied by mode occurs. If the process
is started, arg is passed to it as a parameter.
mode determines the condition when execution pauses:
• const run = 0 Execute until a breakpoint is hit, an exception occurs,
or the process terminates normally.
• const stepinto = 1 Execute the next statement, stepping into
function calls.
• const step = 2 Execute the next statement, behaving like
debug.run within functions called from this frame.
• const stepout = 3 Execute until the current function returns, oth-
erwise behaving like debug.run.
Throws ErrInUse if process is not compiled or paused.
debug.open
• function open(name)→ Native Object
Opens the script with name name to debug it, creates a new debuggable
process, and returns it. The script is not yet compiled or loaded.
Throws ErrNotFound if the script does not exist.
debug.pause
• function pause(process)→ null
Pauses the debuggable process, as if a breakpoint has been hit.
debug.pos
• function pos(process,frame=0)→ Array
Get the current position of execution for the frame with index frame.
The position is returned as an array with the following fields:
debug.state
• function state(process)→ Number|String
Get the state the debuggable process is in.
If a string is returned, execution terminated with an exception, and the
return value is the expression thrown (normally the error message).
If a number is returned, the debuggable is in one of the following states:
• const opened = 0 The process has been opened with debug.open.
• const compiled = 1 The process has been compiled successfully
with debug.compile.
• const running = 2 The process is running and executing code.
• const waiting = 3 The process is running and waiting from some
asynchronous external event (input, timeout, message arriving).
• const paused = 4 The process is not running (a breakpoint was hit,
or an execution step was completed). It can be continued with debug.go
(p. 13).
• const ended = 5 The process terminated, either normally or with
an exception. Variables can still be examined.
• const died = 6 The process has been closed and was removed.
debug.vcount
• function vcount(process,mod,cls=0,func=-1)→ Number
Returns the number of variables (or the maximum variable index + 1):
debug.vglobal
• function vglobal(process,mod,var,follow=[])→ Array
Returns value and type of the global variable var in module mod of the
debuggable process. If the value is an array or a class instance, its
elements or member variables are derefenced in order by the element
indices or member variable indices in follow.
The array returned has the following elements:
Index Meaning Type
0 Value of variable Number or String
1 Type of variable String
2 If Array, the number of elements Number
2 If Instance, the module index of its class Number
3 If Instance, the class index of its class Number
Note that non-numeric values are always returned as strings, since
data from the debugged process cannot be accessed directly from the
debugging process.
The possible types are Number, String, Array, Native, Boolean, null,
Instance, Function, InstanceFunction.
Throws ErrNotReady if process has not been started. Throws ErrInUse
if process is executing.
debug.vindex
• function vindex(process,name,mod,cls=0,func=-1)→
Number
Returns the index of a variable with name name:
debug.vinfo
• function vinfo(process,mod,cls,func,var)→ Array
Returns information about a variable with index var:
cls func Information returned
0 <0 About global variable in module mod.
0 >=0 About local variable or parameter in function func in
module mod.
>0 <0 About member variable in class cls in module mod.
>0 >=0 About local variable or parameter in function func in
class cls in module mod.
The information is returned as an array with the same fields as those
returned by debug.cinfo (p. 11):
Key Meaning Type
file Source file path String
pos -1 Number
mod Module index Number
cls Class index Number
func Function index Number
name Name of variable String
flags Flag bits Number
debug.vlocal
• function vlocal(process,var,frame=0,follow=[])→ Array
Returns value and type of the local variable with index var in the function
at frame frame of debuggable process. If the value is an array or a
class instance, its elements or member variables are derefenced in order
debug.wait
• function wait(process,timeout=-1)→ Number|String
Waits until the debuggable process pauses or terminates, and returns
its new state, like debug.state (p. 14).
If timeout>=0 and timeout milliseconds have passed without the script
pausing, the current state is returned.
3. Generating
Documentation
Generating documentation from m source is a simple way of producing
reference documentation, in particular for APIs. If a source is commented
properly and marked up where necessary, helpful HTML documentation
can be generated automatically.
• The module mdoc scans list of m sources (and the sources imported
by them) and generates HTML documentation from them. The
generated documentation is configurable by class properties, and
of course by subclassing and overriding the HTML generating
methods.
• A sample application mDocumenter adds a user interface on top of
module mdoc to select source files and generate documentation.
All the documentations of m modules in the mdoc index have been
generated using this tool.
Sample m screen
is considered the item’s description and included into the collected data
and generated output. For the module or script itself, it is the comment
the module source starts with.
The comment is output ‘‘as is’’, i.e. can be marked up with HTML. The
following @-tags in comments are specially processed:
Here is an example:
/*
Run the event handling loop. This updates the UI,
handles UI commands, idle timer ticks, and, if set,
reads from streams. Returns if either {@link exit()}
has been called, or a menu command has been executed.
@return the menu command, or null if {@link exit()}
has been called.
*/
function run()
...
4. Scanning m Sources
Scanning an m source means reading the tokens (keywords, identifiers,
separators, string and number literals, comments) one after another.
Scanning is the first step when analyzing m sources, e.g. extracting static
metrics, extracting comments, instrumenting it, etc.
The module mscanner is used by module mdoc (p. 20) to read an m
source and all the files it imports.
Index
breakp function (in debug), 10 func, code information field, 12, 16
func, code position field, 14
ccount function (in debug), 11 function index, 6
cindex function (in debug), 11
cinfo function (in debug), 11 go function (in debug), 13
class index, 6
close function (in debug), 10 isconst constant (in debug), 12
cls, code information field, 12, 16 isinherited constant (in debug), 12
cls, code position field, 14 isnative constant (in debug), 12
Code position, 7
mdoc module, 20
code position, 7
mod, code information field, 12, 16
compile function (in debug), 12
mod, code position field, 14
compiled constant (in debug), 14
module index, 6
variable index, 7
vcount function (in debug), 14
vglobal function (in debug), 15
vindex function (in debug), 15
vinfo function (in debug), 16
vlocal function (in debug), 16