shithub: mc

Download patch

ref: 74c20890c23bd5047330e52c062f9fa10ede6e7f
parent: 10c5a7f3c6bd6d8c52a42f3d7ffb64eed6edf677
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jan 17 18:43:31 EST 2017

Add description of casts.

--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -534,94 +534,235 @@
 
     4.6. Expressions:
 
-	Myrddin expressions should be fairly familiiar to most programmers.
-	The operators are listed below in order of precedence, and a short
-	summary of what they do is listed given. For the sake of clarity, 'x'
-	will stand in for any expression composed entirely of subexpressions
-	with higher precedence than the current current operator. 'e' will
-	stand in for any expression. Unless marked otherwise, expressions are
-	left associative.
+	4.6.1. Summary and Precedence:
 
-            Precedence 12:
-                x.name          Member lookup
-                x++             Postincrement
-                x--             Postdecrement
-                x#              Dereference
-                x[e]            Index
-                x[lo:hi]        Slice
-		x(arg,list)	Call
+		expr:		expr <binop> expr | prefixexpr | postfixexpr
+		postfixexpr:	<prefixop> postfixexpr
+		prefixexpr:	atomicexpr <unaryop>
 
-            Precedence 11:
-                ++x             Preincrement
-                --x             Predecrement
-                &x              Address
-                !x              Logical negation
-                ~x              Bitwise negation
-                +x              Positive (no operation)
-                -x              Negate x
+	    Myrddin expressions should be fairly familiiar to most programmers.
+	    The operators are listed below in order of precedence, and a short
+	    summary of what they do is listed given. For the sake of clarity, 'x'
+	    will stand in for any expression composed entirely of subexpressions
+	    with higher precedence than the current current operator. 'e' will
+	    stand in for any expression. Unless marked otherwise, expressions are
+	    left associative.
 
-            Precedence 10:
-                x << y          Shift left
-                x >> y          Shift right
+	    Precedence 13:
+		    x		    Atomic expression
+		    literal	    Atomic expression
+		    (expr)	    Atomic expression
 
-            Precedence 9:
-                x * y           Multiply
-                x / y           Divide
-                x % y           Modulo
+	    Precedence 12:
+		    x.name          Member lookup
+		    x++             Postincrement
+		    x--             Postdecrement
+		    x#              Dereference
+		    x[e]            Index
+		    x[lo:hi]        Slice
+		    x(arg,list)	Call
 
-            Precedence 8:
-                x + y           Add
-                x - y           Subtract
+	    Precedence 11:
+		    ++x             Preincrement
+		    --x             Predecrement
+		    &x              Address
+		    !x              Logical negation
+		    ~x              Bitwise negation
+		    +x              Positive (no operation)
+		    -x              Negate x
 
-            Precedence 7:
-                x & y           Bitwise and
+	    Precedence 10:
+		    x << y          Shift left
+		    x >> y          Shift right
 
-            Precedence 6:
-                x | y           Bitwise or
-                x ^ y           Bitwise xor
+	    Precedence 9:
+		    x * y           Multiply
+		    x / y           Divide
+		    x % y           Modulo
 
-            Precedence 5:
-                `Name x         Union construction
+	    Precedence 8:
+		    x + y           Add
+		    x - y           Subtract
 
-            Precedence 4:
-                x == x          Equality
-                x != x          Inequality
-                x > x           Greater than
-                x >= x          Greater than or equal to
-                x < x           Less than
-                x <= x          Less than or equal to
+	    Precedence 7:
+		    x & y           Bitwise and
 
-            Precedence 3:
-                x && y          Logical and
+	    Precedence 6:
+		    x | y           Bitwise or
+		    x ^ y           Bitwise xor
 
-            Precedence 2:
-                x || y          Logical or
+	    Precedence 5:
+		    `Name x         Union construction
 
-            Precedence 1:
-                x = y           Assign                  Right assoc
-                x += y          Fused add/assign        Right assoc
-                x -= y          Fused sub/assign        Right assoc
-                x *= y          Fused mul/assign        Right assoc
-                x /= y          Fused div/assign        Right assoc
-                x %= y          Fused mod/assign        Right assoc
-                x |= y          Fused or/assign         Right assoc
-                x ^= y          Fused xor/assign        Right assoc
-                x &= y          Fused and/assign        Right assoc
-                x <<= y         Fused shl/assign        Right assoc
-                x >>= y         Fused shr/assign        Right assoc
+	    Precedence 4:
+		    x == x          Equality
+		    x != x          Inequality
+		    x > x           Greater than
+		    x >= x          Greater than or equal to
+		    x < x           Less than
+		    x <= x          Less than or equal to
 
-            Precedence 0:
-                -> x            Return expression
+	    Precedence 3:
+		    x && y          Logical and
 
-	All expressions on integers act on two's complement values which wrap
-	on overflow. Right shift expressions fill with the sign bit on signed
-	types, and fill with zeros on unsigned types.
+	    Precedence 2:
+		    x || y          Logical or
 
+	    Precedence 1:
+		    x = y           Assign                  Right assoc
+		    x += y          Fused add/assign        Right assoc
+		    x -= y          Fused sub/assign        Right assoc
+		    x *= y          Fused mul/assign        Right assoc
+		    x /= y          Fused div/assign        Right assoc
+		    x %= y          Fused mod/assign        Right assoc
+		    x |= y          Fused or/assign         Right assoc
+		    x ^= y          Fused xor/assign        Right assoc
+		    x &= y          Fused and/assign        Right assoc
+		    x <<= y         Fused shl/assign        Right assoc
+		    x >>= y         Fused shr/assign        Right assoc
 
+	    Precedence 0:
+		    -> x            Return expression
+
+	4.6.2. Atomic Expressions:
+	    
+                atomicexpr:     ident | gap | literal | "(" expr ")" | 
+                                "sizeof" "(" type ")" | castexpr
+                castexpr:       "(" expr ":" type ")"
+                gap:            "_"
+
+            Atomic expressions are the building blocks of expressions, and
+            are either parenthesized expressions or directly represent
+            literals. Literals are covered in depth in section 4.2.
+
+            An identifier specifies a variable, and are looked up via
+            the scoping rules specified in section 4.9.
+
+            Gap expressions (`_`) represent an anonymous sink value. Anything
+            can be assigned to a gap, and it may be used in pattern matching.
+            It is equivalent to creating a new temporary that is never read
+            from whenever it is used. For example:
+
+                _ = 123
+
+            is equivalent to:
+                
+                var anon666 = 123
+
+            In match contexts, it is equivalent to a fresh variable in the
+            match, again, given that it is never read from in the body of the
+            match.
+
+
+        4.6.3. Cast Expressions:
+
+            Cast expressions convert a value from one type to another.
+            Casting proceeds according to the following rules:
+
+
+                SType   DType        Action
+                -------------------------------------------------------------
+                int/int Conversions
+                -------------------------------------------------------------
+                intN    intK        If n < k, sign extend the source
+                                    type, filling the top bits with the
+                                    sign bit of the source until it is the
+                                    same width as the destination type.
+
+                                    if n > k, truncate the top bits of the
+                                    source to the width of the destination
+                                    type.
+
+                uintN  uintK        If n < k, zero extend the source
+                                    type, filling the top bits with zero
+                                    until it is the same width as the
+                                    destination type.
+
+                                    If n > k, truncate the top bits of the
+                                    source to the width of the destination
+                                    type.
+                -------------------------------------------------------------
+                int/float conversions
+                -------------------------------------------------------------
+                intN    fltN        The closest representable integer value
+                                    to the source should be stored in the
+                                    destination.
+
+                uintN   fltN        The closest representable integer value
+                                    to the source should be stored in the
+                                    destination.
+
+                fltN    intN        The closest representable integer value
+                                    to the source should be stored in the
+                                    destination.
+
+                fltN    uintN       The closest representable integer value
+                                    to the source should be stored in the
+                                    destination.
+                -------------------------------------------------------------
+                int/pointer conversions
+                -------------------------------------------------------------
+                intN   T#           Extend the source value to the width
+                                    of a pointer in bits in an implementation
+                                    defined manner.
+
+                uintN  T#           Extend the source value to the width
+                                    of a pointer in bits in an implementation
+                                    defined manner.
+
+                T#     intN         Convert the address of the pointer to an
+                                    integer in an implementation specified
+                                    manner. There should exist at least one
+                                    integer type for which this conversion
+                                    will round trip.
+
+                T#     uintN        Convert the address of the pointer to an
+                                    integer in an implementation specified
+                                    manner. There should exist at least one
+                                    integer type for which this conversion
+                                    will round trip.
+                -------------------------------------------------------------
+                pointer/pointer conversions
+                -------------------------------------------------------------
+                T#      U#          If the destination type has compatible
+                                    alignment and other storage requirements,
+                                    the pointer should be converted losslessly
+                                    and in a round-tripping manner to point to
+                                    a U. If it does not have compatible
+                                    requirements, the conversion is not
+                                    required to round trip safely, but should
+                                    still produce a valid pointer.
+                -------------------------------------------------------------
+                pointer/slice conversions
+                -------------------------------------------------------------
+                T[:]    T#          Returns a pointer to t[0]
+                -------------------------------------------------------------
+                pointer/function conversions
+                -------------------------------------------------------------
+                (args->ret)   T#    Returns a pointer to an implementation
+                                    specific value representing the executable
+                                    code for the function.
+
+
+
+	4.6.4. Assignment:
+
+	4.6.5. Bitwise Expressions:
+
+	4.6.6: Arithmetic Expressons:
+
+        4.6.7: Postfix Expressiosn:
+
+        4.6.8: Prefix Expressions
+
+
     4.8. Packages and Uses:
 
-            pkg     use
+	    bareuse:	use ident
+	    quoteuse:	use "<quoted string>"
+	    pkgdef:	"pkg" ident = decl* ";;"
 
+
         There are two keywords for module system. 'use' is the simpler
         of the two, and has two cases:
 
@@ -628,22 +769,13 @@
             use syspkg
             use "localfile"
 
-        The unquoted form searches all system include paths for 'syspkg'
-        and imports it into the namespace. By convention, the namespace
-        defined by 'syspkg' is 'syspkg', and is unique and unmerged. This
-        is not enforced, however. Typical usage of unquoted names is to
-        import a library that already exists.
+	The first form, which does not have the package name quoted, will
+	search the system include paths for the package listed. It does not
+	search relative to the file or the compiler working directory.
 
-        The quoted form searches the local directory for "localpkg".  By
-        convention, the package it imports does not match the name
-        "localpkg", but instead is used as partial of the definition of the
-        importers package. This is a confusing description.
+        The quoted form searches the current directory for a use file named
+	"localpkg" and imports it.
 
-        A typical use of a quoted import is to allow splitting one package
-        into multiple files. In order to support this behavior, if a package
-        is defined in the current file, and a use statements imports a
-        package with the same namespace, the two namespaces are merged.
-
         The 'pkg' keyword allows you to define a (partial) package by
         listing the symbols and types for export. For example,
 
@@ -660,6 +792,9 @@
         them in the body of the code for readability. Scanning the export
         list is desirable from a readability perspective.
 
+    4.9. Scoping and Namespaces:
+
+
 5. TYPES:
 
     5.1. Data Types:
@@ -685,11 +820,11 @@
                     long            ulong
                     float32         float64
 
-                These types are as you would expect. 'void' represents a
-                lack of type, although for the sake of genericity, you can
-                assign between void types, return values of void, and so on.
-                This allows generics to not have to somehow work around void
-                being a toxic type. The void value is named `void`.
+		'void' is a type and a value  although for the sake of
+		genericity, you can assign between void types, return values
+		of void, and so on.  This allows generics to not have to
+		somehow work around void being a toxic type. The void value is
+		named `void`.
 
                 It is interesting to note that these types are not keywords,
                 but are instead merely predefined identifiers in the type
@@ -699,10 +834,10 @@
                 assigned, tested for equality, and used in the various boolean
                 operators.
 
-                char is a 32 bit integer type, and is guaranteed to be able
-                to hold exactly one codepoint. It can be assigned integer
-                literals, tested against, compared, and all the other usual
-                numeric types.
+		char is a 32 bit integer type, and is guaranteed to hold
+		exactly one Unicode codepoint. It can be assigned integer
+		literals, tested against, compared, and all the other usual
+		numeric types.
 
                 The various [u]intXX types hold, as expected, signed and
                 unsigned integers of the named sizes respectively.