ref: fb9332b1d5f80d242c0ba5dec47805f4d85495a7
parent: 27ca8d448e65696f0194fe9f7f367ddc6ba3a00b
author: Ori Bernstein <[email protected]>
date: Fri Aug 10 20:05:41 EDT 2012
Rearrange sections.
--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -10,14 +10,13 @@
3.1. Declarations
3.2. Literal Values
3.3. Control Constructs and Blocks
- 3.4. Data Types
- 3.5. Packages and Uses
- 3.6. Expressions
- 4. TYPE SYSTEM
- 5. TOOLCHAIN
- 6. EXAMPLES
- 7. STYLE GUIDE
- 8. FUTURE DIRECTIONS
+ 3.4. Expressions
+ 3.5. Data Types
+ 3.6. Packages and Uses
+ 4. TOOLCHAIN
+ 5. EXAMPLES
+ 6. STYLE GUIDE
+ 7. FUTURE DIRECTIONS
1. OVERVIEW:
@@ -275,9 +274,106 @@
and increments. They run the test on every iteration of the loop,
and
+ 3.4. Expressions:
- 3.4. Data Types:
+ Myrddin expressions are relatively similar to expressions in C. 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.
+ BUG: There are too many precedence levels.
+
+
+ Precedence 0: (*ok, not really operators)
+ (,,,) Tuple Construction
+ (e) Grouping
+ name Bare names
+ literal Values
+
+ Precedence 1:
+ x.name Member lookup
+ x++ Postincrement
+ x-- Postdecrement
+ x[e] Index
+ x[from,to] Slice
+
+ Precedence 2:
+ ++x Preincrement
+ --x Predecrement
+ *x Dereference
+ &x Address
+ !x Logical negation
+ ~x Bitwise negation
+ +x Positive (no operation)
+ -x Negate x
+
+ Precedence 3:
+ x << x Shift left
+ x >> x Shift right
+
+ Precedence 4:
+ x * x Multiply
+ x / x Divide
+ x % x Modulo
+
+ Precedence 5:
+ x + x Add
+ x - x Subtract
+
+ Precedence 6:
+ x & y Bitwise and
+
+ Precedence 7:
+ x | y Bitwise or
+ x ^ y Bitwise or
+
+ Precedence 8:
+ `Name x Union construction
+
+ Precedence 9:
+ x casttto(type) Cast expression
+
+ Precedence 10:
+ 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 11:
+ x && x Logical and
+
+ Precedence 12:
+ x || x Logical or
+
+ Precedence 13:
+ x = x Assign Right assoc
+ x += x Fused add/assign Right assoc
+ x -= x Fused sub/assign Right assoc
+ x *= x Fused mul/assign Right assoc
+ x /= x Fused div/assign Right assoc
+ x %= x Fused mod/assign Right assoc
+ x |= x Fused or/assign Right assoc
+ x ^= x Fused xor/assign Right assoc
+ x &= x Fused and/assign Right assoc
+ x <<= x Fused shl/assign Right assoc
+ x >>= x Fused shr/assign Right assoc
+
+ Precedence 14:
+ -> x Return expression
+
+ All expressions on integers act on complement-two values which wrap
+ on overflow. Right shift expressions fill with the sign bit on
+ signed types, and fill with zeros on unsigned types.
+
+
+
+ 3.5. Data Types:
+
The language defines a number of built in primitive types. These
are not keywords, and in fact live in a separate namespace from
the variable names. Yes, this does mean that you could, if you want,
@@ -287,7 +383,7 @@
must be explicitly cast if you want to convert, and the casts must
be of compatible types, as will be described later.
- 3.4.1. Primitive types:
+ 3.5.1. Primitive types:
void
bool char
@@ -322,7 +418,7 @@
var y : float32 declare y as a 32 bit float
- 3.4.2. Composite types:
+ 3.5.2. Composite types:
pointer
slice array
@@ -346,7 +442,7 @@
foo[123] type: array of 123 foo
foo[,] type: slice of foo
- 3.4.3. Aggregate types:
+ 3.5.3. Aggregate types:
tuple struct
union
@@ -380,7 +476,7 @@
;;
- 3.4.4. Magic types:
+ 3.5.4. Magic types:
tyvar typaram
tyname
@@ -409,10 +505,36 @@
@foo creates a type parameter
named '@foo'.
- 3.4.5. :
- 3.6. Packages and Uses:
+ 3.6.
+ The myrddin type system is a system similar to the Hindley Milner
+ system, however, types are not implicitly generalized. Instead, type
+ schemes (type parameters, in Myrddin lingo) must be explicitly provided
+ in the declarations. For purposes of brevity, instead of specifying type
+ rules for every operator, we group operators which behave identically
+ from the type system perspective into a small set of classes. and define
+ the constraints that they require.
+
+ num-binop:
+ + - * / %
+ += -= *= /= %
+ num-unary:
+ - +
+
+ int-binop:
+ | & ^ << >>
+ |= &= ^= <<= >>
+ int-unary:
+ ~ ++ --
+
+ bool-binop:
+ || && == !=
+ < <= > >=
+
+
+ 3.7. Packages and Uses:
+
pkg use
There are two keywords for module system. 'use' is the simpler
@@ -453,127 +575,7 @@
them in the body of the code for readability. Scanning the export
list is desirable from a readability perspective.
- 3.7. Expressions:
-
- Myrddin expressions are relatively similar to expressions in C. 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.
-
- BUG: There are too many precedence levels.
-
-
- Precedence 0: (*ok, not really operators)
- (,,,) Tuple Construction
- (e) Grouping
- name Bare names
- literal Values
-
- Precedence 1:
- x.name Member lookup
- x++ Postincrement
- x-- Postdecrement
- x[e] Index
- x[from,to] Slice
-
- Precedence 2:
- ++x Preincrement
- --x Predecrement
- *x Dereference
- &x Address
- !x Logical negation
- ~x Bitwise negation
- +x Positive (no operation)
- -x Negate x
-
- Precedence 3:
- x << x Shift left
- x >> x Shift right
-
- Precedence 4:
- x * x Multiply
- x / x Divide
- x % x Modulo
-
- Precedence 5:
- x + x Add
- x - x Subtract
-
- Precedence 6:
- x & y Bitwise and
-
- Precedence 7:
- x | y Bitwise or
- x ^ y Bitwise or
-
- Precedence 8:
- `Name x Union construction
-
- Precedence 9:
- x casttto(type) Cast expression
-
- Precedence 10:
- 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 11:
- x && x Logical and
-
- Precedence 12:
- x || x Logical or
-
- Precedence 13:
- x = x Assign Right assoc
- x += x Fused add/assign Right assoc
- x -= x Fused sub/assign Right assoc
- x *= x Fused mul/assign Right assoc
- x /= x Fused div/assign Right assoc
- x %= x Fused mod/assign Right assoc
- x |= x Fused or/assign Right assoc
- x ^= x Fused xor/assign Right assoc
- x &= x Fused and/assign Right assoc
- x <<= x Fused shl/assign Right assoc
- x >>= x Fused shr/assign Right assoc
-
- Precedence 14:
- -> x Return expression
-
- All expressions on integers act on complement-two values which wrap
- on overflow. Right shift expressions fill with the sign bit on
- signed types, and fill with zeros on unsigned types.
-
4. TYPE SYSTEM:
-
- The myrddin type system is a system similar to the Hindley Milner
- system, however, types are not implicitly generalized. Instead, type
- schemes (type parameters, in Myrddin lingo) must be explicitly provided
- in the declarations. For purposes of brevity, instead of specifying type
- rules for every operator, we group operators which behave identically
- from the type system perspective into a small set of classes. and define
- the constraints that they require.
-
- num-binop:
- + - * / %
- += -= *= /= %
- num-unary:
- - +
-
- int-binop:
- | & ^ << >>
- |= &= ^= <<= >>
- int-unary:
- ~ ++ --
-
- bool-binop:
- || && == !=
- < <= > >=
5. TOOLCHAIN:
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -595,7 +595,6 @@
| forstmt
| whilestmt
| matchstmt
- | Tendln {$$ = NULL;}
;
forstmt : Tfor optexprln optexprln optexprln block
@@ -659,12 +658,8 @@
;
blockbody
- : stmt
- {$$ = mkblock(line, mkstab());
- if ($1)
- lappend(&$$->block.stmts, &$$->block.nstmts, $1);
- if ($1 && $1->type == Ndecl)
- putdcl($$->block.scope, $1);}
+ : /* empty */
+ {$$ = mkblock(line, mkstab());}
| blockbody stmt
{if ($2)
lappend(&$1->block.stmts, &$1->block.nstmts, $2);
@@ -671,6 +666,8 @@
if ($2 && $2->type == Ndecl)
putdcl($1->block.scope, $2);
$$ = $1;}
+ | blockbody Tendln
+ {$$ = $1;}
;
label : Tcolon Tident