field.go 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package rules
  2. import (
  3. "reflect"
  4. )
  5. import (
  6. "fw/cp/node"
  7. "fw/rt2"
  8. "fw/rt2/context"
  9. "fw/rt2/frame"
  10. "fw/rt2/scope"
  11. "ypk/halt"
  12. )
  13. func fieldSeq(in ...IN) (out OUT) {
  14. f := in[0].frame
  15. n := rt2.NodeOf(f)
  16. sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
  17. switch l := n.Left().(type) {
  18. case node.VariableNode:
  19. sc.Select(l.Object().Adr(), func(v scope.Value) {
  20. rt2.ValueOf(f.Parent())[n.Adr()] = v.(scope.Record).Get(n.Object().Adr())
  21. })
  22. out = End()
  23. case node.FieldNode:
  24. rt2.Push(rt2.New(l), f)
  25. rt2.Assert(f, func(f frame.Frame) (bool, int) {
  26. _, ok := rt2.ValueOf(f)[l.Adr()].(scope.Record)
  27. return ok, 60
  28. })
  29. out.do = func(in ...IN) OUT {
  30. v := rt2.ValueOf(in[0].frame)[l.Adr()].(scope.Record)
  31. rt2.ValueOf(f.Parent())[n.Adr()] = v.Get(n.Object().Adr())
  32. return End()
  33. }
  34. out.next = LATER
  35. default:
  36. halt.As(100, reflect.TypeOf(l))
  37. }
  38. return out
  39. }