From 6cc5adcd25737994df83cd644ec9e0ea9b0ed78a Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 4 Nov 2023 14:52:19 -0400 Subject: [PATCH] lang, test, examples: lang: Use new syntax for structlookup Sugar makes the world go round. --- examples/lang/datetime2.mcl | 2 +- examples/lang/datetime3.mcl | 2 +- examples/lang/hysteresis1.mcl | 2 +- examples/lang/load0.mcl | 6 +++--- examples/lang/structlookup1.mcl | 4 ++-- .../TestAstFunc2/struct-duplicate3.txtar | 2 +- lang/interpret_test/TestAstFunc2/structlookup0.txtar | 6 +++--- lang/interpret_test/TestAstFunc2/structlookup1.txtar | 10 +++++----- lang/interpret_test/TestAstFunc2/structlookup2.txtar | 6 +++--- test/shell/load0.sh | 6 +++--- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/lang/datetime2.mcl b/examples/lang/datetime2.mcl index 1bc93367..97ba4859 100644 --- a/examples/lang/datetime2.mcl +++ b/examples/lang/datetime2.mcl @@ -8,7 +8,7 @@ $ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000) $tmplvalues = struct{year => $secplusone, load => $theload,} -$theload = structlookup(sys.load(), "x1") +$theload = sys.load()->x1 if 5 > 3 { file "/tmp/mgmt/datetime" { diff --git a/examples/lang/datetime3.mcl b/examples/lang/datetime3.mcl index 8d6bec7c..53de40fa 100644 --- a/examples/lang/datetime3.mcl +++ b/examples/lang/datetime3.mcl @@ -9,7 +9,7 @@ $ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000) $tmplvalues = struct{year => $secplusone, load => $theload, vumeter => $vumeter,} -$theload = structlookup(sys.load(), "x1") +$theload = sys.load()->x1 $vumeter = example.vumeter("====", 10, 0.9) diff --git a/examples/lang/hysteresis1.mcl b/examples/lang/hysteresis1.mcl index 5fc96e67..281cf1c7 100644 --- a/examples/lang/hysteresis1.mcl +++ b/examples/lang/hysteresis1.mcl @@ -7,7 +7,7 @@ file "/tmp/mgmt/systemload" { $tmplvalues = struct{load => $theload, threshold => $threshold,} -$theload = structlookup(sys.load(), "x1") +$theload = sys.load()->x1 $threshold = 1.5 # change me if you like # simple hysteresis implementation diff --git a/examples/lang/load0.mcl b/examples/lang/load0.mcl index 8333b57e..48b7ba4c 100644 --- a/examples/lang/load0.mcl +++ b/examples/lang/load0.mcl @@ -3,9 +3,9 @@ import "sys" $theload = sys.load() -$x1 = structlookup($theload, "x1") -$x5 = structlookup($theload, "x5") -$x15 = structlookup($theload, "x15") +$x1 = $theload->x1 +$x5 = $theload->x5 +$x15 = $theload->x15 print "print1" { msg => fmt.printf("load average: %f, %f, %f", $x1, $x5, $x15), diff --git a/examples/lang/structlookup1.mcl b/examples/lang/structlookup1.mcl index 45690364..b4efc15e 100644 --- a/examples/lang/structlookup1.mcl +++ b/examples/lang/structlookup1.mcl @@ -2,13 +2,13 @@ import "fmt" $st = struct{f1 => 42, f2 => true, f3 => 3.14,} -$f1 = structlookup($st, "f1") +$f1 = $st->f1 print "print1" { msg => fmt.printf("f1 field is: %d", $f1), } -$f2 = structlookup($st, "f2") +$f2 = $st->f2 print "print2" { msg => fmt.printf("f2 field is: %t", $f2), diff --git a/lang/interpret_test/TestAstFunc2/struct-duplicate3.txtar b/lang/interpret_test/TestAstFunc2/struct-duplicate3.txtar index cf3f5c00..988cdacc 100644 --- a/lang/interpret_test/TestAstFunc2/struct-duplicate3.txtar +++ b/lang/interpret_test/TestAstFunc2/struct-duplicate3.txtar @@ -1,5 +1,5 @@ -- main.mcl -- $st struct{x str} = struct{x => "hello", x => "world",} -test structlookup($st, "x") {} +test $st->x {} -- OUTPUT -- # err: errInit: duplicate struct field name of: `x` diff --git a/lang/interpret_test/TestAstFunc2/structlookup0.txtar b/lang/interpret_test/TestAstFunc2/structlookup0.txtar index 057f6c94..d7ab546c 100644 --- a/lang/interpret_test/TestAstFunc2/structlookup0.txtar +++ b/lang/interpret_test/TestAstFunc2/structlookup0.txtar @@ -1,12 +1,12 @@ -- main.mcl -- $st0 struct{x str} = struct{x => "hello",} -test structlookup($st0, "x") {} +test $st0->x {} $st1 = struct{y => "world",} -test structlookup($st1, "y") {} +test $st1->y {} $st2 = struct{x => true, y=> 42, z => "hello world",} -test structlookup($st2, "z") {} +test $st2->z {} -- OUTPUT -- Vertex: test[hello world] Vertex: test[hello] diff --git a/lang/interpret_test/TestAstFunc2/structlookup1.txtar b/lang/interpret_test/TestAstFunc2/structlookup1.txtar index 0f889ab5..d1a4b1a4 100644 --- a/lang/interpret_test/TestAstFunc2/structlookup1.txtar +++ b/lang/interpret_test/TestAstFunc2/structlookup1.txtar @@ -1,18 +1,18 @@ -- main.mcl -- $st0 = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,} -$s0a = if structlookup($st0, "x1") == 1.0 { +$s0a = if $st0->x1 == 1.0 { "passed0a" } else { "failed" } test $s0a {} -$s0b = if structlookup($st0, "x5") == 2.1 { +$s0b = if $st0->x5 == 2.1 { "passed0b" } else { "failed" } test $s0b {} -$s0c = if structlookup($st0, "x15") == 3.2 { +$s0c = if $st0->x15 == 3.2 { "passed0c" } else { "failed" @@ -20,7 +20,7 @@ $s0c = if structlookup($st0, "x15") == 3.2 { test $s0c {} $st1 struct{x1 float; x5 float; x15 float} = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,} -$s1 = if structlookup($st1, "x5") == 2.1 { +$s1 = if $st1->x5 == 2.1 { "passed1" } else { "failed" @@ -28,7 +28,7 @@ $s1 = if structlookup($st1, "x5") == 2.1 { test $s1 {} $st2 = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,} -$s2 = if structlookup($st2, "x5") == 2.1 { +$s2 = if $st2->x5 == 2.1 { "passed2" } else { "failed" diff --git a/lang/interpret_test/TestAstFunc2/structlookup2.txtar b/lang/interpret_test/TestAstFunc2/structlookup2.txtar index b27cd1c5..b2b1f97c 100644 --- a/lang/interpret_test/TestAstFunc2/structlookup2.txtar +++ b/lang/interpret_test/TestAstFunc2/structlookup2.txtar @@ -1,12 +1,12 @@ -- main.mcl -- $st0 struct{x str} = struct{x => "hello",} -test structlookup($st0, "x") {} +test $st0->x {} $st1 = struct{y => "world",} -test structlookup($st1, "y") {} +test $st1->y {} $st2 = struct{x => true, y => 42, z => "hello world",} -test structlookup($st2, "z") {} +test $st2->z {} test "foo" { mixedstruct => struct{ somebool => true, diff --git a/test/shell/load0.sh b/test/shell/load0.sh index 964fc039..7010314e 100755 --- a/test/shell/load0.sh +++ b/test/shell/load0.sh @@ -27,9 +27,9 @@ import "sys" \$theload = sys.load() -\$x1 = structlookup(\$theload, "x1") -\$x5 = structlookup(\$theload, "x5") -\$x15 = structlookup(\$theload, "x15") +\$x1 = \$theload->x1 +\$x5 = \$theload->x5 +\$x15 = \$theload->x15 file "${tmpdir}/loadavg" { content => fmt.printf("load average: %f, %f, %f\n", \$x1, \$x5, \$x15),