Nathan Ringo: 1 Some more runtime fixes and test fixes. 11 files changed, 35 insertions(+), 33 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~remexre/public-inbox/patches/25863/mbox | git am -3Learn more about email & git
This doesn't require a re-bootstrap, though it does require a runtime rebuild before the tests pass again. Not all the tests pass currently, due to a mysterious, possibly metatranslation-involving test failure. (So really, this might require a re-bootstrap before the tests pass again.) --- runtime/java/src/common/Reflection.java | 4 ++-- runtime/java/src/common/rawlib/RawGraph.java | 4 ++-- runtime/java/src/common/rawlib/RawXML.java | 4 ++-- test/patt/Basics.sv | 4 ++-- test/silver_construction/SilverConstruction.sv | 4 ++-- test/silver_features/Convenience.sv | 14 +++++++------- test/silver_features/Reflection.sv | 8 ++++---- test/silver_features/Tuple.sv | 4 ++-- test/silver_features/TypeClasses.sv | 14 ++++++++------ test/silver_features/Types.sv | 2 +- test/silver_features/rewrite/Tests.sv | 6 +++--- 11 files changed, 35 insertions(+), 33 deletions(-) diff --git a/runtime/java/src/common/Reflection.java b/runtime/java/src/common/Reflection.java index 3b4fbdcd..ade037be 100644 --- a/runtime/java/src/common/Reflection.java +++ b/runtime/java/src/common/Reflection.java @@ -320,12 +320,12 @@ public final class Reflection { final Object[] reorderedNamedArgs = new Object[fnType.namedParams.length]; for (ConsCell current = namedArgs; !current.nil(); current = current.tail()) { final NPair entry = (NPair)current.head(); - final String name = entry.getChild(0).toString(); + final String name = entry.getAnno_silver_core_fst().toString(); int index = Arrays.asList(fnType.namedParams).indexOf(name); if (index == -1) { return new Pleft(new StringCatter("Unexpected named argument " + name)); } - final NMaybe item = (NMaybe)entry.getChild(1); + final NMaybe item = (NMaybe)entry.getAnno_silver_core_snd(); if (item instanceof Pjust) { Object o; try { diff --git a/runtime/java/src/common/rawlib/RawGraph.java b/runtime/java/src/common/rawlib/RawGraph.java index f583ad63..fbf5055f 100644 --- a/runtime/java/src/common/rawlib/RawGraph.java +++ b/runtime/java/src/common/rawlib/RawGraph.java @@ -58,10 +58,10 @@ public final class RawGraph { // contains :: (Boolean ::= Pair<a a> Graph<a>) public static boolean contains(silver.core.NPair p, TreeMap<Object,TreeSet<Object>> g) { assert(p instanceof silver.core.Ppair); // document as an assert why not - final TreeSet<Object> set = g.get(p.getChild(0)); + final TreeSet<Object> set = g.get(p.getAnno_silver_core_fst()); if(set == null) return false; - return set.contains(p.getChild(1)); + return set.contains(p.getAnno_silver_core_snd()); } // toList :: ([Pair<a a>] ::= Graph<a>) diff --git a/runtime/java/src/common/rawlib/RawXML.java b/runtime/java/src/common/rawlib/RawXML.java index b3771d4a..f2cac9db 100644 --- a/runtime/java/src/common/rawlib/RawXML.java +++ b/runtime/java/src/common/rawlib/RawXML.java @@ -378,8 +378,8 @@ public final class RawXML { resolver = new TreeMap<String, String>(); for(NPair elem : new ConsCellCollection<NPair>(current)) { - String fst = elem.getChild(0).toString(); - String snd = elem.getChild(1).toString(); + String fst = elem.getAnno_silver_core_fst().toString(); + String snd = elem.getAnno_silver_core_snd().toString(); resolver.put(fst, snd); } diff --git a/test/patt/Basics.sv b/test/patt/Basics.sv index 944c0b51..f069a6f8 100644 --- a/test/patt/Basics.sv +++ b/test/patt/Basics.sv @@ -126,9 +126,9 @@ Integer ::= p::Pair<Integer Integer> { return case p of | (1,2) -> 1 -| silver:core:pair(1,_) -> 2 +| silver:core:pair(fst=1,snd=_) -> 2 | (2,1) -> 3 -| silver:core:pair(_,1) -> 4 +| silver:core:pair(fst=_,snd=1) -> 4 | _ -> 5 end; } diff --git a/test/silver_construction/SilverConstruction.sv b/test/silver_construction/SilverConstruction.sv index 5c5bffa1..ab40855d 100644 --- a/test/silver_construction/SilverConstruction.sv +++ b/test/silver_construction/SilverConstruction.sv @@ -28,7 +28,7 @@ Pattern ::= v1::Boolean v2::Boolean { local a::Pattern = if v1 then Silver_Pattern {true} else Silver_Pattern {false}; local b::Pattern = if v2 then Silver_Pattern {true} else Silver_Pattern {false}; - return Silver_Pattern { silver:core:pair($Pattern{a}, $Pattern{b}) }; + return Silver_Pattern { silver:core:pair(fst=$Pattern{a}, snd=$Pattern{b}) }; } equalityTest(hackUnparse(testPatternBools(true, true)), "silver:compiler:extension:patternmatching:prodAppPattern(silver:compiler:definition:core:qNameCons(silver:compiler:definition:core:nameIdLower('silver'), ':', silver:compiler:definition:core:qNameCons(silver:compiler:definition:core:nameIdLower('core'), ':', silver:compiler:definition:core:qNameId(silver:compiler:definition:core:nameIdLower('pair')))), '(', silver:compiler:extension:patternmatching:patternList_snoc(silver:compiler:extension:patternmatching:patternList_one(silver:compiler:extension:patternmatching:truePattern('true')), ',', silver:compiler:extension:patternmatching:truePattern('true')), ')')", String, silver_construction_tests); @@ -43,4 +43,4 @@ equalityTest(hackUnparse(Silver_TypeExpr { Boolean }), "silver:compiler:definiti equalityTest(hackUnparse(Silver_TypeExpr { Integer }), "silver:compiler:definition:type:syntax:integerTypeExpr('Integer')", String, silver_construction_tests); equalityTest(hackUnparse(Silver_TypeExpr { Float }), "silver:compiler:definition:type:syntax:floatTypeExpr('Float')", String, silver_construction_tests); equalityTest(hackUnparse(Silver_TypeExpr {Pair <String Integer>}), "silver:compiler:definition:type:syntax:appTypeExpr(silver:compiler:definition:type:syntax:nominalTypeExpr(silver:compiler:definition:core:qNameTypeId('Pair')), silver:compiler:definition:type:syntax:bTypeList('<', silver:compiler:definition:type:syntax:typeListCons(silver:compiler:definition:type:syntax:stringTypeExpr('String'), silver:compiler:definition:type:syntax:typeListSingle(silver:compiler:definition:type:syntax:integerTypeExpr('Integer'))), '>'))", String, silver_construction_tests); -equalityTest (hackUnparse(Silver_TypeExpr { [Integer] }), "silver:compiler:extension:list:listTypeExpr('[', silver:compiler:definition:type:syntax:integerTypeExpr('Integer'), ']')", String, silver_construction_tests); \ No newline at end of file +equalityTest (hackUnparse(Silver_TypeExpr { [Integer] }), "silver:compiler:extension:list:listTypeExpr('[', silver:compiler:definition:type:syntax:integerTypeExpr('Integer'), ']')", String, silver_construction_tests); diff --git a/test/silver_features/Convenience.sv b/test/silver_features/Convenience.sv index 17ae6969..e758ae38 100644 --- a/test/silver_features/Convenience.sv +++ b/test/silver_features/Convenience.sv @@ -1,21 +1,21 @@ - -nonterminal ConcreteProductions with fst<ATerm>; +synthesized attribute convValue<a>::a; +nonterminal ConcreteProductions with convValue<ATerm>; terminal ATerm ''; -- Just make sure the syntax is as expected. concrete productions top::ConcreteProductions -(oneElem) | s::ATerm { top.fst = s; } -(consElem) | s::ATerm ss::ConcreteProductions { top.fst = ss.fst; } action { print "hello"; } -(moreElem) | ss::ConcreteProductions precedence = 7 { top.fst = ss.fst; } - | s::ATerm { top.fst = s; } +(oneElem) | s::ATerm { top.convValue = s; } +(consElem) | s::ATerm ss::ConcreteProductions { top.convValue = ss.convValue; } action { print "hello"; } +(moreElem) | ss::ConcreteProductions precedence = 7 { top.convValue = ss.convValue; } + | s::ATerm { top.convValue = s; } wrongCode "$9" { abstract production dummyDontMatter top::ConcreteProductions ::= { - top.fst = $9; + top.convValue = $9; } } diff --git a/test/silver_features/Reflection.sv b/test/silver_features/Reflection.sv index 7bd8a144..10e2aeb2 100644 --- a/test/silver_features/Reflection.sv +++ b/test/silver_features/Reflection.sv @@ -264,11 +264,11 @@ global terminalReifyRes::Either<String Pair<[Foo_t] Maybe<Bar_t>>> = reify(case equalityTest( lessHackyUnparse(terminalTestValue), - s"""silver:core:pair([terminal(silver_features:Foo_t, "foo", ??:-1:-1), terminal(silver_features:Foo_t, "foo", ??:-1:-1)], silver:core:just(terminal(silver_features:Bar_t, "bar42", a:1:2)))""", + s"""silver:core:pair(fst=[terminal(silver_features:Foo_t, "foo", ??:-1:-1), terminal(silver_features:Foo_t, "foo", ??:-1:-1)], snd=silver:core:just(terminal(silver_features:Bar_t, "bar42", a:1:2)))""", String, silver_tests); equalityTest( case terminalSerializeRes of left(msg) -> msg | right(a) -> a end, - s"""silver:core:pair([terminal(silver_features:Foo_t, "foo", silver:core:loc("??", -1, -1, -1, -1, -1, -1)), terminal(silver_features:Foo_t, "foo", silver:core:loc("??", -1, -1, -1, -1, -1, -1))], silver:core:just(terminal(silver_features:Bar_t, "bar42", silver:core:loc("a", 1, 2, 3, 4, 5, 6))))""", + s"""silver:core:pair(fst=[terminal(silver_features:Foo_t, "foo", silver:core:loc("??", -1, -1, -1, -1, -1, -1)), terminal(silver_features:Foo_t, "foo", silver:core:loc("??", -1, -1, -1, -1, -1, -1))], snd=silver:core:just(terminal(silver_features:Bar_t, "bar42", silver:core:loc("a", 1, 2, 3, 4, 5, 6))))""", String, silver_tests); equalityTest(case terminalDeserializeRes of left(msg) -> msg | right(a) -> show(80, a.pp) end, lessHackyUnparse(terminalTestValue), String, silver_tests); equalityTest(reifyResToString(terminalReifyRes), lessHackyUnparse(terminalTestValue), String, silver_tests); @@ -289,11 +289,11 @@ global reifyRes12::Either<String Pair<String [Integer]>> = deserialize("test", f equalityTest( case serializeRes1 of left(msg) -> msg | right(a) -> a end, - s"""silver:core:pair("hello", [1, 2, 3, 4])""", + s"""silver:core:pair(fst="hello", snd=[1, 2, 3, 4])""", String, silver_tests); equalityTest( reifyResToString(reifyRes12), - s"""silver:core:pair("hello", [1, 2, 3, 4])""", + s"""silver:core:pair(fst="hello", snd=[1, 2, 3, 4])""", String, silver_tests); type ForeignString foreign = "String"; diff --git a/test/silver_features/Tuple.sv b/test/silver_features/Tuple.sv index a793004d..1aa4bb1f 100644 --- a/test/silver_features/Tuple.sv +++ b/test/silver_features/Tuple.sv @@ -126,7 +126,7 @@ function makeDate return (day, month, year); } -equalityTest(hackUnparse(makeDate(1, 12, 2021)), "silver:core:pair(1, silver:core:pair(12, 2021))", String, silver_tests); +equalityTest(hackUnparse(makeDate(1, 12, 2021)), "silver:core:pair(fst=1, snd=silver:core:pair(12, 2021))", String, silver_tests); function temp String ::= @@ -273,4 +273,4 @@ global y::Integer = id((1, 3)).1; global z::String = id(("hello", "this", "is", "test")).4; equalityTest(y, 1, Integer, silver_tests); -equalityTest(z, "test", String, silver_tests); \ No newline at end of file +equalityTest(z, "test", String, silver_tests); diff --git a/test/silver_features/TypeClasses.sv b/test/silver_features/TypeClasses.sv index bc06cc69..2a59bd2e 100644 --- a/test/silver_features/TypeClasses.sv +++ b/test/silver_features/TypeClasses.sv @@ -75,12 +75,14 @@ equalityTest(myRemove(3, [1, 2, 3, 4]), [1, 2, 4], [Integer], silver_tests); inherited attribute isEqTo<a>::a; synthesized attribute isEq::Boolean; -nonterminal EqPair<a b> with fst<a>, snd<b>, isEqTo<EqPair<a b>>, isEq; +synthesized attribute fstAttr<a>::a; +synthesized attribute sndAttr<a>::a; +nonterminal EqPair<a b> with fstAttr<a>, sndAttr<b>, isEqTo<EqPair<a b>>, isEq; production eqPair MyEq a, MyEq b => top::EqPair<a b> ::= x::a y::b { - top.fst = x; - top.snd = y; + top.fstAttr = x; + top.sndAttr = y; top.isEq = case top.isEqTo of eqPair(x1, y1) -> myeq(x1, x) && myeq(y1, y) end; } @@ -92,7 +94,7 @@ synthesized attribute isEq2::Boolean occurs on EqPair<a b>; aspect production eqPair top::EqPair<a b> ::= x::a y::b { - top.isEq2 = myeq(top.isEqTo.fst, x) && myeq(top.isEqTo.snd, y); + top.isEq2 = myeq(top.isEqTo.fstAttr, x) && myeq(top.isEqTo.sndAttr, y); } equalityTest(decorate eqPair(42, [1, 2, 3]) with {isEqTo=eqPair(42, [1, 2, 3]);}.isEq2, true, Boolean, silver_tests); @@ -360,7 +362,7 @@ instance MyTypeable Integer { } instance runtimeTypeable a, MyTypeable b => MyTypeable Pair<a b> { - myreify = \ a::AST -> case a of AST { silver:core:pair(fst, snd) } -> (reifyUnchecked(fst), myreify(snd)) | _ -> error("not pair") end; + myreify = \ a::AST -> case a of AST { silver:core:pair(fst=fst, snd=snd) } -> (reifyUnchecked(fst), myreify(snd)) | _ -> error("not pair: " ++ hackUnparse(a)) end; } equalityTest(myreify(reflect(42)), 42, Integer, silver_tests); @@ -438,7 +440,7 @@ instance typeError "Not decorated" => NotDecThing Decorated a with i { global ndt1::String = consumeNDT((12, false)); equalityTest(ndt1, "silver:core:Pair<Integer Boolean>", String, silver_tests); -wrongCode "Not decorated (arising from the instance for silver_features:NotDecThing Decorated silver:core:Pair<Integer Boolean> with {}, arising from the use of consumeNDT)" { +wrongCode "Not decorated (arising from the instance for silver_features:NotDecThing Decorated (Integer, Boolean) with {}, arising from the use of consumeNDT)" { global ndt2::String = consumeNDT(decorate (12, false) with {}); } diff --git a/test/silver_features/Types.sv b/test/silver_features/Types.sv index d536d888..7cbb73c2 100644 --- a/test/silver_features/Types.sv +++ b/test/silver_features/Types.sv @@ -98,7 +98,7 @@ wrongCode "(a1, a)" { global foo::(a1, a) = 42; } wrongCode "(a, b) has initialization expression with type (silver:core:Pair<c a> ::= c a)" { - global foo::(a, b) = (_, _); + global foo::(a, b) = pair(fst=_, snd=_); } -------------------------------------- Type Decls diff --git a/test/silver_features/rewrite/Tests.sv b/test/silver_features/rewrite/Tests.sv index fa460a9a..1b7ffdc9 100644 --- a/test/silver_features/rewrite/Tests.sv +++ b/test/silver_features/rewrite/Tests.sv @@ -92,7 +92,7 @@ equalityTest(s:rewriteWith(s8, [foo(2), foo(2), foo(3)]), just([foo(2), foo(3)]) global s9::s:Strategy = rule on Pair<Integer Integer> of - | (a, b) -> (b, _)(a) + | (a, b) -> pair(fst=b, snd=_)(a) end; equalityTest(s:rewriteWith(s9, (123, 456)), just((456, 123)), Maybe<Pair<Integer Integer>>, silver_tests); @@ -152,7 +152,7 @@ equalityTest(s:rewriteWith(s13, [["a"]]), nothing(), Maybe<[[String]]>, silver_t global inc::s:Strategy = rule on Integer of i -> i + 1 end; -global s15::s:Strategy = traverse (_, inc); +global s15::s:Strategy = traverse pair(fst=_, snd=inc); equalityTest(s:rewriteWith(s15, (1, 2)), just((1, 3)), Maybe<Pair<Integer Integer>>, silver_tests); equalityTest(s:rewriteWith(s15, ("a", "b")), nothing(), Maybe<Pair<String String>>, silver_tests); @@ -162,7 +162,7 @@ global s16::s:Strategy = traverse barI(inc, a1=inc, a1=_, a1=inc); equalityTest(s:rewriteWith(s16, barI(1, a1=2, a2=3)), just(barI(2, a1=4, a2=3)), Maybe<Bar>, silver_tests); -global s17::s:Strategy = s:rec(\ s::s:Strategy -> traverse (s, s) <+ s:try(inc)); +global s17::s:Strategy = s:rec(\ s::s:Strategy -> traverse pair(fst=s, snd=s) <+ s:try(inc)); equalityTest(s:rewriteWith(s17, (1, 2)), just((2, 3)), Maybe<Pair<Integer Integer>>, silver_tests); equalityTest( -- 2.33.0