summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-10 23:24:56 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-10 23:24:56 -0700
commite046fecd8e0736fffc4fd08789a3319af6e544fd (patch)
tree5e1e835e8f744959533c1d5ea5350da316eab93b
parent1fe760642c99d655ce81ebb4ca200ff8502a9abd (diff)
downloadmbld-e046fecd8e0736fffc4fd08789a3319af6e544fd.tar.gz
Split parser from build data.
-rw-r--r--main.myr16
-rw-r--r--parse.myr57
-rw-r--r--types.myr15
3 files changed, 47 insertions, 41 deletions
diff --git a/main.myr b/main.myr
index 38e5290..0154c7c 100644
--- a/main.myr
+++ b/main.myr
@@ -65,7 +65,7 @@ const main = {args : byte[:][:]
.ldscript=bld.opt_ldscript,
.libdeps=[][:]
]
- b = mkbuild("cli")
+ b = mkbuild()
if bintarg
bld.buildbin(b, &mt, true)
else
@@ -73,7 +73,7 @@ const main = {args : byte[:][:]
;;
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 main = {args : byte[:][:]
;;
}
-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
diff --git a/parse.myr b/parse.myr
index 06a8e79..74eb274 100644
--- a/parse.myr
+++ b/parse.myr
@@ -10,12 +10,17 @@ pkg bld =
;;
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 @@ const failparse = {p, msg, args : ...
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 parse = {p
;;
}
-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 @@ const target = {p
}
/* 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 @@ const gentarget = {p
.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)
}
/*
diff --git a/types.myr b/types.myr
index ec72aae..508e8a5 100644
--- a/types.myr
+++ b/types.myr
@@ -3,12 +3,6 @@ use std
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#)#
@@ -17,6 +11,15 @@ pkg bld =
arch : byte[:]
;;
+ type parser = struct
+ /* parse input */
+ data : byte[:]
+ rest : byte[:]
+ fname : byte[:]
+ line : int
+ ;;
+
+
type depgraph = struct
roots : byte[:][:]
deps : std.htab(byte[:], byte[:][:])#