shithub: mc

Download patch

ref: 545d75324d8ad1d9f8f9977b0911e8e9e0704674
parent: d6bd40e37b085aec922c6bb56e867e85a6c36982
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 4 18:00:27 EST 2017

Ucons are now prefix expressions.

	It's just what it looks like. This cleans up taking
	the address of union literals.

--- a/doc/lang.txt
+++ b/doc/lang.txt
@@ -1927,8 +1927,7 @@
     expr:       lorepxr asnop expr | lorexpr
     lorexpr:    lorexpr "||" landexpr | landexpr
     landexpr:   landexpr "&&" cmpexpr | cmpexpr
-    cmpexpr:    cmpexpr ("<" | "<=" | "==" | ">=" | ">") unionexpr | unionexpr
-    unionexpr:  "`" name unionexpr | "`" name | borexpr
+    cmpexpr:    cmpexpr ("<" | "<=" | "==" | ">=" | ">") borexprexpr | borexpr
     borexpr:    borexpr ("|" | "^" ) bandexpr | bandexpr
     bandexpr:   bandexpr "&" addexpr | addexpr
     addexpr:    addexpr ("+" | "-") mulexpr
@@ -1942,8 +1941,10 @@
                 postexpr "++" | postexpr "--" |
                 postexpr "[" expr "]" |
                 postexpr "[" [expr] ":" [expr] "]" |
+                "`" name postexpr | "`" name
                 postepxr "#" |
                 atomicexpr
+
     atomicexpr: ident | literal | "(" expr ")" | "sizeof" "(" type ")"
 
     /* literals */
--- a/lib/date/zoneinfo+posixy.myr
+++ b/lib/date/zoneinfo+posixy.myr
@@ -71,7 +71,7 @@
 	;;
 	ds = zone.ttinfo[zone.timetype[i]].gmtoff
 	free(zone)
-	->  `std.Some (ds : date.duration) * 1_000_000
+	->  `std.Some ((ds : date.duration) * 1_000_000)
 }
 
 const load = {file
--- a/lib/std/fltparse.myr
+++ b/lib/std/fltparse.myr
@@ -27,8 +27,8 @@
 
 	match fltparse(str)
 	| `Badflt:	-> `std.None
-	| `Inf sign:	-> `std.Some (sign : flt64) * std.flt64inf()
-	| `Nan sign:	-> `std.Some (sign : flt64) * std.flt64nan()
+	| `Inf sign:	-> `std.Some ((sign : flt64) * std.flt64inf())
+	| `Nan sign:	-> `std.Some ((sign : flt64) * std.flt64nan())
 	| `Flt (sign, mant, exp):
 		val = toflt(sign, mant, exp, &lim64)
 		std.bigfree(mant)
@@ -41,8 +41,8 @@
 
 	match fltparse(str)
 	| `Badflt:	-> `std.None
-	| `Inf sign:	-> `std.Some (sign : flt32) * std.flt32inf()
-	| `Nan sign:	-> `std.Some (sign : flt32) * std.flt32nan()
+	| `Inf sign:	-> `std.Some ((sign : flt32) * std.flt32inf())
+	| `Nan sign:	-> `std.Some ((sign : flt32) * std.flt32nan())
 	| `Flt (sign, mant, exp):
 		val = toflt(sign, mant, exp, &lim32)
 		std.bigfree(mant)
--- a/lib/std/readall.myr
+++ b/lib/std/readall.myr
@@ -22,5 +22,5 @@
 			-> `Err e
 		;;
 	;;
-	-> `Ok sz - dst.len
+	-> `Ok (sz - dst.len)
 }
--- a/lib/std/syswrap+posixy.myr
+++ b/lib/std/syswrap+posixy.myr
@@ -156,7 +156,7 @@
 	if r >= 0
 		sec = (sb.mtime.sec : time)
 		nsec = (sb.mtime.nsec : time)
-		-> `Ok sec*1000 + nsec/1_000_000
+		-> `Ok (sec*1000 + nsec/1_000_000)
 	else
 		-> check(r)
 	;;
--- a/lib/std/test/search.myr
+++ b/lib/std/test/search.myr
@@ -5,13 +5,13 @@
 const main = {
 
 	expect(std.lsearch(sl[:], 1, std.numcmp), `std.Some 0)
-	expect(std.lsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
+	expect(std.lsearch(sl[:], 33, std.numcmp), `std.Some (sl.len - 1))
 	expect(std.lsearch(sl[:], 5, std.numcmp), `std.Some 2)
 	expect(std.lsearch(sl[:], 6, std.numcmp), `std.None)
 	expect(std.lsearch(sl[:0], 6, std.numcmp), `std.None)
 
 	expect(std.bsearch(sl[:], 1, std.numcmp), `std.Some 0)
-	expect(std.bsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
+	expect(std.bsearch(sl[:], 33, std.numcmp), `std.Some (sl.len - 1))
 	expect(std.bsearch(sl[:], 5, std.numcmp), `std.Some 2)
 	expect(std.bsearch(sl[:], 6, std.numcmp), `std.None)
 	expect(std.bsearch(sl[:0], 1, std.numcmp), `std.None)	/* empty slice */
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -140,7 +140,7 @@
 
 %type<node> exprln retexpr goto continue break expr atomicexpr
 %type<node> littok literal lorexpr landexpr borexpr strlit bandexpr
-%type<node> cmpexpr unionexpr addexpr mulexpr shiftexpr prefixexpr
+%type<node> cmpexpr addexpr mulexpr shiftexpr prefixexpr
 %type<node> postfixexpr funclit seqlit tuplit name block stmt label
 %type<node> use fnparam declbody declcore typedeclcore structent
 %type<node> arrayelt structelt tuphead ifstmt forstmt whilestmt
@@ -384,7 +384,7 @@
 	}
 	;
 
-traitdef: Ttrait Tident generictype optauxtypes Tendln { /* trait prototype */
+traitdef: Ttrait Tident generictype optauxtypes { /* trait prototype */
 		$$ = mktrait($1->loc,
 			mkname($2->loc, $2->id), $3,
 			$4.types, $4.ntypes,
@@ -639,20 +639,14 @@
 	| cmpexpr
 	;
 
-cmpexpr : cmpexpr cmpop unionexpr
+cmpexpr : cmpexpr cmpop borexpr
 	{$$ = mkexpr($1->loc, binop($2->type), $1, $3, NULL);}
-	| unionexpr
+	| borexpr
 	;
 
 cmpop   : Teq | Tgt | Tlt | Tge | Tle | Tne ;
 
-unionexpr
-	: Ttick name unionexpr {$$ = mkexpr($1->loc, Oucon, $2, $3, NULL);}
-	| Ttick name {$$ = mkexpr($1->loc, Oucon, $2, NULL);}
-	| borexpr
-	;
 
-
 borexpr : borexpr Tbor bandexpr
 	{$$ = mkexpr($1->loc, binop($2->type), $1, $3, NULL);}
 	| borexpr Tbxor bandexpr
@@ -696,6 +690,8 @@
 	| Tbnot prefixexpr     {$$ = mkexpr($1->loc, Obnot, $2, NULL);}
 	| Tminus prefixexpr    {$$ = mkexpr($1->loc, Oneg, $2, NULL);}
 	| Tplus prefixexpr     {$$ = $2;} /* positive is a nop */
+	| Ttick name prefixexpr {$$ = mkexpr($1->loc, Oucon, $2, $3, NULL);}
+	| Ttick name {$$ = mkexpr($1->loc, Oucon, $2, NULL);}
 	| postfixexpr
 	;
 
--- a/test/exporttrait.myr
+++ b/test/exporttrait.myr
@@ -2,6 +2,7 @@
 
 pkg =
 	trait t @a
+
 	impl t int
 ;;