Changeset 5977


Ignore:
Timestamp:
02/25/04 23:52:28 (17 years ago)
Author:
piso
Message:

Refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/ash.java

    r5908 r5977  
    33 *
    44 * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: ash.java,v 1.5 2004-02-23 19:56:58 piso Exp $
     5 * $Id: ash.java,v 1.6 2004-02-25 23:52:28 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2222package org.armedbear.lisp;
    2323
    24 import java.math.BigInteger;
    25 
    2624// ### ash
    2725// ash integer count => shifted-integer
     
    3634        throws ConditionThrowable
    3735    {
    38         if (first instanceof Fixnum && second instanceof Fixnum) {
    39             int count = ((Fixnum)second).value;
    40             if (count == 0)
    41                 return first;
    42             long n = ((Fixnum)first).value;
    43             if (n == 0)
    44                 return first;
    45             if (count < -32) {
    46                 // Right shift.
    47                 return n >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE;
    48             }
    49             if (count <= 32)
    50                 return number(count > 0 ? (n << count) : (n >> -count));
    51         }
    52         BigInteger n;
    53         if (first instanceof Fixnum)
    54             n = BigInteger.valueOf(((Fixnum)first).value);
    55         else if (first instanceof Bignum)
    56             n = ((Bignum)first).getValue();
    57         else
    58             return signal(new TypeError(first, "integer"));
    59         if (second instanceof Fixnum) {
    60             int count = ((Fixnum)second).value;
    61             if (count == 0)
    62                 return first;
    63             // BigInteger.shiftLeft() succumbs to a stack overflow if count
    64             // is Integer.MIN_VALUE, so...
    65             if (count == Integer.MIN_VALUE)
    66                 return n.signum() >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE;
    67             return number(n.shiftLeft(count));
    68         }
    69         if (second instanceof Bignum) {
    70             BigInteger count = ((Bignum)second).getValue();
    71             if (count.signum() > 0)
    72                 return signal(new LispError("can't represent result of left shift"));
    73             if (count.signum() < 0)
    74                 return n.signum() >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE;
    75             Debug.bug(); // Shouldn't happen.
    76         }
    77         return signal(new TypeError(second, "integer"));
     36        return first.ash(second);
    7837    }
    7938
    80     private static final ash ASH = new ash();
     39    private static final Primitive2 ASH = new ash();
    8140}
Note: See TracChangeset for help on using the changeset viewer.