forsyth20121205-174063a80cc13 years agoHistory
189 lines · 4.7 KB · Text
RawDownload
.TH INTRO 2.SH NAMEintro \- introduction to Limbo modules for the Inferno system.SH SYNOPSIS.EXinclude "sys.m";sys := load Sys Sys->PATH; include "draw.m";draw := load Draw Draw->PATH; include "tk.m";tk := load Tk Tk->PATH; .I "... etc." .I "Generically:".EE.EXinclude "\fImodule\fP.m";.EE.fi.IB module " := ".BI load " Module".IB Module ->PATH;.SH DESCRIPTIONThis section introduces the Limbo modules available to the programmer;see the corresponding manual pages for more information.Each module is declared with a single Limbo.B includefile.Before calling a module's functions, an application must.B loadthe module; the application stores the resulting value in a variable for later use asthe module qualifier.The examples above illustrate the style.It will usually be necessary in some cases to qualify names with the appropriatemodule pointer or to.B importthe types and functions; the manual pages assume the names are accessiblein the current scope..PPAlthough many modules are self-contained,dependencies may exist.For example, the system module,.BR Sys ,provides basic services that many other modules require.These are the Inferno equivalent to `system calls'..PPIn a few cases, several related modulesshare a single.B includefile;for instance,.BR security.m ..PPThe manual pages describe how to.B includea module definition duringcompilation and.B loadan implementation during execution.The documentation also lists relevant functions or abstractdata types.Although the.B includefiles declare these components, the manual pages list them explicitly.In all cases, the enclosing.B moduledeclaration is assumed so that unqualified identifiers can beused in the text without ambiguity, reducing clutter in the text.In practice when programming, many consider it good style touse an explicit module reference for functions and constants..PPThe Limbo modules are identical on any machine that is running Inferno,whether native or hosted, which enables Limbo programs to be writtenand tested on any Inferno system..PPMany modules are described in a single page, such as.IR regex (2).Several larger modules are explained in several sections, such as.IR math-intro (2),.IR math-elem (2),.IR math-fp (2),and.IR math-linalg (2)..SS ExceptionsException handling is now part of the Limbo language, replacing an olderscheme that used special system calls.Various exceptions can be raised by the virtual machine when run-time errorsare detected.These are the common ones:.RS.TP.B "alt send/recv on same chan"It is currently illegal for a channel to appear in two.B altstatements if they either both receive or both send on it.(It is fine to send in one and receive in the other.).TP.B "array bounds error"Array subscript out of bounds..TP.B "dereference of nil"Attempt to use a.B "ref" adt or index an array with value.B "nil" ..TP.B "invalid math argument"Inconsistent values provided to functions of.IR math-intro (2)..TP.B "module not loaded"Attempt to use an uninitialised module variable..TP.B "negative array size"The limit in an array constructor was negative..TP.BI "out of memory:" " pool"The given memory.I poolis exhausted..I Poolis currently one of.B main(kernel memory including Tk allocations),.B heap(most Limbo data),and.B imagememory for.IR draw (3)..TP.B "zero divide"Integer division (or mod) by zero..RE.PPThere are currently two more classes of exception string with a conventional interpretationimposed not by the run-time system proper, but by Limbo components:.RS.TP.BI "fail:" "reason"Commands use this exception to provide an `exit status' to a calling program,particularly the shell.IR sh (1);see also.IR sh (2).The status is given by the.I reasonfollowing the.RB ` fail: 'prefix..TP.BI "assertion:" "error"A module detected the specified internal.IR error .This is most often used for cases where a particular possibility ``cannot happen''and there is no other need for an error value in the interface..RE.PPOtherwise, most module interfaces tend to use explicit error return values, not exceptions..PPNote that a Limbo exception handler can do pattern matching to catch a class of exceptions:.IP.EX{	\f2body of code to protect\fP} exception e {"out of memory:*" =>	\f2recovery action\fP"assertion:*" =>	fatal_error(e);}.EE.PPThe effect of an unhandled exception in a process that is part of an error-recovery groupcan be controlled using the mechanisms described in.IR prog (3)as accessed using.IR exception (2)..SH SEE ALSO.IR draw-intro (2),.IR exception (2),.IR keyring-intro (2),.IR math-intro (2),.IR prefab-intro (2),.IR security-intro (2),.IR sys-intro (2)