summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-01-14 13:57:54 -0800
committerOri Bernstein <ori@eigenstate.org>2018-01-14 13:57:54 -0800
commit72958419b4fb70531051e05e2ca56ecccc524b6b (patch)
tree44057d5a8ee4ed777a2296ba462f502cf52a1bfe
parente7ebda38777e5251b3479c3fdced4cb108f252e4 (diff)
downloadmc-72958419b4fb70531051e05e2ca56ecccc524b6b.tar.gz
Update language spec for new trait syntax.
-rw-r--r--doc/lang.txt66
-rw-r--r--parse/gram.y18
2 files changed, 42 insertions, 42 deletions
diff --git a/doc/lang.txt b/doc/lang.txt
index c1507dd..459ac50 100644
--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -190,7 +190,8 @@ TABLE OF CONTENTS:
3.3. Declarations:
- decl: attrs ("var" | "const" | "generic") decllist
+ decl: attrs declkind decllist [traitspec]
+ declkind: ("var" | "const" | "generic")
attrs: ("extern" | "pkglocal" | "$noret")*
decllist: declbody ("," declbody)*
declbody: declcore ["=" expr]
@@ -530,9 +531,7 @@ TABLE OF CONTENTS:
4.3. Generic types:
- typaram: "@" ident ["::" paramlist]
- paramlist: ident | "(" ident ("," ident)* ")"
-
+ typaram: "@" ident
A nametype refers to a (potentially parameterized) named type, as
defined in section 4.5.
@@ -591,7 +590,7 @@ TABLE OF CONTENTS:
4.4.2. Impls:
- implstmt: "impl" ident impltypes "=" implbody
+ implstmt: "impl" ident impltypes traitspec "=" implbody
impltypes: type ["->" type ("," type)*]
implbody: (name [":" type] "=" expr)*
@@ -637,8 +636,8 @@ TABLE OF CONTENTS:
specific type that represents them.
- Types are freshened. Freshening is the process of replacing
unbound type parameters with type variables, such that
- '@a::(integral,numeric)' is replaced with the type variable
- '$n::(integral,numeric)'.
+ '@a :: integral @a, numeric @a' is replaced with the type variable
+ '$n :: integral $n, numeric $n'.
- Union tags are registered for delayed unification, with the type
for unions being the declaration type of the variable.
@@ -782,8 +781,8 @@ TABLE OF CONTENTS:
a single pass suffices.
At this point, default types are applied. An unconstrained type
- with type $t::(numeric,integral) is replaced with int. An
- unconstrained type with $t::(numeric,floating) is replaced with
+ with type $t :: numeric $t, integral $t is replaced with int. An
+ unconstrained type with $t :: numeric $t, floating $t is replaced with
flt64.
4.6. Built In Traits:
@@ -950,7 +949,7 @@ TABLE OF CONTENTS:
e.g. 0x123_fff, 0b1111, 0o777, 1234
- They have the type `@a::(numeric,integral)
+ They have the type `@a :: numeric @a, integral @a
5.1.1.4: Boolean Literals:
@@ -980,7 +979,7 @@ TABLE OF CONTENTS:
e.g. 123.456, 10.0e7, 1_000.
- They have type `@a::(numeric,floating)`
+ They have type `@a :: numeric @a, floating @a`
5.1.2. Sequence and Tuple Literals:
@@ -1043,7 +1042,8 @@ TABLE OF CONTENTS:
5.1.3. Function Literals:
- funclit: "{" arglist ["->" rettype] "\n" blockbody "}"
+ funclit: "{" arglist ["->" rettype] [traitspec] "\n"
+ blockbody "}"
arglist: (ident [":" type])*
Function literals describe a function. They begin with a '{',
@@ -1461,8 +1461,7 @@ TABLE OF CONTENTS:
Type:
- ( e1 : @a OP e2 : @a ) : bool
- where @a :: numeric
+ ( e1 : @a OP e2 : @a ) : bool :: numeric @a
5.2.11. Union Constructors:
@@ -1488,8 +1487,7 @@ TABLE OF CONTENTS:
Type:
- (e1 : @a OP e2:@a) : @a
- where @a :: integral
+ (e1 : @a OP e2:@a) : @a :: integral @a
5.2.13. Addition:
@@ -1503,8 +1501,7 @@ TABLE OF CONTENTS:
Type:
- ( e1 : @a OP e2 : @a ) : bool
- where @a :: numeric
+ ( e1 : @a OP e2 : @a ) : bool :: numeric @a
5.2.14. Multiplication and Division
@@ -1516,8 +1513,7 @@ TABLE OF CONTENTS:
Type:
- ( e1 : @a OP e2 : @a ) : bool
- where @a :: numeric
+ ( e1 : @a OP e2 : @a ) : bool :: numeric @a
5.2.15. Modulo:
@@ -1528,8 +1524,7 @@ TABLE OF CONTENTS:
Type:
- ( e1 : @a OP e2 : @a ) : bool
- where @a :: (numeric,integral)
+ ( e1 : @a OP e2 : @a ) : bool :: numeric @a, integral @a
5.2.16. Shift:
@@ -1545,8 +1540,7 @@ TABLE OF CONTENTS:
Type:
- (e1 : @a OP e2:@a) : @a
- where @a :: integral
+ (e1 : @a OP e2:@a) : @a :: integral @a
5.2.17: Postincrement, Postdecrement:
@@ -1570,7 +1564,7 @@ TABLE OF CONTENTS:
(e1++ : @a) : @a
(e1-- : @a) : @a
- where @a :: integral
+ :: integral @a
5.2.18: Address:
@@ -1636,7 +1630,7 @@ TABLE OF CONTENTS:
(expr : <aggregate>).name : @a
(expr : <seq>).len : @idx
- where @idx :: (integral,numeric)
+ :: integral @a, numeric @a
5.2.22: Index:
@@ -1653,7 +1647,7 @@ TABLE OF CONTENTS:
(expr : @a[N])[(idx : @idx)] : @a
(expr : @a[:])[(idx : @idx)] : @a
- where @idx :: (integral,numeric)
+ :: integral, numeric @idx
5.2.23: Slice:
@@ -1675,8 +1669,7 @@ TABLE OF CONTENTS:
(expr : @a[N])[(lo : @lo) : (hi : @hi)] : @a[:]
(expr : @a[:])[(lo : @lo) : (hi : @hi)] : @a[:]
(expr : @#)[(lo : @lo) : (hi : @hi)] : @a[:]
- where @lo :: (integral,numeric)
- and @hi :: (integral,numeric)
+ :: integral, numeric @lo, integral, numeric @hi
5.2.24: Call:
@@ -1960,21 +1953,23 @@ TABLE OF CONTENTS:
pkgbody: (decl | attrs tydef | traitdef | impldef)*
/* declarations */
- decl: attrs ("var" | "const" | "generic") decllist
+ decl: attrs ("var" | "const" | "generic") decllist
attrs: ("$noret" | "extern" | "pkglocal")*
decllist: declbody ("," declbody)+
declbody: declcore ["=" expr]
declcore: ident [":" type]
/* traits */
- traitdef: "trait" ident typaram [auxtypes] ("\n" | "=" traitbody ";;")
+ traitdef: "trait" ident typaram [auxtypes] [traitspec] ("\n" | "=" traitbody ";;")
auxtypes: "->" type ("," type)*
traitbody: "\n"* (ident ":" type "\n"*)*
- impldef: "impl" ident type [auxtypes] ("\n" | "=" implbody ";;")
+ impldef: "impl" ident type [auxtypes] [traitspec] ("\n" | "=" implbody ";;")
implbody: "\n"* (ident [":" type] "=" expr "\n"*)*
/* types */
- tydef: "type" typeid "=" type
+ traitspec: "::" traitvar+
+ traitvar: name+ type ["->" type]
+ tydef: "type" typeid [traitspec] "=" type
typeid: ident | ident "(" typarams ")"
typarams: typaram ("," typaram)*
type: structdef | uniondef | tupledef |
@@ -1984,8 +1979,7 @@ TABLE OF CONTENTS:
uniondef: "union" unionbody ";;"
unionbody: ("`" ident [type])*
tupledef: "(" type ("," type)* ")"
- generic: typaram ["::" traitlist]
- traitlist: name | "(" name ("," name)
+ generic: typaram
constructed: functype | sicetype | arraytype | ptrtype | void | name
functype: "(" arglist "->" type ")"
arglist: [arg ("," arg)*]
@@ -2024,7 +2018,7 @@ TABLE OF CONTENTS:
/* literals */
literal: funclit | seqlit | tuplit | simplelit
- funclit: "{" [funcargs] ";" blockbody "}"
+ funclit: "{" [funcargs] [traitspec] "\n" blockbody "}"
funcargs: ident [ ":" type] ("," ident [ ":" type])*
seqlit: "[" structelts | [arrayelts] "]"
arrayelts: arrayelt ("," arrayelt)*
diff --git a/parse/gram.y b/parse/gram.y
index f9fa892..5c73295 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -1114,7 +1114,8 @@ label : Tcolon Tident {
%%
-static void setupinit(Node *n)
+static void
+setupinit(Node *n)
{
char name[1024];
char *p, *s;
@@ -1136,7 +1137,8 @@ static void setupinit(Node *n)
n->decl.name->name.name = strdup(s);
}
-static Node *mkpseudodecl(Srcloc l, Type *t)
+static Node *
+mkpseudodecl(Srcloc l, Type *t)
{
static int nextpseudoid;
char buf[128];
@@ -1145,7 +1147,8 @@ static Node *mkpseudodecl(Srcloc l, Type *t)
return mkdecl(l, mkname(l, buf), t);
}
-static void setattrs(Node *dcl, char **attrs, size_t nattrs)
+static void
+setattrs(Node *dcl, char **attrs, size_t nattrs)
{
size_t i;
@@ -1159,7 +1162,8 @@ static void setattrs(Node *dcl, char **attrs, size_t nattrs)
}
}
-static void setwith(Type *ty, Traitspec **ts, size_t nts)
+static void
+setwith(Type *ty, Traitspec **ts, size_t nts)
{
size_t i, j;
@@ -1201,7 +1205,8 @@ static void setwith(Type *ty, Traitspec **ts, size_t nts)
}
}
-static void installucons(Stab *st, Type *t)
+static void
+installucons(Stab *st, Type *t)
{
Type *b;
size_t i;
@@ -1227,7 +1232,8 @@ static void installucons(Stab *st, Type *t)
}
-static Op binop(int tt)
+static Op
+binop(int tt)
{
Op o;