lang: Refactor most functions to support modules

This is a giant refactor to move functions into a hierarchial module
layout. While this isn't entirely implemented yet, it should work
correctly once all the import bits have landed. What's broken at the
moment is the template function, which currently doesn't understand the
period separator.
This commit is contained in:
James Shubin
2018-11-10 22:19:28 -05:00
parent c32183eb70
commit 046b21b907
55 changed files with 400 additions and 106 deletions

View File

@@ -1,19 +1,22 @@
$tmpdir = defaultenv("TMPDIR", "/tmp")
import "fmt"
import "sys"
$x = getenv("TEST")
$y = getenv("DOESNOTEXIST")
$z = getenv("EMPTY")
$tmpdir = sys.defaultenv("TMPDIR", "/tmp")
$a = defaultenv("TEST", "321")
$b = defaultenv("DOESNOTEXIST", "321")
$c = defaultenv("EMPTY", "456")
$x = sys.getenv("TEST")
$y = sys.getenv("DOESNOTEXIST")
$z = sys.getenv("EMPTY")
$t = hasenv("TEST")
$f = hasenv("DOESNOTEXIST")
$a = sys.defaultenv("TEST", "321")
$b = sys.defaultenv("DOESNOTEXIST", "321")
$c = sys.defaultenv("EMPTY", "456")
$env = env()
$t = sys.hasenv("TEST")
$f = sys.hasenv("DOESNOTEXIST")
$env = sys.env()
$m = maplookup($env, "TEST", "321")
file "${tmpdir}/environ" {
content => printf("%s,%s,%s:%s,%s,%s:%t,%t:%s", $x, $y, $z, $a, $b, $c, $t, $f, $m),
content => fmt.printf("%s,%s,%s:%s,%s,%s:%t,%t:%s", $x, $y, $z, $a, $b, $c, $t, $f, $m),
}

View File

@@ -25,14 +25,17 @@ if [[ ! "$tmpdir" =~ "/tmp" ]]; then
fi
cat > "$tmpdir/load0.mcl" <<EOF
\$theload = load()
import "fmt"
import "sys"
\$theload = sys.load()
\$x1 = structlookup(\$theload, "x1")
\$x5 = structlookup(\$theload, "x5")
\$x15 = structlookup(\$theload, "x15")
file "${tmpdir}/loadavg" {
content => printf("load average: %f, %f, %f", \$x1, \$x5, \$x15),
content => fmt.printf("load average: %f, %f, %f", \$x1, \$x5, \$x15),
state => "exists",
}
EOF