aboutsummaryrefslogtreecommitdiff
path: root/doc/sphinx
diff options
context:
space:
mode:
authorAna2020-12-01 08:52:12 +0000
committerAna2021-02-26 13:32:41 +0000
commit4302a75d82b9ac983cd89dd01c742c36777d921b (patch)
tree8f6f437bb65bc3534e7f0f9851cdb05627ec885e /doc/sphinx
parent15074f171cdf250880bd0f7a2806356040c89f36 (diff)
Signed primitive integers
Signed primitive integers defined on top of the existing unsigned ones with two's complement. The module Sint63 includes the theory of signed primitive integers that differs from the unsigned case. Additions to the kernel: les (signed <=), lts (signed <), compares (signed compare), divs (signed division), rems (signed remainder), asr (arithmetic shift right) (The s suffix is not used when importing the Sint63 module.) The printing and parsing of primitive ints was updated and the int63_syntax_plugin was removed (we use Number Notation instead). A primitive int is parsed / printed as unsigned or signed depending on the scope. In the default (Set Printing All) case, it is printed in hexadecimal.
Diffstat (limited to 'doc/sphinx')
-rw-r--r--doc/sphinx/language/core/primitive.rst17
-rw-r--r--doc/sphinx/user-extensions/syntax-extensions.rst23
2 files changed, 35 insertions, 5 deletions
diff --git a/doc/sphinx/language/core/primitive.rst b/doc/sphinx/language/core/primitive.rst
index 4505fc4b4d..7211d00dd0 100644
--- a/doc/sphinx/language/core/primitive.rst
+++ b/doc/sphinx/language/core/primitive.rst
@@ -8,15 +8,20 @@ Primitive Integers
The language of terms features 63-bit machine integers as values. The type of
such a value is *axiomatized*; it is declared through the following sentence
-(excerpt from the :g:`Int63` module):
+(excerpt from the :g:`PrimInt63` module):
.. coqdoc::
Primitive int := #int63_type.
-This type is equipped with a few operators, that must be similarly declared.
-For instance, equality of two primitive integers can be decided using the :g:`Int63.eqb` function,
-declared and specified as follows:
+This type can be understood as representing either unsigned or signed integers,
+depending on which module is imported or, more generally, which scope is open.
+:g:`Int63` and :g:`int63_scope` refer to the unsigned version, while :g:`Sint63`
+and :g:`sint63_scope` refer to the signed one.
+
+The :g:`PrimInt63` module declares the available operators for this type.
+For instance, equality of two unsigned primitive integers can be determined using
+the :g:`Int63.eqb` function, declared and specified as follows:
.. coqdoc::
@@ -25,7 +30,9 @@ declared and specified as follows:
Axiom eqb_correct : forall i j, (i == j)%int63 = true -> i = j.
-The complete set of such operators can be obtained looking at the :g:`Int63` module.
+The complete set of such operators can be found in the :g:`PrimInt63` module.
+The specifications and notations are in the :g:`Int63` and :g:`Sint63`
+modules.
These primitive declarations are regular axioms. As such, they must be trusted and are listed by the
:g:`Print Assumptions` command, as in the following example.
diff --git a/doc/sphinx/user-extensions/syntax-extensions.rst b/doc/sphinx/user-extensions/syntax-extensions.rst
index 609884ce1d..03571ad680 100644
--- a/doc/sphinx/user-extensions/syntax-extensions.rst
+++ b/doc/sphinx/user-extensions/syntax-extensions.rst
@@ -1741,6 +1741,12 @@ Number notations
sorts, primitive integers, primitive floats, primitive arrays and type
constants for primitive types) will be considered for printing.
+ .. note::
+ For example, :n:`@qualid__type` can be :n:`PrimInt63.int`,
+ in which case :n:`@qualid__print` takes :n:`PrimInt63.int_wrapper` as input
+ instead of :n:`PrimInt63.int`. See below for an
+ :ref:`example <example-number-notation-primitive-int>`.
+
.. _number-string-via:
:n:`via @qualid__ind mapping [ {+, @qualid__constant => @qualid__constructor } ]`
@@ -2066,6 +2072,23 @@ The following errors apply to both string and number notations:
Check 3.
+.. _example-number-notation-primitive-int:
+
+.. example:: Number Notation for primitive integers
+
+ This shows the use of the primitive
+ integers :n:`PrimInt63.int` as :n:`@qualid__type`. It is the way
+ parsing and printing of primitive integers are actually implemented
+ in `PrimInt63.v`.
+
+ .. coqtop:: in reset
+
+ Require Import Int63.
+ Definition parser (x : pos_neg_int63) : option int :=
+ match x with Pos p => Some p | Neg _ => None end.
+ Definition printer (x : int_wrapper) : pos_neg_int63 := Pos (int_wrap x).
+ Number Notation int parser printer : int63_scope.
+
.. _example-number-notation-non-inductive:
.. example:: Number Notation for a non inductive type