Advertisement
Guest User

Untitled

a guest
Mar 11th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.30 KB | None | 0 0
  1. /*
  2. * pixelle - Graphics algorithmic editor
  3. * Copyright (C) 2008-2012 Dave Brosius
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. grammar Pixelle;
  20.  
  21. @header {
  22. package com.mebigfatguy.pixelle.antlr;
  23. import org.objectweb.asm.ClassWriter;
  24. import org.objectweb.asm.Label;
  25. import org.objectweb.asm.MethodVisitor;
  26. import org.objectweb.asm.Opcodes;
  27. }
  28.  
  29. @lexer::header {
  30. package com.mebigfatguy.pixelle.antlr;
  31. }
  32.  
  33. @members {
  34. ClassWriter cw;
  35. MethodVisitor mv;
  36. String clz;
  37.  
  38. public PixelleParser(CommonTokenStream tokens, String clsName) {
  39. super(tokens, new RecognizerSharedState());
  40.  
  41. clz = clsName.replace('.', '/');
  42. cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
  43. cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, clz, null, "java/lang/Object", new String[] {"com/mebigfatguy/pixelle/PixelleExpr"});
  44.  
  45. cw.visitField(Opcodes.ACC_PRIVATE, "width", "I", null, Integer.valueOf(0));
  46. cw.visitField(Opcodes.ACC_PRIVATE, "height", "I", null, Integer.valueOf(0));
  47. cw.visitField(Opcodes.ACC_PRIVATE, "stack", "Ljava/util/List;", "Ljava/lang/List<Ljava/lang/Double;>;", null);
  48.  
  49. mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
  50. mv.visitVarInsn(Opcodes.ALOAD, 0);
  51. mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
  52. mv.visitVarInsn(Opcodes.ALOAD, 0);
  53. mv.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
  54. mv.visitInsn(Opcodes.DUP);
  55. mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V");
  56. mv.visitFieldInsn(Opcodes.PUTFIELD, clz, "stack", "Ljava/util/List;");
  57. mv.visitInsn(Opcodes.RETURN);
  58. mv.visitMaxs(0,0);
  59.  
  60. mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setOutputSize", "(II)V", null, new String[0]);
  61. mv.visitVarInsn(Opcodes.ALOAD, 0);
  62. mv.visitInsn(Opcodes.DUP);
  63. mv.visitVarInsn(Opcodes.ILOAD, 1);
  64. mv.visitFieldInsn(Opcodes.PUTFIELD, clz, "width", "I");
  65. mv.visitVarInsn(Opcodes.ILOAD, 2);
  66. mv.visitFieldInsn(Opcodes.PUTFIELD, clz, "height", "I");
  67. mv.visitInsn(Opcodes.RETURN);
  68. mv.visitMaxs(0,0);
  69.  
  70. mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "eval", "([Lcom/mebigfatguy/pixelle/PixelleEval;II)D", null, new String[0]);
  71. mv.visitVarInsn(Opcodes.ALOAD, 1);
  72. mv.visitInsn(Opcodes.ARRAYLENGTH);
  73. mv.visitVarInsn(Opcodes.ISTORE, 4);
  74. }
  75.  
  76. public byte[] getClassBytes() {
  77. return cw.toByteArray();
  78. }
  79. }
  80.  
  81. @rulecatch {
  82. catch ( RecognitionException ex ) {
  83. throw ex;
  84. }
  85. }
  86.  
  87. pixelle :
  88. expr
  89. {
  90. mv.visitInsn(Opcodes.DRETURN);
  91. mv.visitMaxs(0,0);
  92. cw.visitEnd();
  93. } ;
  94.  
  95. expr :
  96. cond_expr ;
  97.  
  98. cond_expr
  99. @init
  100. {
  101. Label falseLabel = null;
  102. Label continueLabel = null;
  103. }
  104. :
  105. cond_and_expr
  106. ( '?'
  107. {
  108. mv.visitInsn(Opcodes.DCONST_0); //FALSE
  109. mv.visitInsn(Opcodes.DCMPG);
  110. falseLabel = new Label();
  111. mv.visitJumpInsn(Opcodes.IFEQ, falseLabel);
  112. }
  113. expr ':'
  114. {
  115. continueLabel = new Label();
  116. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  117. mv.visitLabel(falseLabel);
  118. }
  119. expr
  120. {
  121. mv.visitLabel(continueLabel);
  122. }
  123. )? ;
  124.  
  125. cond_and_expr
  126. @init
  127. {
  128. Label false1Label = null;
  129. Label false2Label = null;
  130. Label continueLabel = null;
  131. }
  132. :
  133. cond_or_expr
  134. ( '&&' cond_or_expr
  135. {
  136. false1Label = new Label();
  137. false2Label = new Label();
  138. continueLabel = new Label();
  139.  
  140. mv.visitInsn(Opcodes.DCONST_0);
  141. mv.visitInsn(Opcodes.DCMPG);
  142. mv.visitJumpInsn(Opcodes.IFEQ, false1Label);
  143. mv.visitInsn(Opcodes.DCONST_0);
  144. mv.visitInsn(Opcodes.DCMPG);
  145. mv.visitJumpInsn(Opcodes.IFEQ, false2Label);
  146. mv.visitInsn(Opcodes.DCONST_1);
  147. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  148. mv.visitLabel(false1Label);
  149. mv.visitInsn(Opcodes.POP2);
  150. mv.visitLabel(false2Label);
  151. mv.visitInsn(Opcodes.DCONST_0);
  152. mv.visitLabel(continueLabel);
  153. }
  154. )* ;
  155.  
  156. cond_or_expr
  157. @init
  158. {
  159. Label true1Label = null;
  160. Label true2Label = null;
  161. Label continueLabel = null;
  162. }
  163. :
  164. eq_expr
  165. ( '||' eq_expr
  166. {
  167. true1Label = new Label();
  168. true2Label = new Label();
  169. continueLabel = new Label();
  170.  
  171. mv.visitInsn(Opcodes.DCONST_0);
  172. mv.visitInsn(Opcodes.DCMPG);
  173. mv.visitJumpInsn(Opcodes.IFNE, true1Label);
  174. mv.visitInsn(Opcodes.DCONST_0);
  175. mv.visitInsn(Opcodes.DCMPG);
  176. mv.visitJumpInsn(Opcodes.IFNE, true2Label);
  177. mv.visitInsn(Opcodes.DCONST_0);
  178. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  179. mv.visitLabel(true1Label);
  180. mv.visitInsn(Opcodes.POP2);
  181. mv.visitLabel(true2Label);
  182. mv.visitInsn(Opcodes.DCONST_1);
  183. mv.visitLabel(continueLabel);
  184. }
  185. )* ;
  186.  
  187. eq_expr
  188. @init
  189. {
  190. Label cmpSucceedLabel = null;
  191. Label continueLabel = null;
  192. }
  193. :
  194. rel_expr
  195. ( op=('==' | '!=') rel_expr
  196. {
  197. mv.visitInsn(Opcodes.DCMPG);
  198. cmpSucceedLabel = new Label();
  199. if ("==".equals($op.text))
  200. {
  201. mv.visitJumpInsn(Opcodes.IFEQ, cmpSucceedLabel);
  202. }
  203. else
  204. {
  205. mv.visitJumpInsn(Opcodes.IFNE, cmpSucceedLabel);
  206. }
  207. mv.visitInsn(Opcodes.DCONST_0); //FALSE
  208. continueLabel = new Label();
  209. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  210. mv.visitLabel(cmpSucceedLabel);
  211. mv.visitInsn(Opcodes.DCONST_1); //TRUE
  212. mv.visitLabel(continueLabel);
  213. }
  214. )* ;
  215.  
  216. rel_expr
  217. @init
  218. {
  219. Label falseLabel = null;
  220. Label continueLabel = null;
  221. }
  222. :
  223. add_expr
  224. ( r=rel_op add_expr
  225. {
  226. falseLabel = new Label();
  227. continueLabel = new Label();
  228. if ($r.text.equals("<=")) {
  229. mv.visitInsn(Opcodes.DCMPG);
  230. mv.visitJumpInsn(Opcodes.IFGT, falseLabel);
  231. mv.visitInsn(Opcodes.DCONST_1);
  232. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  233. mv.visitLabel(falseLabel);
  234. mv.visitInsn(Opcodes.DCONST_0);
  235. } else if ($r.text.equals(">=")) {
  236. mv.visitInsn(Opcodes.DCMPG);
  237. mv.visitJumpInsn(Opcodes.IFLT, falseLabel);
  238. mv.visitInsn(Opcodes.DCONST_1);
  239. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  240. mv.visitLabel(falseLabel);
  241. mv.visitInsn(Opcodes.DCONST_0);
  242. } else if ($r.text.equals("<")) {
  243. mv.visitInsn(Opcodes.DCMPG);
  244. mv.visitJumpInsn(Opcodes.IFGE, falseLabel);
  245. mv.visitInsn(Opcodes.DCONST_1);
  246. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  247. mv.visitLabel(falseLabel);
  248. mv.visitInsn(Opcodes.DCONST_0);
  249. } else {
  250. mv.visitInsn(Opcodes.DCMPG);
  251. mv.visitJumpInsn(Opcodes.IFLE, falseLabel);
  252. mv.visitInsn(Opcodes.DCONST_1);
  253. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  254. mv.visitLabel(falseLabel);
  255. mv.visitInsn(Opcodes.DCONST_0);
  256. }
  257. mv.visitLabel(continueLabel);
  258. }
  259. )* ;
  260.  
  261. rel_op :
  262. ('<=')
  263. | ('>=')
  264. | '<'
  265. | '>'
  266. ;
  267.  
  268. add_expr :
  269. mul_expr
  270. (op=('+' | '-') mul_expr
  271. {
  272. mv.visitInsn("+".equals($op.text)?Opcodes.DADD:Opcodes.DSUB);
  273. }
  274. )* ;
  275.  
  276. mul_expr :
  277. unaryExpression
  278. (op=('*' | '/') unaryExpression
  279. {
  280. mv.visitInsn("*".equals($op.text)?Opcodes.DMUL:Opcodes.DDIV);
  281. }
  282. )* ;
  283.  
  284. unaryExpression
  285. : '!' unaryExpression
  286. {
  287. Label falseLabel = new Label();
  288. Label continueLabel = new Label();
  289. mv.visitInsn(Opcodes.DCONST_0);
  290. mv.visitInsn(Opcodes.DCMPG);
  291. mv.visitJumpInsn(Opcodes.IFEQ, falseLabel);
  292. mv.visitInsn(Opcodes.DCONST_0);
  293. mv.visitJumpInsn(Opcodes.GOTO, continueLabel);
  294. mv.visitLabel(falseLabel);
  295. mv.visitInsn(Opcodes.DCONST_1);
  296. mv.visitLabel(continueLabel);
  297. }
  298. | '-' unaryExpression
  299. {
  300. mv.visitInsn(Opcodes.DNEG);
  301. }
  302. | factor ;
  303.  
  304. factor
  305. : NUMBER
  306. {
  307. mv.visitLdcInsn(Double.valueOf($NUMBER.text));
  308. }
  309. | '(' expr ')'
  310. | functionExpr
  311. | specialExpr
  312. | pixelExpr
  313. | locationExpr;
  314.  
  315. pixelExpr
  316. : P
  317. {
  318. mv.visitVarInsn(Opcodes.ALOAD, 1);
  319. }
  320. ( '(' selector=expr ')' )?
  321. {
  322. if ($selector.text == null)
  323. mv.visitInsn(Opcodes.ICONST_0);
  324. else
  325. {
  326. mv.visitInsn(Opcodes.D2I);
  327. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "abs", "(I)I");
  328. }
  329.  
  330. mv.visitVarInsn(Opcodes.ILOAD, 4);
  331. mv.visitInsn(Opcodes.IREM);
  332. mv.visitInsn(Opcodes.AALOAD);
  333. }
  334. '[' expr
  335. {
  336. mv.visitInsn(Opcodes.D2I);
  337. }
  338. ',' expr
  339. {
  340. mv.visitInsn(Opcodes.D2I);
  341. }
  342. ']' '.' spec=(R|G|B|T|S)
  343. {
  344. String s = $spec.text;
  345. mv.visitLdcInsn(Character.valueOf(s.charAt(0)));
  346. mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/mebigfatguy/pixelle/PixelleEval", "getValue", "(IIC)D" );
  347. };
  348.  
  349. locationExpr
  350. : X
  351. {
  352. mv.visitVarInsn(Opcodes.ILOAD, 2);
  353. mv.visitInsn(Opcodes.I2D);
  354. }
  355. | Y
  356. {
  357. mv.visitVarInsn(Opcodes.ILOAD, 3);
  358. mv.visitInsn(Opcodes.I2D);
  359. }
  360. | WIDTH
  361. {
  362. mv.visitVarInsn(Opcodes.ALOAD, 0);
  363. mv.visitFieldInsn(Opcodes.GETFIELD, clz, "width", "I");
  364. mv.visitInsn(Opcodes.I2D);
  365. }
  366. | HEIGHT
  367. {
  368. mv.visitVarInsn(Opcodes.ALOAD, 0);
  369. mv.visitFieldInsn(Opcodes.GETFIELD, clz, "height", "I");
  370. mv.visitInsn(Opcodes.I2D);
  371. };
  372.  
  373. functionExpr
  374. : ABS '(' expr ')'
  375. {
  376. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "abs", "(D)D");
  377. }
  378. | MAX '(' expr ',' expr ')'
  379. {
  380. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "max", "(DD)D");
  381. }
  382. | MIN '(' expr ',' expr ')'
  383. {
  384. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "min", "(DD)D");
  385. }
  386. | POW '(' expr ',' expr ')'
  387. {
  388. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "pow", "(DD)D");
  389. }
  390. | SQRT '(' expr ')'
  391. {
  392. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "sqrt", "(D)D");
  393. }
  394. | SIN '(' expr ')'
  395. {
  396. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "sin", "(D)D");
  397. }
  398. | COS '(' expr ')'
  399. {
  400. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "cos", "(D)D");
  401. }
  402. | TAN '(' expr ')'
  403. {
  404. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "tan", "(D)D");
  405. }
  406. | ASIN '(' expr ')'
  407. {
  408. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "asin", "(D)D");
  409. }
  410. | ACOS '(' expr ')'
  411. {
  412. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "acos", "(D)D");
  413. }
  414. | ATAN '(' expr ')'
  415. {
  416. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "atan", "(D)D");
  417. }
  418. | LOG '(' expr ')'
  419. {
  420. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "log", "(D)D");
  421. }
  422. | EXP '(' expr ')'
  423. {
  424. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "exp", "(D)D");
  425. }
  426. | E '(' ')'
  427. {
  428. mv.visitLdcInsn(Double.valueOf(Math.E));
  429. }
  430. | PI '(' ')'
  431. {
  432. mv.visitLdcInsn(Double.valueOf(Math.PI));
  433. }
  434. | RANDOM '(' ')'
  435. {
  436. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "random", "()D");
  437. } ;
  438.  
  439. specialExpr
  440. @init
  441. {
  442. Label leftLabel = null;
  443. Label rightLabel = null;
  444. Label topLabel = null;
  445. Label bottomLabel = null;
  446. Label failureLabel = null;
  447. Label successLabel = null;
  448. Label exitLabel = null;
  449. }
  450. : PIXELINRECT '(' expr ',' expr ',' expr ',' expr ')'
  451. {
  452. exitLabel = new Label();
  453. leftLabel = new Label();
  454. rightLabel = new Label();
  455. topLabel = new Label();
  456. bottomLabel = new Label();
  457. successLabel = new Label();
  458.  
  459. mv.visitLabel(rightLabel);
  460. mv.visitVarInsn(Opcodes.ILOAD, 3);
  461. mv.visitInsn(Opcodes.I2D);
  462. mv.visitInsn(Opcodes.DCMPG);
  463. mv.visitJumpInsn(Opcodes.IFGE, bottomLabel);
  464. mv.visitInsn(Opcodes.POP2);
  465. mv.visitInsn(Opcodes.POP2);
  466. mv.visitInsn(Opcodes.POP2);
  467. mv.visitInsn(Opcodes.DCONST_0);
  468. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  469.  
  470. mv.visitLabel(bottomLabel);
  471. mv.visitVarInsn(Opcodes.ILOAD, 2);
  472. mv.visitInsn(Opcodes.I2D);
  473. mv.visitInsn(Opcodes.DCMPG);
  474. mv.visitJumpInsn(Opcodes.IFGE, leftLabel);
  475. mv.visitInsn(Opcodes.POP2);
  476. mv.visitInsn(Opcodes.POP2);
  477. mv.visitInsn(Opcodes.DCONST_0);
  478. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  479.  
  480. mv.visitLabel(leftLabel);
  481. mv.visitVarInsn(Opcodes.ILOAD, 3);
  482. mv.visitInsn(Opcodes.I2D);
  483. mv.visitInsn(Opcodes.DCMPG);
  484. mv.visitJumpInsn(Opcodes.IFLT, topLabel);
  485. mv.visitInsn(Opcodes.POP2);
  486. mv.visitInsn(Opcodes.DCONST_0);
  487. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  488.  
  489. mv.visitLabel(topLabel);
  490. mv.visitVarInsn(Opcodes.ILOAD, 2);
  491. mv.visitInsn(Opcodes.I2D);
  492. mv.visitInsn(Opcodes.DCMPG);
  493. mv.visitJumpInsn(Opcodes.IFLT, successLabel);
  494. mv.visitInsn(Opcodes.DCONST_0);
  495. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  496.  
  497. mv.visitLabel(successLabel);
  498. mv.visitInsn(Opcodes.DCONST_1);
  499. mv.visitLabel(exitLabel);
  500. }
  501. | PIXELINCIRCLE '(' expr ',' expr ',' expr ')'
  502. {
  503. successLabel = new Label();
  504. exitLabel = new Label();
  505.  
  506. mv.visitInsn(Opcodes.DUP2);
  507. mv.visitInsn(Opcodes.DMUL);
  508. mv.visitVarInsn(Opcodes.ALOAD, 0);
  509. mv.visitFieldInsn(Opcodes.GETFIELD, clz, "stack", "Ljava/util/List;");
  510. mv.visitInsn(Opcodes.DUP_X2);
  511. mv.visitInsn(Opcodes.POP);
  512. mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
  513. mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z");
  514. mv.visitInsn(Opcodes.POP);
  515.  
  516. mv.visitVarInsn(Opcodes.ILOAD, 3);
  517. mv.visitInsn(Opcodes.I2D);
  518. mv.visitInsn(Opcodes.DSUB);
  519. mv.visitInsn(Opcodes.DUP2);
  520. mv.visitInsn(Opcodes.DMUL);
  521. mv.visitInsn(Opcodes.DUP2_X2);
  522. mv.visitInsn(Opcodes.POP2);
  523.  
  524. mv.visitVarInsn(Opcodes.ILOAD, 2);
  525. mv.visitInsn(Opcodes.I2D);
  526. mv.visitInsn(Opcodes.DSUB);
  527. mv.visitInsn(Opcodes.DUP2);
  528. mv.visitInsn(Opcodes.DMUL);
  529. mv.visitInsn(Opcodes.DADD);
  530.  
  531. mv.visitVarInsn(Opcodes.ALOAD, 0);
  532. mv.visitFieldInsn(Opcodes.GETFIELD, clz, "stack", "Ljava/util/List;");
  533. mv.visitInsn(Opcodes.DUP);
  534. mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "size", "()I");
  535. mv.visitInsn(Opcodes.ICONST_1);
  536. mv.visitInsn(Opcodes.ISUB);
  537. mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "remove", "(I)Ljava/lang/Object;");
  538. mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Double");
  539. mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D");
  540. mv.visitInsn(Opcodes.DCMPG);
  541. mv.visitJumpInsn(Opcodes.IFLT, successLabel);
  542. mv.visitInsn(Opcodes.DCONST_0);
  543. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  544.  
  545. mv.visitLabel(successLabel);
  546. mv.visitInsn(Opcodes.DCONST_1);
  547. mv.visitLabel(exitLabel);
  548. }
  549. | PIXELONEDGE '(' expr ')'
  550. {
  551. exitLabel = new Label();
  552. leftLabel = new Label();
  553. rightLabel = new Label();
  554. topLabel = new Label();
  555. bottomLabel = new Label();
  556. failureLabel = new Label();
  557.  
  558. mv.visitLabel(leftLabel);
  559. mv.visitInsn(Opcodes.DUP2);
  560. mv.visitVarInsn(Opcodes.ILOAD, 2);
  561. mv.visitInsn(Opcodes.I2D);
  562. mv.visitInsn(Opcodes.DCMPG);
  563. mv.visitJumpInsn(Opcodes.IFLE, rightLabel);
  564. mv.visitInsn(Opcodes.POP2);
  565. mv.visitInsn(Opcodes.DCONST_1);
  566. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  567.  
  568. mv.visitLabel(rightLabel);
  569. mv.visitInsn(Opcodes.DUP2);
  570. mv.visitVarInsn(Opcodes.ALOAD, 0);
  571. mv.visitFieldInsn(Opcodes.GETFIELD, clz, "width", "I");
  572. mv.visitInsn(Opcodes.I2D);
  573. mv.visitInsn(Opcodes.DSUB);
  574. mv.visitInsn(Opcodes.DNEG);
  575. mv.visitVarInsn(Opcodes.ILOAD, 2);
  576. mv.visitInsn(Opcodes.I2D);
  577. mv.visitInsn(Opcodes.DCMPG);
  578. mv.visitJumpInsn(Opcodes.IFGE, topLabel);
  579. mv.visitInsn(Opcodes.POP2);
  580. mv.visitInsn(Opcodes.DCONST_1);
  581. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  582.  
  583. mv.visitLabel(topLabel);
  584. mv.visitInsn(Opcodes.DUP2);
  585. mv.visitVarInsn(Opcodes.ILOAD, 3);
  586. mv.visitInsn(Opcodes.I2D);
  587. mv.visitInsn(Opcodes.DCMPG);
  588. mv.visitJumpInsn(Opcodes.IFLE, bottomLabel);
  589. mv.visitInsn(Opcodes.POP2);
  590. mv.visitInsn(Opcodes.DCONST_1);
  591. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  592.  
  593. mv.visitLabel(bottomLabel);
  594. mv.visitInsn(Opcodes.DUP2);
  595. mv.visitVarInsn(Opcodes.ALOAD, 0);
  596. mv.visitFieldInsn(Opcodes.GETFIELD, clz, "height", "I");
  597. mv.visitInsn(Opcodes.I2D);
  598. mv.visitInsn(Opcodes.DSUB);
  599. mv.visitInsn(Opcodes.DNEG);
  600. mv.visitVarInsn(Opcodes.ILOAD, 3);
  601. mv.visitInsn(Opcodes.I2D);
  602. mv.visitInsn(Opcodes.DCMPG);
  603. mv.visitJumpInsn(Opcodes.IFGE, failureLabel);
  604. mv.visitInsn(Opcodes.POP2);
  605. mv.visitInsn(Opcodes.DCONST_1);
  606. mv.visitJumpInsn(Opcodes.GOTO, exitLabel);
  607.  
  608. mv.visitLabel(failureLabel);
  609. mv.visitInsn(Opcodes.POP2);
  610. mv.visitInsn(Opcodes.DCONST_0);
  611.  
  612. mv.visitLabel(exitLabel);
  613. }
  614. | PIXELAVERAGE '(' expr, ',' expr ',' expr ')'
  615. {
  616. mv.visitInsn(Opcodes.POP);
  617. mv.visitInsn(Opcodes.POP);
  618. mv.visitInsn(Opcodes.POP);
  619. mv.visitInsn(Opcodes.DCONST_0);
  620. } ;
  621.  
  622.  
  623. ABS : 'ABS';
  624. MAX : 'MAX';
  625. MIN : 'MIN';
  626. POW : 'POW';
  627. SQRT : 'SQRT';
  628. SIN : 'SIN';
  629. COS : 'COS';
  630. TAN : 'TAN';
  631. ASIN : 'ASIN';
  632. ACOS : 'ACOS';
  633. ATAN : 'ATAN';
  634. LOG : 'LOG';
  635. EXP : 'EXP';
  636. E : 'E';
  637. PI : 'PI';
  638. RANDOM : 'RANDOM';
  639. PIXELINRECT : 'PIXELINRECT';
  640. PIXELINCIRCLE : 'PIXELINCIRCLE';
  641. PIXELONEDGE : 'PIXELONEDGE';
  642. PIXELAVERAGE : 'PIXELAVERAGE';
  643. X : 'X';
  644. Y : 'Y';
  645. WIDTH : 'WIDTH';
  646. HEIGHT : 'HEIGHT';
  647. P : 'P';
  648. R : 'R';
  649. G : 'G';
  650. B : 'B';
  651. T : 'T';
  652. S : 'S';
  653.  
  654.  
  655. NUMBER : '0'..'9'+ ( '.' ('0'..'9'+))?;
  656.  
  657. WS : (' '|'\t'|'\f'|'\n'|'\r')+{ skip(); };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement