Appendix B

The sys Module

On this page

The sys module, which is imported by default, contains built-ins that are relevant to the Picat system. The built-ins in the sys module perform operations that include compiling programs, tracing execution, and displaying statistics and information about the Picat system.

B.1 Compiling and Loading Programs

The sys module includes a number of built-ins for compiling programs and loading them into memory.

B.2 Tracing Execution

The Picat system has three execution modes: non-trace mode, trace mode, and spy mode. In trace mode, it is possible to trace the execution of a program, showing every call in every possible stage. In order to trace the execution, the program must be recompiled while the system is in trace mode. In spy mode, it is possible to trace the execution of individual functions and predicates. The following predicates are used to switch between non-trace mode and trace mode.

B.2.1 Debugging Commands

In trace mode, the system displays a message when a function or a predicate is entered (Call), exited (Exit), re-entered (Redo) or has failed (Fail). After a function or a predicate is entered or re-entered, the system waits for a command from the user. A command is a single letter followed by a carriage-return, or may simply be a carriage-return. The following commands are available:

B.3 Information about the Picat System

The sys module contains a number of built-ins that display information about the Picat system. This information includes statistics about the system, including the memory that is used, and the amount of time that it takes to perform a goal.

B.3.1 Statistics

The following built-ins display statistics about the memory that the Picat system uses.

Example

Picat> statistics
      Stack+Heap:    8, 000, 000 bytes
        Stack in use:    1, 156 bytes
        Heap in use:    28, 592 bytes
      
      Program:       8, 000, 000 bytes
        In use:      1, 448, 436 bytes
        Symbols:         5, 300
      
      Trail:         4, 000, 000 bytes
        In use:            936 bytes
      
      Memory manager:
         GC:         Call(0), Time(0 ms)
         Expansions: Stack+Heap(0), Program(0), Trail(0), Table(0)

Picat> statistics(Key, Value)
      Key = runtime
      Value = [359947,66060]?;

      Key = program
      Value = [1451656,6548344]?;

      Key = heap
      Value = [34112,7964524]?;

      Key = control
      Value = [1360,7964524]?;

      Key = trail
      Value = [1496,3998504]?;

      Key = table
      Value = [0,4000000]?;

      Key = table_blocks
      Value = 1?;

      Key = gc
      Value = 0?;

      Key = backtracks
      Value = 0 ?;

      Key = gc_time
      Value = 0 

Picat> L = statistics_all()
L = [[runtime, [359947,66060]], [program, [1451656,6548344]], 
     [heap, [34112,7964524]], [control, [1360,7964524]], 
     [trail, [1496,3998504]], [table, [0,4000000]], 
     [table_blocks,1],[gc, 0], [backtracks, 0], [gc_time, 0]]

B.3.2 Time

The following predicates display the amount of CPU time that it takes to perform a goal.

B.3.3 Other System Information

B.4 Garbage Collection

Picat incorporates an incremental garbage collector for the control stack and the heap. The garbage collector is active by default. The sys module includes the following predicates for garbage collection.

B.5 Quitting the Picat System

The following predicates can be used to terminate the Picat interpreter.

1Each block has 1 million words.