ref: d6a4111c2451b088137d18502cc4b7f8f860d6c5
parent: 0c14bdce7f2c20becd103d0c8d0641a038b5d83b
parent: b98b1cb5d6f7e068de349cbac3d5418c5c174dbe
author: Ori Bernstein <[email protected]>
date: Thu Aug 23 12:43:16 EDT 2012
Merge branch 'master' of git+ssh://mimir.eigenstate.org/git/ori/mc2
--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -43,7 +43,7 @@
The language is composed of several classes of token. There
are comments, identifiers, keywords, punctuation, and whitespace.
-
+
Comments, begin with "/*" and end with "*/". They may nest.
/* this is a comment /* with another inside */ */
@@ -83,8 +83,8 @@
In the compiler, single semicolons (';') , semicolons and newlines (\x10)
characters are treated identically, and are therefore interchangable.
They will both be referred to "endline"s thoughout this manual.
-
+
3. SYNTAX OVERVIEW:
Myrddin syntax will likely have a familiar-but-strange taste
@@ -105,7 +105,7 @@
modified at run time. Constants must have
initializers defined.
var: Declares a variable value. This value may be
- assigned to, copied from, and
+ assigned to, copied from, and
generic: Declares a specializable value. This value
has the same restricitions as a const, but
taking its address is not defined. The type
@@ -125,8 +125,8 @@
and will be inferred:
const x = 123
-
- Declare a variable with no value and no type defined. The
+
+ Declare a variable with no value and no type defined. The
value can be assigned later (and must be assigned before use),
and the type will be inferred.
@@ -216,7 +216,7 @@
eg: {a : int, b
-> a + b
}
-
+
Sequence literals describe either an array or a structure
literal. They begin with a '[', followed by an initializer
sequence and closing ']'. For array literals, the initializer
@@ -239,10 +239,10 @@
eg: (1,), (1,'b',"three")
3.3. Control Constructs and Blocks:
-
+
if for
while match
- goto
+ goto
The control statements in Myrddin are similar to those in many other
popular languages, and with the exception of 'match', there should
@@ -257,10 +257,10 @@
number of declarations, expressions, control constructs, and empty
lines. Every control statement example below will (and, in fact,
must) have a block attached to the control statement.
-
+
If statements branch one way or the other depending on the truth
value of their argument. The truth statement is separated from the
- block body
+ block body
if true
std.put("The program always get here")
@@ -303,7 +303,7 @@
a value to match against.
- Literal patterns
-
+
Any literal value can be matched against.
- Constant patterns
@@ -349,13 +349,13 @@
BUG: There are too many precedence levels.
- Precedence 0: (*ok, not really operators)
+ Precedence 14: (*ok, not really operators)
(,,,) Tuple Construction
(e) Grouping
name Bare names
literal Values
- Precedence 1:
+ Precedence 13:
x.name Member lookup
x++ Postincrement
x-- Postdecrement
@@ -362,7 +362,7 @@
x[e] Index
x[from,to] Slice
- Precedence 2:
+ Precedence 12:
++x Preincrement
--x Predecrement
*x Dereference
@@ -372,33 +372,33 @@
+x Positive (no operation)
-x Negate x
- Precedence 3:
+ Precedence 11:
x << x Shift left
x >> x Shift right
- Precedence 4:
+ Precedence 10:
x * x Multiply
x / x Divide
x % x Modulo
- Precedence 5:
+ Precedence 9:
x + x Add
x - x Subtract
-
- Precedence 6:
+
+ Precedence 8:
x & y Bitwise and
Precedence 7:
x | y Bitwise or
- x ^ y Bitwise or
+ x ^ y Bitwise xor
- Precedence 8:
+ Precedence 6:
`Name x Union construction
- Precedence 9:
+ Precedence 5:
x casttto(type) Cast expression
- Precedence 10:
+ Precedence 4:
x == x Equality
x != x Inequality
x > x Greater than
@@ -406,13 +406,13 @@
x < x Less than
x <= x Less than or equal to
- Precedence 11:
+ Precedence 3:
x && x Logical and
- Precedence 12:
+ Precedence 2:
x || x Logical or
- Precedence 13:
+ Precedence 1:
x = x Assign Right assoc
x += x Fused add/assign Right assoc
x -= x Fused sub/assign Right assoc
@@ -445,7 +445,7 @@
3.5.1. Primitive types:
- void
+ void
bool char
int8 uint8
int16 uint16
@@ -498,7 +498,7 @@
They are reference types that store the length of their
contents. They are declared by appending a '[,]' to the base
type.
-
+
foo* type: pointer to foo
foo[123] type: array of 123 foo
foo[,] type: slice of foo
@@ -528,7 +528,7 @@
struct a struct containing an int named
a : int 'a', and a char named 'b'.
- b : char
+ b : char
;;
union a union containing one of
@@ -567,7 +567,7 @@
named '@foo'.
- 3.6.
+ 3.6.
The myrddin type system is a system similar to the Hindley Milner
system, however, types are not implicitly generalized. Instead, type
@@ -584,15 +584,15 @@
3.6.1 Types for leaf nodes:
- Variable Type
+ Variable Type
----------------------
var foo $t
-
+
A type variable is the most specific type for a declaration
or function without any specified type
var foo : t t
-
+
If a type is specified, that type is taken for the
declaration.
@@ -606,7 +606,7 @@
Char literals are of type 'char'
true bool
- false bool
+ false bool
true/false are boolean literals
@@ -614,7 +614,7 @@
Integer literals get a fresh type variable of type with
the constraints for int-like types.
-
+
123.1 $t::(tcfloat,tcnum,tctest)
Float literals get a fresh type variable of type with
@@ -631,8 +631,8 @@
+ - * / %
+= -= *= /= %
- Number binops require the constraint 'tcnum' for both the
-
+ Number binops require the constraint 'tcnum' for both the
+
num-unary:
- +
Number binops require the constraint 'tcnum'.
@@ -710,7 +710,7 @@
-> 0
}
- TODO: DESCRIBE CONSTRUCTS.
+ TODO: DESCRIBE CONSTRUCTS.
5.2. Conditions
@@ -729,7 +729,7 @@
std.put("The max of %i, %i is %i\n", x, y, max(x, y))
}
- TODO: DESCRIBE CONSTRUCTS.
+ TODO: DESCRIBE CONSTRUCTS.
5.3. Looping
@@ -746,8 +746,8 @@
std.put("The inner product is %i\n", innerprod([1,2,3], [4,5,6]))
}
- TODO: DESCRIBE CONSTRUCTS.
-
+ TODO: DESCRIBE CONSTRUCTS.
+
6. STYLE GUIDE:
6.1. Brevity:
@@ -767,13 +767,13 @@
to what the function does. For functions, a single verb is ideal. For
local variables, a single character might suffice. Compact notation
is simpler to read, typographically.
-
+
Variables names should describe the value contained, and function
names should describe the value returned.
Good: spawn(myfunc)
Bad: create_new_thread_starting_at_function(myfunc)
-
+
The identifiers used for constant values are put in Initialcase.
Functions and types are in singleword style, although underscores are
occasionally necessary to specify additional information within
@@ -801,7 +801,7 @@
6.3. Collections:
-
+
7. STANDARD LIBRARY: