anchor.diff:              for f in functions do
                   SemanticFunctions.compile f 
   
  -    [<Demo("aaaag")>]
  +    let tryGetSynFunction<'a> (name : string) : Option<obj -> 'a> =
  +        match Globals.tryGetAttributeIndex name with
  +            | Some i ->
  +                match Globals.synDispatchers.[i] with
  +                    | null -> None
  +                    | :? IDispatcher<Scope, 'a> as d ->
  +                        let f = fun (n : obj) -> d.Invoke(n, Scope(null, n))
  +                        Some f
  +                    | _ -> None
  +            | None ->
  +                None
  +    
  +    let getSynFunction<'a> (name : string) : obj -> 'a =
  +        match tryGetSynFunction<'a> name with
  +            | Some f -> f 
  +            | _ -> failwithf "[Ag] could not get syn rule for '%s'" name
  +
  +
  +module NewestAgDemo =
  +
  +    [<AllowNullLiteral>]
  +    type SumScope =
  +        class 
  +            inherit Ag.Implementation.Scope
  +            val mutable public Index : int
  +
  +            member x.ChildScope(child : obj) =
  +                if isNull x.Node then SumScope(null, child, Index = 0)
  +                else SumScope(x, child)
  +
  +            new(p,n) = { inherit Ag.Implementation.Scope(p,n); Index = 0 }
  +        end
  +
  +    type IList =
  +        abstract member Sum : SumScope -> int
  +        abstract member All : SumScope -> list<int>
  + 
  +    type Nil() = 
  +        interface IList with
  +            member x.Sum (s : SumScope) =
  +                s.Index
  +
  +            member x.All (s : SumScope) =
  +                [ s.Index ]
  +
  +    type Cons(head : int, tail : IList) =
  +        interface IList with
  +            member x.Sum s = 
  +                let child = s.ChildScope tail
  +                child.Index <- s.Index + 1
  +                head + tail.Sum(child)
  +
  +
  +            member x.All (s : SumScope) =
  +                let child = s.ChildScope tail
  +                child.Index <- s.Index + 1
  +                head :: tail.All child
  +
  +
  +        member x.Head = head
  +        member x.Tail = tail
  +
  +    [<ReflectedDefinition>]
  +    module SomeSems =
  +        open Ag.Frontend
  +
  +        type IList with
  +            [<Attribute(AttributeKind.Synthesized)>]
  +            member x.Sum() : int = x?Sum()
  +
  +            [<Attribute(AttributeKind.Synthesized)>]
  +            member x.All() : list<int> = x?All()
  +
  +            [<Attribute(AttributeKind.Inherited)>]
  +            member x.Index : int = x?Index
  +
  +            [<Attribute(AttributeKind.Inherited)>]
  +            member x.Bla : int = x?Bla
  +
  +        [<Semantic>]
  +        type Sems =
  +            static member All(n : Nil) : list<int> = 
  +                [n.Index]
  +
  +            static member All(c : Cons) : list<int> = 
  +                c.Head :: c.Tail.All()
  +
  +            static member Sum(n : Nil) : int = 
  +                n.Index
  +
  +            static member Sum(c : Cons) : int = 
  +                c.Head + c.Tail.Sum()
  +
  +            static member Index(r : Root<IList>) =
  +                inh <<= 0
  +
  +            static member Index(c : Cons) =
  +                inh <<= 1 + c.Index
  +
  +            static member Bla(r : Root<IList>) =
  +                inh <<= 0
  +
  +            static member Bla(c : Cons) =
  +                inh <<= 10 + c.Bla
  +
  +    [<Demo("Ag Demo")>]
       let run() =
  -        init()
  -        let all : obj -> list<int>  = Ag.synFunction "All"
  -        let sum : obj -> int        = Ag.synFunction "Sum"
  +        Ag.init()
  +        let all : obj -> list<int>  = Ag.getSynFunction "All"
  +        let sum : obj -> int        = Ag.getSynFunction "Sum"
           let list = Cons(0, Cons(1, Nil()))
  -        Log.line "sum = %A" (sum list)
  -        Log.line "all = %A" (all list)
  +        Log.line "sum [0;1] = %A" (sum list)
  +        Log.line "all [0;1] = %A" (all list)
   
           
   
  
positive.code: open QuotationCompiler.Simple
  open Aardvark.Base.Incremental
  
  
  module NewestAg =
      open Microsoft.FSharp.Quotations
      open Microsoft.FSharp.Quotations.Patterns
      open Microsoft.FSharp.Quotations.ExprShape
      open System.Runtime.CompilerServices
  
      type AttributeKind =
          | None          = 0x00
          | Inherited     = 0x01
          | Synthesized   = 0x02
          | Mixed         = 0x03
  
          
      [<AttributeUsage(AttributeTargets.Class, AllowMultiple = false)>]
      type SemanticAttribute() = inherit Attribute()
  
      [<AttributeUsage(AttributeTargets.Property ||| AttributeTargets.Method, AllowMultiple = false); AllowNullLiteral>]
      type AttributeAttribute(name : string, kind : AttributeKind) =
          inherit Attribute()
  
          member x.Name = name
          member x.Kind = kind
  
          new(kind : AttributeKind) = AttributeAttribute(null, kind)
  
      type Root<'a> = class end
  
      type SemanticFunction =
          {
              name        : string
              kind        : AttributeKind
              original    : MethodInfo
              nodeType    : Type
              code        : Expr
              isRoot      : bool
              inherits    : Set<string>
              synthesizes : Set<string>
          }
  
      type SemanticFunctions =
          {
              index           : int
              name            : string
              kind            : AttributeKind
              valueType       : Type
              functions       : list<SemanticFunction>
          }
  
      [<AutoOpen>]
      module Operators =
          
          type Inh = class end
          let inh : Inh = Unchecked.defaultof<Inh>
  
          [<MethodImpl(MethodImplOptions.NoInlining)>]
          let (?) (o : 'a) (name : string) : 'b =
              failwith ""
              
          [<MethodImpl(MethodImplOptions.NoInlining)>]
          let (<<=) (m : Inh) (value : 'a) =
              ()
  
          let private isUnitFunction (t : Type) =
              if t.Name.StartsWith "FSharpFunc" then
                  let (d,_) = FSharpType.GetFunctionElements t
                  d = typeof<unit>
              else
                  false
  
          [<AutoOpen>]
          module LookupExtensions = 
              open Aardvark.Base.IL
  
              let private attributeLookupCache = System.Collections.Concurrent.ConcurrentDictionary<MethodInfo, Option<string * AttributeKind>>()
              let private rx = System.Text.RegularExpressions.Regex @"(get_)?(?<name>[a-zA-Z_0-9]+$)"
              let (|AttributeLookup|_|) (mi : MethodInfo) =
                  attributeLookupCache.GetOrAdd (mi, fun mi ->
                      let att = mi.GetCustomAttribute<AttributeAttribute>()
  
negative.code:                     |> Seq.toArray
  
              let cnt = Globals.attributeCount()
              Implementation.semanticFunctions <- functions |> Seq.map (fun sf -> sf.name,sf) |> Map.ofSeq
              Globals.synDispatchers <- Array.zeroCreate cnt
              Globals.inhDispatchers <- Array.zeroCreate cnt
              Globals.rootDispatchers <- Array.zeroCreate cnt
  