Difference between revisions of "Language Reference/Built-in entities/Domains"

From wiki.visual-prolog.com
(Handle size)
(clarify)
(9 intermediate revisions by 2 users not shown)
Line 23: Line 23:
|-
|-
|[[#integer|integer]]
|[[#integer|integer]]
|Integral signed integer number.
|32 bit signed integer.
|-
|-
|[[#integer64|integer64]]
|[[#integer64|integer64]]
|Integral signed integer number.
|64 bit signed integer.
|-
|[[#integerNative|integerNative]]
|Signed integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
|-
|-
|[[#unsigned|unsigned]]
|[[#unsigned|unsigned]]
|Integral unsigned integer number.
|32 bit unsigned integer.
|-
|-
|[[#unsigned64|unsigned64]]
|[[#unsigned64|unsigned64]]
|Integral unsigned integer number.
|64 bit unsigned integer.
|-
|[[#unsignedNative|unsignedNative]]
|Unsigned integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
|-
|-
|[[#real|real]]
|[[#real|real]]
Line 94: Line 100:
==== compareResult ====
==== compareResult ====


The compareResult is a built-in domain. It is used to define a comparison result. The built-in [[#compare/2->|compare]] predicate's result is compareResult domain.
The compareResult is a built-in domain. It is used to define a comparison result. The built-in {{lang2|Built-in entities|compare|compare/2->}} predicate's result is compareResult domain.
<vip>domains
<vip>domains
   compareResult = less; equal; greater.
   compareResult = less; equal; greater.
Line 180: Line 186:
<vip>binaryNonAtomic</vip>
<vip>binaryNonAtomic</vip>


Same as [[#binary|binary]], but can contain pointer.
Same as [[#binary|binary]], but can contain pointers because it is scanned by the garbage collector.


==== integer ====
==== integer ====


Integral signed number.
32 bit signed integer.


<vip>integer</vip>
<vip>integer</vip>


Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, [[#div/2->|div]], [[#mod/2->|mod]], [[#quot/2->|quot]], and [[#rem/2->|rem]] operations are applied to values of this domain.
Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, {{lang2|Built-in entities|Operators|div/2->}}, {{lang2|Built-in entities|Operators|mod/2->}}, {{lang2|Built-in entities|Operators|quot/2->}}, and {{lang2|Built-in entities|Operators|rem/2->}} operations are applied to values of this domain.


The permitted number range is from <vp>-2147483648</vp> to <vp>2147483647</vp>.
The permitted number range is from <vp>-2147483648</vp> to <vp>2147483647</vp>.
Line 216: Line 222:
==== integer64 ====
==== integer64 ====


Integral signed number.
64 bit signed integer.


<vip>integer64</vip>
<vip>integer64</vip>
Line 222: Line 228:
Values of this domain occupy 8 bytes.
Values of this domain occupy 8 bytes.


The permitted number range is from <vp>-2^63 = -9,223,372,036,854,775,808</vp> to <vp>2^63-1 = 9,223,372,036,854,775,807</vp>.
The permitted number range is from <vp>-2^63 = -9223372036854775808</vp> to <vp>2^63-1 = 9223372036854775807</vp>.


The syntax for <vp>integer64</vp> literal is the same as <vpbnf><Integer></vpbnf> rule.
The syntax for <vp>integer64</vp> literal is the same as <vpbnf><Integer></vpbnf> rule.


The set of operations for <vp>integer64</vp> is similar to the one for <vpbnf><Integer></vpbnf>.
The set of operations for <vp>integer64</vp> is similar to the one for <vpbnf><Integer></vpbnf>.
==== integerNative ====
Signed integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
<vip>integerNative</vip>


==== unsigned ====
==== unsigned ====


Integral unsigned number.
32 bit unsigned integer.


<vip>unsigned</vip>
<vip>unsigned</vip>


Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, {{lang2|Built-in entities|operators|div/2->}}, {{lang2|Built-in entities|operators|mod/2->}}, {{lang2|Built-in entities|operators|rem/2->}}, and {{lang2|Built-in entities|operators|quot/2->}} operations are applied to values of this domain.
Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, {{lang2|Built-in entities|Operators|div/2->}}, {{lang2|Built-in entities|Operators|mod/2->}}, {{lang2|Built-in entities|Operators|rem/2->}}, and {{lang2|Built-in entities|Operators|quot/2->}} operations are applied to values of this domain.


The permitted number range is from <vp>0</vp> to <vp>4294967295</vp>.
The permitted number range is from <vp>0</vp> to <vp>4294967295</vp>.
Line 242: Line 254:
==== unsigned64 ====
==== unsigned64 ====


Integral unsigned number.
64 bit unsigned integer.


<vip>unsigned64</vip>
<vip>unsigned64</vip>
Line 253: Line 265:


The set of operations for <vp>unsigned64</vp> is similar to the one for <vpbnf><Unsigned></vpbnf>.
The set of operations for <vp>unsigned64</vp> is similar to the one for <vpbnf><Unsigned></vpbnf>.
==== unsignedNative ====
Unsigned integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
<vip>unsignedNative</vip>


==== real ====
==== real ====
Line 336: Line 354:


All user-defined names of facts sections are the constants of this domain. The compiler automatically builds the corresponding compound terms from such constants whenever it's in need. At the runtime the 1st field of this structure contains the address of the corresponding domain descriptor and the 2nd field contains either zero (for class facts sections) or pointer to an object (i.e. <vp>This</vp>, for object facts sections).
All user-defined names of facts sections are the constants of this domain. The compiler automatically builds the corresponding compound terms from such constants whenever it's in need. At the runtime the 1st field of this structure contains the address of the corresponding domain descriptor and the 2nd field contains either zero (for class facts sections) or pointer to an object (i.e. <vp>This</vp>, for object facts sections).
 
<noinclude>{{LanguageReferenceSubarticle|Built-in entities/Domains}}</noinclude>
<noinclude>[[Category:Language Reference Subarticle]]</noinclude>

Revision as of 12:24, 28 September 2017

any Universal term type.
char Wide (two-bytes) character.
string Wide zero-terminated sequence of wide characters.
string8 Zero-terminated sequence of ASCII (one-byte) characters.
symbol Wide zero-terminated sequence of wide characters.
binary Sequence of bytes.
binaryNonAtomic Sequence of bytes.
integer 32 bit signed integer.
integer64 64 bit signed integer.
integerNative Signed integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
unsigned 32 bit unsigned integer.
unsigned64 64 bit unsigned integer.
unsignedNative Unsigned integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
real Float-pointing number.
real32 Float-pointing number.
pointer pointer to a memory address.
handle a handle (e.g. native file and windows handles).
boolean Boolean values.
factDB Descriptors of named internal databases.
compareResult Values of comparison result.

any

Universal term type.

any

The values of this domain are any terms. Such a value contains the reference to the term type library and a term itself.

char

Wide character.

char

The values of this domain are UNICODE characters. Implemented as 2 unsigned bytes.

Only assignment and comparison (in the lexicographical sense) operations are applied to the values of this domain. The image of a character has the following syntax:

Char_image :
      ' Char_value '
Char_value :
      Letter
      Digit
      Graphical_symbol
      \ Escape_seq
Escape_seq:
      t
      n
      r
      \
      '
      "
      u <HHHH>

In the syntax above HHHH correspond to 4 hexadecimal digits. Also, the backslash symbol and the single quote can be represented by an escape-sequence only.

compareResult

The compareResult is a built-in domain. It is used to define a comparison result. The built-in compare/2-> predicate's result is compareResult domain.

domains
   compareResult = less; equal; greater.

string

Wide zero terminated sequence of wide characters.

string

A string is a sequence of UNICODE characters. It's implemented as a pointer to the wide zero-terminated array of wide characters. Only assignment and comparison (in the lexicographical sense) operations are applied to values of this domain.

In source code a string literal can be specified as a set of sequences of characters surrounded by the double quotes.

StringLiteral:
   StringLiteralPart-list
StringLiteralPart :
   @" AnyCharacter-list-opt "
   " CharacterValue-list-opt "

A string literal consists of one or more StringLiteralPart's, which are concatenated. StringLiteralPart's starting with @ does not use escape sequences, whereas StringLiteralPart's without @ uses the following escape sequences:

  • \\ representing \
  • \t representing Tab-character
  • \n representing newline-character
  • \r representing carriage return
  • \' representing single quote
  • \" representing double quote
  • \u followed by exactly four HexadecimalDigit's representing the Unicode character corresponding to the digits.

The double quotes in the string can be represented by the escape-sequence only (the single quote can be represented both with an escape-sequence and a graphical symbol).

string8

A term of the built-in string8 domain is a sequence of ASCII (one-byte) characters. It is implemented as a pointer to the zero terminated array of ASCII characters. Only assignment and comparison for equality (in the lexicographical sense) operations are applied to the values of this domain. Currently no literals are allowed for this domain.

symbol

Wide zero terminated sequence of wide characters.

symbol

Similar to a string, a symbol is also a sequence of the UNICODE characters. It's implemented as a pointer to an entry in a symbol table that contains strings. The operations that can be applied to symbols are the same as for strings.

The image of a symbol is represented with a <string_literal> (any string surrounded by the double quotes).

Symbols and strings are largely interchangeable but they are stored differently. Symbols are kept in a look-up table and their addresses, rather than the symbols themselves, are stored to represent objects. This means that symbols can be matched very quickly and, if a symbol occurs repeatedly in a program, it can be stored very compactly. Strings are not kept in a look-up table. Visual Prolog examines strings character-by-character whenever they are to be matched.

binary

Sequence of N bytes.

binary

Values of this domain are used for holding binary data. A binary value is implemented as a pointer to the sequence of bytes that represents the contents of a binary term.

The length of a binary term is situated in the 4 bytes immediately preceding this sequence of bytes. The 4 bytes contains:

TotalNumberOfBytesOccupiedByBinary = ByteLen + 4

where ByteLen - is the length of the binary term and 4 is number of bytes occupied by size field.

Only assignment and comparison operations are applied to values of binary domain.

Two binary terms are compared in the following way:

  • If they are of different sizes, the bigger is considered larger.
  • Otherwise, they are compared byte by byte, as unsigned values. Comparison stops when two differing bytes are found and the result of their comparison is the result of the comparison of the binary terms. Two binary terms are equal if they have the same sizes and all bytes are equal.

The text syntax for binary images is determined by the Binary rules:

Binary :
       $ [ Byte_value-comma-sep-list-opt ]
Byte_value :
      Expression

Each expression should be calculate on compiling time and its value should be in the range from 0 to 255.

binaryNonAtomic

Sequence of N bytes.

binaryNonAtomic

Same as binary, but can contain pointers because it is scanned by the garbage collector.

integer

32 bit signed integer.

integer

Values of this domain occupy 4 bytes. Arithmetic operations (+, -, /, *, ^), comparison, assignment, div/2->, mod/2->, quot/2->, and rem/2-> operations are applied to values of this domain.

The permitted number range is from -2147483648 to 2147483647.

The syntax for the integer literal is determined by the Integer rule:

Integer :
      Add_operation-opt 0o Oct_number
      Add_operation-opt Dec_number
      Add_operation-opt 0x Hex_number
Add_operation :
      +
      -
Oct_number :
      Oct_digit-list
Oct_digit : one of
      0 1 2 3 4 5 6 7
Dec_number :
      Dec_digit-list
Dec_digit : one of
      Oct_digit 8 9
Hex_number :
      Hex_digit-list
Hex_digit : one of
      Dec_digit a b c d e f A B C D E F

integer64

64 bit signed integer.

integer64

Values of this domain occupy 8 bytes.

The permitted number range is from -2^63 = -9223372036854775808 to 2^63-1 = 9223372036854775807.

The syntax for integer64 literal is the same as Integer rule.

The set of operations for integer64 is similar to the one for Integer.

integerNative

Signed integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).

integerNative

unsigned

32 bit unsigned integer.

unsigned

Values of this domain occupy 4 bytes. Arithmetic operations (+, -, /, *, ^), comparison, assignment, div/2->, mod/2->, rem/2->, and quot/2-> operations are applied to values of this domain.

The permitted number range is from 0 to 4294967295.

The syntax for unsigned number images is the same as for integer numbers. The usage of minus sign (UnaryMinus) is not allowed for an image of an unsigned number.

unsigned64

64 bit unsigned integer.

unsigned64

Values of this domain occupy 8 bytes.

The permitted number range is from 0 to 2^64-1 = 18,446,744,073,709,551,615.

The syntax for unsigned64 number images is the same as for integer64 numbers. The usage of minus sign (UnaryMinus) is not allowed for an image of an unsigned64 number.

The set of operations for unsigned64 is similar to the one for Unsigned.

unsignedNative

Unsigned integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).

unsignedNative

real

Float-pointing number.

real

Values of this domain occupy 8 bytes. This numerical real domain is introduced for the user's convenience only. All arithmetic, comparison, and assignment operations are applied to values of real domain.

The permitted number range is -1.7e+308 to 1.7e+308. Values from integral domains are automatically converted to real numbers when necessary.

The syntax for the floating-point number literal is determined by the Real rule:

Real :
      Add_operation-opt Fraction Exponent-opt
Fraction :
      Dec_number Fractional_part-opt
Fractional_part :
      . Dec_number
Exponent :
      Exp Add_operation-opt Dec_number
Exp :
      e
      E
Add_operation :
      +
      -
Dec_number :
      Dec_digit-list
Dec_digit : one of
      0 1 2 3 4 5 6 7 8 9

real32

Float-pointing number.

real32

Values of this domain occupy 4 bytes. This numerical real32 domain is introduced for the user's convenience only. All arithmetic, comparison, and assignment operations can be applied to values of real32 domain.

The permitted number range is -3.4e+38 to 3.4e+38.

The syntax of real32 literals is the same as real lietrals.

pointer

A pointer to a memory address.

pointer

A pointer directly corresponds to memory addresses. Only the equality operation can be applied to the values of this domain. There is a built-in null constant for this type

handle

A handle is used for Windows API function call. Values of this domain has the same size as a pointer (i.e. 4 on 32bit platfor and 8 on 64bit platform).

There are no operations for this domain and cannot be converted (except uncheckedConvert) to/from other domains.

There is a built-in nullHandle and invalidHandle constant for this type

boolean

Boolean values.

boolean

This domain is introduced for the user convenience only. It is treated as usual compound domain with the following definition:

domains
   boolean = false(); true().

factDB

Descriptors of named internal databases.

factDB

This domain has the following hidden meta-declaration:

domains
   factDB = struct @factdb( named_internal_database_domain, object ).

All user-defined names of facts sections are the constants of this domain. The compiler automatically builds the corresponding compound terms from such constants whenever it's in need. At the runtime the 1st field of this structure contains the address of the corresponding domain descriptor and the 2nd field contains either zero (for class facts sections) or pointer to an object (i.e. This, for object facts sections).