ref: e046fecd8e0736fffc4fd08789a3319af6e544fd
parent: 1fe760642c99d655ce81ebb4ca200ff8502a9abd
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 10 19:24:56 EDT 2015
Split parser from build data.
--- a/main.myr
+++ b/main.myr
@@ -65,7 +65,7 @@
.ldscript=bld.opt_ldscript,
.libdeps=[][:]
]
- b = mkbuild("cli")
+ b = mkbuild()
if bintarg
bld.buildbin(b, &mt, true)
else
@@ -73,7 +73,7 @@
;;
std.free(b)
else
- b = mkbuild(bld.opt_bldfile)
+ b = mkbuild()
bld.load(b, bld.opt_bldfile)
/*bld.configure()*/
/* default: buildall */
@@ -95,14 +95,12 @@
;;
}
-const mkbuild = {path
- var p
+const mkbuild = {
+ var b
- p = std.zalloc()
- p.line = 1
- p.fname = std.sldup(path)
- p.gensrc = std.mkht(std.strhash, std.streq)
- -> p
+ b = std.zalloc()
+ b.gensrc = std.mkht(std.strhash, std.streq)
+ -> b
}
const usage = {prog
--- a/parse.myr
+++ b/parse.myr
@@ -10,12 +10,17 @@
;;
const load = {b, path
+ var p : parser#
+
+ p = std.zalloc()
+ p.line = 1
+ p.fname = std.sldup(path)
match std.slurp(path)
- | `std.Ok d: b.data = d
+ | `std.Ok d: p.data = d
| `std.Fail _: std.fatal(1, "could not open file 'bldfile'\n")
;;
- b.rest = b.data
- -> bld.parse(b)
+ p.rest = p.data
+ -> bld.parse(b, p)
}
@@ -30,10 +35,10 @@
std.exit(1)
}
-const parse = {p
+const parse = {b, p
while true
skipspace(p)
- if !target(p)
+ if !target(b, p)
break
;;
;;
@@ -46,14 +51,14 @@
;;
}
-const target = {p
+const target = {b, p
match word(p)
- | `std.Some "bin": bintarget(p)
- | `std.Some "test": testtarget(p)
- | `std.Some "lib": libtarget(p)
- | `std.Some "gen": gentarget(p)
- | `std.Some "sub": subtarget(p)
- | `std.Some "man": mantarget(p)
+ | `std.Some "bin": bintarget(b, p)
+ | `std.Some "test": testtarget(b, p)
+ | `std.Some "lib": libtarget(b, p)
+ | `std.Some "gen": gentarget(b, p)
+ | `std.Some "sub": subtarget(b, p)
+ | `std.Some "man": mantarget(b, p)
| `std.Some targtype: failparse(p, "unknown targtype type %s\n", targtype)
| `std.None: -> false
;;
@@ -61,32 +66,32 @@
}
/* bintarget: myrtarget */
-const bintarget = {p
- p.targs = std.slpush(p.targs, `Bin myrtarget(p, "bin"))
+const bintarget = {b, p
+ b.targs = std.slpush(b.targs, `Bin myrtarget(p, "bin"))
}
/* testtarget: myrtarget */
-const testtarget = {p
- p.targs = std.slpush(p.targs, `Test myrtarget(p, "test"))
+const testtarget = {b, p
+ b.targs = std.slpush(b.targs, `Test myrtarget(p, "test"))
}
/* libtarget: myrtarget */
-const libtarget = {p
- p.targs = std.slpush(p.targs, `Lib myrtarget(p, "lib"))
+const libtarget = {b, p
+ b.targs = std.slpush(b.targs, `Lib myrtarget(p, "lib"))
}
/* subtarget : anontarget */
-const subtarget = {p
- p.targs = std.slpush(p.targs, `Sub anontarget(p, "sub"))
+const subtarget = {b, p
+ b.targs = std.slpush(b.targs, `Sub anontarget(p, "sub"))
}
/* mantarget: anontarget */
-const mantarget = {p
- p.targs = std.slpush(p.targs, `Man anontarget(p, "man"))
+const mantarget = {b, p
+ b.targs = std.slpush(b.targs, `Man anontarget(p, "man"))
}
-/* gentarget: wordlist = wordlist ;; */
-const gentarget = {p
+/* gentarget: wordlist {attrs} = wordlist ;; */
+const gentarget = {b, p
var outlist, cmdlist
var durable
var attrs
@@ -137,9 +142,9 @@
.cmd=cmdlist
])
for o in outlist
- std.htput(p.gensrc, o, gt)
+ std.htput(b.gensrc, o, gt)
;;
- p.targs = std.slpush(p.targs, `Gen gt)
+ b.targs = std.slpush(b.targs, `Gen gt)
}
/*
--- a/types.myr
+++ b/types.myr
@@ -3,12 +3,6 @@
pkg bld =
type build = struct
cmd : byte[:][:]
- /* parse input */
- data : byte[:]
- rest : byte[:]
- fname : byte[:]
- line : int
-
/* build params */
targs : targ[:]
gensrc : std.htab(byte[:], gentarg#)#
@@ -16,6 +10,15 @@
system : byte[:]
arch : byte[:]
;;
+
+ type parser = struct
+ /* parse input */
+ data : byte[:]
+ rest : byte[:]
+ fname : byte[:]
+ line : int
+ ;;
+
type depgraph = struct
roots : byte[:][:]