shithub: mc

Download patch

ref: 763b93301675ced644ce16f645102c2bc0357ea3
parent: da5bfc6d15a50130afdcd37ed9af737a81724506
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 9 15:50:57 EST 2016

Moving mparse to another directory for development.

diff: cannot open a/mparse//null: file does not exist: 'a/mparse//null'
--- a/mparse/ast.myr
+++ /dev/null
@@ -1,10 +1,0 @@
-use std
-
-use "types.use"
-use "tokdefs.use"
-use "tok.use"
-use "util.use"
-
-pkg parse =
-;;
-
--- a/mparse/bld.proj
+++ /dev/null
@@ -1,11 +1,0 @@
-bin tok =
-	ast.myr
-	dump.myr
-	main.myr
-	parse.myr
-	stab.myr
-	tok.myr
-	tokdefs.myr
-	types.myr
-	util.myr
-;;
--- a/mparse/dump.myr
+++ /dev/null
@@ -1,181 +1,0 @@
-use std
-
-use "types.use"
-use "util.use"
-
-pkg parse =
-;;
-
-const __init__ = {
-	var f : file
-	var d : dcl
-	var st : stab
-	var e : expr
-
-	std.fmtinstall(std.typeof(&f), fmtfile, [][:])
-	std.fmtinstall(std.typeof(&d), fmtdcl, [][:])
-	std.fmtinstall(std.typeof(&e), fmtexpr, [][:])
-	std.fmtinstall(std.typeof(&st), fmtstab, [][:])
-}
-
-const fmtfile = {sb, ap, opts
-	var f : file#
-	f = std.vanext(ap)
-	filedump(sb, f, 0)
-}
-
-const fmtdcl = {sb, ap, opts
-	var f : dcl#
-	f = std.vanext(ap)
-	dcldump(sb, f, 0)
-}
-
-const fmtstab = {sb, ap, opts
-	var f : stab#
-	f = std.vanext(ap)
-	stabdump(sb, f, 0)
-}
-
-const fmtexpr = {sb, ap, opts
-	var f : expr#
-	f = std.vanext(ap)
-	exprdump(sb, f)
-}
-
-
-const filedump = {sb, f, ind
-	ifmt(sb, ind, "file: {}\n", f.path)
-	for u in f.uses
-		match u
-		| `Ulocal l:	ifmt(sb, ind + 1, "local-use:\t{}\n", l)
-		| `Ulib l:	ifmt(sb, ind + 1, "lib-use:\t{}\n", l)
-		;;
-	;;
-	ifmt(sb, ind, "libs: {}\n", f.extlibs)
-	ifmt(sb, ind, "extlibs: {}\n", f.extlibs)
-
-	for i in f.extinit
-		dcldump(sb, i, ind + 1)
-	;;
-
-	match f.init
-	| `std.Some d:	dcldump(sb, d, ind + 1)
-	| `std.None:
-	;;
-
-	stabdump(sb, f.builtin, ind + 1)
-	stabdump(sb, f.globls, ind + 1)
-
-	for s in f.dcls
-		dcldump(sb, s, ind + 1)
-	;;
-}
-
-const dcldump = {sb, dcl, ind
-	ifmt(sb, ind, "{}: {} {}: {}\t", dcl.id, dcl.vis, dcl.name, dcl.ty)
-	ifmt(sb, ind + 2, "globl:{}, const:{}, noret:{}, init:{}, exportinit:{}\n", \
-		dcl.isglobl, dcl.isconst, dcl.isnoret, dcl.isinit, dcl.isexportinit)
-	ifmt(sb, ind + 2, "extern:{}, import:{}, hidden:{}, pkglocal:{}, generic:{}\n", \
-		dcl.isextern, dcl.isimport, dcl.ishidden, dcl.ispkglocal, dcl.isgeneric)
-	ifmt(sb, ind + 1, "{}", dcl.init)
-}
-
-const exprdump = {sb, e
-	match e#
-	| [.e = `Oadd (a, b)]:	std.sbfmt(sb, "{} + {}", a, b)
-	| [.e = `Osub (a, b)]:	std.sbfmt(sb, "{} - {}", a, b)
-	| [.e = `Omul (a, b)]:	std.sbfmt(sb, "{} * {}", a, b)
-	| [.e = `Odiv (a, b)]:	std.sbfmt(sb, "{} / {}", a, b)
-	| [.e = `Omod (a, b)]:	std.sbfmt(sb, "{} % {}", a, b)
-	| [.e = `Oneg exp]:	std.sbfmt(sb, "-{}", exp)
-	| [.e = `Obor (a, b)]:	std.sbfmt(sb, "{} | {}", a, b)
-	| [.e = `Oband (a, b)]:	std.sbfmt(sb, "{} & {}", a, b)
-	| [.e = `Obxor (a, b)]:	std.sbfmt(sb, "{} ^ {}", a, b)
-	| [.e = `Obsl (a, b)]:	std.sbfmt(sb, "{} << {}", a, b)
-	| [.e = `Obsr (a, b)]:	std.sbfmt(sb, "{} >> {}", a, b)
-	| [.e = `Obnot exp]:	std.sbfmt(sb, "~{}", exp)
-	| [.e = `Opreinc exp]:	std.sbfmt(sb, "++{}", exp)
-	| [.e = `Opostinc exp]:	std.sbfmt(sb, "{}++", exp)
-	| [.e = `Opredec exp]:	std.sbfmt(sb, "++{}", exp)
-	| [.e = `Opostdec exp]:	std.sbfmt(sb, "{}--", exp)
-	| [.e = `Oaddr exp]:	std.sbfmt(sb, "&{}", exp)
-	| [.e = `Oderef exp]:	std.sbfmt(sb, "{}#", exp)
-	| [.e = `Olor (a, b)]:	std.sbfmt(sb, "{} || {}", a, b)
-	| [.e = `Oland (a, b)]:	std.sbfmt(sb, "{} && {}", a, b)
-	| [.e = `Olnot exp]:	std.sbfmt(sb, "!{}", exp)
-	| [.e = `Oeq (a, b)]:	std.sbfmt(sb, "{} == {}", a, b)
-	| [.e = `One (a, b)]:	std.sbfmt(sb, "{} != {}", a, b)
-	| [.e = `Ogt (a, b)]:	std.sbfmt(sb, "{} > {}", a, b)
-	| [.e = `Oge (a, b)]:	std.sbfmt(sb, "{} >= {}", a, b)
-	| [.e = `Olt (a, b)]:	std.sbfmt(sb, "{} < {}", a, b)
-	| [.e = `Ole (a, b)]:	std.sbfmt(sb, "{} <= {}", a, b)
-	| [.e = `Oasn (a, b)]:	std.sbfmt(sb, "{} = {}", a, b)
-	| [.e = `Oaddeq (a, b)]:	std.sbfmt(sb, "{} += {}", a, b)
-	| [.e = `Osubeq (a, b)]:	std.sbfmt(sb, "{} -= {}", a, b)
-	| [.e = `Omuleq (a, b)]:	std.sbfmt(sb, "{} *= {}", a, b)
-	| [.e = `Odiveq (a, b)]:	std.sbfmt(sb, "{} /= {}", a, b)
-	| [.e = `Omodeq (a, b)]:	std.sbfmt(sb, "{} %= {}", a, b)
-	| [.e = `Oboreq (a, b)]:	std.sbfmt(sb, "{} |= {}", a, b)
-	| [.e = `Obandeq (a, b)]:	std.sbfmt(sb, "{} &= {}", a, b)
-	| [.e = `Obxoreq (a, b)]:	std.sbfmt(sb, "{} ^= {}", a, b)
-	| [.e = `Obsleq (a, b)]:	std.sbfmt(sb, "{} <<= {}", a, b)
-	| [.e = `Obsreq (a, b)]:	std.sbfmt(sb, "{} >>= {}", a, b)
-	| [.e = `Oidx (a, b)]:	std.sbfmt(sb, "{}[{}]", a, b)
-	| [.e = `Oslice (a, b, c)]:	std.sbfmt(sb, "{}[{} : {}]", a, b, c)
-	| [.e = `Omemb (a, memb)]:	std.sbfmt(sb, "{}.{}", a, memb)
-	| [.e = `Osize ty]:	std.sbfmt(sb, "sizeof({})", ty)
-	| [.e = `Ocast exp]:	std.sbfmt(sb, "{} castto({})", exp)
-	| [.e = `Oret exp]:	std.sbfmt(sb, "-> {}", exp)
-	| [.e = `Ojmp name]:	std.sbfmt(sb, "goto {}", name)
-	| [.e = `Obreak]:		std.sbfmt(sb, "break")
-	| [.e = `Ocontinue]:	std.sbfmt(sb, "continue")
-	| [.e = `Ovar name]:	std.sbfmt(sb, "{}", name)
-	| [.e = `Ogap]:		std.sbfmt(sb, "_")
-	| [.e = `Olit lit]:	std.sbfmt(sb, "{}", lit)
-	| [.e = `Ocall (f, args)]:	std.sbfmt(sb, "{}({})", f, args)
-	| [.e = `Oucon (t, `std.Some v)]:
-		std.sbfmt(sb, "{} {}", t, v)
-	| [.e = `Oucon (t, `std.None)]:
-		std.sbfmt(sb, "{}", t)
-	| [.e = `Otup al]:
-		std.sbfmt(sb, "{}", al)
-	| [.e = `Ostruct ml]:
-		std.sbfmt(sb, "{}", ml)
-	| [.e = `Oarr il]:
-		std.sbfmt(sb, "{}", il)
-	| [.e = `Oidxlen]:
-		std.sbfmt(sb, "$")
-	;;
-}
-
-const stabdump = {sb, st, ind
-	var keys
-
-	if st.name.len != 0
-		ifmt(sb, ind, "ns: {}", st.name)
-	;;
-	keys = std.htkeys(st.syms)
-	for k in keys
-		match std.get(std.htget(st.syms, k))
-		| `Dcl d:	
-			ifmt(sb, ind, "{} : {}\n", k, d.ty)
-		| `Ucon uc:	
-			match uc.ety
-			| `std.Some t:	ifmt(sb, ind, "{} : {}\n", k, t)
-			| `std.None:	ifmt(sb, ind, "{}\n", k)
-			;;
-		;;
-	;;
-	std.slfree(keys)
-
-	keys = std.htkeys(st.types)
-	for k in keys
-		match std.get(std.htget(st.types, k))
-		| `Tyfwd:	ifmt(sb, ind, "type {} [PROTO]", k)
-		| `Trfwd:	ifmt(sb, ind, "trait {} [PROTO]", k)
-		| `Tydef d:	ifmt(sb, ind, "type {} = {}\n", k, d)
-		| `Trdef tr:	ifmt(sb, ind, "trait {} = ...\n", k)
-		;;
-	;;
-	std.slfree(keys)
-}
--- a/mparse/main.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-
-use "tok.use"
-use "parse.use"
-use "dump.use"
-
-const main = {
-	var ts, f
-
-	ts = parse.tokinitf(0, "stdin")
-	f = parse.tsfile(ts)
-	std.put("parsed\n")
-	std.put("{}\n", f)
-}
--- a/mparse/parse.myr
+++ /dev/null
@@ -1,122 +1,0 @@
-use std
-
-use "ast.use"
-use "stab.use"
-use "types.use"
-use "tokdefs.use"
-use "tok.use"
-use "util.use"
-
-pkg parse =
-	const tsfile	: (ts : tokstream# -> file#)
-;;
-
-const tsfile = {ts
-	var f
-
-	f = std.mk([
-		.uses = [][:],
-		.libs = [][:],
-		.extlibs = [][:],
-		.dcls = [][:],
-		.extinit = [][:],
-		.init = `std.None,
-		.globls = mkstab(),
-		.builtin = mkstab(),
-		.ns = std.mkht(std.strhash, std.streq),
-	])
-	f.globls.super = `std.Some f.builtin
-	optendlns(ts)
-	while true
-		match tokpeek(ts)
-		| (loc, `Teof):	
-			break
-		| (loc, `Tuse):
-			usestmt(ts, f)
-		| (loc, `Tpkg):
-			pkgdef(ts, f)
-		| (loc, `Ttrait):
-			traitdef(ts, f)
-		| (loc, `Ttype):
-			tydef(ts, f)
-		| (loc, tok):	
-			if !decl(ts, ts)
-				err(loc, "invalid top level item near {}", tok)
-			;;
-		;;
-		endlns(ts)
-	;;
-	-> f
-}
-
-const usestmt = {ts, f
-	match toknext(ts)
-	| (loc, `Tuse): /* ok */
-	| (loc, t):	err(loc, "unexpected token in use {}\n", t)
-	;;
-
-	match toknext(ts)
-	| (loc, `Tstrlit str):	f.uses = std.slpush(f.uses, `Ulocal str)
-	| (loc, `Tident id):	f.uses = std.slpush(f.uses, `Ulib id)
-	| (loc, t):	err(loc, "unexpected {} after use\n", t)
-	;;
-}
-
-const pkgdef = {ts, f
-	match toknext(ts)
-	| (loc, `Tpkg):	/* ok */
-	| (loc, t):	err(loc, "unexpected token in pkg {}\n", t)
-	;;
-
-	match toknext(ts)
-	| (loc, `Tident id):	setpkg(f, f.globls, id)
-	| (loc, `Tgap):	/* pkg _ */
-	| (loc, t):	err(loc, "invalid package name {}\n", t)
-	;;
-
-	match toknext(ts)
-	| (loc, `Tasn):	/* ok */
-	| (loc, t):	err(loc, "expected '=' after pkg name, got {}\n", t)
-	;;
-
-	pkgbody(ts, f)
-
-	expectendblk(ts, f)
-}
-
-const pkgbody = {ts, f
-	optendlns(ts)
-}
-
-const traitdef = {ts, f
-}
-
-const tydef = {ts, f
-}
-
-const decl = {ts, f
-	-> false
-}
-
-const endlns = {ts
-	match tokpeek(ts)
-	| (loc, `Tendln):	optendlns(ts)
-	| (loc, t):	err(loc, "expected \\n, got {}\n", t)
-	;;
-}
-
-const optendlns = {ts
-	while true
-		match tokpeek(ts)
-		| (loc, `Tendln):	toknext(ts)
-		| _:	break
-		;;
-	;;
-}
-
-const expectendblk = {ts, f
-	match toknext(ts)
-	| (loc, `Tendblk):	/* ok */
-	| (loc, t):	err(loc, "expected ;; after block, got {}\n", t)
-	;;
-}
--- a/mparse/stab.myr
+++ /dev/null
@@ -1,40 +1,0 @@
-use std
-
-use "types.use"
-use "tokdefs.use"
-use "tok.use"
-use "util.use"
-
-pkg parse =
-	const setpkg	: (f : file#, st : stab#, name : byte[:]-> void)
-	const mkstab	: (-> stab#)
-;;
-
-const mkstab = {
-	-> std.mk([
-		.super = `std.None,
-		.name = "",
-		.isfunc = false,
-		.syms = std.mkht(stnamehash, stnameeq),
-		.types = std.mkht(stnamehash, stnameeq),
-		.impls = std.mkht(stnamehash, stnameeq),
-		.env = std.mkht(stnamehash, stnameeq),
-	])
-}
-
-const setpkg = {f, st, name
-	if st.name.len != 0
-		std.fatal("package name already set for pkg {}\n", st.name)
-	;;
-	st.name = name
-	std.htput(f.ns, name, st)
-}
-
-const stnamehash = {n
-	-> std.strhash(n.name)
-}
-
-const stnameeq = {a, b
-	-> std.streq(a.name, b.name)
-}
-
--- a/mparse/tok.myr
+++ /dev/null
@@ -1,595 +1,0 @@
-use std
-
-use "types.use"
-use "tokdefs.use"
-use "util.use"
-
-pkg parse =
-	type tokstream = struct
-		next	: std.option((srcloc, tok))
-		rest	: byte[:]
-		data	: byte[:]
-		loc	: srcloc
-	;;
-
-	const tokinit	: (path : byte[:]	-> tokstream#)
-	const tokinitf	: (fd : std.fd, path : byte[:]	-> tokstream#)
-	const tokclose	: (ts : tokstream#	-> void)
-
-	const toknext	: (ts : tokstream#	-> (srcloc, tok))
-	const tokpeek	: (ts : tokstream#	-> (srcloc, tok))
-;;
-
-const Eof = std.Badchar
-
-const tokinit = {path
-	match std.slurp(path)
-	| `std.Ok data: -> mkparser(path, data)
-	| `std.Fail e:	std.fatal("could not read file {}: {}\n", path, e)
-	;;
-}
-
-const tokinitf = {fd, name
-	match std.fslurp(fd)
-	| `std.Ok data: -> mkparser(name, data)
-	| `std.Fail e:	std.fatal("could not read file {}: {}\n", fd, e)
-	;;
-}
-
-const mkparser = {name, data
-	-> std.mk([
-		.loc = [.file=name, .line=1, .col=1],
-		.next=`std.None,
-		.rest=data,
-		.data=data,
-	])
-}
-
-const tokclose = {ts
-	std.slfree(ts.data)
-	std.free(ts)
-}
-
-const toknext = {ts
-	var t
-	match ts.next
-	| `std.Some tok:
-		ts.next = `std.None
-		-> tok
-	| `std.None:
-		t = tokread(ts)
-		-> t
-	;;
-}
-
-const tokpeek = {ts
-	var tok
-
-	match ts.next
-	| `std.Some t:
-		-> t
-	| `std.None:
-		tok = tokread(ts)
-		ts.next = `std.Some tok
-		-> tok
-	;;
-}
-
-const tokread = {ts
-	var c, loc
-
-	skipspace(ts)
-	loc = ts.loc
-	c = peekc(ts)
-	if ts.rest.len == 0
-		-> (loc, `Teof)
-	elif c == '\n'
-		takec(ts)
-		ts.loc.line++
-		ts.loc.col = 1
-		-> (loc, `Tendln)
-	elif c == '\''
-		-> (loc, chrlit(ts))
-	elif c == '"'
-		-> (loc, strlit(ts))
-	elif c == '@'
-		-> (loc, typaram(ts))
-	elif std.isdigit(c)
-		-> (loc, numlit(ts))
-	elif isident(c)
-		-> (loc, kwident(ts))
-	else
-		-> (loc, oper(ts))
-	;;
-}
-
-const skipspace = {ts
-	var ignorenl
-
-	ignorenl = false
-	while true
-		match peekc(ts)
-		| '\n':
-			if ignorenl
-				takec(ts)
-				ts.loc.line++
-				ts.loc.col = 1
-			else
-				break
-			;;
-		| '\\':
-			ignorenl = true
-			takec(ts)
-		| '/':
-			match npeekc(ts, 1)
-			| '/':	skipto(ts, '\n')
-			| '*':	skipcomment(ts)
-			| _:	break
-			;;
-		| c:
-			if std.isspace(c)
-				takec(ts)
-			else
-				break
-			;;
-		;;
-	;;
-}
-
-const skipcomment = {ts
-	var depth, startln
-
-	depth = 0
-	startln = ts.loc.line
-	while true
-		match takec(ts)
-		| '/':
-			if matchc(ts, '*')
-				depth++
-			;;
-		| '*':
-			if matchc(ts, '/')
-				depth--
-			;;
-		| '\n':
-			ts.loc.line++
-			ts.loc.col = 1
-		| Eof:
-			err(ts.loc, "file ended in comment starting on line {}\n", startln)
-		| _:
-		;;
-
-		if depth == 0
-			break
-		;;
-	;;
-}
-
-const chrlit = {ts
-	var c, close
-
-	takec(ts)
-	c = takec(ts)
-	if c == '\\'
-		c = unescape(ts)
-	;;
-	close = takec(ts)
-	if close != '\''
-		err(ts.loc, "expected closing ' in character literal, got {}\n", close)
-	;;
-	-> `Tchrlit c
-}
-
-const strlit = {ts
-	var sb
-
-	takec(ts)
-	sb = std.mksb()
-	while true
-		match takec(ts)
-		| Eof:
-			err(ts.loc, "unexpected EOF within string literal\n")
-		| '\n':
-			err(ts.loc, "unexpected \\n within string literal\n")
-		| '"':
-			break
-		| '\\':
-			std.sbputc(sb, unescape(ts))
-		| c:
-			std.sbputc(sb, c)
-		;;
-	;;
-	-> `Tstrlit std.sbfin(sb)
-}
-
-const unescape = {ts
-	var c, c1, c2
-
-	c = takec(ts)
-	/* we've already seen the '\' */
-	match c
-	| 'n':	-> '\n'
-	| 'r':	-> '\r'
-	| 't':	-> '\t'
-	| 'b':	-> '\b'
-	| '"':	-> '\"'
-	| '\'':	-> '\''
-	| 'v':	-> '\v'
-	| '\\':	-> '\\'
-	| '0':	-> '\0'
-	| 'u':	-> utfesc(ts);
-	| 'x':
-		c1 = takec(ts)
-		if !std.isxdigit(c1)
-			err(ts.loc, "expected hex digit, got {}\n", c1)
-		;;
-		c2 = takec(ts)
-		if !std.isxdigit(c2)
-			err(ts.loc, "expected hex digit, got {}\n", c2)
-		;;
-		-> 16*std.charval(c1, 16) + std.charval(c2, 16)
-
-		c2 = takec(ts)
-	| esc:
-		err(ts.loc, "unknown escape code \\{}\n", esc)
-	;;
-}
-
-const utfesc = {ts
-	var c, v
-
-	if takec(ts) != '{'
-		err(ts.loc, "\\u escape sequence without initial '{'\n")
-	;;
-	v = 0
-	c = std.Badchar
-	while true
-		c = takec(ts)
-		if std.isxdigit(c)
-			v *= 16
-			v += std.charval(c, 16)
-		else
-			break
-		;;
-		if v > 0x10FFFF
-			err(ts.loc, "invalid codepoint in \\u escape sequence\n")
-		;;
-	;;
-	if c != '}'
-		err(ts.loc, "\\u escape sequence without closing '{'\n")
-	;;
-	-> v
-}
-
-const typaram = {ts
-	takec(ts)
-	match kwident(ts)
-	| `Tident id:
-		-> `Ttyparam id
-	| kw:
-		err(ts.loc, "'{}' used as type parameter\n", kw)
-	;;
-
-}
-
-const numlit = {ts
-	var t
-
-	std.put("parsing number: {}\n", ts.rest[:10])
-	if matchc(ts, '0')
-		if matchc(ts, 'x')
-			t = number(ts, 16)
-		elif matchc(ts, 'b')
-			t = number(ts, 2)
-		elif matchc(ts, 'o')
-			t = number(ts, 8)
-		else
-			t = number(ts, 10)
-		;;
-	else
-		t = number(ts, 10)
-	;;
-	-> t
-}
-
-
-/*
-only deals with the body of the number. if we reach
-this code, then it's guaranteed that we already have
-a numerical value.
-*/
-const number = {ts, base
-	var buf, nbuf
-	var isfloat, issigned
-	var v, bits
-
-	buf = ts.rest
-	nbuf = 0
-	isfloat = false
-	for var c = peekc(ts); std.isxdigit(c) || c == '.' || c == '_'; c = peekc(ts)
-		takec(ts)
-		if c == '_'
-			continue
-		elif c == '.'
-			isfloat = true
-		else 
-			v = std.charval(c, base)
-			if v < 0
-				err(ts.loc, "digit {} out of range of base {}\n", c, base)
-			;;
-		;;
-		nbuf++
-	;;
-
-	if isfloat
-		if base != 10
-			err(ts.loc, "floats must be in base 10\n")
-		;;
-		std.fatal("unable to parse floats: fuck me\n")
-		/*
-		-> `Tfltlit std.flt64parse(buf[:n])
-		*/
-	else
-		issigned = true
-		if peekc(ts) == 'u'
-			takec(ts)
-			issigned = false
-		;;
-
-		match peekc(ts)
-		| 'l':	bits = 64
-		| 'i':	bits = 32
-		| 's':	bits = 16
-		| 'b':	bits = 8
-		| _:	bits = 0
-		;;
-		v = std.get(std.intparsebase(buf[:nbuf], base))
-		/* guaranteed to be ok */
-		-> `Tintlit (v, bits, issigned)
-	;;
-}
-
-const kwident = {ts
-	match identstr(ts)
-	| "$": 	-> `Tidxlen
-	| "_": 	-> `Tgap
-	| "$noret": 	-> `Tattr `Attrnoret
-	| "break": 	-> `Tbreak
-	| "castto": 	-> `Tcast
-	| "const": 	-> `Tconst
-	| "continue": 	-> `Tcontinue
-	| "elif": 	-> `Telif
-	| "else": 	-> `Telse
-	| "extern": 	-> `Tattr `Attrextern
-	| "false": 	-> `Tboollit false
-	| "for": 	-> `Tfor
-	| "generic": 	-> `Tgeneric
-	| "goto": 	-> `Tgoto
-	| "if": 	-> `Tif
-	| "impl": 	-> `Timpl
-	| "in": 	-> `Tin
-	| "match": 	-> `Tmatch
-	| "pkg": 	-> `Tpkg
-	| "pkglocal": 	-> `Tattr `Attrpkglocal
-	| "sizeof": 	-> `Tsizeof
-	| "struct": 	-> `Tstruct
-	| "trait": 	-> `Ttrait
-	| "true": 	-> `Tboollit true
-	| "type": 	-> `Ttype
-	| "union": 	-> `Tunion
-	| "use": 	-> `Tuse
-	| "var": 	-> `Tvar
-	| "void": 	-> `Tvoidlit
-	| "while": 	-> `Twhile
-	| ident:	-> `Tident ident
-	;;
-}
-
-const oper = {ts
-	var t, chr
-
-	chr = takec(ts)
-	match chr
-	| '{': t = `Tobrace
-	| '}': t = `Tcbrace
-	| '(': t = `Toparen
-	| ')': t = `Tcparen
-	| '[': t = `Tosqbrac
-	| ']': t = `Tcsqbrac
-	| ',': t = `Tcomma
-	| '`': t = `Ttick
-	| '#': t = `Tderef
-	| '~': t = `Tbnot
-	| ':':
-		if matchc(ts, ':')
-			t = `Twith
-		else
-			t = `Tcolon;
-		;;
-	| ';':
-		if matchc(ts, ';')
-			t = `Tendblk;
-		else
-			t = `Tendln;
-		;;
-	| '.':
-		if npeekc(ts, 1) == '.' && npeekc(ts, 2) == '.'
-			takec(ts)
-			takec(ts)
-			t = `Tellipsis;
-		else
-			t = `Tdot;
-		;;
-	| '+':
-		if matchc(ts, '=')
-			t = `Taddeq;
-		elif matchc(ts, '+')
-			t = `Tinc;
-		else
-			t = `Tplus;
-		;;
-	| '-':
-		if matchc(ts, '=')
-			t = `Tsubeq;
-		elif matchc(ts, '-')
-			t = `Tdec;
-		elif matchc(ts, '>')
-			t = `Tret;
-		else
-			t = `Tminus;
-		;;
-	| '*':
-		if matchc(ts, '=')
-			t = `Tmuleq;
-		else
-			t = `Tmul;
-		;;
-	| '/':
-		if matchc(ts, '=')
-			t = `Tdiveq;
-		else
-			t = `Tdiv;
-		;;
-	| '%':
-		if matchc(ts, '=')
-			t = `Tmodeq;
-		else
-			t = `Tmod;
-		;;
-	| '=':
-		if matchc(ts, '=')
-			t = `Teq;
-		else
-			t = `Tasn;
-		;;
-	| '|':
-		if matchc(ts, '=')
-			t = `Tboreq;
-		elif matchc(ts, '|')
-			t = `Tlor;
-		else
-			t = `Tbor;
-		;;
-	| '&':
-		if matchc(ts, '=')
-			t = `Tbandeq;
-		elif matchc(ts, '&')
-			t = `Tland;
-		else
-			t = `Tband;
-		;;
-	| '^':
-		if matchc(ts, '=')
-			t = `Tbxoreq;
-		else
-			t = `Tbxor;
-		;;
-	| '<':
-		if matchc(ts, '=')
-			t = `Tle;
-		elif matchc(ts, '<')
-			if matchc(ts, '=')
-				t = `Tbsleq;
-			else
-				t = `Tbsl;
-			;;
-		else
-			t = `Tlt;
-		;;
-	| '>':
-		if matchc(ts, '=')
-			t = `Tge;
-		elif matchc(ts, '>')
-			if matchc(ts, '=')
-				t = `Tbsreq;
-			else
-				t = `Tbsr;
-			;;
-		else
-			t = `Tgt;
-		;;
-
-	| '!':
-		if matchc(ts, '=')
-			t = `Tne;
-		else
-			t = `Tlnot;
-		;;
-	| c:
-		t = `Terror;
-		err(ts.loc, "junk character {}", c);
-	;;
-	-> t
-}
-
-const identstr = {ts
-	var i, str
-
-	/* ASCII */
-	if ts.rest.len == 0 || std.isdigit(ts.rest[0] castto(char))
-		-> ""
-	;;
-
-	for i = 0; i < ts.rest.len; i++
-		if !isident(ts.rest[i] castto(char))
-			break
-		;;
-	;;
-	str = ts.rest[:i]
-	ts.rest = ts.rest[i:]
-	-> std.sldup(str)
-}
-
-const isident = {c
-	-> c & 0x80 == 0 && \
-		(c >= 'a' && c <= 'z' || \
-		 c >= 'A' && c <= 'Z' || \
-		 c >= '0' && c <= '9' || \
-		 c == '_' || c == '$')
-}
-
-const peekc = {ts
-	-> std.decode(ts.rest)
-}
-
-const npeekc = {ts, n
-	var c, s
-
-	s = ts.rest
-	for var i = 0; i < n; i++
-		(c, s) = std.strstep(s)
-	;;
-	-> std.decode(s)
-}
-
-const takec = {ts
-	var c, s
-
-	(c, s) = std.strstep(ts.rest)
-	ts.rest = s
-	-> c
-}
-
-const skipto = {ts, chr
-	var c, s
-
-	s = ts.rest
-	while true
-		(c, s) = std.strstep(s)
-		if s.len == 0 || c == chr
-			break
-		;;
-	;;
-}
-
-const matchc = {ts, chr
-	var c, s
-
-	(c, s) = std.strstep(ts.rest)
-	if c == chr
-		ts.rest = s
-		-> true
-	else
-		-> false
-	;;
-}
--- a/mparse/tokdefs.myr
+++ /dev/null
@@ -1,210 +1,0 @@
-use std
-
-use "types.use"
-
-pkg parse =
-	type tok = union
-		`Terror
-		`Teof
-		`Tplus    /* + */
-		`Tminus   /* - */
-		`Tmul     /* * */
-		`Tdiv     /* / */
-		`Tinc     /* ++ */
-		`Tdec     /* -- */
-		`Tmod     /* % */
-		`Tasn     /* = */
-		`Taddeq   /* += */
-		`Tsubeq   /* -= */
-		`Tmuleq   /* *= */
-		`Tdiveq   /* /= */
-		`Tmodeq   /* %= */
-		`Tboreq   /* |= */
-		`Tbxoreq  /* ^= */
-		`Tbandeq  /* &= */
-		`Tbsleq   /* <<= */
-		`Tbsreq   /* >>= */
-		
-		`Tbor     /* | */
-		`Tbxor    /* ^ */
-		`Tband    /* & */
-		`Tbsl     /* << */
-		`Tbsr     /* >> */
-		`Tbnot    /* ~ */
-	
-		`Teq      /* == */
-		`Tgt      /* > */
-		`Tlt      /* < */
-		`Tge      /* >= */
-		`Tle      /* <= */
-		`Tne      /* != */
-	
-		`Tlor     /* || */
-		`Tland    /* && */
-		`Tlnot    /* ! */
-	
-		`Tobrace  /* { */
-		`Tcbrace  /* } */
-		`Toparen  /* ( */
-		`Tcparen  /* ) */
-		`Tosqbrac /* [ */
-		`Tcsqbrac /* ] */
-		`Tat      /* @ */
-		`Ttick    /* ` */
-		`Tderef   /* # */
-		`Tidxlen  /* $ */
-	
-		`Ttype    /* type */
-		`Tfor     /* for */
-		`Tin      /* in */
-		`Twhile   /* while */
-		`Tif      /* if */
-		`Telse    /* else */
-		`Telif    /* else */
-		`Tmatch   /* match */
-		`Tgoto    /* goto */
-		`Tbreak   /* break */
-		`Tcontinue   /* continue */
-	
-		`Tintlit (int64, int, bool) /* val, sz, sign */
-		`Tstrlit byte[:]
-		`Tfltlit flt64
-		`Tchrlit char
-		`Tboollit bool
-		`Tvoidlit
-	
-		`Ttrait   /* trait */
-		`Timpl   /* trait */
-		`Tstruct  /* struct */
-		`Tunion   /* union */
-		`Ttyparam byte[:] /* @typename */
-	
-		`Tconst   /* const */
-		`Tvar     /* var */
-		`Tgeneric /* var */
-		`Tcast    /* castto */
-	
-		`Tgap     /* _ */
-		`Tellipsis/* ... */
-		`Tendln   /* ; or \n */
-		`Tendblk  /* ;; */
-		`Tcolon   /* : */
-		`Twith    /* :: */
-		`Tdot     /* . */
-		`Tcomma   /* , */
-		`Tret     /* -> */
-		`Tuse     /* use */
-		`Tpkg     /* pkg */
-		`Tsizeof  /* sizeof */
-		`Tattr attr   /* $attr */
-		`Tident byte[:]
-	;;
-;;
-
-const __init__ = {
-	var dummy : tok
-
-	dummy = `Terror
-	std.fmtinstall(std.typeof(dummy), tokfmt, [][:])
-}
-
-const tokfmt = {sb, ap, opts
-	var tok
-
-	tok = std.vanext(ap)
-	match tok
-	| `Terror:	std.sbfmt(sb, "ERROR")
-	| `Teof:	std.sbfmt(sb, "EOF")
-	| `Tplus:	std.sbfmt(sb, "+")
-	| `Tminus:	std.sbfmt(sb, "-")
-	| `Tmul:	std.sbfmt(sb, "*")
-	| `Tdiv:	std.sbfmt(sb, "/")
-	| `Tinc:	std.sbfmt(sb, "++")
-	| `Tdec:	std.sbfmt(sb, "--")
-	| `Tmod:	std.sbfmt(sb, "%")
-	| `Tasn:	std.sbfmt(sb, "=")
-	| `Taddeq:	std.sbfmt(sb, "+=")
-	| `Tsubeq:	std.sbfmt(sb, "-=")
-	| `Tmuleq:	std.sbfmt(sb, "*=")
-	| `Tdiveq:	std.sbfmt(sb, "/=")
-	| `Tmodeq:	std.sbfmt(sb, "%=")
-	| `Tboreq:	std.sbfmt(sb, "|=")
-	| `Tbxoreq:	std.sbfmt(sb, "^=")
-	| `Tbandeq:	std.sbfmt(sb, "&=")
-	| `Tbsleq:	std.sbfmt(sb, "<<=")
-	| `Tbsreq:	std.sbfmt(sb, ">>=")
-	| `Tbor:	std.sbfmt(sb, "|")
-	| `Tbxor:	std.sbfmt(sb, "^")
-	| `Tband:	std.sbfmt(sb, "&")
-	| `Tbsl:	std.sbfmt(sb, "<<")
-	| `Tbsr:	std.sbfmt(sb, ">>")
-	| `Tbnot:	std.sbfmt(sb, "~")
-
-	| `Teq:		std.sbfmt(sb, "==")
-	| `Tgt:		std.sbfmt(sb, ">")
-	| `Tlt:		std.sbfmt(sb, "<")
-	| `Tge:		std.sbfmt(sb, ">=")
-	| `Tle:		std.sbfmt(sb, "<=")
-	| `Tne:		std.sbfmt(sb, "!=")
-
-	| `Tlor:	std.sbfmt(sb, "||")
-	| `Tland:	std.sbfmt(sb, "&&")
-	| `Tlnot:	std.sbfmt(sb, "!")
-
-	| `Tobrace:	std.sbfmt(sb, "{{")
-	| `Tcbrace:	std.sbfmt(sb, "}}")
-	| `Toparen:	std.sbfmt(sb, "(")
-	| `Tcparen:	std.sbfmt(sb, ")")
-	| `Tosqbrac:	std.sbfmt(sb, "[")
-	| `Tcsqbrac:	std.sbfmt(sb, "]")
-	| `Tat:		std.sbfmt(sb, "@")
-	| `Ttick:	std.sbfmt(sb, "`")
-	| `Tderef:	std.sbfmt(sb, "#")
-	| `Tidxlen:	std.sbfmt(sb, "$")
-
-	| `Ttype:	std.sbfmt(sb, "type")
-	| `Tfor:	std.sbfmt(sb, "for")
-	| `Tin:		std.sbfmt(sb, "in")
-	| `Twhile:	std.sbfmt(sb, "while")
-	| `Tif:		std.sbfmt(sb, "if")
-	| `Telse:	std.sbfmt(sb, "else")
-	| `Telif:	std.sbfmt(sb, "else")
-	| `Tmatch:	std.sbfmt(sb, "match")
-	| `Tgoto:	std.sbfmt(sb, "goto")
-	| `Tbreak:	std.sbfmt(sb, "break")
-	| `Tcontinue:	std.sbfmt(sb, "continue")
-
-	| `Tintlit v:	std.sbfmt(sb, "{}", v)
-	| `Tstrlit v:	std.sbfmt(sb, "{e}", v)
-	| `Tfltlit v:	std.sbfmt(sb, "{}", v)
-	| `Tchrlit v:	std.sbfmt(sb, "{}", v)
-	| `Tboollit v:	std.sbfmt(sb, "{}", v)
-	| `Tvoidlit:	std.sbfmt(sb, "void")
-
-	| `Ttrait:	std.sbfmt(sb, "trait")
-	| `Timpl:	std.sbfmt(sb, "trait")
-	| `Tstruct:	std.sbfmt(sb, "struct")
-	| `Tunion:	std.sbfmt(sb, "union")
-	| `Ttyparam tp:	std.sbfmt(sb, "@{}", tp)
-
-	| `Tconst:	std.sbfmt(sb, "const")
-	| `Tvar:	std.sbfmt(sb, "var")
-	| `Tgeneric:	std.sbfmt(sb, "var")
-	| `Tcast:	std.sbfmt(sb, "castto")
-	| `Tgap:	std.sbfmt(sb, "_")
-
-	| `Tellipsis:	std.sbfmt(sb, "...")
-	| `Tendln:	std.sbfmt(sb, ";")
-	| `Tendblk:	std.sbfmt(sb, ";;")
-	| `Tcolon:	std.sbfmt(sb, ":")
-	| `Twith:	std.sbfmt(sb, "::")
-	| `Tdot:	std.sbfmt(sb, ".")
-	| `Tcomma:	std.sbfmt(sb, ",")
-	| `Tret:	std.sbfmt(sb, "->")
-	| `Tuse:	std.sbfmt(sb, "use")
-	| `Tpkg:	std.sbfmt(sb, "pkg")
-	| `Tattr a:	std.sbfmt(sb, "{}", a)
-	| `Tsizeof:	std.sbfmt(sb, "sizeof")
-	| `Tident str:	std.sbfmt(sb, "{}", str)
-	;;
-}
--- a/mparse/types.myr
+++ /dev/null
@@ -1,290 +1,0 @@
-use std
-
-pkg parse =
-	type srcloc = struct
-		file	: byte[:]
-		line	: int
-		col	: int
-	;;
-
-	type attr = union
-		`Attrpkglocal
-		`Attrextern
-		`Attrnoret
-	;;
-
-	type file = struct
-		path	: byte[:]
-		uses	: usefile[:]
-		libs	: byte[:][:]
-		extlibs	: byte[:][:]
-		extinit	: dcl#[:]
-		init	: std.option(dcl#)
-		builtin	: stab#
-		globls	: stab#
-		ns	: std.htab(byte[:], stab#)#
-		dcls	: dcl#[:]
-	;;
-
-	type node = union
-		`Nexpr	expr
-		`Nlit	lit
-		`Nloop	loopstmt
-		`Niter	iterstmt
-		`Nif	ifstmt
-		`Nmatch matchstmt
-		`Ncase	matchcase
-		`Ndcl	dcl#
-		`Nfunc	func
-		`Ntrait traitdef
-		`Nimpl	impldef
-	;;
-
-	type tydef = struct
-		ty	: ty
-		id	: int32
-		loc	: srcloc
-		fixed	: bool
-		found	: bool
-		traits	: std.bitset#
-	;;
-		
-	type ty = union
-		`Tyvoid
-		`Tybool
-		/* integers */
-		`Tyint8
-		`Tyint16
-		`Tyint32
-		`Tyint
-		/* unsigned integers */
-		`Tychar
-		`Tybyte
-		`Tyint64
-		`Tyuint8
-		`Tyuint16
-		`Tyuint32
-		`Tyuint
-		`Tyuint64
-		/*floats */
-		`Tyflt32
-		`Tyflt64
-		/* a bit odd.. */
-		`Tyvalist
-		/* compound types */
-		`Tyslice tydef#
-		`Typtr tydef#
-		`Tyarray (tydef#, node#)
-		`Tystruct (dcl#[:])
-		`Tyunion (ucon#[:])
-		/* user defined types */
-		`Tygeneric (tydef#[:], tydef#)
-		`Tyname	(tydef#[:], tydef#)
-		`Typaram byte[:]
-		`Tyvar int64
-	;;
-
-	type ucon = struct
-		loc	: srcloc
-		name	: name#
-		uty	: tydef#
-		ety	: std.option(tydef#)
-	;;
-
-	type impldef = struct
-		vis	: vis
-		tr	: name#
-		ty	: tydef#
-		aux	: tydef#[:]
-		dcls	: dcl#[:]
-		isimport	: bool
-	;;
-
-	type expr = struct
-		ty	: tydef#
-		loc	: srcloc
-		e	: union
-			`Oadd	(node#, node#)
-			`Osub	(node#, node#)
-			`Omul	(node#, node#)
-			`Odiv	(node#, node#)
-			`Omod	(node#, node#)
-			`Oneg	node#
-			`Obor	(node#, node#)
-			`Oband	(node#, node#)
-			`Obxor	(node#, node#)
-			`Obsl	(node#, node#)
-			`Obsr	(node#, node#)
-			`Obnot	node#
-			`Opreinc	node#
-			`Opostinc	node#
-			`Opredec	node#
-			`Opostdec	node#
-			`Oaddr	node#
-			`Oderef	node#
-			`Olor	(node#, node#)
-			`Oland	(node#, node#)
-			`Olnot	node#
-			`Oeq	(node#, node#)
-			`One	(node#, node#)
-			`Ogt	(node#, node#)
-			`Oge	(node#, node#)
-			`Olt	(node#, node#)
-			`Ole	(node#, node#)
-			`Oasn	(node#, node#)
-			`Oaddeq	(node#, node#)
-			`Osubeq	(node#, node#)
-			`Omuleq	(node#, node#)
-			`Odiveq	(node#, node#)
-			`Omodeq	(node#, node#)
-			`Oboreq	(node#, node#)
-			`Obandeq	(node#, node#)
-			`Obxoreq	(node#, node#)
-			`Obsleq	(node#, node#)
-			`Obsreq	(node#, node#)
-			`Oidx	(node#, node#)
-			`Oslice	(node#, node#, node#)
-			`Omemb	(node#, byte[:])
-			`Osize	ty#
-			`Ocall	(node#, node#[:])
-			`Ocast	node#
-			`Oret	node#
-			`Ojmp	name#
-			`Obreak
-			`Ocontinue
-			`Ovar	name#
-			`Ogap
-			`Olit	lit
-			`Oucon	(name#, std.option(node#))
-			`Otup	node#[:]
-			`Ostruct	(name#, node#)[:]
-			`Oarr	(node#, node#)[:]
-			`Oidxlen
-		;;
-	;;
-
-	type dcl = struct
-		id	: int32
-		name	: name
-		vis	: vis
-
-		ty	: tydef#
-		init	: expr#
-		tr	: traitdef#
-		impls	: std.htab(tydef#, dcl#)
-
-		isglobl	: bool
-		isconst	: bool
-		isnoret	: bool
-		isinit	: bool
-		isexportinit	: bool
-		isextern	: bool
-		isimport	: bool
-		ishidden	: bool
-		ispkglocal	: bool
-		isgeneric	: bool
-	;;
-
-	type loopstmt = struct
-		init	: expr#
-		cond	: expr#
-		step	: expr#
-		body	: block#
-		scope	: stab#
-	;;
-
-	type iterstmt = struct
-		elt	: expr#
-		seq	: expr#
-		body	: block#
-	;;
-
-	type ifstmt = struct
-		cond	: expr#
-		iftrue	: block#
-		iffalse	: block#
-	;;
-
-	type block = struct
-		stab	: stab#
-		stmts	: node#[:]
-	;;
-
-	type matchstmt = struct
-		val	: expr#
-		matches	: matchcase#[:]
-	;;
-
-	type matchcase = struct
-		expr	: node#
-		blk	: block#
-	;;
-
-	type lit = union
-		`Lint	uint64
-		`Lflt	flt64
-		`Lchr	char
-		`Lstr	byte[:]
-		`Llbl	byte[:]
-		`Lbool	bool
-		`Lvoid
-	;;
-
-	type traitdef = struct
-		id	: int32
-		loc	: srcloc
-		vis	: vis
-		name	: name
-		param	: tydef#
-		aux	: tydef#[:]
-		memb	: dcl#[:]
-		funcs	: dcl#[:]
-	;;
-
-	type usefile = union
-		`Ulocal	byte[:]
-		`Ulib	byte[:]
-	;;
-
-	type func = struct
-		stab	: stab#
-		ty	: tydef#
-		args	: dcl#[:]
-		body	: block#
-	;;
-
-	type stab = struct
-		super	: std.option(stab#)
-		name	: byte[:]
-		isfunc	: bool
-
-		syms	: std.htab(name, sym)#
-		types	: std.htab(name, tysym)#
-		impls	: std.htab(name, node#)#
-		env	: std.htab(name, node#)#
-	;;
-
-	type sym = union
-		`Dcl	dcl#
-		`Ucon	ucon#
-	;;
-
-	type tysym = union
-		`Tyfwd
-		`Trfwd
-		`Tydef	tydef#
-		`Trdef	traitdef#
-	;;
-
-	type name = struct
-		ns	: byte[:]
-		name	: byte[:]
-	;;
-
-	type vis = union
-		`Visintern
-		`Vishidden
-		`Visexport
-		`Visbuiltin
-	;;
-;;
--- a/mparse/util.myr
+++ /dev/null
@@ -1,36 +1,0 @@
-use std
-
-use "types.use"
-
-pkg parse =
-	const ifmt	: (sb : std.strbuf#, ind : int, fmt : byte[:], args : ... -> void)
-	$noret const err	: (loc : srcloc, msg : byte[:], args : ... -> void)
-	$noret const verr	: (loc : srcloc, msg : byte[:], args : std.valist# -> void)
-;;
-
-const err = {loc, msg, args
-	var ap
-	
-	ap = std.vastart(&args)
-	verr(loc, msg, &ap)
-}
-
-const verr = {loc, msg, ap
-	var sb, ln
-
-	sb = std.mksb()
-	std.sbfmtv(sb, msg, ap)
-	ln = std.sbfin(sb)
-	std.fatal("{}:{}:{}: {}\n", loc.file, loc.line, loc.col, ln)
-	std.slfree(ln)
-}
-
-const ifmt = {sb, ind, fmt, args : ...
-	var ap
-
-	ap = std.vastart(&args)
-	for var i = 0; i < ind; i++
-		std.sbputs(sb, "  ")
-	;;
-	std.sbfmtv(sb, fmt, &ap)
-}