Changeset 3966
- Timestamp:
- 09/21/03 15:09:05 (19 years ago)
- Location:
- trunk/j/src/org/armedbear/lisp
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/LispClass.java
r3933 r3966 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: LispClass.java,v 1.2 0 2003-09-20 18:20:47piso Exp $5 * $Id: LispClass.java,v 1.21 2003-09-21 15:04:48 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 28 28 protected static final HashMap map = new HashMap(); 29 29 30 public static void addClass(Symbol symbol, LispClass c) 31 { 32 synchronized (map) { 33 map.put(symbol, c); 34 } 35 } 36 37 public static LispClass findClass(Symbol symbol) 38 { 39 synchronized (map) { 40 return (LispClass) map.get(symbol); 41 } 42 } 43 30 44 protected final Symbol symbol; 45 private LispObject directSuperclasses; // A list. 31 46 32 47 protected LispClass(Symbol symbol) 33 48 { 34 49 this.symbol = symbol; 50 this.directSuperclasses = NIL; 35 51 } 36 52 37 public Symbol getSymbol() 53 protected LispClass(Symbol symbol, LispObject directSuperclasses) 54 { 55 this.symbol = symbol; 56 this.directSuperclasses = directSuperclasses; 57 } 58 59 public final Symbol getSymbol() 38 60 { 39 61 return symbol; 62 } 63 64 public final LispObject getDirectSuperclasses() 65 { 66 return directSuperclasses; 67 } 68 69 public final void setDirectSuperclasses(Cons directSuperclasses) 70 { 71 this.directSuperclasses = directSuperclasses; 72 } 73 74 // When there's only one direct superclass... 75 public final void setDirectSuperclass(LispObject superclass) 76 { 77 directSuperclasses = new Cons(superclass); 40 78 } 41 79 … … 64 102 } 65 103 66 public static LispClass findClass(Symbol symbol)67 {68 return (LispClass) map.get(symbol);69 }70 71 104 // ### find-class 72 105 private static final Primitive FIND_CLASS = new Primitive("find-class") { … … 92 125 } 93 126 }; 127 128 private static final Primitive1 CLASS_DIRECT_SUPERCLASSES = 129 new Primitive1("class-direct-superclasses", PACKAGE_SYS, false) 130 { 131 public LispObject execute(LispObject arg) throws ConditionThrowable 132 { 133 if (arg instanceof LispClass) 134 return ((LispClass)arg).getDirectSuperclasses(); 135 throw new ConditionThrowable(new TypeError(arg, "class")); 136 } 137 }; 94 138 } -
trunk/j/src/org/armedbear/lisp/StandardClass.java
r3933 r3966 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: StandardClass.java,v 1. 2 2003-09-20 18:16:55piso Exp $5 * $Id: StandardClass.java,v 1.3 2003-09-21 15:07:13 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 24 24 public class StandardClass extends LispClass 25 25 { 26 protected LispObject directSuperclasses; // A list. 26 public StandardClass(Symbol symbol, LispObject directSuperclasses) 27 { 28 super(symbol, directSuperclasses); 29 } 27 30 28 public St andardClass(Symbol symbol)31 public String toString() 29 32 { 30 super(symbol); 33 StringBuffer sb = new StringBuffer("#<STANDARD-CLASS "); 34 sb.append(symbol.getName()); 35 sb.append('>'); 36 return sb.toString(); 31 37 } 32 38 } -
trunk/j/src/org/armedbear/lisp/StructureClass.java
r3930 r3966 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: StructureClass.java,v 1. 1 2003-09-20 18:15:48piso Exp $5 * $Id: StructureClass.java,v 1.2 2003-09-21 15:06:39 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 26 26 private StructureClass(Symbol symbol) 27 27 { 28 super(symbol );28 super(symbol, new Cons(BuiltInClass.STRUCTURE_OBJECT)); 29 29 } 30 30 … … 64 64 Symbol symbol = checkSymbol(arg); 65 65 StructureClass c = new StructureClass(symbol); 66 map.put(symbol, c);66 addClass(symbol, c); 67 67 return c; 68 68 } -
trunk/j/src/org/armedbear/lisp/StructureObject.java
r3933 r3966 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: StructureObject.java,v 1.1 4 2003-09-20 18:18:28piso Exp $5 * $Id: StructureObject.java,v 1.15 2003-09-21 15:07:43 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 24 24 public final class StructureObject extends LispObject 25 25 { 26 private final Symbol symbol;26 private final LispClass structureClass; 27 27 private final LispObject[] slots; 28 28 29 29 public StructureObject(Symbol symbol, LispObject list) throws ConditionThrowable 30 30 { 31 this.symbol = symbol; 31 structureClass = LispClass.findClass(symbol); // Might return null. 32 Debug.assertTrue(structureClass instanceof StructureClass); 32 33 slots = list.copyToArray(); 33 34 } … … 35 36 public StructureObject(StructureObject obj) 36 37 { 37 this.s ymbol = obj.symbol;38 this.structureClass = obj.structureClass; 38 39 slots = new LispObject[obj.slots.length]; 39 40 for (int i = slots.length; i-- > 0;) … … 43 44 public LispObject typeOf() 44 45 { 45 return s ymbol;46 return structureClass.getSymbol(); 46 47 } 47 48 48 49 public LispClass classOf() 49 50 { 50 return LispClass.findClass(symbol);51 return structureClass; 51 52 } 52 53 53 54 public LispObject typep(LispObject type) throws ConditionThrowable 54 55 { 55 if (type == symbol) 56 if (type instanceof StructureClass) 57 return type == structureClass ? T : NIL; // FIXME Could be a superclass. 58 if (type == structureClass.getSymbol()) 56 59 return T; 57 if (type instanceof StructureClass)58 return type == LispClass.findClass(symbol) ? T : NIL;59 60 if (type == Symbol.STRUCTURE_OBJECT) 60 61 return T; … … 67 68 { 68 69 StringBuffer sb = new StringBuffer("#S("); 69 sb.append(s ymbol);70 sb.append(structureClass.getSymbol()); 70 71 // FIXME Use *PRINT-LENGTH*. 71 72 final int limit = Math.min(slots.length, 10); -
trunk/j/src/org/armedbear/lisp/define-condition.lisp
r3926 r3966 2 2 ;;; 3 3 ;;; Copyright (C) 2003 Peter Graves 4 ;;; $Id: define-condition.lisp,v 1. 1 2003-09-20 16:57:05piso Exp $4 ;;; $Id: define-condition.lisp,v 1.2 2003-09-21 15:08:43 piso Exp $ 5 5 ;;; 6 6 ;;; This program is free software; you can redistribute it and/or … … 22 22 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs) 23 23 &body options) 24 `(%define-condition ',name)) 24 (let ((parent-types (or parent-types '(condition)))) 25 `(%define-condition ',name ',parent-types ',slot-specs ',options))) -
trunk/j/src/org/armedbear/lisp/define_condition.java
r3926 r3966 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: define_condition.java,v 1. 1 2003-09-20 16:56:02piso Exp $5 * $Id: define_condition.java,v 1.2 2003-09-21 15:09:05 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 29 29 } 30 30 31 // define-condition name (parent-type*) ({slot-spec}*) option* => name 31 32 public LispObject execute(LispObject[] args) throws ConditionThrowable 32 33 { 33 if (args.length < 1)34 if (args.length != 4) 34 35 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 35 return NIL; 36 Symbol symbol = checkSymbol(args[0]); 37 Debug.trace("symbol = " + symbol); 38 LispObject parentTypes = checkCons(args[1]); 39 LispObject slotSpecs = args[2]; 40 LispObject options = args[3]; 41 42 StandardClass c = new StandardClass(symbol, parentTypes); 43 LispClass.addClass(symbol, c); 44 return c; 36 45 } 37 46
Note: See TracChangeset
for help on using the changeset viewer.