1.117 class pce

Class pce has one predefined instance, called @pce. The object @pce provides operations to control the overall environment of PCE as well as operations that are not a clear action on some object.

@pce is also used to control the debugger/tracer; handle exceptions, etc.

See also
- topic Errors
- topic Debugging
- topic Exceptions
- class host

1.117.1 Instance variables

pce <-> application_data: directory
Directory for storing xpce-related application data. On Unix systems the default is ~/.xpce. On Windows it is <appdata>/xpce, where <appdata> is the directory from CSIDL_APPDATA. This directory typically contains the following files:
Defaults
User-level class variable values.
Geometry
Saved geometries for persistent frames (see persistent_frame.pl).
emacs_bookmarks
Bookmarks created by PceEmacs

Applications using the pce_config.pl library create additional files.

pce <- catch_error_signals: bool
Determines PCE's response to (normally) fatal error situations reported by the operating system. When such an error occurs, a [PCE SYSTEM ERROR] is generated. The following signals are considered fatal:
SIGQUIT		So, ^\ can be used to generate an error
SIGILL		Illegal instruction
SIGEMT		Emulator trap
SIGBUS		Bus error (illegal aligned pointer)
SIGSEGV		Segmentation fault (out-of-range pointer)
SIGSYS		Bad argument to system call
SIGPIPE		Broken pipe
SIGFPE		Floating point exception

See your Unix manual for details on these signals.

Defaults: The initial value is @off (do not trap signals). Some host languages switch this flag to @on at initialisation time.

See also
- pce->crash
- pce-print_c_stack
pce <- catched_errors: chain
Chain holding all errors currently catched. Each element is either an error_id or a chain with error_id’.
See also
- pce->catch_error
- class error
pce <- debugging: bool
Variable to indicate debugging-status of PCE. Set by pce ->trace' and program_object->trace‘.

Defaults: @off (no debugging)

See also
pce->debug
pce <-> defaults: source_sink|char_array
File/rc from which to load defaults. See pce->load_defaults, class class_variable and class_variable/4.

The default value is the file("$PCEHOME/Defaults")

A runtime application that wishes the defauts to be in the resource file should do:

resource(pce, defaults,	pce('Defaults')).

:- initialization
        send(@pce, defaults, rc(pce, defaults)).
pce <- exception_handlers: sheet
Sheet with exception handlers used by pce->exception. Each entry of this sheet maps an exception-name onto a code object which is executed when the corresponding exception occurs. The argument bindings for @arg1, ... are the second, ... argument passed to pce->exception. The following exceptions are currently defined:

pce <- exit_messages: chain
Chain of code objects. When the PCE process is killed, each of these messages is executed in turn with the following argument:
@arg1	Exit status of the process

Filled by pce->exit_message.

See also
- !killed_on_exit
- pce->exit_message
- pce->die
pce -> home: [name]
Home directory of the pce system. Its value is used to find

pce <-> last_error: name*
Last error catched by the application. See also pce->catch_error and pce->catch_pop.
See also
- pce<-os_error
- pce-error_object
pce <- machine: name
Identifier name for the hardware architecture used.
See also
pce-operating_system
pce <- operating_system: name
Identifier for the operating system running on your system. On Unix systems this is extracted from the autoconf standard system naming <os>-<vendor>-<cpu>. On MS-Windows this is one of:
win32 	The actual version could not be retreived
win32s	XPCE dowsn't run on this ..
win95	DOS-7 based Windows (95,98,ME,...)
winnt	NT based Windows (NT, 2000)

See also pce<-machine, pce<-window_system, pce<-window_system_revision and pce->has_feature.

See also
pce-machine
pce <- trap_errors: bool
This flag, which is only available in the development version, controls XPCE's behaviour if a runtime error is trapped in an application. When @on (default), the system will normally enter the tracer, allowing the user to inspect the context of the error. If @off, the system will use the object->report mechanism to report the error and the tracer will not be trapped. The latter behaviour is the only behaviour supported by the runtime system. See also pce->trace.
pce-version: name
Current version number of XPCE. When documenting this method:
'4.4.3, September 1992'

Its format:

1.117.2 Send methods

pce ->banner:
Writes a standard banner message for PCE, indicating version, hardware, operating system, the hostlanguage to which PCE is connected and a copyright notice.
See also
- pce-version
- host-system
pce ->bench: message=message, times=int, how={forward,execute,qad,send}
Sends messages in a tight loop for benchmarking purposed. First argument is the message that is executed repeatedly. Second argument is the number of iterations. Last argument indicates which part of the message invocation is placed in the loop. The rest is moved out of the loop. Its values are:
forward
Invoke the full code->forward behaviour
execute
As pce->forward, put pushing and popping the argument stack outside the loop.
send
Invokes the full send() virtual machine operation
invoke
Move method-resolution outside the loop. Typechecking the arguments and starting the implementing code is all which is left inside the loop.
See also
pce<-cpu_time
pce ->catch_error: identifier=[name|chain]
Inform PCE's error recovery mechanism that the application takes care of the indicated error, one of the indicated errors or all errors (@default). If such an error occurs the method normally fails silently, setting pce<-last_error.

The method pce->catch_pop restores the catched errors to the state before invoking pce->catch_error.

The prolog predicate pce_catch_error/2 provides an interface:

?- send(@pce, hello, pce).
[PCE error: send: No implementation for: @pce/pce ->hello
        in: send(@pce/pce, hello, pce)]
PCE:  1 fail: send(@pce/pce, hello, pce) ?

While

?- pce_catch_error(no_behaviour,
                                   send(@pce, hello, pce)).

No

After which

?- get(@pce, last_error, E).    ==> E = no_behaviour

Note that errors with pce<-feedback: throw can also be handled using Prolog exception-handling.

See also
- pce->catch_pop
- pce->catched
- pce-catched_errors
- class error
pce ->catch_pop:
Restores the catched errors to the state before the latest‘pce pce->catch_error’.
See also
- pce->catch_error
- class error
pce ->catched: identifier=name
Test if the indicated error_id is currently catched. If this method succeeds, raising the indicated error will make the method fail rather than printing an error-message.
See also
- pce->catch_error
- class error
pce ->confirm: format=char_array, argument=any ...
If pce is connected to an open display, invokes display->confirm on @display. Otherwise the text is formatted on the terminal and PCE requests the user to type y or n. Used infrequently.
See also
- pce->inform
- display->confirm
pce ->console_label:
Set the label of the console-window from which XCE was started. Currently only implemented for the MS-Windows version of XPCE, and XPCE started from a Unix xterm(1) application. The latter is verified by checking the environment variable TERM for the value xterm. See also pce->show_console.
pce ->debug_subject: subject=name
Prints messages to the terminal to debug certain aspects of the system. The debug_id's supported change quickly from release to release. Below is a tentative list.
absolute_position	Translation of relative coordinates
allocate			memory allocation
compute				Graphicals ->request_compute and ->compute
cursor				Determining visual cursor
dialog				Dialog layout
editor				Various editor happenings
event				Various things with events
fill				Filling text (editor)
flash				Flashing graphicals
float				Floating point conversions
focus				Event focusing
fragment			Fragment handling
frame				Various frame events
gc					Incremental garbage collection
get_xref			Maintenance of X id database
image				Some image functions
clone				Cloning objects
menu				Menu repaint
message				Execution of message objects
obtain				Failing obtainers
path				Smoothing paths
popup				Popup menu's
post				Event posting (event ->post)
postscript			PostScript generation
process				Actions on handling subprocesses
redraw				Repaint management
save				`Object ->save_in_file`
scan				`char_array <-scan`
scroll				Scrollbar handling
shift				text_image shifting of lines
spatial				execution of spatial constraints
text				Updating of text_images
undo				Undo in text_buffers
xref				X window references database

pce->nodebug_subject removes an item from this list.

User code may exploit the same mechanism and test whether debugging a subject is enabled using pce->debugging_subject.

See also
- display->open
- pce->nodebug_subject
- topic Tracing
- pce->debug
pce ->debugging_subject: subject=name
Test whether the named subject is registered using pce->debug_subject and pce<-debugging is @on. This test may be used in application code to exploit this debugging mechanism of XPCE.

In a runtime system this method is available, but fails always.

pce ->define_class: name=name, super=name, summary=[string], realise=code
Declare a class without details. The system will run code when an action is performed that requires details of the class (such as creating an instance).

All, except for some vital kernel classes of XPCE itself have been declared this way to delay/avoid building the class-definitions.

See also class->realise.

pce ->die: status=[int]
Exit from the combined PCE/{Prolog,Lisp,...} process indicating status. It performs the following steps:

pce ->exception: identifier=name, context=any ...
Raise an exception. The first argument is the name of the exception. The remaining arguments are passed as context parameters to the code dealing with the exception. The exception handlers are defined in the sheet pce<-exception_handlers.

Bugs: The exception mechanism is rudimentaly.

See also
- class<-convert
- class<-instance
- pce-exception_handlers
pce ->exit_message: message=code
Prepends code object to pce<-exit_messages. That is: the last exit message registered will be executed the first.
See also
pce-exit_messages
pce ->expose_console:
Backward compatibility equivalent of pce->show_console: open.

Expose the console window of XPCE. Only implemented for the MS-Windows version. See also pce->console_label.

pce ->fail:
Fails immediately without side-effects.
See also
pce->succeed
pce ->feature: any
Inherits description from: pce-features
pce ->for_name: message=code
Executes the code object on all instances of class name. @arg1 is bound the the successive name objects.

This method is safe: the name-base may be manipulated during its execution. Tbe code will not be executed for named added during the execution of pce->for_name.

pce ->for_name_reference: message=code
Executes code for each defined global name reference (e.g. @pce, @arg1). The exit status of the code is ignored. Arguments:
@arg1	Name of the global object (e.g. `pce`, `arg1`).

This method passes the reference-names rather than the objects themselves. As various of them are functions, good understanding of the expansion-rules for functions is necessary.

See also
- pce<-object_from_reference
- pce->rename_reference
pce ->format: format=char_array, argument=any ...
Write formatted output to the main window. Normally only used for reporting debugging information. For example, the following query dumps the mapping represented by the hash_table object @classes to the terminal:
?- send(@classes, for_all,
                message(@pce, format, '%s\t%s\n',
                                @arg1, @arg2)).

See string->format for a description of the format specification.

pce ->iconify_console:
Backward compatibility equivalent of pce->show_console: iconic.
pce ->info:
@see pce-version
pce ->inform: format=char_array, argument=any ...
If there is an open display, run display->inform. Otherwise pce->format the information on the terminal.
See also
- display->inform
- pce->confirm
pce ->initialise:
Called at boot time to create the one-and-only instance called @pce. No more instances may be created.
pce ->list_wasted_core: list_content=[bool]
Dumps a map of wasted-core cells. Wasted core is core allocated, freed and not yet reused. With list_content @on, PCE tries to identify the object deleted. This might lead to crashes. See also pce<-core_wasted.
See also
pce<-core_wasted
pce ->load_defaults: source_sink
Loads class_variable object default values from the given source. Initialisation of XPCE loads pce<-defaults.

A Defaults file consists of statements. Each statement is on a seperate line. A statement may be split over several lines by preceeding the newline with a backslash (\). The exclamation mark (\!) is the line-comment character. All input from a ! upto the following newline is replaced by a single space-character. Empty lines or lines containing only blank space are ignored.

Default files may include other default files using the statement

pce ->multi_threading:
Enable thread-safe access to XPCE. This method is normally sent from the host-language interface at initialisation time if the host-language wishes to access XPCE from multiple threads. The host-language interface should use the functions pceMTLock() and pceMTUnlock() as wrappers around access to XPCE.

This method fails with an error when invoked too late (for the X11 version this implies after the window system has been initialised). It fails silently if this version of XPCE is not compiled to support multi-threading.

XPCE multi-threading support is currently rather limited: it consists of one global recursive mutex that ensures the system is activated in a single-thread only. This mutex should be locked by the host-language around access to the basic operations (send, get, new and object) and is locked by XPCE itself for any event processed.

XPCE call-back occurs in the thread waiting for events. In the normal XPCE/Prolog context this is the main-thread. As the system is locked during event-processing, smooth interactive operation requires event-processing to be completed quickly. If an event causes a long operation to start the host-language should run this operation in another thread.

pce ->nodebug_subject: subject=name
Inherits description from: pce->debug_subject
See also
pce->debug_subject
pce ->rename_reference: old=name, new=name
Change the name of a global reference. This method may be used to rename functions. Its use is strongly discouraged for normal application programmers. See also object->name_reference.
See also
- object->name_reference
- pce->for_name_reference
pce ->show_console:
Control visibility of the console window, if accessible. This call only works in the Windows version of XPCE, and only if the host interface honours the hostQuery(HOST_CONSOLE) request. The meaning of the argument:
open
The console is opened normally. This is the normal situation for program development.
iconic
The console is displayed as an icon. This is useful for testing applications. If the applications behaves strange, the console may be opened to check it for error messages.
hidden
The console windows is removed from the display. This is the normal situation for finished applications. Make sure that the application terminates if the last windows disappears (see library(pce_main) for some standard predicates to realise the toplevel control loop).
pce ->succeed:
Succeeds without side effects. Maybe used if a code objects that always yields success is needed:
new(@succeed, message(@pce, succeed)).

Note that the following is faster:

new(@succeed, new(and)).
See also
pce->fail
pce ->syntax: syntax={uppercase}, word_separator=[char]
Some languages (notably LISP) use case-insensitive keywords, internally represented in upper-case. host-language keywords are most naturally mapped on PCE-names. This method, which is normally send by the LISP interface right after PCE has been initialised performs the following actions:

pce ->write: argument=any ...
Write the arguments using PCE's internal pretty-printing routine. The arguments are separated by spaces. Note that output is generally not flushed.
See also
pce->write_ln
pce ->write_ln: argument=any ...
Writes the arguments as pce->write and terminates the line with a newline. Useful for dumping information to the terminal:
send(@images, for_all, message(@pce, write_ln, @arg1, @arg2)).

Dumps a map of all named image objects (which is initially empty).

See also
pce->write

1.117.3 Get methods

pce <-answer_stack_size: -> cells=int
Statistics on the incremental garbage collection system. Objects created that are not related to any other object are pushed on the answer stack. They are deleted from this stack iff

  1. 00 seconds, 0 bytes, 1 created - 1 freed = 0 objects NOTE: pceusage/1 should often be called twice to get the intended result. The first call may create objects in the XPCE/Prolog cache.
pce <-convert: object=unchecked, type=type -> converted=unchecked
The method pce<-convert provides access to type<-check, the PCE type checking and conversion system. The first argument is the object to be checked/converted. The second is the type that should be met.

Equivalent to type<-check, but generally more comfortable as this method will automatically translate a type specification into a type object.

The following example converts anything convertible to an integer to an integer:

convert_to_int(Any, Int) :-
        get(@pce, convert, Any, int, Int).

After which

convert_to_int('78', X)				==> 78
convert_to_int(string('1992'), X)	==> 1992
convert_to_int(hello, X)			fails
convert_to_int(100, X)				==> 100
See also
- type<-check
- type<-convert
- topic Conversion
pce <-core_usage: -> bytes=int
Number of bytes core allocated by PCE. Notes:

  1. Memory requested by the X-window libraries or the host-language is not included
  2. Memory requested by PCE is never returned to the process. @see pce<-core_wasted @see tool Statistics
pce <-core_wasted: -> bytes=int
Memory allocated by PCE, but currently not in use.
See also
- pce->list_wasted_core
- pce<-core_usage
- tool Statistics
pce <-cpu_time: kind=[{user,system}] -> seconds=real
CPU time used by the process PCE belongs to. When the argument is @default, this is the combined user and system time, otherwise it is the time specified.

Note that the host language is normally part of the same process.

See also
pce->bench
pce <-date: -> string
Requests the system time using the C-library function ctime(3) and returns the result as a string object. The returned string has no trailing newline (as its Unix counterpart). Its format is:
Sun Sep 16 01:03:52 1973

See also class date.

See also
- date<-string
- class date
pce <-deferred_unalloced: -> number=int
Number of objects that has been object->free’d by the user, but are still referenced. To avoid crashes, the memory belonging to such objects is not freed as long as there are references to the object.
pce <-environment_variable: name=name -> value=name
Read named Unix environment variable which’value is returned as a name.

If name is PCEHOME and this is not defined as a Unix environment variable, the value of pce<-home is returned.

Diagnostics: If the variable is not defined pce<-environment_variable fails silently.

See also
pce-home
pce <-fd: -> number=int
Number of remaining unused Unix file-descriptors. When PCE was based on the SunView windowing environment, each window used a file descriptor and an ungraceful error was generated when no more filedescriptors were available.
pce <-instance: class=class, argument=unchecked ... -> created=object|function
Create an object (as Prolog new/2 or Lisp pce-new()). @pce pce<-instance converts the first argument into a class. This process deals with handling class-names rather then class objects and invokes the autoloader if the class does not yet exist (see pce_autoload/2 and pce<-exception_handlers). Next, the method class<-instance is called to create the new instance.

The following function creates a new point object each time it is evaluated:

?(@pce, instance, point, 4, 5)

See also class create, class<-instance and @vmi_new.

See also
class<-instance
pce <-max_integer: -> value=int
Highest/lowest integer value that may be represented using PCE's data-type int or number. Current range:
-2^29 ... 2^29 - 1 (-536870912 ... 536870911)
See also
- class number
- pce<-min_integer
pce <-min_integer: -> value=int
Inherits description from: pce<-max_integer
See also
pce<-max_integer
pce <-object_from_reference: reference=int|name -> object=unchecked
Converts an object name or integer object-reference into an true object:
?- get(@pce, object_from_reference, prolog, Obj)

Obj = @prolog

This is the inverse of object<-object_reference. See also object<-convert. These methods are used seldomly by application programmers.

See also
- object<-object_reference
- pce->for_name_reference
pce <-objects_allocated: -> number=int
Obsolete method returning the same as
get(class(object), no_created, @on, Count)

See class<-no_created and class<-no_freed.

See also
- pce<-objects_freed
- class-no_created
- tool Statistics
pce <-objects_freed: -> number=int
@see class-no_freed @see pce<-objects_allocated @see tool Statistics
pce <-os_error: -> identifier=name
Name indicating the last operating-system generated error. That is, the text that would normally be printed by the Unix utility perror(2). Its use is not encouraged.
See also
pce-last_error
pce <-pid: -> identifier=int
Unix process identifier for this process. May be used to create unique system-wide names. Note that file objects with a proper temporary name may be created using
?- new(TmpFile, file).

See file->initialise.

pce <-unresolved_types: -> chain
Scans @types for types that are of type<-kind, but have no initialised class associated with them. A name that is not the name of an existing class will be converted into a type of kind class. This type is only useful after the class is actually created. This mechanism allows the programmer to refer to classes as a type before defining them.

The most likely cause of this trouble is a misspelled type-name or a forgotten class definition.

pce <-user: -> user=name
Login name of user. On Unix systems this uses either getlogin() or password information from the current UID. On Windows it examines the environment variable %USER%.

See also pce<-user_info.