Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. OBJECT Grid2D
  2. rnum
  3. cnum
  4. grid
  5. pgrid
  6. border
  7. activate _Grid2D_3cd_activate
  8. simulate _Grid2D_3cd_simulate
  9. fetch _Grid2D_3cd_fetch
  10. plan _Grid2D_3cd_plan
  11. init _Grid2D_3cd_init
  12. getNeighbors _Grid2D_3cd_getNeighbors
  13. act _Grid2D_3cd_act
  14. output _Grid2D_3cd_output
  15. END
  16.  
  17. @DEPENDS console.nx
  18. METHOD _Grid2D_3cd_init rnum cnum
  19. fetch rnum
  20. object_self
  21. object_fetch rnum
  22. set
  23. fetch cnum
  24. object_self
  25. object_fetch cnum
  26. set
  27. fetch rnum
  28. aalocate
  29. object_self
  30. object_fetch grid
  31. set
  32. iconst_0
  33. istore i
  34. b1:
  35. fetch rnum
  36. fetch i
  37. lesser
  38. branchif b2
  39. branch b3
  40. b2:
  41. fetch cnum
  42. aalocate
  43. object_self
  44. object_fetch grid
  45. fetch i
  46. afetch
  47. set
  48. iconst_1
  49. fetch i
  50. add
  51. istore i
  52. branch b1
  53. b3:
  54. fetch rnum
  55. aalocate
  56. object_self
  57. object_fetch pgrid
  58. set
  59. iconst_0
  60. istore i
  61. b4:
  62. fetch rnum
  63. fetch i
  64. lesser
  65. branchif b5
  66. branch b6
  67. b5:
  68. fetch cnum
  69. aalocate
  70. object_self
  71. object_fetch pgrid
  72. fetch i
  73. afetch
  74. set
  75. iconst_1
  76. fetch i
  77. add
  78. istore i
  79. branch b4
  80. b6:
  81. ascii_literal
  82. istore border
  83. iconst_0
  84. istore i
  85. b7:
  86. fetch cnum
  87. fetch i
  88. lesser
  89. branchif b8
  90. branch b9
  91. b8:
  92. ascii_literal -
  93. fetch border
  94. concat
  95. istore border
  96. iconst_1
  97. fetch i
  98. add
  99. istore i
  100. branch b7
  101. b9:
  102. ascii_literal \n
  103. fetch border
  104. concat
  105. object_self
  106. object_fetch border
  107. set
  108. END
  109. METHOD _Grid2D_3cd_output
  110. object_self
  111. object_fetch border
  112. invoke con_printstr
  113. iconst_0
  114. istore i
  115. b1:
  116. object_self
  117. object_fetch rnum
  118. fetch i
  119. lesser
  120. branchif b2
  121. branch b3
  122. b2:
  123. ascii_literal |
  124. invoke con_printstr
  125. iconst_0
  126. istore j
  127. b4:
  128. object_self
  129. object_fetch cnum
  130. fetch j
  131. lesser
  132. branchif b5
  133. branch b6
  134. b5:
  135. object_self
  136. object_fetch grid
  137. fetch i
  138. afetch
  139. fetch j
  140. afetch
  141. branchif b7
  142. ascii_literal
  143. invoke con_printstr
  144. branch b8
  145. b7:
  146. ascii_literal O
  147. invoke con_printstr
  148. b8:
  149. iconst_1
  150. fetch j
  151. add
  152. istore j
  153. branch b4
  154. b6:
  155. ascii_literal |\n
  156. invoke con_printstr
  157. iconst_1
  158. fetch i
  159. add
  160. istore i
  161. branch b1
  162. b3:
  163. object_self
  164. object_fetch border
  165. invoke con_printstr
  166. END
  167. METHOD _Grid2D_3cd_fetch r c
  168. object_self
  169. object_fetch rnum
  170. fetch r
  171. object_self
  172. object_fetch rnum
  173. add
  174. modulo
  175. istore r
  176. object_self
  177. object_fetch cnum
  178. fetch c
  179. object_self
  180. object_fetch cnum
  181. add
  182. modulo
  183. istore c
  184. object_self
  185. object_fetch grid
  186. fetch r
  187. afetch
  188. fetch c
  189. afetch
  190. return_ref
  191. END
  192. METHOD _Grid2D_3cd_plan
  193. iconst_0
  194. istore i
  195. b1:
  196. object_self
  197. object_fetch rnum
  198. fetch i
  199. lesser
  200. branchif b2
  201. branch b3
  202. b2:
  203. iconst_0
  204. istore j
  205. b4:
  206. object_self
  207. object_fetch cnum
  208. fetch j
  209. lesser
  210. branchif b5
  211. branch b6
  212. b5:
  213. object_self
  214. object_fetch grid
  215. fetch i
  216. afetch
  217. fetch j
  218. afetch
  219. istore me
  220. fetch j
  221. fetch i
  222. object_self
  223. object_call getNeighbors
  224. istore neighbors
  225. fetch me
  226. branchif b7
  227. iconst_3
  228. fetch neighbors
  229. eql
  230. branchif b9
  231. branch b10
  232. b9:
  233. iconst -1
  234. object_self
  235. object_fetch grid
  236. fetch i
  237. afetch
  238. fetch j
  239. afetch
  240. set
  241. b10:
  242. branch b8
  243. b7:
  244. iconst_3
  245. fetch neighbors
  246. greater
  247. iconst_2
  248. fetch neighbors
  249. lesser
  250. or
  251. branchif b11
  252. branch b12
  253. b11:
  254. iconst_2
  255. object_self
  256. object_fetch grid
  257. fetch i
  258. afetch
  259. fetch j
  260. afetch
  261. set
  262. b12:
  263. b8:
  264. iconst_1
  265. fetch j
  266. add
  267. istore j
  268. branch b4
  269. b6:
  270. iconst_1
  271. fetch i
  272. add
  273. istore i
  274. branch b1
  275. b3:
  276. END
  277. METHOD _Grid2D_3cd_act
  278. iconst_0
  279. istore i
  280. b1:
  281. object_self
  282. object_fetch rnum
  283. fetch i
  284. lesser
  285. branchif b2
  286. branch b3
  287. b2:
  288. iconst_0
  289. istore j
  290. b4:
  291. object_self
  292. object_fetch cnum
  293. fetch j
  294. lesser
  295. branchif b5
  296. branch b6
  297. b5:
  298. object_self
  299. object_fetch grid
  300. fetch i
  301. afetch
  302. fetch j
  303. afetch
  304. istore me
  305. iconst_2
  306. fetch me
  307. eql
  308. branchif b7
  309. branch b8
  310. b7:
  311. iconst_0
  312. object_self
  313. object_fetch grid
  314. fetch i
  315. afetch
  316. fetch j
  317. afetch
  318. set
  319. b8:
  320. iconst -1
  321. fetch me
  322. eql
  323. branchif b9
  324. branch b10
  325. b9:
  326. iconst_1
  327. object_self
  328. object_fetch grid
  329. fetch i
  330. afetch
  331. fetch j
  332. afetch
  333. set
  334. b10:
  335. iconst_1
  336. fetch j
  337. add
  338. istore j
  339. branch b4
  340. b6:
  341. iconst_1
  342. fetch i
  343. add
  344. istore i
  345. branch b1
  346. b3:
  347. END
  348. METHOD _Grid2D_3cd_getNeighbors r c
  349. iconst_0
  350. istore friendcount
  351. iconst -1
  352. istore i
  353. b1:
  354. iconst_1
  355. fetch i
  356. lesser_eql
  357. branchif b2
  358. branch b3
  359. b2:
  360. iconst -1
  361. istore j
  362. b4:
  363. iconst_1
  364. fetch j
  365. lesser_eql
  366. branchif b5
  367. branch b6
  368. b5:
  369. fetch j
  370. fetch c
  371. add
  372. fetch i
  373. fetch r
  374. add
  375. object_self
  376. object_call fetch
  377. branchif b7
  378. branch b8
  379. b7:
  380. iconst_0
  381. fetch j
  382. eql
  383. iconst_0
  384. fetch i
  385. eql
  386. and
  387. not
  388. branchif b9
  389. branch b10
  390. b9:
  391. iconst_1
  392. fetch friendcount
  393. add
  394. istore friendcount
  395. b10:
  396. b8:
  397. iconst_1
  398. fetch j
  399. add
  400. istore j
  401. branch b4
  402. b6:
  403. iconst_1
  404. fetch i
  405. add
  406. istore i
  407. branch b1
  408. b3:
  409. fetch friendcount
  410. return_x
  411. END
  412. METHOD _Grid2D_3cd_simulate
  413. b1:
  414. iconst_1
  415. branchif b2
  416. branch b3
  417. b2:
  418. object_self
  419. object_call output
  420. object_self
  421. object_call plan
  422. object_self
  423. object_call act
  424. branch b1
  425. b3:
  426. END
  427. METHOD _Grid2D_3cd_activate r c
  428. iconst_1
  429. fetch c
  430. fetch r
  431. object_self
  432. object_call fetch
  433. set
  434. END
  435. METHOD main
  436. iconst 130
  437. iconst 50
  438. object_instantiate Grid2D
  439. istore g
  440. iconst 10
  441. iconst 10
  442. fetch g
  443. object_call activate
  444. iconst 10
  445. iconst 12
  446. fetch g
  447. object_call activate
  448. iconst 13
  449. iconst 13
  450. fetch g
  451. object_call activate
  452. iconst 11
  453. iconst 10
  454. fetch g
  455. object_call activate
  456. iconst 12
  457. iconst 10
  458. fetch g
  459. object_call activate
  460. iconst 11
  461. iconst 11
  462. fetch g
  463. object_call activate
  464. iconst 13
  465. iconst 11
  466. fetch g
  467. object_call activate
  468. iconst 13
  469. iconst 12
  470. fetch g
  471. object_call activate
  472. fetch g
  473. object_call simulate
  474. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement