poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITED] doc: Add new example to the tutorial


From: Mohammad-Reza Nabipoor
Subject: [COMMITED] doc: Add new example to the tutorial
Date: Sun, 14 Mar 2021 02:02:30 +0330

2021-03-14  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>

        * doc/learn-poke-language-in-y-minutes.pk: Add a new example of
        using both constraints and initializers in fields.
---
 ChangeLog                               |  5 +++++
 doc/learn-poke-language-in-y-minutes.pk | 12 ++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a3111dd3..080456cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-14  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>
+
+       * doc/learn-poke-language-in-y-minutes.pk: Add a new example of
+       using both constraints and initializers in fields.
+
 2021-03-13  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/pkl-tab.y (struct_type_field): Adapt to
diff --git a/doc/learn-poke-language-in-y-minutes.pk 
b/doc/learn-poke-language-in-y-minutes.pk
index e96ba3b3..c72a78e7 100644
--- a/doc/learn-poke-language-in-y-minutes.pk
+++ b/doc/learn-poke-language-in-y-minutes.pk
@@ -507,9 +507,17 @@ type HeaderWithInit =
 var hdrauto = HeaderWithInit {};
 /* hdrauto.magic == 100UB && hdrauto.version == 3UB */
 
-/* The only limitation is that we cannot specify a constraint for initialized
- * fields.
+/* It is also possible to specify both a constraint and an initializer in
+ * the same field.
  */
+type HeaderMagicVersion =
+  struct
+  {
+    uint<8> magic : magic in [0xaaUB, 0x55UB] = 0x55UB;
+    uint<8> version = 2UB : version in [1UB, 2UB];
+  };
+var hdrmagver = HeaderMagicVersion {};
+/* hdrmagver.magic == 0x55UB && hdrmagver.version == 0x2UB */
 
 
 /* Integral Structs
-- 
2.30.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]