summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-01-17 23:43:31 -0800
committerOri Bernstein <ori@eigenstate.org>2017-01-17 23:43:31 -0800
commit74c20890c23bd5047330e52c062f9fa10ede6e7f (patch)
treed756515dea3b1dbef569fa26d95ca567362c0b31 /doc
parent10c5a7f3c6bd6d8c52a42f3d7ffb64eed6edf677 (diff)
downloadmc-74c20890c23bd5047330e52c062f9fa10ede6e7f.tar.gz
Add description of casts.
Diffstat (limited to 'doc')
-rw-r--r--doc/lang.txt347
1 files changed, 241 insertions, 106 deletions
diff --git a/doc/lang.txt b/doc/lang.txt
index 4e9abab..a70067e 100644
--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -534,93 +534,234 @@ TABLE OF CONTENTS:
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.
-
- Precedence 12:
- x.name Member lookup
- x++ Postincrement
- x-- Postdecrement
- x# Dereference
- x[e] Index
- x[lo:hi] Slice
- x(arg,list) Call
-
- Precedence 11:
- ++x Preincrement
- --x Predecrement
- &x Address
- !x Logical negation
- ~x Bitwise negation
- +x Positive (no operation)
- -x Negate x
-
- Precedence 10:
- x << y Shift left
- x >> y Shift right
-
- Precedence 9:
- x * y Multiply
- x / y Divide
- x % y Modulo
-
- Precedence 8:
- x + y Add
- x - y Subtract
-
- Precedence 7:
- x & y Bitwise and
-
- Precedence 6:
- x | y Bitwise or
- x ^ y Bitwise xor
-
- Precedence 5:
- `Name x Union construction
-
- 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 3:
- x && y Logical and
-
- 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
-
- 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.
+ 4.6.1. Summary and Precedence:
+
+ expr: expr <binop> expr | prefixexpr | postfixexpr
+ postfixexpr: <prefixop> postfixexpr
+ prefixexpr: atomicexpr <unaryop>
+
+ 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 13:
+ x Atomic expression
+ literal Atomic expression
+ (expr) Atomic expression
+
+ Precedence 12:
+ x.name Member lookup
+ x++ Postincrement
+ x-- Postdecrement
+ x# Dereference
+ x[e] Index
+ x[lo:hi] Slice
+ x(arg,list) Call
+
+ Precedence 11:
+ ++x Preincrement
+ --x Predecrement
+ &x Address
+ !x Logical negation
+ ~x Bitwise negation
+ +x Positive (no operation)
+ -x Negate x
+
+ Precedence 10:
+ x << y Shift left
+ x >> y Shift right
+
+ Precedence 9:
+ x * y Multiply
+ x / y Divide
+ x % y Modulo
+
+ Precedence 8:
+ x + y Add
+ x - y Subtract
+
+ Precedence 7:
+ x & y Bitwise and
+
+ Precedence 6:
+ x | y Bitwise or
+ x ^ y Bitwise xor
+
+ Precedence 5:
+ `Name x Union construction
+
+ 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 3:
+ x && y Logical and
+
+ 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,21 +769,12 @@ TABLE OF CONTENTS:
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 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 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.
- 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 quoted form searches the current directory for a use file named
+ "localpkg" and imports it.
The 'pkg' keyword allows you to define a (partial) package by
listing the symbols and types for export. For example,
@@ -660,6 +792,9 @@ TABLE OF CONTENTS:
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 @@ TABLE OF CONTENTS:
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 @@ TABLE OF CONTENTS:
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.