val.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. package modern
  2. import (
  3. "fmt"
  4. "fw/cp"
  5. "fw/cp/node"
  6. "fw/cp/object"
  7. "fw/rt2/scope"
  8. "math"
  9. "math/big"
  10. "reflect"
  11. "strings"
  12. "ypk/assert"
  13. "ypk/halt"
  14. )
  15. type data struct {
  16. link object.Object
  17. val interface{}
  18. }
  19. type arr struct {
  20. link object.Object
  21. val []interface{}
  22. length int64
  23. }
  24. type dynarr struct {
  25. link object.Object
  26. val []interface{}
  27. }
  28. type proc struct {
  29. link object.Object
  30. }
  31. type rec struct {
  32. link object.Object
  33. scope.Record
  34. l *level
  35. }
  36. type idx struct {
  37. arr *arr
  38. idx int
  39. }
  40. func (r *rec) String() string {
  41. return r.link.Name()
  42. }
  43. func (r *rec) Id() cp.ID {
  44. return r.link.Adr()
  45. }
  46. func (r *rec) Set(v scope.Value) {
  47. }
  48. func (r *rec) Get(id cp.ID) scope.Value {
  49. k := r.l.k[id]
  50. if r.l.v[k] == nil { //ref
  51. return r.l.r[k]
  52. } else {
  53. return r.l.v[k]
  54. }
  55. }
  56. func newRec(o object.Object) *rec {
  57. _, ok := o.Complex().(object.RecordType)
  58. assert.For(ok, 20)
  59. return &rec{link: o}
  60. }
  61. func (p *proc) String() string {
  62. return fmt.Sprint(p.link.Adr(), p.link.Name())
  63. }
  64. func (x *data) Id() cp.ID {
  65. return x.link.Adr()
  66. }
  67. func (x *arr) Id() cp.ID {
  68. return x.link.Adr()
  69. }
  70. func (x *dynarr) Id() cp.ID {
  71. return x.link.Adr()
  72. }
  73. func (a *arr) Set(v scope.Value) {
  74. switch x := v.(type) {
  75. case STRING:
  76. v := make([]interface{}, int(a.length))
  77. for i := 0; i < int(a.length) && i < len(x); i++ {
  78. v[i] = CHAR(x[i])
  79. }
  80. a.val = v
  81. default:
  82. halt.As(100, reflect.TypeOf(x))
  83. }
  84. }
  85. func (a *dynarr) Set(v scope.Value) {
  86. switch x := v.(type) {
  87. case *arr:
  88. a.val = x.val
  89. case STRING:
  90. v := make([]interface{}, len(x))
  91. for i := 0; i < len(x); i++ {
  92. v[i] = CHAR(x[i])
  93. }
  94. a.val = v
  95. case SHORTSTRING:
  96. v := make([]interface{}, len(x))
  97. for i := 0; i < len(x); i++ {
  98. v[i] = SHORTCHAR(x[i])
  99. }
  100. a.val = v
  101. default:
  102. halt.As(100, reflect.TypeOf(x))
  103. }
  104. }
  105. func (a *arr) String() (ret string) {
  106. ret = fmt.Sprint("array", "[", a.length, "]")
  107. for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
  108. switch x := a.val[i].(type) {
  109. case CHAR:
  110. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  111. case SHORTCHAR:
  112. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  113. default:
  114. halt.As(100, reflect.TypeOf(x))
  115. }
  116. }
  117. return ret
  118. }
  119. func (a *arr) Get(id scope.Value) scope.Value {
  120. switch i := id.(type) {
  121. case *data:
  122. return a.Get(i.val.(scope.Value))
  123. case INTEGER:
  124. assert.For(int64(i) < a.length, 20)
  125. if len(a.val) == 0 {
  126. a.val = make([]interface{}, int(a.length))
  127. }
  128. return &idx{arr: a, idx: int(i)}
  129. default:
  130. halt.As(100, reflect.TypeOf(i))
  131. }
  132. panic(0)
  133. }
  134. func (i *idx) Id() cp.ID {
  135. return i.arr.Id()
  136. }
  137. func (i *idx) String() string {
  138. return fmt.Sprint("@", i.Id(), "[", i.idx, "]")
  139. }
  140. func (i *idx) Set(v scope.Value) {
  141. fmt.Println(i, len(i.arr.val))
  142. switch x := v.(type) {
  143. case *idx:
  144. i.arr.val[i.idx] = x.arr.val[x.idx]
  145. case CHAR:
  146. i.arr.val[i.idx] = x
  147. default:
  148. halt.As(100, reflect.TypeOf(x))
  149. }
  150. }
  151. func (a *dynarr) String() (ret string) {
  152. ret = fmt.Sprint("dyn array")
  153. for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
  154. switch x := a.val[i].(type) {
  155. case CHAR:
  156. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  157. case SHORTCHAR:
  158. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  159. default:
  160. halt.As(100, reflect.TypeOf(x))
  161. }
  162. }
  163. return ret
  164. }
  165. func (d *data) Set(v scope.Value) {
  166. fmt.Println("set data")
  167. switch x := v.(type) {
  168. case *data:
  169. assert.For(d.link.Type() == x.link.Type(), 20)
  170. d.val = x.val
  171. case *proc:
  172. assert.For(d.link.Type() == object.COMPLEX, 20)
  173. t, ok := d.link.Complex().(object.BasicType)
  174. assert.For(ok, 21, reflect.TypeOf(d.link.Complex()))
  175. assert.For(t.Type() == object.PROCEDURE, 22)
  176. d.val = x
  177. case INTEGER:
  178. switch d.link.Type() {
  179. case object.INTEGER:
  180. d.val = x
  181. case object.LONGINT:
  182. d.val = LONGINT(x)
  183. default:
  184. halt.As(20, d.link.Type())
  185. }
  186. case BOOLEAN:
  187. assert.For(d.link.Type() == object.BOOLEAN, 20)
  188. d.val = x
  189. case SHORTCHAR:
  190. assert.For(d.link.Type() == object.SHORTCHAR, 20)
  191. d.val = x
  192. case CHAR:
  193. assert.For(d.link.Type() == object.CHAR, 20)
  194. d.val = x
  195. case SHORTINT:
  196. assert.For(d.link.Type() == object.SHORTINT, 20)
  197. d.val = x
  198. case LONGINT:
  199. assert.For(d.link.Type() == object.LONGINT, 20)
  200. d.val = x
  201. case BYTE:
  202. assert.For(d.link.Type() == object.BYTE, 20)
  203. d.val = x
  204. case SET:
  205. assert.For(d.link.Type() == object.SET, 20)
  206. d.val = x
  207. case REAL:
  208. assert.For(d.link.Type() == object.REAL, 20)
  209. d.val = x
  210. case SHORTREAL:
  211. assert.For(d.link.Type() == object.SHORTREAL, 20)
  212. d.val = x
  213. default:
  214. panic(fmt.Sprintln(reflect.TypeOf(x)))
  215. }
  216. }
  217. func (d *data) String() string {
  218. return fmt.Sprint(d.link.Name(), "=", d.val)
  219. }
  220. type INTEGER int32
  221. type BOOLEAN bool
  222. type BYTE int8
  223. type SHORTINT int16
  224. type LONGINT int64
  225. type SET struct {
  226. bits *big.Int
  227. }
  228. type CHAR rune
  229. type REAL float64
  230. type SHORTREAL float32
  231. type SHORTCHAR rune
  232. type STRING string
  233. type SHORTSTRING string
  234. func (x SHORTSTRING) String() string { return string(x) }
  235. func (x STRING) String() string { return string(x) }
  236. func (x SHORTCHAR) String() string { return fmt.Sprint(rune(x)) }
  237. func (x SHORTREAL) String() string { return fmt.Sprint(float32(x)) }
  238. func (x REAL) String() string { return fmt.Sprint(float64(x)) }
  239. func (x CHAR) String() string { return fmt.Sprint(rune(x)) }
  240. func (x SET) String() string { return fmt.Sprint(x.bits) }
  241. func (x LONGINT) String() string { return fmt.Sprint(int64(x)) }
  242. func (x SHORTINT) String() string { return fmt.Sprint(int16(x)) }
  243. func (x BYTE) String() string { return fmt.Sprint(int8(x)) }
  244. func (x INTEGER) String() string { return fmt.Sprint(int32(x)) }
  245. func (x BOOLEAN) String() string { return fmt.Sprint(bool(x)) }
  246. func NewData(o object.Object) (ret scope.Variable) {
  247. switch o.Type() {
  248. case object.INTEGER:
  249. ret = &data{link: o, val: INTEGER(0)}
  250. case object.BOOLEAN:
  251. ret = &data{link: o, val: BOOLEAN(false)}
  252. case object.BYTE:
  253. ret = &data{link: o, val: BYTE(0)}
  254. case object.CHAR:
  255. ret = &data{link: o, val: CHAR(0)}
  256. case object.LONGINT:
  257. ret = &data{link: o, val: LONGINT(0)}
  258. case object.SHORTINT:
  259. ret = &data{link: o, val: SHORTINT(0)}
  260. case object.SET:
  261. ret = &data{link: o, val: SET{bits: big.NewInt(0)}}
  262. case object.REAL:
  263. ret = &data{link: o, val: REAL(0)}
  264. case object.SHORTREAL:
  265. ret = &data{link: o, val: SHORTREAL(0)}
  266. case object.SHORTCHAR:
  267. ret = &data{link: o, val: SHORTCHAR(0)}
  268. case object.COMPLEX:
  269. switch t := o.Complex().(type) {
  270. case object.BasicType:
  271. switch t.Type() {
  272. case object.PROCEDURE:
  273. ret = &data{link: o, val: nil}
  274. default:
  275. halt.As(100, t.Type())
  276. }
  277. case object.ArrayType:
  278. ret = &arr{link: o, length: t.Len()}
  279. case object.DynArrayType:
  280. ret = &dynarr{link: o}
  281. default:
  282. halt.As(100, reflect.TypeOf(t))
  283. }
  284. default:
  285. panic(fmt.Sprintln("unsupported type", o.Type()))
  286. }
  287. return ret
  288. }
  289. func fromg(x interface{}) scope.Value {
  290. switch x := x.(type) {
  291. case int32:
  292. return INTEGER(x)
  293. case bool:
  294. return BOOLEAN(x)
  295. default:
  296. halt.As(100, reflect.TypeOf(x))
  297. }
  298. panic(100)
  299. }
  300. func NewProc(o object.Object) scope.Value {
  301. p, ok := o.(object.ProcedureObject)
  302. assert.For(ok, 20, reflect.TypeOf(o))
  303. return &proc{link: p}
  304. }
  305. func NewConst(n node.Node) scope.Value {
  306. switch x := n.(type) {
  307. case node.ConstantNode:
  308. switch x.Type() {
  309. case object.INTEGER:
  310. return INTEGER(x.Data().(int32))
  311. case object.REAL:
  312. return REAL(x.Data().(float64))
  313. case object.BOOLEAN:
  314. return BOOLEAN(x.Data().(bool))
  315. case object.SHORTCHAR:
  316. return SHORTCHAR(x.Data().(rune))
  317. case object.LONGINT:
  318. return LONGINT(x.Data().(int64))
  319. case object.SHORTINT:
  320. return SHORTINT(x.Data().(int16))
  321. case object.SHORTREAL:
  322. return SHORTREAL(x.Data().(float32))
  323. case object.BYTE:
  324. return BYTE(x.Data().(int8))
  325. case object.SET:
  326. return SET{bits: x.Data().(*big.Int)}
  327. case object.CHAR:
  328. return CHAR(x.Data().(rune))
  329. case object.STRING:
  330. return STRING(x.Data().(string))
  331. case object.SHORTSTRING:
  332. return SHORTSTRING(x.Data().(string))
  333. default:
  334. panic(fmt.Sprintln(x.Type()))
  335. }
  336. }
  337. panic(0)
  338. }
  339. func vfrom(v scope.Value) scope.Value {
  340. switch n := v.(type) {
  341. case *data:
  342. switch n.link.Type() {
  343. case object.INTEGER:
  344. return n.val.(INTEGER)
  345. case object.BYTE:
  346. return n.val.(BYTE)
  347. case object.CHAR:
  348. return n.val.(CHAR)
  349. case object.SET:
  350. return n.val.(SET)
  351. default:
  352. halt.As(100, n.link.Type())
  353. }
  354. case INTEGER:
  355. return n
  356. default:
  357. halt.As(100, reflect.TypeOf(n))
  358. }
  359. return nil
  360. }
  361. func gfrom(v scope.Value) interface{} {
  362. switch n := v.(type) {
  363. case *data:
  364. if n.val == nil {
  365. return nil
  366. } else {
  367. return gfrom(n.val.(scope.Value))
  368. }
  369. case *proc:
  370. return n.link
  371. case INTEGER:
  372. return int32(n)
  373. case BOOLEAN:
  374. return bool(n)
  375. default:
  376. halt.As(100, reflect.TypeOf(n))
  377. }
  378. return nil
  379. }
  380. type ops struct{}
  381. func (o *ops) Sum(a, b scope.Value) scope.Value {
  382. switch a.(type) {
  383. case *data:
  384. return o.Sum(vfrom(a), b)
  385. default:
  386. switch b.(type) {
  387. case *data:
  388. return o.Sum(a, vfrom(b))
  389. default:
  390. switch x := a.(type) {
  391. case INTEGER:
  392. switch y := b.(type) {
  393. case INTEGER:
  394. return INTEGER(int32(x) + int32(y))
  395. default:
  396. panic(fmt.Sprintln(reflect.TypeOf(y)))
  397. }
  398. case SET:
  399. switch y := b.(type) {
  400. case SET:
  401. return SET{bits: x.bits.Add(x.bits, y.bits)}
  402. default:
  403. panic(fmt.Sprintln(reflect.TypeOf(y)))
  404. }
  405. default:
  406. panic(fmt.Sprintln(reflect.TypeOf(x)))
  407. }
  408. }
  409. }
  410. panic(0)
  411. }
  412. func (o *ops) Sub(a, b scope.Value) scope.Value {
  413. switch a.(type) {
  414. case *data:
  415. return o.Sub(vfrom(a), b)
  416. default:
  417. switch b.(type) {
  418. case *data:
  419. return o.Sub(a, vfrom(b))
  420. default:
  421. switch x := a.(type) {
  422. case INTEGER:
  423. switch y := b.(type) {
  424. case INTEGER:
  425. return INTEGER(int32(x) - int32(y))
  426. default:
  427. panic(fmt.Sprintln(reflect.TypeOf(y)))
  428. }
  429. default:
  430. panic(fmt.Sprintln(reflect.TypeOf(x)))
  431. }
  432. }
  433. }
  434. panic(0)
  435. }
  436. func (o *ops) Len(a object.Object, _a, _b scope.Value) (ret scope.Value) {
  437. //assert.For(a != nil, 20)
  438. assert.For(_b != nil, 21)
  439. var b int32 = gfrom(_b).(int32)
  440. assert.For(b == 0, 22)
  441. if a != nil {
  442. assert.For(a.Type() == object.COMPLEX, 23)
  443. switch typ := a.Complex().(type) {
  444. case object.ArrayType:
  445. ret = INTEGER(int32(typ.Len()))
  446. case object.DynArrayType:
  447. switch t := _a.(type) {
  448. //case string:
  449. // ret = int64(utf8.RuneCountInString(_a.(string)))
  450. default:
  451. ret = INTEGER(0)
  452. fmt.Sprintln("unsupported", reflect.TypeOf(t))
  453. }
  454. default:
  455. panic(fmt.Sprintln("unsupported", reflect.TypeOf(a.Complex())))
  456. }
  457. } else {
  458. switch a := _a.(type) {
  459. // case string:
  460. // ret = int64(utf8.RuneCountInString(_a.(string)))
  461. // case []interface{}:
  462. // ret = int64(len(_a.([]interface{})))
  463. case *arr:
  464. ret = INTEGER(int32(a.length))
  465. case *dynarr:
  466. ret = INTEGER(int32(len(a.val)))
  467. default:
  468. panic(fmt.Sprintln("unsupported", reflect.TypeOf(a)))
  469. }
  470. }
  471. return ret
  472. }
  473. func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
  474. var compare func(x, a object.RecordType) bool
  475. compare = func(x, a object.RecordType) bool {
  476. switch {
  477. case x.Name() == a.Name():
  478. // fmt.Println("eq")
  479. return true //опасно сравнивать имена конеш
  480. case x.BaseType() != nil:
  481. // fmt.Println("go base")
  482. return compare(x.BaseType(), a)
  483. default:
  484. return false
  485. }
  486. }
  487. switch x := a.(type) {
  488. case *rec:
  489. z, a := x.link.Complex().(object.RecordType)
  490. y, b := typ.(object.RecordType)
  491. fmt.Println("compare", x.link.Complex(), typ, a, b, a && b && compare(z, y))
  492. return BOOLEAN(a && b && compare(z, y))
  493. default:
  494. halt.As(100, reflect.TypeOf(x))
  495. }
  496. panic(0)
  497. }
  498. func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
  499. switch typ {
  500. case object.INTEGER:
  501. switch x := a.(type) {
  502. case *data:
  503. return o.Conv(vfrom(x), typ)
  504. case BYTE:
  505. return INTEGER(x)
  506. case SET:
  507. return INTEGER(x.bits.Int64())
  508. default:
  509. halt.As(100, reflect.TypeOf(x))
  510. }
  511. case object.SET:
  512. switch x := a.(type) {
  513. case *data:
  514. return o.Conv(vfrom(x), typ)
  515. case INTEGER:
  516. return SET{bits: big.NewInt(int64(x))}
  517. default:
  518. halt.As(100, reflect.TypeOf(x))
  519. }
  520. default:
  521. halt.As(100, typ)
  522. }
  523. panic(100)
  524. }
  525. func (o *ops) Not(a scope.Value) scope.Value {
  526. switch x := a.(type) {
  527. case *data:
  528. return o.Not(vfrom(x))
  529. case BOOLEAN:
  530. return BOOLEAN(!x)
  531. default:
  532. halt.As(100, reflect.TypeOf(x))
  533. }
  534. panic(100)
  535. }
  536. func (o *ops) Abs(a scope.Value) scope.Value {
  537. switch x := a.(type) {
  538. case *data:
  539. return o.Abs(vfrom(x))
  540. case INTEGER:
  541. return INTEGER(int32(math.Abs(float64(x))))
  542. default:
  543. halt.As(100, reflect.TypeOf(x))
  544. }
  545. panic(100)
  546. }
  547. func (o *ops) Odd(a scope.Value) scope.Value {
  548. switch x := a.(type) {
  549. case *data:
  550. return o.Odd(vfrom(x))
  551. case INTEGER:
  552. return BOOLEAN(int32(math.Abs(float64(x)))%2 == 1)
  553. default:
  554. halt.As(100, reflect.TypeOf(x))
  555. }
  556. panic(100)
  557. }
  558. func (o *ops) Cap(a scope.Value) scope.Value {
  559. switch x := a.(type) {
  560. case *data:
  561. return o.Cap(vfrom(x))
  562. case CHAR:
  563. return CHAR([]rune(strings.ToUpper(string(x)))[0])
  564. default:
  565. halt.As(100, reflect.TypeOf(x))
  566. }
  567. panic(100)
  568. }
  569. func (o *ops) Bits(a scope.Value) scope.Value {
  570. switch x := a.(type) {
  571. case *data:
  572. return o.Bits(vfrom(x))
  573. case INTEGER:
  574. return SET{bits: big.NewInt(int64(x))}
  575. default:
  576. halt.As(100, reflect.TypeOf(x))
  577. }
  578. panic(100)
  579. }
  580. func (o *ops) Eq(a, b scope.Value) scope.Value {
  581. switch a.(type) {
  582. case *data:
  583. return o.Eq(vfrom(a), b)
  584. default:
  585. switch b.(type) {
  586. case *data:
  587. return o.Eq(a, vfrom(b))
  588. default:
  589. switch x := a.(type) {
  590. case INTEGER:
  591. switch y := b.(type) {
  592. case INTEGER:
  593. return BOOLEAN(x == y)
  594. default:
  595. panic(fmt.Sprintln(reflect.TypeOf(y)))
  596. }
  597. default:
  598. panic(fmt.Sprintln(reflect.TypeOf(x)))
  599. }
  600. }
  601. }
  602. panic(0)
  603. }
  604. func (o *ops) Neq(a, b scope.Value) scope.Value {
  605. switch a.(type) {
  606. case *data:
  607. return o.Neq(vfrom(a), b)
  608. default:
  609. switch b.(type) {
  610. case *data:
  611. return o.Neq(a, vfrom(b))
  612. default:
  613. switch x := a.(type) {
  614. case INTEGER:
  615. switch y := b.(type) {
  616. case INTEGER:
  617. return BOOLEAN(x != y)
  618. default:
  619. panic(fmt.Sprintln(reflect.TypeOf(y)))
  620. }
  621. default:
  622. panic(fmt.Sprintln(reflect.TypeOf(x)))
  623. }
  624. }
  625. }
  626. panic(0)
  627. }
  628. func (o *ops) Lss(a, b scope.Value) scope.Value {
  629. switch a.(type) {
  630. case *data:
  631. return o.Lss(vfrom(a), b)
  632. default:
  633. switch b.(type) {
  634. case *data:
  635. return o.Lss(a, vfrom(b))
  636. default:
  637. switch x := a.(type) {
  638. case INTEGER:
  639. switch y := b.(type) {
  640. case INTEGER:
  641. return BOOLEAN(x < y)
  642. default:
  643. panic(fmt.Sprintln(reflect.TypeOf(y)))
  644. }
  645. default:
  646. panic(fmt.Sprintln(reflect.TypeOf(x)))
  647. }
  648. }
  649. }
  650. panic(0)
  651. }
  652. func (o *ops) Gtr(a, b scope.Value) scope.Value {
  653. switch a.(type) {
  654. case *data:
  655. return o.Gtr(vfrom(a), b)
  656. default:
  657. switch b.(type) {
  658. case *data:
  659. return o.Gtr(a, vfrom(b))
  660. default:
  661. switch x := a.(type) {
  662. case INTEGER:
  663. switch y := b.(type) {
  664. case INTEGER:
  665. return BOOLEAN(x > y)
  666. default:
  667. panic(fmt.Sprintln(reflect.TypeOf(y)))
  668. }
  669. default:
  670. panic(fmt.Sprintln(reflect.TypeOf(x)))
  671. }
  672. }
  673. }
  674. panic(0)
  675. }
  676. func (o *ops) Leq(a, b scope.Value) scope.Value {
  677. switch a.(type) {
  678. case *data:
  679. return o.Leq(vfrom(a), b)
  680. default:
  681. switch b.(type) {
  682. case *data:
  683. return o.Leq(a, vfrom(b))
  684. default:
  685. switch x := a.(type) {
  686. case INTEGER:
  687. switch y := b.(type) {
  688. case INTEGER:
  689. return BOOLEAN(x <= y)
  690. default:
  691. panic(fmt.Sprintln(reflect.TypeOf(y)))
  692. }
  693. default:
  694. panic(fmt.Sprintln(reflect.TypeOf(x)))
  695. }
  696. }
  697. }
  698. panic(0)
  699. }
  700. func init() {
  701. scope.ValueFrom = vfrom
  702. scope.GoTypeFrom = gfrom
  703. scope.TypeFromGo = fromg
  704. scope.Ops = &ops{}
  705. }