Changeset 5870


Ignore:
Timestamp:
02/19/04 00:45:42 (17 years ago)
Author:
piso
Message:

VECTOR-PUSH-EXTEND

File:
1 edited

Legend:

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

    r5860 r5870  
    33 *
    44 * Copyright (C) 2002-2004 Peter Graves
    5  * $Id: Primitives.java,v 1.572 2004-02-17 01:39:24 piso Exp $
     5 * $Id: Primitives.java,v 1.573 2004-02-19 00:45:42 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    19691969    // vector-push new-element vector &optional extension => index-of-new-element
    19701970    private static final Primitive VECTOR_PUSH_EXTEND =
    1971         new Primitive("vector-push-extend","new-element vector &optional extension") {
    1972         public LispObject execute(LispObject[] args) throws ConditionThrowable
    1973         {
    1974             if (args.length < 2 || args.length > 3)
    1975                 signal(new WrongNumberOfArgumentsException(this));
    1976             AbstractVector v = checkVector(args[1]);
    1977             int extension = 0;
    1978             if (args.length == 3) {
    1979                 // Extension was supplied.
    1980                 extension = Fixnum.getValue(args[2]);
    1981             }
    1982             int fillPointer = v.getFillPointer();
     1971        new Primitive("vector-push-extend",
     1972                      "new-element vector &optional extension")
     1973    {
     1974        public LispObject execute(LispObject first, LispObject second)
     1975            throws ConditionThrowable
     1976        {
     1977            AbstractVector v = checkVector(second);
     1978            final int fillPointer = v.getFillPointer();
    19831979            if (fillPointer < 0)
    1984                 signal(new TypeError("array does not have a fill pointer"));
     1980                signal(new TypeError("Array does not have a fill pointer."));
     1981            if (fillPointer >= v.capacity()) {
     1982                // Need to extend vector.
     1983                v.ensureCapacity(v.capacity() * 2 + 1);
     1984            }
     1985            v.set(fillPointer, first);
     1986            v.setFillPointer(fillPointer + 1);
     1987            return new Fixnum(fillPointer);
     1988        }
     1989        public LispObject execute(LispObject first, LispObject second,
     1990                                  LispObject third)
     1991            throws ConditionThrowable
     1992        {
     1993            AbstractVector v = checkVector(second);
     1994            int extension = Fixnum.getValue(third);
     1995            final int fillPointer = v.getFillPointer();
     1996            if (fillPointer < 0)
     1997                signal(new TypeError("Array does not have a fill pointer."));
    19851998            if (fillPointer >= v.capacity()) {
    19861999                // Need to extend vector.
     
    19882001                v.ensureCapacity(v.capacity() + extension);
    19892002            }
    1990             v.set(fillPointer, args[0]);
     2003            v.set(fillPointer, first);
    19912004            v.setFillPointer(fillPointer + 1);
    19922005            return new Fixnum(fillPointer);
Note: See TracChangeset for help on using the changeset viewer.