shithub: mc

Download patch

ref: 1fe760642c99d655ce81ebb4ca200ff8502a9abd
parent: b2a4bb910a7d0cee34dfd860896e75be5e1abf1d
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 10 19:19:02 EDT 2015

Rename 'parser' to 'build'

    First step in splitting parser and build code.

--- a/build.myr
+++ b/build.myr
@@ -9,11 +9,11 @@
 use "subdir.use"
 
 pkg bld =
-	const buildall	: (p : parser# -> bool)
-	const genall	: (p : parser# -> bool)
-	const build	: (p : parser#, target : byte[:] -> bool)
-	const buildbin	: (p : parser#, bt : myrtarg#, addsrc : bool -> void)
-	const buildlib	: (p : parser#, lt : myrtarg# -> void)
+	const buildall	: (p : build# -> bool)
+	const genall	: (p : build# -> bool)
+	const build	: (p : build#, target : byte[:] -> bool)
+	const buildbin	: (p : build#, bt : myrtarg#, addsrc : bool -> void)
+	const buildlib	: (p : build#, lt : myrtarg# -> void)
 ;;
 
 const buildall = {p
--- a/clean.myr
+++ b/clean.myr
@@ -8,8 +8,8 @@
 use "types.use"
 
 pkg bld =
-	const cleanall	: (p : parser# -> bool)
-	const clean	: (p : parser#, targ : byte[:] -> bool)
+	const cleanall	: (p : build# -> bool)
+	const clean	: (p : build#, targ : byte[:] -> bool)
 ;;
 
 const cleanall = {p
--- a/deps.myr
+++ b/deps.myr
@@ -8,7 +8,7 @@
 use "util.use"
 
 pkg bld =
-	const myrdeps	: (p : parser#, mt : myrtarg#, islib : bool, isclean : bool, addsrc : bool, dg : depgraph#	-> bool)
+	const myrdeps	: (b : build#, mt : myrtarg#, islib : bool, isclean : bool, addsrc : bool, dg : depgraph#	-> bool)
 
 	/* a bit ugly: initialized from main() */
 	var usepat	: regex.regex#
@@ -21,7 +21,7 @@
 	`Lib byte[:]
 ;;
 
-const myrdeps = {p, mt, islib, isclean, addsrc, dg
+const myrdeps = {b, mt, islib, isclean, addsrc, dg
 	var objs, uses, srcs, incs
 	var out, useout, depstk
 	var i
@@ -66,7 +66,7 @@
 
 	for i = 0; i < srcs.len; i++
 		depstk = [][:]
-		srcdeps(p, dg, srcs[i], objs[i], uses[i], incs, &depstk, isclean, addsrc)
+		srcdeps(b, dg, srcs[i], objs[i], uses[i], incs, &depstk, isclean, addsrc)
 		std.slfree(depstk)
 	;;
 	dumpgraph(dg)
@@ -99,7 +99,7 @@
 	std.put("}\n")
 }
 
-const srcdeps = {p, g, path, obj, usefile, incs, depstk, isclean, addsrc
+const srcdeps = {b, g, path, obj, usefile, incs, depstk, isclean, addsrc
 	var deps
 
 	if std.hthas(g.done, path)
@@ -114,7 +114,7 @@
 		;;
 		std.exit(1)
 	;;
-	deps = getdeps(p, path)
+	deps = getdeps(b, path)
 	std.htput(g.seen, path, true)
 	for d in deps
 		match d
@@ -136,7 +136,7 @@
 			if usefile.len != 0
 				pushdep(g, l, usefile)
 			;;
-			addusedep(p, g, path, l, incs, depstk, isclean, addsrc)
+			addusedep(b, g, path, l, incs, depstk, isclean, addsrc)
 		;;
 	;;
 	depstk# = std.slgrow(depstk#, depstk#.len - 1)
@@ -144,7 +144,7 @@
 	std.htput(g.done, path, true)
 }
 
-const addusedep = {p, g, f, usefile, incs, depstk, isclean, addsrc
+const addusedep = {b, g, f, usefile, incs, depstk, isclean, addsrc
 	var src
 
 	if std.hthas(g.done, usefile)
@@ -166,17 +166,17 @@
 	;;
 	pushdep(g, src, usefile)
 	std.htput(g.input, usefile, src)
-	srcdeps(p, g, src, "", usefile, incs, depstk, isclean, addsrc)
+	srcdeps(b, g, src, "", usefile, incs, depstk, isclean, addsrc)
 	std.htput(g.done, usefile, true)
 }
 
-const getdeps = {p, path
+const getdeps = {b, path
 	var f
 	var deps : dep[:]
 
 	deps = [][:]
 	if !std.fexists(path)
-		match std.htget(p.gensrc, path)
+		match std.htget(b.gensrc, path)
 		| `std.Some gt:	run(gt.cmd, "")
 		| `std.None:	std.fatal(1, "no input file %s\n", path)
 		;;
--- a/install.myr
+++ b/install.myr
@@ -10,8 +10,8 @@
 use "build.use"
 
 pkg bld =
-	const install	: (p : parser#	-> bool)
-	const uninstall	: (p : parser#	-> bool)
+	const install	: (p : build#	-> bool)
+	const uninstall	: (p : build#	-> bool)
 ;;
 
 const install = {p
--- a/main.myr
+++ b/main.myr
@@ -12,7 +12,7 @@
 use "types.use"
 
 const main = {args : byte[:][:]
-	var p : bld.parser#
+	var b : bld.build#
 	var mt : bld.myrtarg
 	var targname
 	var bintarg
@@ -65,30 +65,30 @@
 			.ldscript=bld.opt_ldscript,
 			.libdeps=[][:]
 		]
-		p = mkparser("cli")
+		b = mkbuild("cli")
 		if bintarg
-			bld.buildbin(p, &mt, true)
+			bld.buildbin(b, &mt, true)
 		else
-			bld.buildlib(p, &mt)
+			bld.buildlib(b, &mt)
 		;;
-		std.free(p)
+		std.free(b)
 	else
-		p = loadbuild(bld.opt_bldfile)
-		p.cmd = args
+		b = mkbuild(bld.opt_bldfile)
+		bld.load(b, bld.opt_bldfile)
 		/*bld.configure()*/
 		/* default: buildall */
 		if optctx.args.len == 0
-			bld.buildall(p)
+			bld.buildall(b)
 		else
 			for cmd in optctx.args
 				match cmd
-				| "all":	bld.buildall(p)
-				| "gen":	bld.genall(p)
-				| "clean":	bld.cleanall(p)
-				| "install":	bld.install(p)
-				| "uninstall":	bld.uninstall(p)
-				| "test":	bld.test(p)
-				| target:	bld.build(p, target)
+				| "all":	bld.buildall(b)
+				| "gen":	bld.genall(b)
+				| "clean":	bld.cleanall(b)
+				| "install":	bld.install(b)
+				| "uninstall":	bld.uninstall(b)
+				| "test":	bld.test(b)
+				| target:	bld.build(b, target)
 				;;
 			;;
 		;;
@@ -95,21 +95,7 @@
 	;;
 }
 
-const loadbuild =  {path
-	var p
-
-	p = mkparser(path)
-	match std.slurp(path)
-	| `std.Ok d:	p.data = d
-	| `std.Fail _:	std.fatal(1, "could not open file 'bldfile'\n")
-	;;
-	p.rest = p.data
-	bld.parse(p)
-
-	-> p
-}
-
-const mkparser = {path
+const mkbuild = {path
 	var p
 
 	p = std.zalloc()
--- a/parse.myr
+++ b/parse.myr
@@ -6,10 +6,20 @@
 use "fsel.use"
 
 pkg bld =
-	const parse	: (p : parser#	-> bool)
+	const load	: (b : build#, path : byte[:]	-> bool)
 ;;
 
-const failparse = {p : parser#, msg, args : ...
+const load = {b, path
+	match std.slurp(path)
+	| `std.Ok d:	b.data = d
+	| `std.Fail _:	std.fatal(1, "could not open file 'bldfile'\n")
+	;;
+	b.rest = b.data
+	-> bld.parse(b)
+}
+
+
+const failparse = {p, msg, args : ...
 	var buf : byte[1024]
 	var ap
 	var sl
@@ -36,7 +46,7 @@
 	;;
 }
 
-const target = {p : parser#
+const target = {p
 	match word(p)
 	| `std.Some "bin":	bintarget(p)
 	| `std.Some "test":	testtarget(p)
@@ -320,7 +330,7 @@
 }
 
 /* word: /wordchar*/
-const word = {p : parser#
+const word = {p
 	var c, n
 	var start
 
@@ -371,7 +381,7 @@
 		c == '+'
 }
 
-const skipspace = {p : parser#
+const skipspace = {p
 	var c, r
 
 	r = p.rest
--- a/subdir.myr
+++ b/subdir.myr
@@ -4,7 +4,7 @@
 use "util.use"
 
 pkg bld =
-	const subdirs	: (p : parser#, subs : byte[:][:], targ : std.option(byte[:]) -> void)
+	const subdirs	: (p : build#, subs : byte[:][:], targ : std.option(byte[:]) -> void)
 ;;
 
 const subdirs = {p, subs, targ
--- a/test.myr
+++ b/test.myr
@@ -12,7 +12,7 @@
 use "config.use"
 
 pkg bld =
-	const test	: (p : parser# -> void)
+	const test	: (p : build# -> void)
 ;;
 
 const test = {p
--- a/types.myr
+++ b/types.myr
@@ -1,7 +1,7 @@
 use std
 
 pkg bld =
-	type parser = struct
+	type build = struct
 		cmd	: byte[:][:]
 		/* parse input */
 		data	: byte[:]