Константы — различия между версиями

Материал из Compilers Wiki
Перейти к: навигация, поиск
 
Строка 5: Строка 5:
 
   | $IDENT        # Глобальный символ
 
   | $IDENT        # Глобальный символ
  
 +
В [[QBE | промежуточном языке]] константы задаются с помощью единого синтаксиса и семантики. Константы используются явно, непосредственно в инструкциях; нет необходимости в команде «загрузки константы» (из памяти).
 +
<pre>Throughout the IL, constants are specified with a unified syntax and semantics. Constants are immediates, meaning that they can be used directly in instructions; there is no need for a "load constant" instruction.</pre>
  
Throughout the IL, constants are specified with a unified syntax and semantics. Constants are immediates, meaning that they can be used directly in instructions; there is no need for a "load constant" instruction.
+
Представление целых чисел является [https://ru.wikipedia.org/wiki/Дополнительный_код дополнительным кодом]. Числа с плавающей запятой представлены с использованием одноточечных и двухточечных форматов стандарта [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754].
 +
<pre>The representation of integers is two's complement. Floating-point numbers are represented using the single-precision and double-precision formats of the IEEE 754 standard.</pre>
  
The representation of integers is two's complement. Floating-point numbers are represented using the single-precision and double-precision formats of the IEEE 754 standard.
+
Константы определяют последовательность бит и являются нетипизированными. Они всегда анализируются как 64-битные блобы (прим. примерно тоже самое, что кластер). В зависимости от контекста, окружающего константу, могут использоваться только некоторые из ее битов. Например, в приведенной ниже программе обе указанные переменные имеют одинаковое значение, так как первый операнд вычитания представляет собой w - word (32-бит) контекст.
 
+
<pre>Constants specify a sequence of bits and are untyped. They are always parsed as 64-bit blobs. Depending on the context surrounding a constant, only some of its bits are used. For example, in the program below, the two variables defined have the same value since the first operand of the subtraction is a word (32-bit) context.</pre>
Constants specify a sequence of bits and are untyped. They are always parsed as 64-bit blobs. Depending on the context surrounding a constant, only some of its bits are used. For example, in the program below, the two variables defined have the same value since the first operand of the subtraction is a word (32-bit) context.
 
  
 
  %x =w sub -1, 0
 
  %x =w sub -1, 0
 
  %y =w sub 4294967295, 0
 
  %y =w sub 4294967295, 0
  
Because specifying floating-point constants by their bits makes the code less readable, syntactic sugar is provided to express them. Standard scientific notation is prefixed with s_ and d_ for single and double precision numbers respectively. Once again, the following example defines twice the same double-precision constant.
+
Поскольку указание констант с плавающей запятой на их биты делает код менее читаемым, то для их выражения предоставляется [https://ru.wikipedia.org/wiki/Синтаксический_сахар синтаксический сахар]. Стандартная экспоненциальная запись имеет префикс <code>s_</code> и <code>d_</code> для чисел с одной и двумя точками соответственно. Следующий пример определяет дважды ту же константу с двойной точностью.
 +
<pre>Because specifying floating-point constants by their bits makes the code less readable, syntactic sugar is provided to express them. Standard scientific notation is prefixed with s_ and d_ for single and double precision numbers respectively. Once again, the following example defines twice the same double-precision constant.</pre>
  
 
  %x =d add d_0, d_-1
 
  %x =d add d_0, d_-1
 
  %y =d add d_0, -4616189618054758400
 
  %y =d add d_0, -4616189618054758400
Global symbols can also be used directly as constants; they will be resolved and turned into actual numeric constants by the linker.
+
 
 +
Глобальные символы также могут использоваться непосредственно как константы; они будут разрешены и превращены в фактические числовые константы компоновщиком.
 +
<pre>Global symbols can also be used directly as constants; they will be resolved and turned into actual numeric constants by the linker.</pre>

Текущая версия на 16:44, 24 марта 2018

CONST :=
   ['-'] NUMBER  # Десятичное целое число
 | 's_' FP       # Число одинарной точности
 | 'd_' FP       # Число двойной точности
 | $IDENT        # Глобальный символ

В промежуточном языке константы задаются с помощью единого синтаксиса и семантики. Константы используются явно, непосредственно в инструкциях; нет необходимости в команде «загрузки константы» (из памяти).

Throughout the IL, constants are specified with a unified syntax and semantics. Constants are immediates, meaning that they can be used directly in instructions; there is no need for a "load constant" instruction.

Представление целых чисел является дополнительным кодом. Числа с плавающей запятой представлены с использованием одноточечных и двухточечных форматов стандарта IEEE 754.

The representation of integers is two's complement. Floating-point numbers are represented using the single-precision and double-precision formats of the IEEE 754 standard.

Константы определяют последовательность бит и являются нетипизированными. Они всегда анализируются как 64-битные блобы (прим. примерно тоже самое, что кластер). В зависимости от контекста, окружающего константу, могут использоваться только некоторые из ее битов. Например, в приведенной ниже программе обе указанные переменные имеют одинаковое значение, так как первый операнд вычитания представляет собой w - word (32-бит) контекст.

Constants specify a sequence of bits and are untyped. They are always parsed as 64-bit blobs. Depending on the context surrounding a constant, only some of its bits are used. For example, in the program below, the two variables defined have the same value since the first operand of the subtraction is a word (32-bit) context.
%x =w sub -1, 0
%y =w sub 4294967295, 0

Поскольку указание констант с плавающей запятой на их биты делает код менее читаемым, то для их выражения предоставляется синтаксический сахар. Стандартная экспоненциальная запись имеет префикс s_ и d_ для чисел с одной и двумя точками соответственно. Следующий пример определяет дважды ту же константу с двойной точностью.

Because specifying floating-point constants by their bits makes the code less readable, syntactic sugar is provided to express them. Standard scientific notation is prefixed with s_ and d_ for single and double precision numbers respectively. Once again, the following example defines twice the same double-precision constant.
%x =d add d_0, d_-1
%y =d add d_0, -4616189618054758400

Глобальные символы также могут использоваться непосредственно как константы; они будут разрешены и превращены в фактические числовые константы компоновщиком.

Global symbols can also be used directly as constants; they will be resolved and turned into actual numeric constants by the linker.