ref: 7c884e9cb6c97c99a6d3310da3feb473b15ba02a
parent: dd99ac66ac4c14eea361b2b60f91a4907b4c44d2
author: Ori Bernstein <[email protected]>
date: Fri Oct 12 12:12:29 EDT 2012
Move towards compiling the option parsing code.
--- a/libstd/option.myr
+++ b/libstd/option.myr
@@ -1,10 +1,12 @@
+use "types.use"
+use "alloc.use"
use "utf.use"
pkg std =
type optctx = struct
/* data passed in */
- opts : byte[:][:]
opts : byte[:]
+ args : byte[:][:]
/* state */
optidx : size
@@ -31,7 +33,7 @@
const optnext = {ctx
var c
- if !curopt.len
+ if !ctx.curopt.len
if !nextopt(ctx)
-> Badchar
;;
@@ -44,10 +46,11 @@
var i
for i = ctx.optidx + 1; i < ctx.optidx.len; i++
- if decode(ctx.opts[i]) == '-'
+ if decode(ctx.args[i]) == '-'
goto foundopt
else
- ctx.args = slappend(ctx.args,
+ /* FIXME: implement slappend */
+ /* ctx.args = slappend(ctx.args, ctx.args[i]) */
;;
;;
:foundopt
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -129,7 +129,7 @@
%type <tydef> tydef typeid
-%type <node> exprln retexpr expr atomicexpr littok literal asnexpr lorexpr landexpr borexpr
+%type <node> exprln retexpr goto expr atomicexpr littok literal asnexpr lorexpr landexpr borexpr
%type <node> bandexpr cmpexpr unionexpr addexpr mulexpr shiftexpr prefixexpr postfixexpr
%type <node> funclit seqlit name block stmt label use
%type <node> decl declbody declcore structelt seqelt tuphead
@@ -404,6 +404,10 @@
{$$ = NULL;}
;
+goto : Tgoto Tident
+ {$$ = mkexpr($1->line, Ojmp, mklbl($2->line, $2->str), NULL);}
+ ;
+
retexpr : Tret expr
{$$ = mkexpr($1->line, Oret, $2, NULL);}
| expr
@@ -625,6 +629,7 @@
;
stmt : decl
+ | goto
| retexpr
| label
| ifstmt
@@ -704,7 +709,7 @@
;
label : Tcolon Tident
- {$$ = mklbl($1->line, $1->str);}
+ {$$ = mklbl($2->line, $2->str);}
;
%%
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -741,12 +741,16 @@
static void inferseq(Inferstate *st, Node *n)
{
size_t i;
+ Type *t;
+ Node *len;
+ len = mkintlit(n->line, n->lit.nelt);
+ t = mktyarray(n->line, mktyvar(n->line), len);
for (i = 0; i < n->lit.nelt; i++) {
infernode(st, n->lit.seqval[i], NULL, NULL);
- unify(st, n, type(st, n->lit.seqval[0]), type(st, n->lit.seqval[i]));
+ unify(st, n, t->sub[0], type(st, n->lit.seqval[i]));
}
- settype(st, n, mktyarray(n->line, type(st, n->lit.seqval[0]), mkintlit(n->line, n->lit.nelt)));
+ settype(st, n, t);
}
static void inferpat(Inferstate *st, Node *n, Node *val, Node ***bind, size_t *nbind)