# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ ? def vm__uriGetter := # value: ? def makeNounExpr := # value: ? def makeViaPattern := # value: ? def makeFinalPattern := # value: ? def makeIgnorePattern := # value: ? def makeLiteralExpr := # value: --- Node-specific tests --- LiteralExpr ? def oneExpr := makeLiteralExpr(null, 1, null) # value: e`1` ? oneExpr.staticScope() # value: <[] := [] =~ [] + var []> Bug test: print of char ? makeLiteralExpr(null, 'a', null) # value: e`'a'` XXX other value types XXX Data requirement XXX methods AssignExpr ? def makeAssignExpr := # value: ? def expr := makeAssignExpr(null, makeNounExpr(null, "pi", null), makeLiteralExpr(null, 3.14159, null), null) # value: e`pi := 3.14159` ? expr.getRValue() # value: e`3.14159` ? expr.getNoun() # value: e`pi` Kernel-E check x ? e`a[] := b`.eval(safeScope) x # problem: e`$$ := b` must have "noun" of type NounExpr, but had GetExpr XXX this test can't work until e`` is made to generate nonkernel expressions DefineExpr ? def makeDefineExpr := # value: ? def expr := makeDefineExpr(null, makeFinalPattern(null, makeNounExpr(null, "a", null), null, null), null, makeLiteralExpr(null, 1, null), null) # value: e`def a := 1` print of trinary ? makeDefineExpr(null, makeFinalPattern(null, makeNounExpr(null, "a", null), null, null), makeNounExpr(null, "ej", null), makeLiteralExpr(null, 1, null), null) # value: e`def a exit ej := 1` ? expr.getRValue() # value: e`1` ? expr.getPattern() # value: epatt`a` ? makeDefineExpr(null, makeFinalPattern(null, makeNounExpr(null, "a", null), null, null), null, makeLiteralExpr(null, 1, null), null).staticScope() # value: <[] := [] =~ ["a"] + var []> ? makeDefineExpr(null, 1, 2, 3, null) # problem: the int 1 doesn't coerce to a Pattern XXX trinary-define scope Reject pseudo-self-reference ? def nounA := makeNounExpr(null, "a", null); null ? def nounB := makeNounExpr(null, "b", null); null ? {makeDefineExpr(null, makeFinalPattern(null, nounA, null, null), null, nounA, null)}.eval(safeScope) # problem: ? {makeDefineExpr(null, makeFinalPattern(null, nounA, null, null), nounA, makeNounExpr(null, "null", null), null)}.eval(safeScope) # problem: ? {makeDefineExpr(null, makeViaPattern(null, nounA, makeIgnorePattern(null, null), null), null, makeDefineExpr(null, makeFinalPattern(null, nounA, null, null), null, nounB, null), null)}.eval(safeScope) # problem: ? {makeDefineExpr(null, makeViaPattern(null, nounA, makeIgnorePattern(null, null), null), makeDefineExpr(null, makeFinalPattern(null, nounA, null, null), null, nounB, null), nounB, null)}.eval(safeScope) # problem: XXX more specifically test what part of the system does this check rather than just 'somewhere in the eval process' FinalPattern ? makeFinalPattern(null, makeNounExpr(null, "timer", null), null, null) # value: epatt`timer` ? makeFinalPattern(null, makeNounExpr(null, "items", null), makeNounExpr(null, "List", null), null) # value: epatt`items :List` ? makeFinalPattern(null, makeNounExpr(null, "*bip*", null), null, null) # value: epatt`::"*bip*"` ? makeFinalPattern(null, def n := makeNounExpr(null, "a", null), null, null).getNoun() == n # value: true ? makeFinalPattern(null, makeNounExpr(null, "a", null), null, null).staticScope() # value: <[] := [] =~ ["a"] + var []> XXX scope with guard expr XXX methods CallExpr ? def makeCallExpr := # value: ? def sumExpr := makeCallExpr(null, oneExpr, "add", [oneExpr], null) # value: e`1.add(1)` ? sumExpr.staticScope() # value: <[] := [] =~ [] + var []> ? sumExpr.getRecipient() # value: e`1` ? sumExpr.getVerb() # value: "add" ? sumExpr.getArgs() # value: [e`1`] print test - XXX move this to syntax tests ? makeCallExpr(null, oneExpr, "%%", [oneExpr], null) # value: e`1."%%"(1)` CatchExpr ? def expr := (null, oneExpr, makeIgnorePattern(null, null), makeNounExpr(null, "fail", null), null) # value: e`try { # 1 # } catch _ { # fail # }` ? expr.getAttempt() # value: e`1` ? expr.getPattern() # value: epatt`_` ? expr.getCatcher() # value: e`fail` XXX incomplete?, written just for checking getter methods HideExpr ? # value: ? def expr := (null, (null, "a", null), null) # value: e`{ # a # }` ? expr.getBlock() # value: e`a` IfExpr ? def expr := (null, makeNounExpr(null, "a", null), makeNounExpr(null, "b", null), makeNounExpr(null, "c", null), null) # value: e`if (a) { # b # } else { # c # }` ? expr.getTest() # value: e`a` ? expr.getThen() # value: e`b` ? expr.getElse() # value: e`c` NounExpr ? makeNounExpr(null, "xy", null) # value: e`xy` ? makeNounExpr(null, "a", null).getName() # value: "a" ? makeNounExpr(null, "b", null).staticScope() # value: <[] := ["b"] =~ [] + var []> non-identifier ? makeNounExpr(null, "wasn't", null) # value: e`::"wasn't"` EMethod ? def makeEMethod := # value: ? makeEMethod(null, "egf", "rhg", [], null, makeLiteralExpr(null, 1, null), null) # value: e??` # /** egf */ # method rhg() { # 1 # }` ? def methd := makeEMethod(null, "egf", "rhg", [], makeNounExpr(null, "void", null), makeLiteralExpr(null, 1, null), null) # value: e??` # /** egf */ # method rhg() :void { # 1 # }` ? methd.getDocComment() # value: "egf" ? methd.getVerb() # value: "rhg" ? methd.getPatterns() # value: [] ? methd.getOptResultGuard() # value: e`void` ? methd.getBody() # value: e`1` ? makeEMethod(null, null, "+", [], makeNounExpr(null, "any", null), makeLiteralExpr(null, 1, null), null) # value: e??` # method "+"() :any { # 1 # }` ? makeEMethod(null, "egf", "rhg", [], null, makeNounExpr(null, "tjh", null), null).staticScope() # value: <[] := ["tjh"] =~ [] + var []> XXX other methods of EMethod XXX separate out print tests ObjectExpr, EScript ? def makeObjectExpr := # value: ? def makeEScript := # value: ? def makeEMatcher := # value: ? def makeAuditors := # value: ? def emptyAuditors := makeAuditors(null, null, [], null) # value: e??`` XXX write tests for Auditors ? def emptyObject := makeObjectExpr(null, "foo", makeFinalPattern(null, makeNounExpr(null, "bar", null), null, null), emptyAuditors, def emptyScript := makeEScript(null, [], [], null), null) # value: e`/** foo */ # def bar { # }` ? emptyObject.getDocComment() # value: "foo" ? emptyObject.getPattern() # value: epatt`bar` ? emptyObject.getAuditors() # value: e??`` ? emptyObject.getScript() # value: e??`{ # }` ? emptyObject.asTypeDesc(safeScope.getFQNPrefix()) == emptyObject.eval(safeScope).__getAllegedType() # value: true ? emptyObject.staticScope() # value: <[] := [] =~ ["bar"] + var []> Implements expression is not visible ? makeObjectExpr(null, "foo", makeIgnorePattern(null, null), makeAuditors(null, null, [makeDefineExpr(null, makeFinalPattern(null, nounA, null, null), null, nounB, null)], null), emptyScript, null).staticScope() # value: <[] := ["b"] =~ [] + var []> ? def thunkScript := makeEScript(null, [makeEMethod(null, null, "run", [], null, makeNounExpr(null, "foo", null), null)], [], null) # value: e??`{ # # method run() { # foo # } # }` XXX check all arrangemets of null subnodes ? thunkScript.staticScope() # value: <[] := ["foo"] =~ [] + var []> ? def fooThunk := makeObjectExpr(null, null, makeFinalPattern(null, makeNounExpr(null, "fooThunk", null), null, null), emptyAuditors, thunkScript, null) # value: e`def fooThunk { # # method run() { # foo # } # }` ? fooThunk.staticScope() # value: <[] := ["foo"] =~ ["fooThunk"] + var []> ? fooThunk.getScript() == thunkScript # value: true ? fooThunk.asTypeDesc(safeScope.getFQNPrefix()) == fooThunk.eval(safeScope.with("foo", 1)).__getAllegedType() # value: true printing implements ? makeObjectExpr(null, null, makeFinalPattern(null, makeNounExpr(null, "audited", null), null, null), makeAuditors(null, null, [makeNounExpr(null, "auditor", null)], null), emptyScript, null) # value: e`def audited implements auditor { # }` printing _ ? makeObjectExpr(null, null, makeIgnorePattern(null, null), emptyAuditors, def emptyScript := makeEScript(null, [], [], null), null) # value: e`def _ { # }` script printing with matchers XXX standalone IgnorePattern tests ? def bothScript := makeEScript(null, [makeEMethod(null, null, "run", [], null, makeNounExpr(null, "foo", null), null)], [makeEMatcher(null, makeIgnorePattern(null, null), makeLiteralExpr(null, 1, null), null)], null) # value: e??`{ # # method run() { # foo # } # match _ { # 1 # } # }` ? bothScript.getMethods() # value: [e??` # method run() { # foo # }`] ? bothScript.getMatchers() # value: [e??`match _ { # 1 # }`] ? def matcher := makeEMatcher(null, makeIgnorePattern(null, null), makeLiteralExpr(null, 1, null), null) # value: e??`match _ { # 1 # }` Plumbing print: ? makeObjectExpr(null, null, makeIgnorePattern(null, null), emptyAuditors, matcher, null) # value: e`def _ match _ { # 1 # }` XXX multiple-matcher printing tests SeqExpr ? def makeSeqExpr := # value: ? makeSeqExpr(null, [], null) # problem: SeqExpr must have at least one subexpression ? makeSeqExpr(null, [sumExpr], null) # value: e`1.add(1)` ? def expr := makeSeqExpr(null, [sumExpr, oneExpr], null) # value: e`1.add(1) # 1` ? expr.getSubs() # value: [e`1.add(1)`, e`1`] EscapeExpr ? def makeEscapeExpr := # value: ? makeEscapeExpr(null, makeFinalPattern(null, makeNounExpr(null, "foo", null), null, null), makeLiteralExpr(null, 1, null), null, null, null) # value: e`escape foo { # 1 # }` ? makeEscapeExpr(null, makeFinalPattern(null, makeNounExpr(null, "foo", null), null, null), makeSeqExpr(null, [makeNounExpr(null, "foo", null), makeNounExpr(null, "baz", null)], null), null, null, null).staticScope() # value: <[] := ["baz"] =~ [] + var []> VarPattern ? def makeVarPattern := # value: ? makeVarPattern(null, makeNounExpr(null, "foo", null), null, null) # value: epatt`var foo` ? makeVarPattern(null, makeNounExpr(null, "i", null), makeNounExpr(null, "int", null), null) # value: epatt`var i :int` ? makeVarPattern(null, makeNounExpr(null, "*bip*", null), null, null) # value: epatt`var ::"*bip*"` --- node scope computation --- ? def StaticWalkEnvironment := # value: StaticWalkEnvironment ? def makeReporter() { > var i := 0 > var outs := [stdout].diverge() > def submake() { > def label := i += 1 > return def reporter implements StaticWalkEnvironment { > to __printOn(out :TextWriter) { out.print("<", label, ">") } > to withHide(f) { > def subRep := submake() > outs.last().print("\n", reporter, ".withHide(", f, ") => f(", subRep, ")") > outs.push(outs.last().indent()) > def res := f(subRep) > outs.pop() > def answer := submake() > outs.last().print("\n=> ", res, " => ", answer) > return answer > } > to withScript(f) { > def subRep := submake() > outs.last().print("\n", reporter, ".withScript(", f, ") => f(", subRep, ")") > outs.push(outs.last().indent()) > def res := f(subRep) > outs.pop() > def answer := submake() > outs.last().print("\n=> ", res, " => ", answer) > return answer > } > match msg { > def answer := submake() > outs.last().print("\n", reporter, ".", msg[0], msg[1], " => ", answer) > answer > } > } > } > return submake() > } # value: AssignExpr ? e`a := (def bb := b)`.asKernelE().staticScope() # value: <["a"] := ["b"] =~ ["bb"] + var []> ? e`a := b`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withAssignment[e`a`] => <2> # <2>.withSubnode["rValue", e`b`] => <3> # value: <3> BindingExpr ? e`&&any`.asKernelE().staticScope() # value: <[] := ["any"] =~ [] + var []> ? e`&&a`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withNounUse[e`a`] => <2> # value: <2> CallExpr ? e`a.b(def cc := c, d)`.asKernelE().staticScope() # value: <[] := ["d", "c", "a"] =~ ["cc"] + var []> ? e`a.b(c, d)`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["recipient", e`a`] => <2> # <2>.withSubnodeIndex["args", 0, e`c`] => <3> # <3>.withSubnodeIndex["args", 1, e`d`] => <4> # value: <4> CatchExpr ? e`try { def aa := a } catch via (c) b { def dd := d }`.asKernelE().staticScope() # value: <[] := ["d", "c", "a"] =~ [] + var []> ? e`try { a } catch b { c }`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["attempt", e`a`] => <3> # => <3> => <4> # <4>.withHide(<...lisp$_>) => f(<5>) # <5>.withSubnode["pattern", epatt`b`] => <6> # <6>.withSubnode["catcher", e`c`] => <7> # => <7> => <8> # value: <8> DefineExpr ? e`def a := (def bb := b)`.asKernelE().staticScope() # value: <[] := ["b"] =~ ["bb", "a"] + var []> ? e`def a := b`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["pattern", epatt`a`] => <2> # <2>.withSubnode["rValue", e`b`] => <3> # value: <3> ? e`def a exit b := c`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["pattern", epatt`a`] => <2> # <2>.withSubnode["optEjectorExpr", e`b`] => <3> # <3>.withSubnode["rValue", e`c`] => <4> # value: <4> EscapeExpr ? e`escape via (b) a { def cc := c }`.asKernelE().staticScope() # value: <[] := ["c", "b"] =~ [] + var []> ? e`escape a { b }`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["ejectorPattern", epatt`a`] => <3> # <3>.withSubnode["body", e`b`] => <4> # => <4> => <5> # <5>.withHide(<...lisp$_>) => f(<6>) # => <6> => <7> # value: <7> ? e`escape a { b } catch c { d }`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["ejectorPattern", epatt`a`] => <3> # <3>.withSubnode["body", e`b`] => <4> # => <4> => <5> # <5>.withHide(<...lisp$_>) => f(<6>) # <6>.withSubnode["optCatchPattern", epatt`c`] => <7> # <7>.withSubnode["optCatchBody", e`d`] => <8> # => <8> => <9> # value: <9> FinallyExpr ? e`try { def aa := a } finally { def bb := b }`.asKernelE().staticScope() # value: <[] := ["b", "a"] =~ [] + var []> ? e`try { a } finally { b }`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["attempt", e`a`] => <3> # => <3> => <4> # <4>.withHide(<...lisp$_>) => f(<5>) # <5>.withSubnode["unwinder", e`b`] => <6> # => <6> => <7> # value: <7> HideExpr ? e`{ def aa := a }`.asKernelE().staticScope() # value: <[] := ["a"] =~ [] + var []> ? e`{ a }`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["block", e`a`] => <3> # => <3> => <4> # value: <4> IfExpr ? e`if (def aa := a) { def bb := b } else { def cc := c }`.asKernelE().staticScope() # value: <[] := ["c", "b", "a"] =~ [] + var []> ? e`if (a) { b } else { c }`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["test", e`a`] => <3> # <3>.withSubnode["then", e`b`] => <4> # => <4> => <5> # <5>.withHide(<...lisp$_>) => f(<6>) # <6>.withSubnode["else", e`c`] => <7> # => <7> => <8> # value: <8> LiteralExpr ? e`"hi"`.asKernelE().staticScope() # value: <[] := [] =~ [] + var []> ? e`"hi"`.asKernelE().walkScopes(makeReporter()) # value: <1> MetaContextExpr ? e`meta.context()`.asKernelE().staticScope() # value: <[] := [] =~ [] + var []> ? e`meta.context()`.asKernelE().walkScopes(makeReporter()) # value: <1> MetaStateExpr ? e`meta.getState()`.asKernelE().staticScope() # value: <[] := [] =~ [] + var [], meta.getState()> ? def mSSS := e`fn { meta.getState() }`.asKernelE().staticScope() # value: <[] := [] =~ [] + var [], { meta.getState() }> ? [mSSS.hasMetaStateExpr(), > mSSS.hasOuterMetaStateExpr(), > mSSS."uses"("x")] # value: [true, false, false] ? e`meta.getState()`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withMetaState[] => <2> # value: <2> NounExpr ? e`boolean`.asKernelE().staticScope() # value: <[] := ["boolean"] =~ [] + var []> ? e`a`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withNounUse[e`a`] => <2> # value: <2> ObjectExpr ? e`def x implements a, b { > method y(c) :d { e } > match f { g } > }`.asKernelE().staticScope() # value: <[] := ["g", "e", "d", "b", "a"] =~ ["x"] + var []> ? e`def x as a implements b {}`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["pattern", epatt`x`] => <2> # <2>.withHide(<...lisp$_>) => f(<3>) # <3>.withSubnode["auditors", e??` as a implements b`] => <4> # => <4> => <5> # <5>.withScript(<...lisp$_>) => f(<6>) # <6>.withSubnode["script", e??`{ # }`] => <7> # => <7> => <8> # value: <8> Plumbing ObjectExpr ? e`def x implements a match b { c }`.asKernelE().staticScope() # value: <[] := ["c", "a"] =~ ["x"] + var []> There is no walkScopes test for this case since it's composed of ObjectExpr and EMatcher. EScript ? def script := e`def _ { > method y(c) :(def dd := d) { c; dd; def ee := e } > match f { f; def gg := g } > }`.asKernelE().getScript(); null ? script.staticScope() # value: <[] := ["g", "e", "d"] =~ [] + var []> ? script.walkScopes(makeReporter()) # stdout: # <1>.withSubnodeIndex["methods", 0, e??` # method y(c) :(def dd := d) { # c # dd # def ee := e # }`] => <2> # <2>.withSubnodeIndex["matchers", 0, e??`match f { # f # def gg := g # }`] => <3> # value: <3> EMethod ? def ::"method" := script.getMethods()[0]; null ? ::"method".staticScope() # value: <[] := ["e", "d"] =~ [] + var []> ? ::"method".walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnodeIndex["patterns", 0, epatt`c`] => <3> # <3>.withSubnode["optResultGuard", e`def dd := d`] => <4> # <4>.withSubnode["body", e`c # dd # def ee := e`] => <5> # => <5> => <6> # value: <6> EMatcher ? def matcher := script.getMatchers()[0]; null ? matcher.staticScope() # value: <[] := ["g"] =~ [] + var []> ? matcher.walkScopes(makeReporter()) # stdout: # <1>.withHide(<...lisp$_>) => f(<2>) # <2>.withSubnode["pattern", epatt`f`] => <3> # <3>.withSubnode["body", e`f # def gg := g`] => <4> # => <4> => <5> # value: <5> SeqExpr ? e`(def aa := a); (def bb := b)`.asKernelE().staticScope() # value: <[] := ["b", "a"] =~ ["bb", "aa"] + var []> ? e`a; b`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnodeIndex["subs", 0, e`a`] => <2> # <2>.withSubnodeIndex["subs", 1, e`b`] => <3> # value: <3> BindingPattern ? epatt`&&a`.asKernelE().staticScope() # value: <[] := [] =~ [] + var ["a"]> ? epatt`&&a`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withBindingPattern[epatt`&&a`] => <2> # value: <2> FinalPattern ? epatt`a`.asKernelE().staticScope() # value: <[] := [] =~ ["a"] + var []> ? epatt`a :b`.asKernelE().staticScope() # value: <[] := ["b"] =~ ["a"] + var []> ? epatt`a`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withFinalPattern[epatt`a`] => <2> # value: <2> ? epatt`a :b`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["optGuardExpr", e`b`] => <2> # <2>.withFinalPattern[epatt`a :b`] => <3> # value: <3> IgnorePattern ? epatt`_`.asKernelE().staticScope() # value: <[] := [] =~ [] + var []> ? epatt`_`.asKernelE().walkScopes(makeReporter()) # value: <1> ListPattern ? epatt`[a, b, c]`.asKernelE().staticScope() # value: <[] := [] =~ ["c", "b", "a"] + var []> ? epatt`[a, b]`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnodeIndex["subs", 0, epatt`a`] => <2> # <2>.withSubnodeIndex["subs", 1, epatt`b`] => <3> # value: <3> ViaPattern ? epatt`via (def aa := a) b`.asKernelE().staticScope() # value: <[] := ["a"] =~ ["b", "aa"] + var []> ? epatt`via (def aa := a) via (aa) b`.asKernelE().staticScope() # value: <[] := ["a"] =~ ["b", "aa"] + var []> ? epatt`via (a) b`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["function", e`a`] => <2> # <2>.withSubnode["pattern", epatt`b`] => <3> # value: <3> VarPattern ? epatt`var a`.asKernelE().staticScope() # value: <[] := [] =~ [] + var ["a"]> ? epatt`var a :b`.asKernelE().staticScope() # value: <[] := ["b"] =~ [] + var ["a"]> ? epatt`var a`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withVarPattern[epatt`var a`] => <2> # value: <2> ? epatt`var a :b`.asKernelE().walkScopes(makeReporter()) # stdout: # <1>.withSubnode["optGuardExpr", e`b`] => <2> # <2>.withVarPattern[epatt`var a :b`] => <3> # value: <3> --- Visitors --- These tests check the arguments which nodes give to visitors. ? def makeVisitor(depth) :any { > return def spamVisitor { > match [`visit@name`, [optOriginal] + elements] { > println(`${" " * depth}$name ${E.toQuote(optOriginal).split("\n")[0]}...`) > for element in elements { > if (element.__respondsTo("welcome", 1)) { element.welcome(makeVisitor(depth + 1)) > } else if (element =~ l :List ? (l !~ s :String)) { E.call(makeVisitor(depth + 1), "visit_list", [null] + l) > } else { > println(`${" " * (depth + 1)}$element`) > } > } > } > } > } # value: ? e`target := value`.asKernelE().welcome(makeVisitor(0)) # stdout: AssignExpr e`target := value`... # NounExpr e`target`... # target # NounExpr e`value`... # value # ? e`1 + 1`.asKernelE().welcome(makeVisitor(0)) # stdout: CallExpr e`1.add(1)`... # LiteralExpr e`1`... # 1 # add # _list null... # LiteralExpr e`1`... # 1 # ? e`try { attempt } catch cpatt { catcher }`.asKernelE().welcome(makeVisitor(0)) # stdout: CatchExpr e`try {... # NounExpr e`attempt`... # attempt # FinalPattern epatt`cpatt`... # NounExpr e`cpatt`... # cpatt # null # NounExpr e`catcher`... # catcher # ? e`def a := b`.asKernelE().welcome(makeVisitor(0)) # stdout: DefineExpr e`def a := b`... # FinalPattern epatt`a`... # NounExpr e`a`... # a # null # null # NounExpr e`b`... # b # ? e`escape patt { body } catch cpatt { catcher }`.asKernelE().welcome(makeVisitor(0)) # stdout: EscapeExpr e`escape patt {... # FinalPattern epatt`patt`... # NounExpr e`patt`... # patt # null # NounExpr e`body`... # body # FinalPattern epatt`cpatt`... # NounExpr e`cpatt`... # cpatt # null # NounExpr e`catcher`... # catcher # ? e`try { attempt } finally { cleanup }`.asKernelE().welcome(makeVisitor(0)) # stdout: FinallyExpr e`try {... # NounExpr e`attempt`... # attempt # NounExpr e`cleanup`... # cleanup # ? e`{ body }`.asKernelE().welcome(makeVisitor(0)) # stdout: HideExpr e`{... # NounExpr e`body`... # body # ? e`if (cond) { true } else { false }`.asKernelE().welcome(makeVisitor(0)) # stdout: IfExpr e`if (cond) {... # NounExpr e`cond`... # cond # NounExpr e`true`... # true # NounExpr e`false`... # false # ? e`"abc"`.asKernelE().welcome(makeVisitor(0)) # stdout: LiteralExpr e`"abc"`... # abc # ? e`meta.context()`.asKernelE().welcome(makeVisitor(0)) # stdout: MetaContextExpr e`meta.context()`... # ? e`meta.getState()`.asKernelE().welcome(makeVisitor(0)) # stdout: MetaStateExpr e`meta.getState()`... # ? e`noun`.asKernelE().welcome(makeVisitor(0)) # stdout: NounExpr e`noun`... # noun # ? e`def obj1 implements auditor { > method aMethod(param) :resultGuard { methodBody } > match matcherPatt { matcherBody } > }`.asKernelE().welcome(makeVisitor(0)) # stdout: ObjectExpr e`def obj1 implements auditor {... # null # FinalPattern epatt`obj1`... # NounExpr e`obj1`... # obj1 # null # Auditors e??` implements auditor`... # null # _list null... # NounExpr e`auditor`... # auditor # EScript e??`{... # _list null... # EMethod e??`... # null # aMethod # _list null... # FinalPattern epatt`param`... # NounExpr e`param`... # param # null # NounExpr e`resultGuard`... # resultGuard # NounExpr e`methodBody`... # methodBody # _list null... # EMatcher e??`match matcherPatt {... # FinalPattern epatt`matcherPatt`... # NounExpr e`matcherPatt`... # matcherPatt # null # NounExpr e`matcherBody`... # matcherBody # ? e`def obj2 match plumbingPatt { plumbingBody }`.asKernelE().welcome(makeVisitor(0)) # stdout: ObjectExpr e`def obj2 match plumbingPatt {... # null # FinalPattern epatt`obj2`... # NounExpr e`obj2`... # obj2 # null # Auditors e??``... # null # _list null... # EMatcher e??`match plumbingPatt {... # FinalPattern epatt`plumbingPatt`... # NounExpr e`plumbingPatt`... # plumbingPatt # null # NounExpr e`plumbingBody`... # plumbingBody # ? e`first; second`.asKernelE().welcome(makeVisitor(0)) # stdout: SeqExpr e`first... # _list null... # NounExpr e`first`... # first # NounExpr e`second`... # second # ? e`&&bindingNoun`.asKernelE().welcome(makeVisitor(0)) # stdout: BindingExpr e`&&bindingNoun`... # NounExpr e`bindingNoun`... # bindingNoun # ? epatt`_`.asKernelE().welcome(makeVisitor(0)) # stdout: IgnorePattern epatt`_`... # ? epatt`[listelem]`.asKernelE().welcome(makeVisitor(0)) # stdout: ListPattern epatt`[listelem]`... # _list null... # FinalPattern epatt`listelem`... # NounExpr e`listelem`... # listelem # null # ? epatt`finalNoun :guard`.asKernelE().welcome(makeVisitor(0)) # stdout: FinalPattern epatt`finalNoun :guard`... # NounExpr e`finalNoun`... # finalNoun # NounExpr e`guard`... # guard # ? epatt`var varNoun :guard`.asKernelE().welcome(makeVisitor(0)) # stdout: VarPattern epatt`var varNoun :guard`... # NounExpr e`varNoun`... # varNoun # NounExpr e`guard`... # guard # ? epatt`&&bindingNoun`.asKernelE().welcome(makeVisitor(0)) # stdout: BindingPattern epatt`&&bindingNoun`... # NounExpr e`bindingNoun`... # bindingNoun # --- getOptPrincipalNoun --- ? (def simplest := (null, (null, "foo", null), null, null)).getOptPrincipalNoun() # value: "foo" ? (null, (null, "foo", null), null, null).getOptPrincipalNoun() # value: "foo" ? (null, (null, "foo", null), null).getOptPrincipalNoun() # value: "foo" XXX should be &&foo? ? (def listPatt := (null, [simplest], null)).getOptPrincipalNoun() ? (null, null).getOptPrincipalNoun() --- requireKernelE --- This section tests that the requireKernelE/1 method works and that it reports all types of errors through the ejector parameter, as it should. It does not test all of the Kernel-E constraints; merely one of each code path. ? def rket(n) { return [true, escape r { n.requireKernelE(r) } catch p { return [false,p] }] }; null XXX should something like this, for distinguishing ejection from return from throw, be available as a utility? (also rfst below) Kernel-E node types ? rket(e`x`) # value: [true, null] x ? rket(e`[x]`) x # value: [true, problem: e`[x]` is not Kernel-E] XXX this SHOULD be a failure, but requireKernelE doesn't actually check that the nodes are kernel node types, just other stuff Scope-based checks ? rket(e`${makeDefineExpr(null, epatt`var x`, null, e`1`, null)}; ${makeAssignExpr(null, e`x`, e`2`, null)}`) # value: [true, null] ? rket(e`${makeDefineExpr(null, epatt`x`, null, e`1`, null)}; ${makeAssignExpr(null, e`x`, e`2`, null)}`) # value: [false, problem: x is not an assignable variable] Usage constraints ? rket(makeDefineExpr(null, epatt`x`, null, e`y`, null)) # value: [true, null] ? rket(makeDefineExpr(null, epatt`x`, null, e`x`, null)) # value: [false, problem: ] Special usage constraint ? rket(epatt`a :b`) # value: [true, null] ? rket(epatt`a :a`) # value: [false, problem: kernel FinalPattern may not use its own noun (e`a`) in its guard (e`a`)] Property types ? rket(makeAssignExpr(null, e`a`, e`b`, null)) # value: [true, null] ? rket(makeAssignExpr(null, e`1`, e`b`, null)) # value: [false, problem: e`1 := b` must have noun of type NounExpr, but had 1] --- requireFitsScope --- ? def rfst(n, s) { return [true, escape r { n.requireFitsScope(s, r) } catch p { return [false,p] }] }; null ? rfst(e`int`, 99) # problem: no such method: org.cubik.cle.native.int#fetchSlot/2 XXX should coerce or not? ? rfst(e`int`, safeScope) # value: [true, null] ? rfst(e`asfdghjk`, safeScope) # value: [false, problem: undefined variable: asfdghjk] ? rfst(makeAssignExpr(null, e`int`, e`1`, null), safeScope) # value: [false, problem: int is not an assignable variable] XXX well-formedness constraints tested before eval, but not at construction so we can build conveniently no shadowing without an intervening HideExpr no recursive definitions in DefineExpr (evaluator constraint?) XXX test quasi features (quasi expr/pattern allowed everywhere it should be)