From: Alexander I. Baranovsky
Subject: 32-bit Version of Freeware VIRT Interpreter (Win95/NT)
Date:
Message-ID: <ABsWluv0uN@blast.donetsk.ua>
Thanks for the interest for my works.
New version of freeware VIRT interpreter is a Win95/NT console
application. Here is comparison with the previous version :
Ver.1.0 16-bit DPMI appl. Ver.1.1 32-bit Win95/NT appl.
-----------------------------------------------------------------------
Source
language: Borland Pascal Object Pascal / Delphi 4.0
String
length : 255 bytes 2 gigabytes
Integer
type : -32768..32767 -2147483648..2147483647
DLL
support : 16-bit DLL 32-bit DLL
Besides there were eliminated internal restrictions of the interpreter
( sizes of stack, heap, pseudocode have grown considerably ).
For the first accuaintance with the language VIRT there is a nonformal
introduction below. Three papers devoted to the language VIRT are
available at the following URL: http://www.botspot.com/virt/.There are
two versions of freeware VIRT interpreter with some demos. My
compatriots can read article "The Universal Programming Language VIRT"
in journal "Cybernetics & System Analysis",5,1998,Kiev,ISSN 0023-1274.
VIRT is object-oriented programming language. My main goal was
included in creating of the expressive programming language with the
minimal number of basic concepts. This language can be used as for
numerical calculations and for knowledge processing as well with the
same success. It supply the indivisible language environment for the
wide ranges of the problems.
One can consider VIRT as peculiar "imperative analog" of the language
LISP. Polymorphic array is one of the built-in data types in VIRT.
Array element can be any abstract data type object particularly the
other polymorphic array. This property allows effectively to construct
any complex data structures ( such as multi-dimensional array, list,
binary tree ) without using pointers at run-time. All OOP paradigmes
( encapsulation, inheritance, polymorphism ) are represented in VIRT.
This language has flexible control structures and supports such
concepts as coroutine, lazy evaluation. However this is a very simple
language.
The first version of VIRT interpreter has been implemented by me for
the protected mode MS DOS. IDE included specialized text editor and
debugger. This language has been examined by wide classes of tasks
such as simulation of dynamic data structures, theorem proving, graph
algorithmes, numerical methods of linear algebra, graphics applica-
tions.
There are some examples.
------------------------- Demo 1 -------------------------------------
-- Basic concepts : ( polymorphic ) array, lambda-object
-- Subject : recursion, lazy evaluation
uses system -- using file system.w
function Cond( A )
for I:=1 to Card( A ) do
if A[ I, 1 ] then
R := EvalObject( A[ I, 2 ], [] )
goto Fin
end
end
label Fin
return R
-- factorial in LISP-style
function Fact( N )
return Cond( [ [ N = 1, 1 ] , [ N > 1, { || N * Fact( N - 1 ) } ] ] )
writeln( Fact( 5 ) )
return -- Terminate program
Notes.
You can see that syntax is similar to the Modula-2. The expression in
curly brackets is defined a lambda-function ( lambda-object ).
Generally the labmda-object can has some parameters. ( In our case
parameters is absent ). Lambda-object is analog of the code block in
the Clipper language but here it has some additional properties. In
the given example the use of the lambda-object allows to avoid
infinite recursion.
------------------------- Demo 2 ------------------------------------
-- Basic concepts : class, object, constructor
-- Subject : abstract data type construction
class Point
function Init( InitX, InitY ) constructor
function "<"( Z ) -- The function sets definition of the operation "<"
function Draw()
end
class Circle : Point
function Init( InitX, InitY, InitR ) constructor
function "<"( Z ) -- Overlapping the function "<" from the class Point
function Draw() -- Overlapping the function Draw from the class Point
end
implementation Point
local X, Y, shared Num -- object's fields
function Init( InitX, InitY )
X := InitX
Y := InitY
if Null( Num ) then
Num := 0
end -- Num is shared for all objects of class Point
Num := Num + 1
return 0
function Norm() -- This is a private method
return X*X + Y*Y
function "<"( Z )
return Norm() < Z.Norm()
function Draw() external -- The external function hasn't a body
end
implementation Circle
local R
function Init( InitX, InitY, InitR )
Point.Init( InitX, InitY )
R := InitR
return 0
function GetR() inline
return R
function "<"( Z )
return R < Z.GetR()
function Draw() external
end
---- Main program -----
object P : Point -- This is a object's declaration.
P.Init( 3, 5 )
object Q( -4, 17 ) : Point
S := Point( 8, 7 ) -- Implicit constructor call
R := Q -- Assignment is defined by default.
if R < P then -- Using operation "<"
writeln( 'R less then P' )
else
writeln( 'R greate then P' )
end
return
Notes.
The program is represented by a collection of ( global ) function
definitions and abstract data type definitions. However the main
program is not function. VIRT is oriented to one-pass compilation.
The operations ":=", "=", "<>" are defined for any abstract data type
objects by default. The concept of "destructor" is not present in the
language VIRT. ( This concept is not necessary here ).
------------------------- Demo 3 ------------------------------------
-- Basic concepts : array
-- Subject : structured data processing
uses system
-- Creation of a matrix
A := array( N ) -- implicit constructor call
for I:=1 to N do
A[ I ] := array( M )
end
A[ 3][ 5 ] := 3.14
A[ 3, 5 ] := 3.14
-- Creation of a list
L := [ 77, [ 'abc', [ 4.7, * ] ] ]
-- Creation of a cycled list
C := [ 77, [ 'abc', [ 4.7, == C ] ] ]
P == L[ 2 ] -- Identify P with [ 'abc', [ 4.7, * ] ]
-- Insertion
P << [ 'cd', << P ]
-- Result : L = [ 77, [ 'abc', [ 'cd', [ 4.7, * ] ] ] ]
-- Printing of the list
P == L
while not Null( P ) do
writeln( P[ 1 ] )
P == P[ 2 ]
end
-- Deletion from the list
P == L[2][2]
-- Now P is a pseudonym of L[ 2, 2 ]
temp << P[ 2 ]
Destroy( @P )
P << temp
-- Result : L = [ 77, [ 'abc', [ 4.7, * ] ] ]
return
Notes.
We can update a list and a tree effectively. We can build and update a
two-way list, a cycled list, balanced tree with the same success.
Parenthesis representation has the imperative semantic.For example, the
statement
P << [ 'cd', << P ]
is an equivalent for the statement sequence :
temp << array( 2 )
temp[ 1 ] := 'cd' ":=" is the assembly operation by default
temp[ 2 ] << P "<<" is the overriden assembly operation
P << temp
The replacement operation "<<" has the following semantic :
A << B
-----------
A := B
Destroy( B )
This operation implements effectively ( copying and destroying are
absent ).
It is useful to compare the way of processing of dynamic data
structures in VIRT with processing in other imperative languages such
as C, Pascal, Ada etc. ( See my article under the URL above ).
------------------------- Demo 4 ------------------------------------
-- Basic concepts : string, functions EvalExpr, EvalLine
-- Subject : string evaluation
uses system
X := 10
Y := EvalExpr( 'X + 1' )
EvalLine( 'Z := X - Y' )
-- Result : Y = 11, Z = -1
return
------------------------- Demo 5 ------------------------------------
-- Basic concepts : corutine
-- Subject : corutine
uses system
class C
function F1()
function F2()
function F3()
end
implementation C
function F1()
writeln( 1 )
resume F2()
writeln( 2 )
resume F2()
return 0
function F2()
repeat
writeln( 'abc' )
resume F3()
until FALSE
return 0
function F3()
writeln( 'xyz' )
resume F1()
return 0
end
--- Main program -------------------
object A : C
writeln( A.F1() )
return
------------------------- Demo 6 ------------------------------------
-- Basic concepts : array, lambda-object, abstract data type ( clause )
-- Subject : knowledge representation
-- Compare with "Chang C.L. and Lee R.C.T.Symbolic Logic and
-- Mechanical Theorem Proving", Academic Press, New York, 1973.
uses system, chang -- using files system.w, chang.w
N := 50
A := array( 50 )
default ==
A[ 1 ] := Clause( { |X| [['+','L',X,['F',X]] ]})
A[ 2 ] := Clause( { |X| [['-','L',X,X] ]})
A[ 3 ] := Clause( { |X,Y| [['-','L',X,Y],['-','L',Y,X] ]})
A[ 4 ] := Clause( { |X,Y| [['-','D',X,['F',Y]],['+','L',Y,X] ]})
A[ 5 ] := Clause( { |X| [['+','P',X],['+','D',['H',X],X] ]})
A[ 6 ] := Clause( { |X| [['+','P',X],['+','P',['H',X]] ]})
A[ 7 ] := Clause( { |X| [['+','P',X],['+','L',['H',X],X] ]})
A[ 8 ] := Clause( { |X| [['-','P',X],['-','L','A',X],['+','L',['F','A'],X] ]})
W := array( N )
for I:=3 to N do
W[ I ] := [ 1, 2 ]
end
writeln( 'Theorem 9 :' )
writeln( 'The set of prime numbers is unlimited' )
TPU( A, W, N, 20 )
return
Note.
We can extract an outcome by means of ANSWER-predicate.
------------------------- Demo 7 -------------------------------------------
-- Basic concepts : function EvalExpr
-- Subject : knowledge representation, binding with Prolog and Datalog.
uses system, chang
S := 'grandfather(X,Y) :- father(X,Z), mother(Z,Y)'
S1 := GetClause( S ) -- GetClause written in VIRT
-- S1 = '{ |X,Y,Z| [['+','grandfather',X,Y],['-','father',X,Z],['-','mother',Z,Y]] }'
C := Clause( EvalExpr( S1 ) )
return
------------------------- Demo 8 -------------------------------------------
-- Basic concepts : external function call
-- Subject : 32-bit DLL interface ( ver. 1.1 ).
uses system
function CreateToolHelp32() external
function Process32First( H ) external
function Process32Next( H ) external
function CloseHandle( H ) external
H := CreateToolHelp32()
S := Process32First( H )
while S <> '' do
writeln( S )
S := Process32Next( H )
end
CloseHandle( H )
return
----------------------------------------------------------------------
Alexander I. Baranovsky
Flat 265, Constitution's square, 1
Donetsk, Ukraine.
E-mail : ·······@blast.donetsk.ua
Tel. 380622-371978
In article <··········@blast.donetsk.ua>, ·······@blast.donetsk.ua wrote:
> One can consider VIRT as peculiar "imperative analog" of the language
> LISP.
Common Lisp is an imperative language. It has also support for functional
and object-oriented programming style.
> Polymorphic array is one of the built-in data types in VIRT.
Same for Common Lisp.
> Array element can be any abstract data type object particularly the
> other polymorphic array. This property allows effectively to construct
> any complex data structures ( such as multi-dimensional array, list,
> binary tree ) without using pointers at run-time.
Same for Common Lisp.
--
http://www.lavielle.com/~joswig