shithub: mc

Download patch

ref: 95f8b3d8a134c32f3c62eeab364c67f29e7542e3
parent: b8b34577b7f5e7c4fa13f927103c80dc417c64d9
author: Ori Bernstein <[email protected]>
date: Sat Jun 30 18:54:21 EDT 2012

More work towards getting sequence literals to work.

--- a/parse/gram.y
+++ b/parse/gram.y
@@ -127,13 +127,13 @@
 %type <node> exprln retexpr expr atomicexpr littok literal asnexpr lorexpr landexpr borexpr
 %type <node> bandexpr cmpexpr unionexpr addexpr mulexpr shiftexpr prefixexpr postfixexpr
 %type <node> funclit seqlit name block blockbody stmt label use
-%type <node> decl declbody declcore structelt
+%type <node> decl declbody declcore structelt seqelt
 %type <node> ifstmt forstmt whilestmt matchstmt elifs optexprln
 %type <node> pat unionpat match
 %type <node> castexpr
 %type <ucon> unionelt
 
-%type <nodelist> arglist argdefs structbody params matches
+%type <nodelist> arglist argdefs structbody params matches seqbody
 %type <uconlist> unionbody
 
 %union {
@@ -519,18 +519,23 @@
         ;
 
 seqlit  : Tosqbrac seqbody Tcsqbrac
-            {$$ = NULL; die("Unimpl seqlit");}
+            {$$ = mkarray($1->line, $2.nl, $2.nn);}
         ;
 
 seqbody : seqelt
+            {$$.nl = NULL; $$.nn = 0;
+             lappend(&$$.nl, &$$.nn, $1);}
         | seqbody Tcomma seqelt
+             {lappend(&$$.nl, &$$.nn, $3);}
         ;
 
-seqelt  : Tdot Tident Tasn expr
-        | Thash atomicexpr Tasn expr
-        | expr
-        | Tendln seqelt
-        | seqelt Tendln
+seqelt  : Tdot Tident Tasn expr 
+            {die("Unimplemented struct member init");}
+        | Thash atomicexpr Tasn expr 
+            {die("Unimplmented array member init");}
+        | expr {$$ = $1;}
+        | Tendln seqelt {$$ = $2;}
+        | seqelt Tendln {$$ = $1;}
         ;
 
 stmt    : decl
--- a/parse/node.c
+++ b/parse/node.c
@@ -208,6 +208,15 @@
     return n;
 }
 
+Node *mkarray(int line, Node **vals, size_t nvals)
+{
+    Node *n;
+
+    n = NULL;
+    die("Yeah, I need an array repr...");
+    return n;
+}
+
 Node *mkname(int line, char *name)
 {
     Node *n;
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -1,3 +1,5 @@
+#define FATAL __attribute__((noreturn))
+
 typedef uint8_t         byte;
 typedef uint32_t        unichar;
 typedef unsigned int    uint;
@@ -159,6 +161,7 @@
         struct {
             Littype littype;
             Type    *type;
+            size_t   nelt;
             union {
                 uvlong   intval;
                 double   fltval;
@@ -190,7 +193,7 @@
         } matchstmt;
 
         struct {
-            Node *pat; /* literal expr. FIXME: this isn't an appropriate type */
+            Node *pat;
             Node *block;
         } match;
 
@@ -282,8 +285,8 @@
 void *xalloc(size_t size);
 void *zrealloc(void *p, size_t oldsz, size_t size);
 void *xrealloc(void *p, size_t size);
-void  die(char *msg, ...);
-void  fatal(int line, char *fmt, ...);
+void  die(char *msg, ...) FATAL;
+void  fatal(int line, char *fmt, ...) FATAL;
 char *strdupn(char *s, size_t len);
 char *strjoin(char *u, char *v);
 void *memdup(void *mem, size_t len);
@@ -298,6 +301,7 @@
 
 void putns(Stab *st, Stab *scope);
 void puttype(Stab *st, Node *n, Type *ty);
+void putcstr(Stab *st, Node *n, Cstr *cstr);
 void updatetype(Stab *st, Node *n, Type *t);
 void putdcl(Stab *st, Node *dcl);
 void putucon(Stab *st, Ucon *uc);
@@ -305,6 +309,7 @@
 Stab *getns(Stab *st, Node *n);
 Node *getdcl(Stab *st, Node *n);
 Type *gettype(Stab *st, Node *n);
+Cstr *getcstr(Stab *st, Node *n);
 Ucon *getucon(Stab *st, Node *n);
 
 Stab *curstab(void);
@@ -358,7 +363,7 @@
 Node *mkstr(int line, char *s);
 Node *mkfloat(int line, double flt);
 Node *mkfunc(int line, Node **args, size_t nargs, Type *ret, Node *body);
-Node *mkarray(int line, Node **vals);
+Node *mkarray(int line, Node **vals, size_t nvals);
 Node *mkname(int line, char *name);
 Node *mknsname(int line, char *ns, char *name);
 Node *mkdecl(int line, Node *name, Type *ty);
--- /dev/null
+++ b/test/arraylit-ni.myr
@@ -1,0 +1,4 @@
+const main = {
+	var a = [1, 3, 2]
+	-> a[2]
+}
--- a/test/tests
+++ b/test/tests
@@ -46,6 +46,7 @@
 B matchargunion	E	69
 B matchbind	E	8
 B arraylit	E	3
+B arraylit-ni	E	3
 B structlit	E	42
 F declmismatch
 F infermismatch