range.go 705 B

123456789101112131415161718192021222324252627282930313233
  1. package rules
  2. import (
  3. "fmt"
  4. "math/big"
  5. )
  6. import (
  7. "fw/rt2"
  8. "fw/rt2/frame"
  9. "fw/rt2/scope"
  10. )
  11. func bit_range(_f scope.Value, _t scope.Value) scope.Value {
  12. f := scope.GoTypeFrom(_f).(int32)
  13. t := scope.GoTypeFrom(_t).(int32)
  14. ret := big.NewInt(0)
  15. for i := f; i <= t; i++ {
  16. ret = ret.SetBit(ret, int(i), 1)
  17. }
  18. fmt.Println("bits", ret)
  19. return scope.TypeFromGo(ret)
  20. }
  21. func rangeSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
  22. n := rt2.NodeOf(f)
  23. return This(expectExpr(f, n.Left(), func(...IN) OUT {
  24. return expectExpr(f, n.Right(), func(...IN) OUT {
  25. rt2.ValueOf(f.Parent())[n.Adr()] = bit_range(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
  26. return End()
  27. })
  28. }))
  29. }