Visual Prolog 7.2 New Features

From wiki.visual-prolog.com

Revision as of 14:54, 20 October 2008 by Thomas Linder Puls (talk | contribs) (→‎Zooming: keys)

Visual Prolog 7.2 introduces many new features and improvements. Following are the most significant changes.

Language Features

Visual Prolog 7.2 brings several language improvements. This section gives a brief overview of some of them.

Anonymous predicates

Anonymous predicates are the Prolog counterparts to anonymous functions as known in functional programming languages. Anonymous predicates are described in details in the article Anonymous Predicates of Visual Prolog Language Reference.

64 bit numbers

integer64 and unsigned64 are two new built-in types, that replace the PFC domains core::integer64 and core::unsigned64. The new domains are like integer and unsigned expect that they have a 64-bit representation. All arithmetic operations (except the power operation) are supported for the types. They are written, read, saved and consulted in normal number format only with much larger range than 32-bit numbers. PFC has been updated to use integer64 and unsigned64 instead of core::integer64 and core::unsigned64. So now (as example) file positions are unsigned64. The same is the case with gmtTimeValue, localTimeValue and timeIntervalValue.

Namespaces

Interfaces and classes can be put into namespaces (like pfc\pie). This allows the same interface/class name to be declared/defined in several name spaces in the same program. So, now it is possible (for example) to have a class called file in the namespace documentManager even though there is also a class named file in PFC. It is planned in a future version of Visual Prolog to put PFC classes in namespaces pfc, pfc\vip5x and pfc\gui. Also there are new pie packages (described below) in the namespace pfc\pie.

binaryNonAtomic domain

A new built-in domain binaryNonAtomic is introduced to distinguish binaries may contain pointers and should therefore be scanned by the garbage collector. The ordinary binary domain is no longer scanned for pointers.

real32

A domain real32 is introduced to ease the integration with foreign API's that sometimes uses such short reals. It is not intended for use in "normal" code.

handle

A new built-in domain handle which corresponds to API handle type is introduced to ease the integration with foreign API's as well. Also, there are two new built-in constants of this type: nullHandle and invalidHandle.

Compiler directive #options

A new compiler directive #options is introduced to define some additional compiler options for a separate compilation init. It has the following syntax:

OptionsDirective:
    #options StringLiteral

This directive affects the whole compilation unit and should be used outside scopes and conditional compilation statements in the main source file for a compilation unit (i.e. in the source file which is passed to the compiler). Otherwise the compiler generates warning message and ignores the directive. The <string_literal> can only contain the following compiler's options: /Warning, /Check, /NOCheck, /Optimize, /DEBug, /GOAL, /MAXErrors and /MAXWarnings. Otherwise the compiler generates error message for invalid option.

Compiler

The compiler is (obviously) updated to deal with the new language features. But it has also been improved in several other respects.

Unreachable code detection

The ability to detect unreachable code has been improved vastly, both when it comes to detecting unused predicates and facts and when it comes to code inside clauses which cannot be reached. Unreachable code will cause warnings.

Superfluous test detection

The compiler will also give warnings about tests, which are trivially fulfilled due to the type of the involved variables. Consider this code for example:

clauses
     ppp(X) :- 
         Y = X - 23, 
         Y >= 0,  
        qqq(Y).

where qqq is declared like this:

predicates
      qqq : (positive V).

The code above might seem reasonable, we only want to call qqq if Y is indeed greater than or equal to zero.

The only problem is Y is always greater than zero, because Y has the type positive, which only contains numbers that are greater than or equal to zero.

If the calculation X - 23 gives a negative number an out-of-range exception will be raised (before reaching the test). So this new warning can help the programmer detect places where it seems that testing ensures validity of the code, while in reality the test will never fail because an exception will be raised instead. The code above can be corrected using this code:

clauses
   ppp(X) :-
       Y = tryConvert(positive, X - 23),
       qqq(Y).

If X - 23 gives a negative number, the tryConvert will fail.

Smaller code

The size of the generated code has become smaller, especially for predicates with many clauses that match different patterns of input.

Less stack usage

Likewise, the stack size has been reduced (dramatically in some cases).

The sub-type relations for some built-in types were changed

The built-in types string, object, string8 and symbol are not sub-types of type pointer any more.

Restrictions for delegate- sections order were removed

Now delegate- sections can be mixed with "usual" sections (like predicates, etc.) inside a class implementation.

IDE

Many bugs and inconveniences have been solved in the IDE. Just like numerous smaller and larger improvements has been made. This section describes some of the major improvements.

Build speed

The build system has been changed such that it can utilize multi-core processors by compiling several packages in parallel. On a quad-core processor this typically gives a factor 4 (sometimes more) when many packages needs to be compiled.

As of this writing, we are also working on letting the compiler itself compile several packages in a single invocation and thus skip many compiler phases for files that are included in several packages.

This feature has given a factor 4 when rebuilding a very large project.

IntelliSence

Browse information (i.e. information about the source code fed from the compiler back to the IDE) is now utilized to provide IntelliSense: When you edit source code the IDE shows possible/sensible completion of the word you are typing. You can then select the completion in the list using mouse, arrow keys and TAB; the IDE will complete the word with your choice. The IDE will also show tool tip windows showing the declaration of the predicate you are about to write arguments for. That way you can see which arguments the predicate takes without changing context.

Window Navigation Dialog

The order, in which Ctrl-TAB shifts between IDE windows, has been changed to visit most-recently-visited windows first.

Furthermore, Ctrl-TAB also brings up a navigation dialog listing all the open windows. The dialog stays up as long as Ctrl-key is pressed. In this dialog you can see the windows in the order they will be shifted to, but you can also choose a window directly using the mouse or the arrow keys. If you press letters the list will be filtered to windows starting with the letters you have pressed.

Ctrl-Del will cancel the navigation to another window and closes the navigation window.

Grouping editor windows

Editor windows can be grouped together to look and behave like a single window. This has the advantage that you can arrange windows in a fixed layout inside the IDE. The IDE will remember two different layouts, one for "normal" mode and one for debug mode. Typically, you want large editor windows in "normal" mode, but smaller editors in debug mode to give more room for the variables window, etc.

Resources view in project tree

When selecting a resource (e.g. a dialog or a bitmap) in the project tree, the right pane will show a preview of the resource.

Zooming

Pressing the Ctrl and using the mouse wheel the IDE will increase/decrease font size in various windows creating a zoom effect. Zooming is also bound to Ctrl-+, Ctrl--, and Ctrl-0 reset the zoom to 100%.

Un-/commenting blocks

The editor has new commands for commenting and un-commenting a block of code with %-chars. The commands are bound to Ctrl-Alt-% and Ctrl-Alt-Shift-%. (It would be more correct to state the keys as Ctrl-Alt-5 and Ctrl-Alt-Shift-5, but it seems simpler to remember the %-key).

Project loading speed

The project loading has been changed such that the speed of this process was increased.

Find In Files dialog

The dialog Find In Files has been improved such that it now shows total number of found entries in a file as well.

Welcome Page

The Welcome Page has been improved such that now it has an extra context menu which can be accessed via right mouse. This menu allows to inspect project file properties, remove project from the list of projects, etc.

TODO Window

It is now possible to view all TODO comments (i.e. the comments like % TODO) in source files which can be rather convenient for developers. This feature is available via the Main menu: View | TODO

PFC

PFC has mainly been consolidated, updated to 64-bit numbers and things like that. But there are also some new things.

PIE

The engine of PIE (Prolog Interpreter Engine) is now added to PFC and will therefore be supported as a tool in future. The most important feature is that you can easily hook-in predicates from you own application. Subsequently, the PIE programs can manipulate your application. So PIE is very useful as a scripting engine in applications. Besides this, the efficiency has been improved and PIE now supports functions and real numbers.

progressBarControl

A progressBarControl binds to the win32 common control progress bar. It is the intension to add additional win32 common controls, but to deal more easily with them certain inner parts of PFC GUI will have to be revised first.

postAction

A new predicate postAction on the window class, makes it possible to post an action to any window. The action will be packed in a user message and when the user message is handled the action is executed. Together with anonymous predicates this makes any other use of user messages superfluous.

popupWindow

A new class popupWindow makes it easier to create popup windows like tooltips. Most importantly popup windows must have the screen as parent so that they can be drawn outside their logical owner and on top of other windows.

radixTree

A radix tree is a map from pointer to any type. Its main advantage (over for example red-black-trees) is that supports very efficient merge of several maps. The disadvantage is that the keys are pointer values, so the trees can only be used on things with unique pointers (like object and symbol).

uxTheme native bindings

Native bindings to uxTheme make it possible to experiment with creating theme aware controls. Theme aware controls are not drawn using lines, circles, rectangles, etc. Instead they are drawn using theme elements. Theme elements are logical graphical entities like divider line, button surface, button outline, drop-down mark, etc. You combine/draw such logical elements into your control, and when the theme changes your control will also change appearance. If you have chosen the elements wisely your control will also blend-in with other themes.

getFactChainLength_nd

A new predicate getFactChainLength_nd (in the profileMemory class) returns the number of facts in each class fact chain in the entire program. It is intended to help tracking down problems with class facts that are not retracted when they should and therefore eats memory by keeping data alive that should have been dead.

weakPointer

Weak pointers are "pointers" that the garbage collector does not see as pointers, so if there are only weak pointers to a piece of memory the garbage collector will recycle that piece of memory. As a consequence, a weak pointer cannot always be dereferenced, sometimes the target as been recycled. Dereferencing of a weak pointer it therefore done using a determ predicate.

So in short a weak pointer is a pointer that will not keep memory alive.

5xChainDB8

This package is introduced for compatibility support in order to handle old external databases (where strings are not in Unicode).

Tools

vipBuilder

Some extra options has been added to vipBuilder:

   /genresource - also generate resourceIdentifiers.i
   /compile <file_name> - compile the file <file_name>


coverageAnalysis

The coverage analysis gives information about the predicates that have been called during execution of the program. The coverage analysis program reads .deb files to get information about a set of classes and predicates in a program and coverage files to get information about the predicates that have been called during execution of the program. The program must be compiled with options /profile:min and /debug:full to use this new tool.