PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/bsh/Primitive.java

#
Java | 842 lines | 573 code | 147 blank | 122 comment | 133 complexity | 6657eea72a25e939490e137a1f66cebc MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*****************************************************************************
  2. * *
  3. * This file is part of the BeanShell Java Scripting distribution. *
  4. * Documentation and updates may be found at http://www.beanshell.org/ *
  5. * *
  6. * Sun Public License Notice: *
  7. * *
  8. * The contents of this file are subject to the Sun Public License Version *
  9. * 1.0 (the "License"); you may not use this file except in compliance with *
  10. * the License. A copy of the License is available at http://www.sun.com *
  11. * *
  12. * The Original Code is BeanShell. The Initial Developer of the Original *
  13. * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright *
  14. * (C) 2000. All Rights Reserved. *
  15. * *
  16. * GNU Public License Notice: *
  17. * *
  18. * Alternatively, the contents of this file may be used under the terms of *
  19. * the GNU Lesser General Public License (the "LGPL"), in which case the *
  20. * provisions of LGPL are applicable instead of those above. If you wish to *
  21. * allow use of your version of this file only under the terms of the LGPL *
  22. * and not to allow others to use your version of this file under the SPL, *
  23. * indicate your decision by deleting the provisions above and replace *
  24. * them with the notice and other provisions required by the LGPL. If you *
  25. * do not delete the provisions above, a recipient may use your version of *
  26. * this file under either the SPL or the LGPL. *
  27. * *
  28. * Patrick Niemeyer (pat@pat.net) *
  29. * Author of Learning Java, O'Reilly & Associates *
  30. * http://www.pat.net/~pat/ *
  31. * *
  32. *****************************************************************************/
  33. package bsh;
  34. /**
  35. Wrapper for primitive types in Bsh. This is package public because it
  36. is used in the implementation of some bsh commands.
  37. See the note in LHS.java about wrapping objects.
  38. */
  39. public class Primitive implements ParserConstants, java.io.Serializable
  40. {
  41. /** The primitive value stored in its java.lang wrapper class */
  42. private Object value;
  43. private static class Special implements java.io.Serializable
  44. {
  45. private Special() { }
  46. public static final Special NULL_VALUE = new Special();
  47. public static final Special VOID_TYPE = new Special();
  48. }
  49. /*
  50. NULL means "no value".
  51. This ia a placeholder for primitive null value.
  52. */
  53. public static final Primitive NULL = new Primitive(Special.NULL_VALUE);
  54. /**
  55. VOID means "no type".
  56. Strictly speaking, this makes no sense here. But for practical
  57. reasons we'll consider the lack of a type to be a special value.
  58. */
  59. public static final Primitive VOID = new Primitive(Special.VOID_TYPE);
  60. // private to prevent invocation with param that isn't a primitive-wrapper
  61. private Primitive(Object value)
  62. {
  63. if(value == null)
  64. throw new InterpreterError(
  65. "Use Primitve.NULL instead of Primitive(null)");
  66. this.value = value;
  67. }
  68. public Primitive(Number number) { this((Object)number); }
  69. public Primitive(Boolean value) { this((Object)value); }
  70. public Primitive(Byte value) { this((Object)value); }
  71. public Primitive(Short value) { this((Object)value); }
  72. public Primitive(Character value) { this((Object)value); }
  73. public Primitive(Integer value) { this((Object)value); }
  74. public Primitive(Long value) { this((Object)value); }
  75. public Primitive(Float value) { this((Object)value); }
  76. public Primitive(Double value) { this((Object)value); }
  77. public Primitive(boolean value) { this(new Boolean(value)); }
  78. public Primitive(byte value) { this(new Byte(value)); }
  79. public Primitive(short value) { this(new Short(value)); }
  80. public Primitive(char value) { this(new Character(value)); }
  81. public Primitive(int value) { this(new Integer(value)); }
  82. public Primitive(long value) { this(new Long(value)); }
  83. public Primitive(float value) { this(new Float(value)); }
  84. public Primitive(double value) { this(new Double(value)); }
  85. /**
  86. Return the primitive value stored in its java.lang wrapper class
  87. */
  88. public Object getValue()
  89. {
  90. if ( value == Special.NULL_VALUE )
  91. return null;
  92. else
  93. if ( value == Special.VOID_TYPE )
  94. throw new InterpreterError("attempt to unwrap void type");
  95. else
  96. return value;
  97. }
  98. public String toString()
  99. {
  100. if(value == Special.NULL_VALUE)
  101. return "null";
  102. else if(value == Special.VOID_TYPE)
  103. return "void";
  104. else
  105. return value.toString();
  106. }
  107. /**
  108. Get the corresponding primitive TYPE class for the Primitive
  109. @return the primitive TYPE class type of the value or Void.TYPE for
  110. Primitive.VOID or null value for type of Primitive.NULL
  111. */
  112. public Class getType()
  113. {
  114. if ( this == Primitive.VOID )
  115. return Void.TYPE;
  116. // NULL return null as type... we currently use null type to indicate
  117. // loose typing throughout bsh.
  118. if ( this == Primitive.NULL )
  119. return null;
  120. if ( value instanceof Boolean )
  121. return Boolean.TYPE;
  122. else if(value instanceof Byte)
  123. return Byte.TYPE;
  124. else if(value instanceof Short)
  125. return Short.TYPE;
  126. else if(value instanceof Character)
  127. return Character.TYPE;
  128. else if(value instanceof Integer)
  129. return Integer.TYPE;
  130. else if(value instanceof Long)
  131. return Long.TYPE;
  132. else if(value instanceof Float)
  133. return Float.TYPE;
  134. else if(value instanceof Double)
  135. return Double.TYPE;
  136. throw new InterpreterError("uknown prim: "+ this );
  137. }
  138. /**
  139. Perform a binary operation on two Primitives or wrapper types.
  140. If both original args were Primitives return a Primitive result
  141. else it was mixed (wrapper/primitive) return the wrapper type.
  142. The exception is for boolean operations where we will return the
  143. primitive type eithe way.
  144. */
  145. public static Object binaryOperation(
  146. Object obj1, Object obj2, int kind)
  147. throws UtilEvalError
  148. {
  149. // special primitive types
  150. if ( obj1 == NULL || obj2 == NULL )
  151. throw new UtilEvalError(
  152. "Null value or 'null' literal in binary operation");
  153. if ( obj1 == VOID || obj2 == VOID )
  154. throw new UtilEvalError(
  155. "Undefined variable, class, or 'void' literal in binary operation");
  156. // keep track of the original types
  157. Class lhsOrgType = obj1.getClass();
  158. Class rhsOrgType = obj2.getClass();
  159. // Unwrap primitives
  160. if ( obj1 instanceof Primitive )
  161. obj1 = ((Primitive)obj1).getValue();
  162. if ( obj2 instanceof Primitive )
  163. obj2 = ((Primitive)obj2).getValue();
  164. Object[] operands = promotePrimitives(obj1, obj2);
  165. Object lhs = operands[0];
  166. Object rhs = operands[1];
  167. if(lhs.getClass() != rhs.getClass())
  168. throw new UtilEvalError("Type mismatch in operator. "
  169. + lhs.getClass() + " cannot be used with " + rhs.getClass() );
  170. Object result;
  171. try {
  172. result = binaryOperationImpl( lhs, rhs, kind );
  173. } catch ( ArithmeticException e ) {
  174. throw new UtilTargetError( "Arithemetic Exception in binary op", e);
  175. }
  176. // If both original args were Primitives return a Primitive result
  177. // else it was mixed (wrapper/primitive) return the wrapper type
  178. // Exception is for boolean result, return the primitive
  179. if ( (lhsOrgType == Primitive.class && rhsOrgType == Primitive.class)
  180. || result instanceof Boolean
  181. )
  182. return new Primitive( result );
  183. else
  184. return result;
  185. }
  186. static Object binaryOperationImpl( Object lhs, Object rhs, int kind )
  187. throws UtilEvalError
  188. {
  189. if(lhs instanceof Boolean)
  190. return booleanBinaryOperation((Boolean)lhs, (Boolean)rhs, kind);
  191. else if(lhs instanceof Integer)
  192. return intBinaryOperation( (Integer)lhs, (Integer)rhs, kind );
  193. else if(lhs instanceof Long)
  194. return longBinaryOperation((Long)lhs, (Long)rhs, kind);
  195. else if(lhs instanceof Float)
  196. return floatBinaryOperation((Float)lhs, (Float)rhs, kind);
  197. else if(lhs instanceof Double)
  198. return doubleBinaryOperation( (Double)lhs, (Double)rhs, kind);
  199. else
  200. throw new UtilEvalError("Invalid types in binary operator" );
  201. }
  202. static Boolean booleanBinaryOperation(Boolean B1, Boolean B2, int kind)
  203. throws UtilEvalError
  204. {
  205. boolean lhs = B1.booleanValue();
  206. boolean rhs = B2.booleanValue();
  207. switch(kind)
  208. {
  209. case EQ:
  210. return new Boolean(lhs == rhs);
  211. case NE:
  212. return new Boolean(lhs != rhs);
  213. case BOOL_OR:
  214. case BOOL_ORX:
  215. return new Boolean( lhs || rhs );
  216. case BOOL_AND:
  217. case BOOL_ANDX:
  218. return new Boolean( lhs && rhs );
  219. default:
  220. throw new InterpreterError("unimplemented binary operator");
  221. }
  222. }
  223. // returns Object covering both Long and Boolean return types
  224. static Object longBinaryOperation(Long L1, Long L2, int kind)
  225. {
  226. long lhs = L1.longValue();
  227. long rhs = L2.longValue();
  228. switch(kind)
  229. {
  230. // boolean
  231. case LT:
  232. case LTX:
  233. return new Boolean(lhs < rhs);
  234. case GT:
  235. case GTX:
  236. return new Boolean(lhs > rhs);
  237. case EQ:
  238. return new Boolean(lhs == rhs);
  239. case LE:
  240. case LEX:
  241. return new Boolean(lhs <= rhs);
  242. case GE:
  243. case GEX:
  244. return new Boolean(lhs >= rhs);
  245. case NE:
  246. return new Boolean(lhs != rhs);
  247. // arithmetic
  248. case PLUS:
  249. return new Long(lhs + rhs);
  250. case MINUS:
  251. return new Long(lhs - rhs);
  252. case STAR:
  253. return new Long(lhs * rhs);
  254. case SLASH:
  255. return new Long(lhs / rhs);
  256. case MOD:
  257. return new Long(lhs % rhs);
  258. // bitwise
  259. case LSHIFT:
  260. case LSHIFTX:
  261. return new Long(lhs << rhs);
  262. case RSIGNEDSHIFT:
  263. case RSIGNEDSHIFTX:
  264. return new Long(lhs >> rhs);
  265. case RUNSIGNEDSHIFT:
  266. case RUNSIGNEDSHIFTX:
  267. return new Long(lhs >>> rhs);
  268. case BIT_AND:
  269. case BIT_ANDX:
  270. return new Long(lhs & rhs);
  271. case BIT_OR:
  272. case BIT_ORX:
  273. return new Long(lhs | rhs);
  274. case XOR:
  275. return new Long(lhs ^ rhs);
  276. default:
  277. throw new InterpreterError("Unimplemented binary long operator");
  278. }
  279. }
  280. // returns Object covering both Integer and Boolean return types
  281. static Object intBinaryOperation(Integer I1, Integer I2, int kind)
  282. {
  283. int lhs = I1.intValue();
  284. int rhs = I2.intValue();
  285. switch(kind)
  286. {
  287. // boolean
  288. case LT:
  289. case LTX:
  290. return new Boolean(lhs < rhs);
  291. case GT:
  292. case GTX:
  293. return new Boolean(lhs > rhs);
  294. case EQ:
  295. return new Boolean(lhs == rhs);
  296. case LE:
  297. case LEX:
  298. return new Boolean(lhs <= rhs);
  299. case GE:
  300. case GEX:
  301. return new Boolean(lhs >= rhs);
  302. case NE:
  303. return new Boolean(lhs != rhs);
  304. // arithmetic
  305. case PLUS:
  306. return new Integer(lhs + rhs);
  307. case MINUS:
  308. return new Integer(lhs - rhs);
  309. case STAR:
  310. return new Integer(lhs * rhs);
  311. case SLASH:
  312. return new Integer(lhs / rhs);
  313. case MOD:
  314. return new Integer(lhs % rhs);
  315. // bitwise
  316. case LSHIFT:
  317. case LSHIFTX:
  318. return new Integer(lhs << rhs);
  319. case RSIGNEDSHIFT:
  320. case RSIGNEDSHIFTX:
  321. return new Integer(lhs >> rhs);
  322. case RUNSIGNEDSHIFT:
  323. case RUNSIGNEDSHIFTX:
  324. return new Integer(lhs >>> rhs);
  325. case BIT_AND:
  326. case BIT_ANDX:
  327. return new Integer(lhs & rhs);
  328. case BIT_OR:
  329. case BIT_ORX:
  330. return new Integer(lhs | rhs);
  331. case XOR:
  332. return new Integer(lhs ^ rhs);
  333. default:
  334. throw new InterpreterError("Unimplemented binary integer operator");
  335. }
  336. }
  337. // returns Object covering both Double and Boolean return types
  338. static Object doubleBinaryOperation(Double D1, Double D2, int kind)
  339. throws UtilEvalError
  340. {
  341. double lhs = D1.doubleValue();
  342. double rhs = D2.doubleValue();
  343. switch(kind)
  344. {
  345. // boolean
  346. case LT:
  347. case LTX:
  348. return new Boolean(lhs < rhs);
  349. case GT:
  350. case GTX:
  351. return new Boolean(lhs > rhs);
  352. case EQ:
  353. return new Boolean(lhs == rhs);
  354. case LE:
  355. case LEX:
  356. return new Boolean(lhs <= rhs);
  357. case GE:
  358. case GEX:
  359. return new Boolean(lhs >= rhs);
  360. case NE:
  361. return new Boolean(lhs != rhs);
  362. // arithmetic
  363. case PLUS:
  364. return new Double(lhs + rhs);
  365. case MINUS:
  366. return new Double(lhs - rhs);
  367. case STAR:
  368. return new Double(lhs * rhs);
  369. case SLASH:
  370. return new Double(lhs / rhs);
  371. case MOD:
  372. return new Double(lhs % rhs);
  373. // can't shift floating-point values
  374. case LSHIFT:
  375. case LSHIFTX:
  376. case RSIGNEDSHIFT:
  377. case RSIGNEDSHIFTX:
  378. case RUNSIGNEDSHIFT:
  379. case RUNSIGNEDSHIFTX:
  380. throw new UtilEvalError("Can't shift doubles");
  381. default:
  382. throw new InterpreterError("Unimplemented binary double operator");
  383. }
  384. }
  385. // returns Object covering both Long and Boolean return types
  386. static Object floatBinaryOperation(Float F1, Float F2, int kind)
  387. throws UtilEvalError
  388. {
  389. float lhs = F1.floatValue();
  390. float rhs = F2.floatValue();
  391. switch(kind)
  392. {
  393. // boolean
  394. case LT:
  395. case LTX:
  396. return new Boolean(lhs < rhs);
  397. case GT:
  398. case GTX:
  399. return new Boolean(lhs > rhs);
  400. case EQ:
  401. return new Boolean(lhs == rhs);
  402. case LE:
  403. case LEX:
  404. return new Boolean(lhs <= rhs);
  405. case GE:
  406. case GEX:
  407. return new Boolean(lhs >= rhs);
  408. case NE:
  409. return new Boolean(lhs != rhs);
  410. // arithmetic
  411. case PLUS:
  412. return new Float(lhs + rhs);
  413. case MINUS:
  414. return new Float(lhs - rhs);
  415. case STAR:
  416. return new Float(lhs * rhs);
  417. case SLASH:
  418. return new Float(lhs / rhs);
  419. case MOD:
  420. return new Float(lhs % rhs);
  421. // can't shift floats
  422. case LSHIFT:
  423. case LSHIFTX:
  424. case RSIGNEDSHIFT:
  425. case RSIGNEDSHIFTX:
  426. case RUNSIGNEDSHIFT:
  427. case RUNSIGNEDSHIFTX:
  428. throw new UtilEvalError("Can't shift floats ");
  429. default:
  430. throw new InterpreterError("Unimplemented binary float operator");
  431. }
  432. }
  433. /**
  434. Promote primitive wrapper type to to Integer wrapper type
  435. Can we use the castPrimitive() (in BSHCastExpression) for this?
  436. */
  437. static Object promoteToInteger(Object primitive)
  438. {
  439. if(primitive instanceof Character)
  440. return new Integer(((Character)primitive).charValue());
  441. else if((primitive instanceof Byte) || (primitive instanceof Short))
  442. return new Integer(((Number)primitive).intValue());
  443. return primitive;
  444. }
  445. /**
  446. Promote the pair of primitives to the maximum type of the two.
  447. e.g. [int,long]->[long,long]
  448. */
  449. static Object[] promotePrimitives(Object lhs, Object rhs)
  450. {
  451. lhs = promoteToInteger(lhs);
  452. rhs = promoteToInteger(rhs);
  453. if((lhs instanceof Number) && (rhs instanceof Number))
  454. {
  455. Number lnum = (Number)lhs;
  456. Number rnum = (Number)rhs;
  457. boolean b;
  458. if((b = (lnum instanceof Double)) || (rnum instanceof Double))
  459. {
  460. if(b)
  461. rhs = new Double(rnum.doubleValue());
  462. else
  463. lhs = new Double(lnum.doubleValue());
  464. }
  465. else if((b = (lnum instanceof Float)) || (rnum instanceof Float))
  466. {
  467. if(b)
  468. rhs = new Float(rnum.floatValue());
  469. else
  470. lhs = new Float(lnum.floatValue());
  471. }
  472. else if((b = (lnum instanceof Long)) || (rnum instanceof Long))
  473. {
  474. if(b)
  475. rhs = new Long(rnum.longValue());
  476. else
  477. lhs = new Long(lnum.longValue());
  478. }
  479. }
  480. return new Object[] { lhs, rhs };
  481. }
  482. public static Primitive unaryOperation(Primitive val, int kind)
  483. throws UtilEvalError
  484. {
  485. if (val == NULL)
  486. throw new UtilEvalError(
  487. "illegal use of null object or 'null' literal");
  488. if (val == VOID)
  489. throw new UtilEvalError(
  490. "illegal use of undefined object or 'void' literal");
  491. Class operandType = val.getType();
  492. Object operand = promoteToInteger(val.getValue());
  493. if ( operand instanceof Boolean )
  494. return new Primitive(booleanUnaryOperation((Boolean)operand, kind));
  495. else if(operand instanceof Integer)
  496. {
  497. int result = intUnaryOperation((Integer)operand, kind);
  498. // ++ and -- must be cast back the original type
  499. if(kind == INCR || kind == DECR)
  500. {
  501. if(operandType == Byte.TYPE)
  502. return new Primitive((byte)result);
  503. if(operandType == Short.TYPE)
  504. return new Primitive((short)result);
  505. if(operandType == Character.TYPE)
  506. return new Primitive((char)result);
  507. }
  508. return new Primitive(result);
  509. }
  510. else if(operand instanceof Long)
  511. return new Primitive(longUnaryOperation((Long)operand, kind));
  512. else if(operand instanceof Float)
  513. return new Primitive(floatUnaryOperation((Float)operand, kind));
  514. else if(operand instanceof Double)
  515. return new Primitive(doubleUnaryOperation((Double)operand, kind));
  516. else
  517. throw new InterpreterError(
  518. "An error occurred. Please call technical support.");
  519. }
  520. static boolean booleanUnaryOperation(Boolean B, int kind)
  521. throws UtilEvalError
  522. {
  523. boolean operand = B.booleanValue();
  524. switch(kind)
  525. {
  526. case BANG:
  527. return !operand;
  528. default:
  529. throw new UtilEvalError("Operator inappropriate for boolean");
  530. }
  531. }
  532. static int intUnaryOperation(Integer I, int kind)
  533. {
  534. int operand = I.intValue();
  535. switch(kind)
  536. {
  537. case PLUS:
  538. return operand;
  539. case MINUS:
  540. return -operand;
  541. case TILDE:
  542. return ~operand;
  543. case INCR:
  544. return operand + 1;
  545. case DECR:
  546. return operand - 1;
  547. default:
  548. throw new InterpreterError("bad integer unaryOperation");
  549. }
  550. }
  551. static long longUnaryOperation(Long L, int kind)
  552. {
  553. long operand = L.longValue();
  554. switch(kind)
  555. {
  556. case PLUS:
  557. return operand;
  558. case MINUS:
  559. return -operand;
  560. case TILDE:
  561. return ~operand;
  562. case INCR:
  563. return operand + 1;
  564. case DECR:
  565. return operand - 1;
  566. default:
  567. throw new InterpreterError("bad long unaryOperation");
  568. }
  569. }
  570. static float floatUnaryOperation(Float F, int kind)
  571. {
  572. float operand = F.floatValue();
  573. switch(kind)
  574. {
  575. case PLUS:
  576. return operand;
  577. case MINUS:
  578. return -operand;
  579. default:
  580. throw new InterpreterError("bad float unaryOperation");
  581. }
  582. }
  583. static double doubleUnaryOperation(Double D, int kind)
  584. {
  585. double operand = D.doubleValue();
  586. switch(kind)
  587. {
  588. case PLUS:
  589. return operand;
  590. case MINUS:
  591. return -operand;
  592. default:
  593. throw new InterpreterError("bad double unaryOperation");
  594. }
  595. }
  596. public int intValue() throws UtilEvalError
  597. {
  598. if(value instanceof Number)
  599. return((Number)value).intValue();
  600. else
  601. throw new UtilEvalError("Primitive not a number");
  602. }
  603. public boolean booleanValue() throws UtilEvalError
  604. {
  605. if(value instanceof Boolean)
  606. return((Boolean)value).booleanValue();
  607. else
  608. throw new UtilEvalError("Primitive not a boolean");
  609. }
  610. /**
  611. Determine if this primitive is a numeric type.
  612. i.e. not boolean, null, or void (but including char)
  613. */
  614. public boolean isNumber() {
  615. return ( !(value instanceof Boolean)
  616. && !(this == NULL) && !(this == VOID) );
  617. }
  618. public Number numberValue() throws UtilEvalError
  619. {
  620. Object value = this.value;
  621. // Promote character to Number type for these purposes
  622. if (value instanceof Character)
  623. value = new Integer(((Character)value).charValue());
  624. if (value instanceof Number)
  625. return (Number)value;
  626. else
  627. throw new UtilEvalError("Primitive not a number");
  628. }
  629. /**
  630. Primitives compare equal with other Primitives containing an equal
  631. wrapped value.
  632. */
  633. public boolean equals( Object obj )
  634. {
  635. if ( obj instanceof Primitive )
  636. return ((Primitive)obj).value.equals( this.value );
  637. else
  638. return false;
  639. }
  640. /**
  641. The hash of the Primitive is tied to the hash of the wrapped value but
  642. shifted so that they are not the same.
  643. */
  644. public int hashCode()
  645. {
  646. return this.value.hashCode() * 21; // arbitrary
  647. }
  648. /**
  649. Unwrap primitive values and map voids to nulls.
  650. Normal (non Primitive) types remain unchanged.
  651. @param obj object type which may be bsh.Primitive
  652. @return corresponding "normal" Java type, "unwrapping"
  653. any bsh.Primitive types to their wrapper types.
  654. */
  655. public static Object unwrap( Object obj )
  656. {
  657. // map voids to nulls for the outside world
  658. if (obj == Primitive.VOID)
  659. return null;
  660. // unwrap primitives
  661. if (obj instanceof Primitive)
  662. return((Primitive)obj).getValue();
  663. else
  664. return obj;
  665. }
  666. /**
  667. Get the appropriate default value per JLS 4.5.4
  668. */
  669. public static Primitive getDefaultValue( Class type )
  670. {
  671. if ( type != null && type.isPrimitive() )
  672. {
  673. if ( type == Boolean.TYPE )
  674. return new Primitive(Boolean.FALSE);
  675. if (type == Byte.TYPE)
  676. return new Primitive((byte)0);
  677. if (type == Short.TYPE)
  678. return new Primitive((short)0);
  679. if (type == Character.TYPE)
  680. return new Primitive((char)0);
  681. if (type == Integer.TYPE)
  682. return new Primitive((int)0);
  683. if (type == Long.TYPE)
  684. return new Primitive(0L);
  685. if (type == Float.TYPE)
  686. return new Primitive(0.0f);
  687. if (type == Double.TYPE)
  688. return new Primitive(0.0d);
  689. throw new InterpreterError("unknown prim");
  690. }
  691. else
  692. return Primitive.NULL;
  693. }
  694. }