val.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. package modern
  2. import (
  3. "fmt"
  4. "fw/cp"
  5. "fw/cp/node"
  6. "fw/cp/object"
  7. "fw/rt2/scope"
  8. "fw/utils"
  9. "math"
  10. "math/big"
  11. "reflect"
  12. "strings"
  13. "ypk/assert"
  14. "ypk/halt"
  15. )
  16. type data struct {
  17. link object.Object
  18. val interface{}
  19. }
  20. type arr struct {
  21. link object.Object
  22. val []interface{}
  23. length int64
  24. }
  25. type dynarr struct {
  26. link object.Object
  27. val []interface{}
  28. }
  29. type proc struct {
  30. link object.Object
  31. }
  32. type rec struct {
  33. link object.Object
  34. scope.Record
  35. l *level
  36. }
  37. type ptr struct {
  38. link object.Object
  39. scope.Pointer
  40. val *ptrValue
  41. }
  42. type idx struct {
  43. arr *arr
  44. idx int
  45. }
  46. func (r *rec) String() string {
  47. return r.link.Name()
  48. }
  49. func (r *rec) Id() cp.ID {
  50. return r.link.Adr()
  51. }
  52. func (r *rec) Set(v scope.Value) {
  53. panic(0)
  54. }
  55. func (r *rec) Get(id cp.ID) scope.Value {
  56. k := r.l.k[id]
  57. if r.l.v[k] == nil { //ref
  58. return r.l.r[k]
  59. } else {
  60. return r.l.v[k]
  61. }
  62. }
  63. func newRec(o object.Object) *rec {
  64. _, ok := o.Complex().(object.RecordType)
  65. assert.For(ok, 20)
  66. return &rec{link: o}
  67. }
  68. func (p *proc) String() string {
  69. return fmt.Sprint(p.link.Adr(), p.link.Name())
  70. }
  71. func (x *data) Id() cp.ID { return x.link.Adr() }
  72. func (x *arr) Id() cp.ID { return x.link.Adr() }
  73. func (x *dynarr) Id() cp.ID { return x.link.Adr() }
  74. func (a *arr) Set(v scope.Value) {
  75. switch x := v.(type) {
  76. case *arr:
  77. a.Set(STRING(x.tryString()))
  78. case STRING:
  79. v := make([]interface{}, int(a.length))
  80. for i := 0; i < int(a.length) && i < len(x); i++ {
  81. v[i] = CHAR(x[i])
  82. }
  83. a.val = v
  84. case SHORTSTRING:
  85. v := make([]interface{}, int(a.length))
  86. for i := 0; i < int(a.length) && i < len(x); i++ {
  87. v[i] = SHORTCHAR(x[i])
  88. }
  89. a.val = v
  90. default:
  91. halt.As(100, reflect.TypeOf(x))
  92. }
  93. }
  94. func (a *dynarr) Set(v scope.Value) {
  95. switch x := v.(type) {
  96. case *arr:
  97. a.val = x.val
  98. case *dynarr:
  99. a.val = x.val
  100. case STRING:
  101. v := make([]interface{}, len(x))
  102. for i := 0; i < len(x); i++ {
  103. v[i] = CHAR(x[i])
  104. }
  105. a.val = v
  106. case SHORTSTRING:
  107. v := make([]interface{}, len(x))
  108. for i := 0; i < len(x); i++ {
  109. v[i] = SHORTCHAR(x[i])
  110. }
  111. a.val = v
  112. case INTEGER:
  113. a.val = make([]interface{}, int(x))
  114. default:
  115. halt.As(100, reflect.TypeOf(x))
  116. }
  117. }
  118. func (a *arr) tryString() (ret string) {
  119. for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
  120. switch x := a.val[i].(type) {
  121. case CHAR:
  122. if int(x) == 0 {
  123. break
  124. }
  125. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  126. case SHORTCHAR:
  127. if int(x) == 0 {
  128. break
  129. }
  130. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  131. default:
  132. halt.As(100, reflect.TypeOf(x))
  133. }
  134. }
  135. return ret
  136. }
  137. func (a *arr) String() (ret string) {
  138. ret = fmt.Sprint("array", "[", a.length, "]")
  139. for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
  140. switch x := a.val[i].(type) {
  141. case CHAR:
  142. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  143. case SHORTCHAR:
  144. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  145. default:
  146. halt.As(100, reflect.TypeOf(x))
  147. }
  148. }
  149. return ret
  150. }
  151. func (a *arr) Get(id scope.Value) scope.Value {
  152. switch i := id.(type) {
  153. case *data:
  154. return a.Get(i.val.(scope.Value))
  155. case INTEGER:
  156. assert.For(int64(i) < a.length, 20)
  157. if len(a.val) == 0 {
  158. a.val = make([]interface{}, int(a.length))
  159. }
  160. return &idx{arr: a, idx: int(i)}
  161. default:
  162. halt.As(100, reflect.TypeOf(i))
  163. }
  164. panic(0)
  165. }
  166. func (i *idx) Id() cp.ID {
  167. return i.arr.Id()
  168. }
  169. func (i *idx) String() string {
  170. return fmt.Sprint("@", i.Id(), "[", i.idx, "]")
  171. }
  172. func (i *idx) Set(v scope.Value) {
  173. //fmt.Println(i, len(i.arr.val))
  174. switch x := v.(type) {
  175. case *idx:
  176. i.arr.val[i.idx] = x.arr.val[x.idx]
  177. case *data:
  178. i.Set(x.val.(scope.Value))
  179. case CHAR:
  180. i.arr.val[i.idx] = x
  181. default:
  182. halt.As(100, reflect.TypeOf(x))
  183. }
  184. }
  185. func (a *dynarr) tryString() (ret string) {
  186. for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
  187. switch x := a.val[i].(type) {
  188. case CHAR:
  189. if int(x) == 0 {
  190. break
  191. }
  192. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  193. case SHORTCHAR:
  194. if int(x) == 0 {
  195. break
  196. }
  197. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  198. default:
  199. halt.As(100, reflect.TypeOf(x))
  200. }
  201. }
  202. return ret
  203. }
  204. func (a *dynarr) String() (ret string) {
  205. ret = fmt.Sprint("dyn array")
  206. for i := 0; i < len(a.val) && a.val[i] != nil; i++ {
  207. switch x := a.val[i].(type) {
  208. case CHAR:
  209. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  210. case SHORTCHAR:
  211. ret = fmt.Sprint(ret, string([]rune{rune(x)}))
  212. default:
  213. halt.As(100, reflect.TypeOf(x))
  214. }
  215. }
  216. return ret
  217. }
  218. func (d *data) Set(v scope.Value) {
  219. utils.PrintScope("set data")
  220. switch x := v.(type) {
  221. case *data:
  222. if d.link.Type() == x.link.Type() {
  223. d.val = x.val
  224. } else {
  225. d.Set(x.val.(scope.Value))
  226. }
  227. case *proc:
  228. assert.For(d.link.Type() == object.COMPLEX, 20)
  229. t, ok := d.link.Complex().(object.BasicType)
  230. assert.For(ok, 21, reflect.TypeOf(d.link.Complex()))
  231. assert.For(t.Type() == object.PROCEDURE, 22)
  232. d.val = x
  233. case *idx:
  234. d.val = x.arr.val[x.idx]
  235. case INTEGER:
  236. switch d.link.Type() {
  237. case object.INTEGER:
  238. d.val = x
  239. case object.LONGINT:
  240. d.val = LONGINT(x)
  241. case object.REAL:
  242. d.val = REAL(x)
  243. default:
  244. halt.As(20, d.link.Type())
  245. }
  246. case BOOLEAN:
  247. assert.For(d.link.Type() == object.BOOLEAN, 20)
  248. d.val = x
  249. case SHORTCHAR:
  250. assert.For(d.link.Type() == object.SHORTCHAR, 20)
  251. d.val = x
  252. case CHAR:
  253. assert.For(d.link.Type() == object.CHAR, 20)
  254. d.val = x
  255. case SHORTINT:
  256. assert.For(d.link.Type() == object.SHORTINT, 20)
  257. d.val = x
  258. case LONGINT:
  259. assert.For(d.link.Type() == object.LONGINT, 20)
  260. d.val = x
  261. case BYTE:
  262. assert.For(d.link.Type() == object.BYTE, 20)
  263. d.val = x
  264. case SET:
  265. assert.For(d.link.Type() == object.SET, 20)
  266. d.val = x
  267. case REAL:
  268. assert.For(d.link.Type() == object.REAL, 20)
  269. d.val = x
  270. case SHORTREAL:
  271. assert.For(d.link.Type() == object.SHORTREAL, 20)
  272. d.val = x
  273. default:
  274. panic(fmt.Sprintln(reflect.TypeOf(x)))
  275. }
  276. }
  277. func (d *data) String() string {
  278. return fmt.Sprint(d.link.Name(), "=", d.val)
  279. }
  280. func (p *ptr) String() string {
  281. return fmt.Sprint("pointer ", p.link.Complex().(object.PointerType).Name(), "&", p.val)
  282. }
  283. func (p *ptr) Id() cp.ID { return p.link.Adr() }
  284. func (p *ptr) Set(v scope.Value) {
  285. switch x := v.(type) {
  286. case *ptr:
  287. p.Set(x.val)
  288. case *ptrValue:
  289. p.val = x
  290. case PTR:
  291. assert.For(x == NIL, 40)
  292. p.val = nil
  293. default:
  294. halt.As(100, reflect.TypeOf(x))
  295. }
  296. }
  297. func (p *ptr) Get() scope.Value {
  298. if p.val == nil {
  299. return NIL
  300. } else {
  301. return p.val.scope.Select(p.val.id)
  302. }
  303. }
  304. func newPtr(o object.Object) scope.Variable {
  305. _, ok := o.Complex().(object.PointerType)
  306. assert.For(ok, 20)
  307. return &ptr{link: o}
  308. }
  309. type ptrValue struct {
  310. scope *area
  311. id cp.ID
  312. link object.Object
  313. }
  314. func (p *ptrValue) String() string {
  315. return fmt.Sprint(p.id)
  316. }
  317. type PTR int
  318. func (p PTR) String() string {
  319. return "NIL"
  320. }
  321. const NIL PTR = 0
  322. type INTEGER int32
  323. type BOOLEAN bool
  324. type BYTE int8
  325. type SHORTINT int16
  326. type LONGINT int64
  327. type SET struct {
  328. bits *big.Int
  329. }
  330. type CHAR rune
  331. type REAL float64
  332. type SHORTREAL float32
  333. type SHORTCHAR rune
  334. type STRING string
  335. type SHORTSTRING string
  336. func (x SHORTSTRING) String() string { return string(x) }
  337. func (x STRING) String() string { return string(x) }
  338. func (x SHORTCHAR) String() string { return fmt.Sprint(rune(x)) }
  339. func (x SHORTREAL) String() string { return fmt.Sprint(float32(x)) }
  340. func (x REAL) String() string { return fmt.Sprint(float64(x)) }
  341. func (x CHAR) String() string { return fmt.Sprint(rune(x)) }
  342. func (x SET) String() string { return fmt.Sprint(x.bits) }
  343. func (x LONGINT) String() string { return fmt.Sprint(int64(x)) }
  344. func (x SHORTINT) String() string { return fmt.Sprint(int16(x)) }
  345. func (x BYTE) String() string { return fmt.Sprint(int8(x)) }
  346. func (x INTEGER) String() string { return fmt.Sprint(int32(x)) }
  347. func (x BOOLEAN) String() string { return fmt.Sprint(bool(x)) }
  348. func newData(o object.Object) (ret scope.Variable) {
  349. switch o.Type() {
  350. case object.INTEGER:
  351. ret = &data{link: o, val: INTEGER(0)}
  352. case object.BOOLEAN:
  353. ret = &data{link: o, val: BOOLEAN(false)}
  354. case object.BYTE:
  355. ret = &data{link: o, val: BYTE(0)}
  356. case object.CHAR:
  357. ret = &data{link: o, val: CHAR(0)}
  358. case object.LONGINT:
  359. ret = &data{link: o, val: LONGINT(0)}
  360. case object.SHORTINT:
  361. ret = &data{link: o, val: SHORTINT(0)}
  362. case object.SET:
  363. ret = &data{link: o, val: SET{bits: big.NewInt(0)}}
  364. case object.REAL:
  365. ret = &data{link: o, val: REAL(0)}
  366. case object.SHORTREAL:
  367. ret = &data{link: o, val: SHORTREAL(0)}
  368. case object.SHORTCHAR:
  369. ret = &data{link: o, val: SHORTCHAR(0)}
  370. case object.COMPLEX:
  371. switch t := o.Complex().(type) {
  372. case object.BasicType:
  373. switch t.Type() {
  374. case object.PROCEDURE:
  375. ret = &data{link: o, val: nil}
  376. default:
  377. halt.As(100, t.Type())
  378. }
  379. case object.ArrayType:
  380. ret = &arr{link: o, length: t.Len()}
  381. case object.DynArrayType:
  382. ret = &dynarr{link: o}
  383. default:
  384. halt.As(100, reflect.TypeOf(t))
  385. }
  386. default:
  387. panic(fmt.Sprintln("unsupported type", o.Type()))
  388. }
  389. return ret
  390. }
  391. func fromg(x interface{}) scope.Value {
  392. switch x := x.(type) {
  393. case int32:
  394. return INTEGER(x)
  395. case bool:
  396. return BOOLEAN(x)
  397. case *big.Int:
  398. return SET{bits: x}
  399. default:
  400. halt.As(100, reflect.TypeOf(x))
  401. }
  402. panic(100)
  403. }
  404. func newProc(o object.Object) scope.Value {
  405. p, ok := o.(object.ProcedureObject)
  406. assert.For(ok, 20, reflect.TypeOf(o))
  407. return &proc{link: p}
  408. }
  409. func newConst(n node.Node) scope.Value {
  410. switch x := n.(type) {
  411. case node.ConstantNode:
  412. switch x.Type() {
  413. case object.INTEGER:
  414. return INTEGER(x.Data().(int32))
  415. case object.REAL:
  416. return REAL(x.Data().(float64))
  417. case object.BOOLEAN:
  418. return BOOLEAN(x.Data().(bool))
  419. case object.SHORTCHAR:
  420. return SHORTCHAR(x.Data().(rune))
  421. case object.LONGINT:
  422. return LONGINT(x.Data().(int64))
  423. case object.SHORTINT:
  424. return SHORTINT(x.Data().(int16))
  425. case object.SHORTREAL:
  426. return SHORTREAL(x.Data().(float32))
  427. case object.BYTE:
  428. return BYTE(x.Data().(int8))
  429. case object.SET:
  430. return SET{bits: x.Data().(*big.Int)}
  431. case object.CHAR:
  432. return CHAR(x.Data().(rune))
  433. case object.STRING:
  434. return STRING(x.Data().(string))
  435. case object.SHORTSTRING:
  436. return SHORTSTRING(x.Data().(string))
  437. case object.NIL:
  438. return NIL
  439. case object.COMPLEX: //не может существовать в реальности, используется для передачи параметров от рантайма
  440. switch d := x.Data().(type) {
  441. case *ptrValue:
  442. return d
  443. default:
  444. halt.As(100, reflect.TypeOf(d))
  445. }
  446. default:
  447. panic(fmt.Sprintln(x.Type()))
  448. }
  449. }
  450. panic(0)
  451. }
  452. func vfrom(v scope.Value) scope.Value {
  453. switch n := v.(type) {
  454. case *data:
  455. switch n.link.Type() {
  456. case object.INTEGER:
  457. return n.val.(INTEGER)
  458. case object.BYTE:
  459. return n.val.(BYTE)
  460. case object.CHAR:
  461. return n.val.(CHAR)
  462. case object.SET:
  463. return n.val.(SET)
  464. case object.BOOLEAN:
  465. return n.val.(BOOLEAN)
  466. case object.REAL:
  467. return n.val.(REAL)
  468. case object.LONGINT:
  469. return n.val.(LONGINT)
  470. default:
  471. halt.As(100, n.link.Type())
  472. }
  473. case INTEGER:
  474. return n
  475. default:
  476. halt.As(100, reflect.TypeOf(n))
  477. }
  478. return nil
  479. }
  480. func gfrom(v scope.Value) interface{} {
  481. switch n := v.(type) {
  482. case *data:
  483. if n.val == nil {
  484. return nil
  485. } else {
  486. return gfrom(n.val.(scope.Value))
  487. }
  488. case *rec:
  489. return n
  490. case *proc:
  491. return n.link
  492. case *dynarr:
  493. switch n.link.Complex().(object.DynArrayType).Base() {
  494. case object.SHORTCHAR:
  495. if n.val != nil {
  496. return n.tryString()
  497. } else {
  498. return ""
  499. }
  500. case object.CHAR:
  501. if n.val != nil {
  502. return n.tryString()
  503. } else {
  504. return ""
  505. }
  506. default:
  507. halt.As(100, n.link.Complex().(object.DynArrayType).Base())
  508. }
  509. panic(0)
  510. case *arr:
  511. switch n.link.Complex().(object.ArrayType).Base() {
  512. case object.SHORTCHAR:
  513. if n.val != nil {
  514. return n.tryString()
  515. } else {
  516. return ""
  517. }
  518. default:
  519. halt.As(100, n.link.Complex().(object.ArrayType).Base())
  520. }
  521. panic(0)
  522. case PTR:
  523. assert.For(n == NIL, 40)
  524. return nil
  525. case INTEGER:
  526. return int32(n)
  527. case BOOLEAN:
  528. return bool(n)
  529. default:
  530. halt.As(100, reflect.TypeOf(n))
  531. }
  532. return nil
  533. }
  534. type ops struct{}
  535. func (o *ops) Sum(a, b scope.Value) scope.Value {
  536. switch a.(type) {
  537. case *data:
  538. return o.Sum(vfrom(a), b)
  539. default:
  540. switch b.(type) {
  541. case *data:
  542. return o.Sum(a, vfrom(b))
  543. default:
  544. switch x := a.(type) {
  545. case INTEGER:
  546. switch y := b.(type) {
  547. case INTEGER:
  548. return INTEGER(int32(x) + int32(y))
  549. default:
  550. panic(fmt.Sprintln(reflect.TypeOf(y)))
  551. }
  552. case SET:
  553. switch y := b.(type) {
  554. case SET:
  555. res := big.NewInt(0)
  556. for i := 0; i < 64; i++ {
  557. if x.bits.Bit(i) == 1 {
  558. res.SetBit(res, i, 1)
  559. }
  560. if y.bits.Bit(i) == 1 {
  561. res.SetBit(res, i, 1)
  562. }
  563. }
  564. return SET{bits: res}
  565. case INTEGER: // INCL(SET, INTEGER)
  566. return SET{bits: x.bits.SetBit(x.bits, int(y), 1)}
  567. default:
  568. panic(fmt.Sprintln(reflect.TypeOf(y)))
  569. }
  570. case *arr:
  571. switch y := b.(type) {
  572. case *arr:
  573. switch {
  574. case x.link.Type() == y.link.Type() && x.link.Complex().(object.ArrayType).Base() == object.CHAR:
  575. return STRING(x.tryString() + y.tryString())
  576. default:
  577. halt.As(100, x.link.Type(), y.link.Type())
  578. }
  579. case STRING:
  580. switch {
  581. case x.link.Complex().(object.ArrayType).Base() == object.CHAR:
  582. return STRING(x.tryString() + string(y))
  583. default:
  584. halt.As(100, x.link.Type())
  585. }
  586. default:
  587. panic(fmt.Sprintln(reflect.TypeOf(y)))
  588. }
  589. case *dynarr:
  590. switch y := b.(type) {
  591. case STRING:
  592. switch {
  593. case x.link.Complex().(object.DynArrayType).Base() == object.CHAR:
  594. return STRING(x.tryString() + string(y))
  595. default:
  596. halt.As(100, x.link.Type())
  597. }
  598. default:
  599. panic(fmt.Sprintln(reflect.TypeOf(y)))
  600. }
  601. case STRING:
  602. switch y := b.(type) {
  603. case STRING:
  604. return STRING(string(x) + string(y))
  605. default:
  606. halt.As(100, reflect.TypeOf(y))
  607. }
  608. case REAL:
  609. switch y := b.(type) {
  610. case REAL:
  611. return REAL(x + y)
  612. default:
  613. halt.As(100, reflect.TypeOf(y))
  614. }
  615. case LONGINT:
  616. switch y := b.(type) {
  617. case LONGINT:
  618. return LONGINT(x + y)
  619. default:
  620. halt.As(100, reflect.TypeOf(y))
  621. }
  622. default:
  623. panic(fmt.Sprintln(reflect.TypeOf(x)))
  624. }
  625. }
  626. }
  627. panic(0)
  628. }
  629. func (o *ops) Sub(a, b scope.Value) scope.Value {
  630. switch a.(type) {
  631. case *data:
  632. return o.Sub(vfrom(a), b)
  633. default:
  634. switch b.(type) {
  635. case *data:
  636. return o.Sub(a, vfrom(b))
  637. default:
  638. switch x := a.(type) {
  639. case INTEGER:
  640. switch y := b.(type) {
  641. case INTEGER:
  642. return INTEGER(int32(x) - int32(y))
  643. default:
  644. panic(fmt.Sprintln(reflect.TypeOf(y)))
  645. }
  646. case SET:
  647. switch y := b.(type) {
  648. case SET:
  649. res := big.NewInt(0).Set(x.bits)
  650. for i := 0; i < 64; i++ {
  651. if y.bits.Bit(i) == 1 {
  652. res.SetBit(res, i, 0)
  653. }
  654. }
  655. return SET{bits: res}
  656. case INTEGER:
  657. null := big.NewInt(0)
  658. res := null.SetBit(x.bits, int(y), 0)
  659. return SET{bits: res}
  660. default:
  661. panic(fmt.Sprintln(reflect.TypeOf(y)))
  662. }
  663. default:
  664. panic(fmt.Sprintln(reflect.TypeOf(x)))
  665. }
  666. }
  667. }
  668. panic(0)
  669. }
  670. func (o *ops) In(a, b scope.Value) scope.Value {
  671. switch a.(type) {
  672. case *data:
  673. return o.In(vfrom(a), b)
  674. default:
  675. switch b.(type) {
  676. case *data:
  677. return o.In(a, vfrom(b))
  678. default:
  679. switch x := a.(type) {
  680. case INTEGER:
  681. switch y := b.(type) {
  682. case SET:
  683. assert.For(int(x) < 64, 20)
  684. return BOOLEAN(y.bits.Bit(int(x)) == 1)
  685. default:
  686. panic(fmt.Sprintln(reflect.TypeOf(y)))
  687. }
  688. default:
  689. panic(fmt.Sprintln(reflect.TypeOf(x)))
  690. }
  691. }
  692. }
  693. panic(0)
  694. }
  695. func (o *ops) Min(a, b scope.Value) scope.Value {
  696. switch a.(type) {
  697. case *data:
  698. return o.Min(vfrom(a), b)
  699. default:
  700. switch b.(type) {
  701. case *data:
  702. return o.Min(a, vfrom(b))
  703. default:
  704. switch x := a.(type) {
  705. case INTEGER:
  706. switch y := b.(type) {
  707. case INTEGER:
  708. return INTEGER(int32(math.Min(float64(x), float64(y))))
  709. default:
  710. panic(fmt.Sprintln(reflect.TypeOf(y)))
  711. }
  712. default:
  713. panic(fmt.Sprintln(reflect.TypeOf(x)))
  714. }
  715. }
  716. }
  717. panic(0)
  718. }
  719. func (o *ops) Max(a, b scope.Value) scope.Value {
  720. switch a.(type) {
  721. case *data:
  722. return o.Max(vfrom(a), b)
  723. default:
  724. switch b.(type) {
  725. case *data:
  726. return o.Max(a, vfrom(b))
  727. default:
  728. switch x := a.(type) {
  729. case INTEGER:
  730. switch y := b.(type) {
  731. case INTEGER:
  732. return INTEGER(int32(math.Max(float64(x), float64(y))))
  733. default:
  734. panic(fmt.Sprintln(reflect.TypeOf(y)))
  735. }
  736. default:
  737. panic(fmt.Sprintln(reflect.TypeOf(x)))
  738. }
  739. }
  740. }
  741. panic(0)
  742. }
  743. func (o *ops) And(a, b scope.Value) scope.Value {
  744. switch a.(type) {
  745. case *data:
  746. return o.And(vfrom(a), b)
  747. default:
  748. switch b.(type) {
  749. case *data:
  750. return o.And(a, vfrom(b))
  751. default:
  752. switch x := a.(type) {
  753. case BOOLEAN:
  754. switch y := b.(type) {
  755. case BOOLEAN:
  756. return BOOLEAN(x && y)
  757. default:
  758. panic(fmt.Sprintln(reflect.TypeOf(y)))
  759. }
  760. default:
  761. panic(fmt.Sprintln(reflect.TypeOf(x)))
  762. }
  763. }
  764. }
  765. panic(0)
  766. }
  767. func (o *ops) Or(a, b scope.Value) scope.Value {
  768. switch a.(type) {
  769. case *data:
  770. return o.Or(vfrom(a), b)
  771. default:
  772. switch b.(type) {
  773. case *data:
  774. return o.Or(a, vfrom(b))
  775. default:
  776. switch x := a.(type) {
  777. case BOOLEAN:
  778. switch y := b.(type) {
  779. case BOOLEAN:
  780. return BOOLEAN(x || y)
  781. default:
  782. panic(fmt.Sprintln(reflect.TypeOf(y)))
  783. }
  784. default:
  785. panic(fmt.Sprintln(reflect.TypeOf(x)))
  786. }
  787. }
  788. }
  789. panic(0)
  790. }
  791. func (o *ops) Ash(a, b scope.Value) scope.Value {
  792. switch a.(type) {
  793. case *data:
  794. return o.Ash(vfrom(a), b)
  795. default:
  796. switch b.(type) {
  797. case *data:
  798. return o.Ash(a, vfrom(b))
  799. default:
  800. switch x := a.(type) {
  801. case INTEGER:
  802. switch y := b.(type) {
  803. case INTEGER:
  804. return INTEGER(x << uint(y))
  805. default:
  806. panic(fmt.Sprintln(reflect.TypeOf(y)))
  807. }
  808. default:
  809. panic(fmt.Sprintln(reflect.TypeOf(x)))
  810. }
  811. }
  812. }
  813. panic(0)
  814. }
  815. func (o *ops) Div(a, b scope.Value) scope.Value {
  816. switch a.(type) {
  817. case *data:
  818. return o.Div(vfrom(a), b)
  819. default:
  820. switch b.(type) {
  821. case *data:
  822. return o.Div(a, vfrom(b))
  823. default:
  824. switch x := a.(type) {
  825. case INTEGER:
  826. switch y := b.(type) {
  827. case INTEGER:
  828. return INTEGER(x / y)
  829. default:
  830. panic(fmt.Sprintln(reflect.TypeOf(y)))
  831. }
  832. case LONGINT:
  833. switch y := b.(type) {
  834. case LONGINT:
  835. return LONGINT(x / y)
  836. default:
  837. panic(fmt.Sprintln(reflect.TypeOf(y)))
  838. }
  839. default:
  840. panic(fmt.Sprintln(reflect.TypeOf(x)))
  841. }
  842. }
  843. }
  844. panic(0)
  845. }
  846. func (o *ops) Mod(a, b scope.Value) scope.Value {
  847. switch a.(type) {
  848. case *data:
  849. return o.Mod(vfrom(a), b)
  850. default:
  851. switch b.(type) {
  852. case *data:
  853. return o.Mod(a, vfrom(b))
  854. default:
  855. switch x := a.(type) {
  856. case INTEGER:
  857. switch y := b.(type) {
  858. case INTEGER:
  859. return INTEGER(x % y)
  860. default:
  861. panic(fmt.Sprintln(reflect.TypeOf(y)))
  862. }
  863. case LONGINT:
  864. switch y := b.(type) {
  865. case LONGINT:
  866. return LONGINT(x % y)
  867. default:
  868. panic(fmt.Sprintln(reflect.TypeOf(y)))
  869. }
  870. default:
  871. panic(fmt.Sprintln(reflect.TypeOf(x)))
  872. }
  873. }
  874. }
  875. panic(0)
  876. }
  877. func (o *ops) Mult(a, b scope.Value) scope.Value {
  878. switch a.(type) {
  879. case *data:
  880. return o.Mult(vfrom(a), b)
  881. default:
  882. switch b.(type) {
  883. case *data:
  884. return o.Mult(a, vfrom(b))
  885. default:
  886. switch x := a.(type) {
  887. case INTEGER:
  888. switch y := b.(type) {
  889. case INTEGER:
  890. return INTEGER(x * y)
  891. default:
  892. panic(fmt.Sprintln(reflect.TypeOf(y)))
  893. }
  894. case SET:
  895. switch y := b.(type) {
  896. case SET:
  897. res := big.NewInt(0)
  898. for i := 0; i < 64; i++ {
  899. if x.bits.Bit(i) == 1 && y.bits.Bit(i) == 1 {
  900. res.SetBit(res, i, 1)
  901. }
  902. }
  903. return SET{bits: res}
  904. default:
  905. panic(fmt.Sprintln(reflect.TypeOf(y)))
  906. }
  907. default:
  908. panic(fmt.Sprintln(reflect.TypeOf(x)))
  909. }
  910. }
  911. }
  912. panic(0)
  913. }
  914. func (o *ops) Divide(a, b scope.Value) scope.Value {
  915. switch a.(type) {
  916. case *data:
  917. return o.Divide(vfrom(a), b)
  918. default:
  919. switch b.(type) {
  920. case *data:
  921. return o.Divide(a, vfrom(b))
  922. default:
  923. switch x := a.(type) {
  924. case INTEGER:
  925. switch y := b.(type) {
  926. case INTEGER:
  927. return REAL(float64(x) / float64(y))
  928. default:
  929. panic(fmt.Sprintln(reflect.TypeOf(y)))
  930. }
  931. case REAL:
  932. switch y := b.(type) {
  933. case REAL:
  934. return REAL(float64(x) / float64(y))
  935. default:
  936. panic(fmt.Sprintln(reflect.TypeOf(y)))
  937. }
  938. case SET:
  939. switch y := b.(type) {
  940. case SET:
  941. res := big.NewInt(0)
  942. for i := 0; i < 64; i++ {
  943. if x.bits.Bit(i) != y.bits.Bit(i) {
  944. res.SetBit(res, i, 1)
  945. }
  946. }
  947. return SET{bits: res}
  948. default:
  949. panic(fmt.Sprintln(reflect.TypeOf(y)))
  950. }
  951. default:
  952. panic(fmt.Sprintln(reflect.TypeOf(x)))
  953. }
  954. }
  955. }
  956. panic(0)
  957. }
  958. func (o *ops) Len(a object.Object, _a, _b scope.Value) (ret scope.Value) {
  959. //assert.For(a != nil, 20)
  960. assert.For(_b != nil, 21)
  961. var b int32 = gfrom(_b).(int32)
  962. assert.For(b == 0, 22)
  963. if a != nil {
  964. assert.For(a.Type() == object.COMPLEX, 23)
  965. switch typ := a.Complex().(type) {
  966. case object.ArrayType:
  967. ret = INTEGER(int32(typ.Len()))
  968. case object.DynArrayType:
  969. switch t := _a.(type) {
  970. case *arr:
  971. ret = INTEGER(t.length)
  972. case *dynarr:
  973. ret = INTEGER(len(t.val))
  974. default:
  975. halt.As(100, "unsupported", reflect.TypeOf(t))
  976. }
  977. default:
  978. panic(fmt.Sprintln("unsupported", reflect.TypeOf(a.Complex())))
  979. }
  980. } else {
  981. switch a := _a.(type) {
  982. // case string:
  983. // ret = int64(utf8.RuneCountInString(_a.(string)))
  984. // case []interface{}:
  985. // ret = int64(len(_a.([]interface{})))
  986. case *arr:
  987. ret = INTEGER(int32(a.length))
  988. case *dynarr:
  989. ret = INTEGER(int32(len(a.val)))
  990. default:
  991. panic(fmt.Sprintln("unsupported", reflect.TypeOf(a)))
  992. }
  993. }
  994. return ret
  995. }
  996. func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
  997. var compare func(x, a object.ComplexType) bool
  998. compare = func(_x, _a object.ComplexType) bool {
  999. switch x := _x.(type) {
  1000. case object.RecordType:
  1001. switch a := _a.(type) {
  1002. case object.RecordType:
  1003. switch {
  1004. case x.Name() == a.Name():
  1005. // fmt.Println("eq")
  1006. return true //опасно сравнивать имена конеш
  1007. case x.BaseType() != nil:
  1008. // fmt.Println("go base")
  1009. return compare(x.BaseType(), a)
  1010. default:
  1011. return false
  1012. }
  1013. default:
  1014. halt.As(100, reflect.TypeOf(a))
  1015. }
  1016. case object.PointerType:
  1017. switch a := _a.(type) {
  1018. case object.PointerType:
  1019. switch {
  1020. case x.Name() == a.Name():
  1021. // fmt.Println("eq")
  1022. return true //опасно сравнивать имена конеш
  1023. case x.Base() != nil:
  1024. // fmt.Println("go base")
  1025. return compare(x.Base(), a)
  1026. default:
  1027. return false
  1028. }
  1029. default:
  1030. halt.As(100, reflect.TypeOf(a))
  1031. }
  1032. default:
  1033. halt.As(100, reflect.TypeOf(a))
  1034. }
  1035. panic(0)
  1036. }
  1037. switch x := a.(type) {
  1038. case *rec:
  1039. z, a := x.link.Complex().(object.RecordType)
  1040. y, b := typ.(object.RecordType)
  1041. //fmt.Println("compare", x.link.Complex(), typ, a, b, a && b && compare(z, y))
  1042. return BOOLEAN(a && b && compare(z, y))
  1043. case *ptr:
  1044. z, a := x.link.Complex().(object.PointerType)
  1045. y, b := typ.(object.PointerType)
  1046. //fmt.Println("compare", x.link.Complex(), typ, a, b, a && b && compare(z, y))
  1047. return BOOLEAN(a && b && compare(z, y))
  1048. default:
  1049. halt.As(100, reflect.TypeOf(x))
  1050. }
  1051. panic(0)
  1052. }
  1053. func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) scope.Value {
  1054. switch typ {
  1055. case object.INTEGER:
  1056. switch x := a.(type) {
  1057. case *data:
  1058. return o.Conv(vfrom(x), typ)
  1059. case BYTE:
  1060. return INTEGER(x)
  1061. case SET:
  1062. return INTEGER(x.bits.Int64())
  1063. case REAL:
  1064. return INTEGER(x)
  1065. default:
  1066. halt.As(100, reflect.TypeOf(x))
  1067. }
  1068. case object.SET:
  1069. switch x := a.(type) {
  1070. case *data:
  1071. return o.Conv(vfrom(x), typ)
  1072. case INTEGER:
  1073. return SET{bits: big.NewInt(int64(x))}
  1074. default:
  1075. halt.As(100, reflect.TypeOf(x))
  1076. }
  1077. case object.REAL:
  1078. switch x := a.(type) {
  1079. case *data:
  1080. return o.Conv(vfrom(x), typ)
  1081. case INTEGER:
  1082. return REAL(float64(x))
  1083. default:
  1084. halt.As(100, reflect.TypeOf(x))
  1085. }
  1086. case object.CHAR:
  1087. switch x := a.(type) {
  1088. case *data:
  1089. return o.Conv(vfrom(x), typ)
  1090. case LONGINT:
  1091. return CHAR(rune(x))
  1092. default:
  1093. halt.As(100, reflect.TypeOf(x))
  1094. }
  1095. case object.NOTYPE:
  1096. assert.For(len(comp) > 0, 20)
  1097. switch t := comp[0].(type) {
  1098. case object.BasicType:
  1099. switch t.Type() {
  1100. case object.SHORTSTRING:
  1101. switch x := a.(type) {
  1102. case *dynarr:
  1103. return SHORTSTRING(x.tryString())
  1104. case *arr:
  1105. return SHORTSTRING(x.tryString())
  1106. default:
  1107. halt.As(100, reflect.TypeOf(x))
  1108. }
  1109. default:
  1110. halt.As(100, t.Type())
  1111. }
  1112. default:
  1113. halt.As(100, reflect.TypeOf(t))
  1114. }
  1115. default:
  1116. halt.As(100, typ)
  1117. }
  1118. panic(100)
  1119. }
  1120. func (o *ops) Not(a scope.Value) scope.Value {
  1121. switch x := a.(type) {
  1122. case *data:
  1123. return o.Not(vfrom(x))
  1124. case BOOLEAN:
  1125. return BOOLEAN(!x)
  1126. default:
  1127. halt.As(100, reflect.TypeOf(x))
  1128. }
  1129. panic(100)
  1130. }
  1131. func (o *ops) Abs(a scope.Value) scope.Value {
  1132. switch x := a.(type) {
  1133. case *data:
  1134. return o.Abs(vfrom(x))
  1135. case INTEGER:
  1136. return INTEGER(int32(math.Abs(float64(x))))
  1137. default:
  1138. halt.As(100, reflect.TypeOf(x))
  1139. }
  1140. panic(100)
  1141. }
  1142. func (o *ops) Odd(a scope.Value) scope.Value {
  1143. switch x := a.(type) {
  1144. case *data:
  1145. return o.Odd(vfrom(x))
  1146. case INTEGER:
  1147. return BOOLEAN(int32(math.Abs(float64(x)))%2 == 1)
  1148. default:
  1149. halt.As(100, reflect.TypeOf(x))
  1150. }
  1151. panic(100)
  1152. }
  1153. func (o *ops) Cap(a scope.Value) scope.Value {
  1154. switch x := a.(type) {
  1155. case *data:
  1156. return o.Cap(vfrom(x))
  1157. case CHAR:
  1158. return CHAR([]rune(strings.ToUpper(string(x)))[0])
  1159. default:
  1160. halt.As(100, reflect.TypeOf(x))
  1161. }
  1162. panic(100)
  1163. }
  1164. func (o *ops) Bits(a scope.Value) scope.Value {
  1165. switch x := a.(type) {
  1166. case *data:
  1167. return o.Bits(vfrom(x))
  1168. case INTEGER:
  1169. return SET{bits: big.NewInt(0).SetBit(big.NewInt(0), int(x), 1)}
  1170. default:
  1171. halt.As(100, reflect.TypeOf(x))
  1172. }
  1173. panic(100)
  1174. }
  1175. func (o *ops) Eq(a, b scope.Value) scope.Value {
  1176. switch a.(type) {
  1177. case *data:
  1178. return o.Eq(vfrom(a), b)
  1179. default:
  1180. switch b.(type) {
  1181. case *data:
  1182. return o.Eq(a, vfrom(b))
  1183. default:
  1184. switch x := a.(type) {
  1185. case INTEGER:
  1186. switch y := b.(type) {
  1187. case INTEGER:
  1188. return BOOLEAN(x == y)
  1189. default:
  1190. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1191. }
  1192. case LONGINT:
  1193. switch y := b.(type) {
  1194. case LONGINT:
  1195. return BOOLEAN(x == y)
  1196. default:
  1197. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1198. }
  1199. default:
  1200. panic(fmt.Sprintln(reflect.TypeOf(x)))
  1201. }
  1202. }
  1203. }
  1204. panic(0)
  1205. }
  1206. func (o *ops) Neq(a, b scope.Value) scope.Value {
  1207. switch a.(type) {
  1208. case *data:
  1209. return o.Neq(vfrom(a), b)
  1210. default:
  1211. switch b.(type) {
  1212. case *data:
  1213. return o.Neq(a, vfrom(b))
  1214. default:
  1215. switch x := a.(type) {
  1216. case *ptr:
  1217. switch y := b.(type) {
  1218. case PTR:
  1219. assert.For(y == NIL, 40)
  1220. return BOOLEAN(x.val != nil && x.val.id != 0)
  1221. default:
  1222. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1223. }
  1224. case INTEGER:
  1225. switch y := b.(type) {
  1226. case INTEGER:
  1227. return BOOLEAN(x != y)
  1228. default:
  1229. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1230. }
  1231. case LONGINT:
  1232. switch y := b.(type) {
  1233. case LONGINT:
  1234. return BOOLEAN(x != y)
  1235. default:
  1236. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1237. }
  1238. case SET:
  1239. switch y := b.(type) {
  1240. case SET:
  1241. return BOOLEAN(x.bits.Cmp(y.bits) != 0)
  1242. default:
  1243. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1244. }
  1245. default:
  1246. panic(fmt.Sprintln(reflect.TypeOf(x)))
  1247. }
  1248. }
  1249. }
  1250. panic(0)
  1251. }
  1252. func (o *ops) Lss(a, b scope.Value) scope.Value {
  1253. switch a.(type) {
  1254. case *data:
  1255. return o.Lss(vfrom(a), b)
  1256. default:
  1257. switch b.(type) {
  1258. case *data:
  1259. return o.Lss(a, vfrom(b))
  1260. default:
  1261. switch x := a.(type) {
  1262. case INTEGER:
  1263. switch y := b.(type) {
  1264. case INTEGER:
  1265. return BOOLEAN(x < y)
  1266. default:
  1267. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1268. }
  1269. case LONGINT:
  1270. switch y := b.(type) {
  1271. case LONGINT:
  1272. return BOOLEAN(x < y)
  1273. default:
  1274. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1275. }
  1276. default:
  1277. panic(fmt.Sprintln(reflect.TypeOf(x)))
  1278. }
  1279. }
  1280. }
  1281. panic(0)
  1282. }
  1283. func (o *ops) Gtr(a, b scope.Value) scope.Value {
  1284. switch a.(type) {
  1285. case *data:
  1286. return o.Gtr(vfrom(a), b)
  1287. default:
  1288. switch b.(type) {
  1289. case *data:
  1290. return o.Gtr(a, vfrom(b))
  1291. default:
  1292. switch x := a.(type) {
  1293. case INTEGER:
  1294. switch y := b.(type) {
  1295. case INTEGER:
  1296. return BOOLEAN(x > y)
  1297. default:
  1298. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1299. }
  1300. default:
  1301. panic(fmt.Sprintln(reflect.TypeOf(x)))
  1302. }
  1303. }
  1304. }
  1305. panic(0)
  1306. }
  1307. func (o *ops) Leq(a, b scope.Value) scope.Value {
  1308. switch a.(type) {
  1309. case *data:
  1310. return o.Leq(vfrom(a), b)
  1311. default:
  1312. switch b.(type) {
  1313. case *data:
  1314. return o.Leq(a, vfrom(b))
  1315. default:
  1316. switch x := a.(type) {
  1317. case INTEGER:
  1318. switch y := b.(type) {
  1319. case INTEGER:
  1320. return BOOLEAN(x <= y)
  1321. default:
  1322. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1323. }
  1324. default:
  1325. panic(fmt.Sprintln(reflect.TypeOf(x)))
  1326. }
  1327. }
  1328. }
  1329. panic(0)
  1330. }
  1331. func (o *ops) Geq(a, b scope.Value) scope.Value {
  1332. switch a.(type) {
  1333. case *data:
  1334. return o.Geq(vfrom(a), b)
  1335. default:
  1336. switch b.(type) {
  1337. case *data:
  1338. return o.Geq(a, vfrom(b))
  1339. default:
  1340. switch x := a.(type) {
  1341. case INTEGER:
  1342. switch y := b.(type) {
  1343. case INTEGER:
  1344. return BOOLEAN(x >= y)
  1345. default:
  1346. panic(fmt.Sprintln(reflect.TypeOf(y)))
  1347. }
  1348. default:
  1349. panic(fmt.Sprintln(reflect.TypeOf(x)))
  1350. }
  1351. }
  1352. }
  1353. panic(0)
  1354. }
  1355. func (o *ops) TypeOf(x scope.Value) (object.Type, object.ComplexType) {
  1356. switch v := x.(type) {
  1357. case *ptr:
  1358. if v.val != nil {
  1359. return v.val.link.Type(), v.val.link.Complex()
  1360. }
  1361. case *rec:
  1362. return v.link.Type(), v.link.Complex()
  1363. default:
  1364. halt.As(100, reflect.TypeOf(v))
  1365. }
  1366. return object.NOTYPE, nil
  1367. }
  1368. func init() {
  1369. scope.ValueFrom = vfrom
  1370. scope.GoTypeFrom = gfrom
  1371. scope.TypeFromGo = fromg
  1372. scope.Ops = &ops{}
  1373. }