Changeset 3648
- Timestamp:
- 09/10/03 13:48:42 (20 years ago)
- Location:
- trunk/j/src/org/armedbear/lisp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Autoload.java
r3638 r3648 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: Autoload.java,v 1.5 2 2003-09-09 23:17:27piso Exp $5 * $Id: Autoload.java,v 1.53 2003-09-10 13:48:42 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 176 176 autoload("import", "PackageFunctions"); 177 177 autoload("list-all-packages", "PackageFunctions"); 178 autoload("logand", "LogicalOperations"); 179 autoload("logbitp", "LogicalOperations"); 180 autoload("logior", "LogicalOperations"); 181 autoload("lognot", "LogicalOperations"); 178 182 autoload("make-string-output-stream", "StringOutputStream"); 179 183 autoload("namestring", "Pathname"); -
trunk/j/src/org/armedbear/lisp/Primitives.java
r3643 r3648 3 3 * 4 4 * Copyright (C) 2002-2003 Peter Graves 5 * $Id: Primitives.java,v 1.38 1 2003-09-10 00:58:14 piso Exp $5 * $Id: Primitives.java,v 1.382 2003-09-10 13:48:14 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 4388 4388 }; 4389 4389 4390 // ### logand4391 // logand &rest integers => result-integer4392 private static final Primitive LOGAND = new Primitive("logand") {4393 public LispObject execute(LispObject first, LispObject second)4394 throws LispError4395 {4396 if (first instanceof Fixnum && second instanceof Fixnum) {4397 return new Fixnum(((Fixnum)first).getValue() &4398 ((Fixnum)second).getValue());4399 } else {4400 BigInteger n1, n2;4401 if (first instanceof Fixnum)4402 n1 = ((Fixnum)first).getBigInteger();4403 else if (first instanceof Bignum)4404 n1 = ((Bignum)first).getValue();4405 else4406 throw new TypeError(first, "integer");4407 if (second instanceof Fixnum)4408 n2 = ((Fixnum)second).getBigInteger();4409 else if (second instanceof Bignum)4410 n2 = ((Bignum)second).getValue();4411 else4412 throw new TypeError(second, "integer");4413 return number(n1.and(n2));4414 }4415 }4416 public LispObject execute(LispObject[] args) throws LispError4417 {4418 BigInteger result = BigInteger.valueOf(-1);4419 for (int i = 0; i < args.length; i++) {4420 BigInteger n;4421 if (args[i] instanceof Fixnum)4422 n = ((Fixnum)args[i]).getBigInteger();4423 else if (args[i] instanceof Bignum)4424 n = ((Bignum)args[i]).getValue();4425 else4426 throw new TypeError(args[i], "integer");4427 result = result.and(n);4428 }4429 return number(result);4430 }4431 };4432 4433 // ### logior4434 // logior &rest integers => result-integer4435 private static final Primitive LOGIOR = new Primitive("logior") {4436 public LispObject execute(LispObject[] args) throws LispError4437 {4438 BigInteger result = BigInteger.ZERO;4439 for (int i = 0; i < args.length; i++) {4440 BigInteger n;4441 if (args[i] instanceof Fixnum)4442 n = ((Fixnum)args[i]).getBigInteger();4443 else if (args[i] instanceof Bignum)4444 n = ((Bignum)args[i]).getValue();4445 else4446 throw new TypeError(args[i], "integer");4447 result = result.or(n);4448 }4449 return number(result);4450 }4451 };4452 4453 // ### lognot4454 private static final Primitive1 LOGNOT = new Primitive1("lognot") {4455 public LispObject execute(LispObject arg) throws LispError4456 {4457 if (arg instanceof Fixnum)4458 return number(~((Fixnum)arg).getValue());4459 if (arg instanceof Bignum)4460 return number(((Bignum)arg).getValue().not());4461 throw new TypeError(arg, "integer");4462 }4463 };4464 4465 // ### logbitp4466 // logbitp index integer => generalized-boolean4467 private static final Primitive2 LOGBITP = new Primitive2("logbitp") {4468 public LispObject execute(LispObject first, LispObject second)4469 throws LispError4470 {4471 int index = -1;4472 if (first instanceof Fixnum) {4473 index = ((Fixnum)first).getValue();4474 } else if (first instanceof Bignum) {4475 // FIXME If the number is really that big, we're not checking4476 // the right bit...4477 if (((Bignum)first).getValue().signum() > 0)4478 index = Integer.MAX_VALUE;4479 }4480 if (index < 0)4481 throw new TypeError(first, "non-negative integer");4482 BigInteger n;4483 if (second instanceof Fixnum)4484 n = ((Fixnum)second).getBigInteger();4485 else if (second instanceof Bignum)4486 n = ((Bignum)second).getValue();4487 else4488 throw new TypeError(second, "integer");4489 // FIXME See above.4490 if (index == Integer.MAX_VALUE)4491 return n.signum() < 0 ? T : NIL;4492 return n.testBit(index) ? T : NIL;4493 }4494 };4495 4496 4390 // ### list 4497 4391 private static final Primitive LIST = new Primitive("list") {
Note: See TracChangeset
for help on using the changeset viewer.