• R/O
  • SSH
  • HTTPS

schluessel: Commit


Commit MetaInfo

Revisión369 (tree)
Tiempo2014-02-12 07:44:34
Autory-moriguchi

Log Message

refactors some classes

Cambiar Resumen

Diferencia incremental

--- trunk/schluessel-nano/test/net/morilib/lisp/nano/test/TCLisp.java (revision 368)
+++ trunk/schluessel-nano/test/net/morilib/lisp/nano/test/TCLisp.java (revision 369)
@@ -23,6 +23,7 @@
2323 import java.util.Stack;
2424
2525 import net.morilib.lisp.nano.Cons;
26+import net.morilib.lisp.nano.ConsListBuilder;
2627 import net.morilib.lisp.nano.Datum;
2728 import net.morilib.lisp.nano.LispBoolean;
2829 import net.morilib.lisp.nano.LispCharacter;
@@ -185,12 +186,28 @@
185186 return LispComplex.newPolar(r, i);
186187 }
187188
188- public static Datum list(Object... lst) {
189- return LispUtils.list(lst);
189+ /**
190+ *
191+ * @param d
192+ * @param lst
193+ * @return
194+ */
195+ public static Datum listDot(Object d, Object... lst) {
196+ ConsListBuilder b = new ConsListBuilder();
197+
198+ for(Object o : lst) {
199+ b.append(LispUtils.toDatum(o));
200+ }
201+ return b.get(LispUtils.toDatum(d));
190202 }
191203
192- public static Datum listDot(Object d, Object... lst) {
193- return LispUtils.listDot(d, lst);
204+ /**
205+ *
206+ * @param lst
207+ * @return
208+ */
209+ public static Datum list(Object... lst) {
210+ return listDot(Nil.NIL, lst);
194211 }
195212
196213 public static Cons cons(Object car, Object cdr) {
--- trunk/schluessel-nano/src/net/morilib/lisp/nano/OutputPort.java (revision 368)
+++ trunk/schluessel-nano/src/net/morilib/lisp/nano/OutputPort.java (revision 369)
@@ -18,7 +18,6 @@
1818 import java.io.File;
1919 import java.io.FileNotFoundException;
2020 import java.io.FileOutputStream;
21-import java.io.IOException;
2221 import java.io.OutputStream;
2322 import java.io.OutputStreamWriter;
2423 import java.io.PrintStream;
@@ -237,77 +236,6 @@
237236 }
238237
239238 /* (non-Javadoc)
240- * @see net.morilib.lisp.r6rs.io.ILispPort#supportsPosition()
241- */
242- public boolean hasPortPosition() {
243- return false;
244- }
245-
246- /* (non-Javadoc)
247- * @see net.morilib.lisp.r6rs.io.ILispPort#getPortPosition()
248- */
249- public Datum getPortPosition() {
250- throw new UnsupportedOperationException();
251- }
252-
253- /* (non-Javadoc)
254- * @see net.morilib.lisp.r6rs.io.ILispPort#supportsSetPosition()
255- */
256- public boolean hasSetPortPosition() {
257- return false;
258- }
259-
260- /* (non-Javadoc)
261- * @see net.morilib.lisp.r6rs.io.ILispPort#setPortPosition(net.morilib.lisp.Datum)
262- */
263- public void setPortPosition(Datum pos) {
264- throw new UnsupportedOperationException();
265- }
266-
267- /* (non-Javadoc)
268- * @see net.morilib.lisp.r6rs.io.ILispR6RSOutputPort#flush()
269- */
270- public void flush() throws IOException {
271- lineWriter.flush();
272- }
273-
274- /* (non-Javadoc)
275- * @see net.morilib.lisp.r6rs.io.ILispTextualOutputPort#putChar(int)
276- */
277- public void putChar(int c) throws IOException {
278- writeChar(LispCharacter.valueOf(c));
279- }
280-
281- /* (non-Javadoc)
282- * @see net.morilib.lisp.r6rs.io.ILispTextualOutputPort#putString(java.lang.String)
283- */
284- public void putString(String s) throws IOException {
285- lineWriter.print(s);
286- }
287-
288- /* (non-Javadoc)
289- * @see net.morilib.lisp.r6rs.io.ILispTextualOutputPort#putString(java.lang.String, int)
290- */
291- public void putString(String s, int start) throws IOException {
292- lineWriter.print(s.substring(start));
293- }
294-
295- /* (non-Javadoc)
296- * @see net.morilib.lisp.r6rs.io.ILispTextualOutputPort#putString(java.lang.String, int, int)
297- */
298- public void putString(String s,
299- int start, int end) throws IOException {
300- lineWriter.print(s.substring(start, end));
301- }
302-
303- /* (non-Javadoc)
304- * @see net.morilib.lisp.r6rs.io.ILispTextualOutputPort#putDatum(net.morilib.lisp.Datum)
305- */
306- public void putDatum(Datum d) throws IOException {
307- writeWithSS(d);
308- }
309-
310- /* (non-Javadoc)
311239 * @see net.morilib.lisp.Datum#toDisplayString(java.lang.StringBuilder)
312240 */
313241 @Override
--- trunk/schluessel-nano/src/net/morilib/lisp/nano/LispUtils.java (revision 368)
+++ trunk/schluessel-nano/src/net/morilib/lisp/nano/LispUtils.java (revision 369)
@@ -307,45 +307,6 @@
307307 /**
308308 *
309309 * @param d
310- * @param dot
311- * @return
312- */
313- public static Datum toCons(Iterable<? extends Datum> d,
314- Datum dot) {
315- Cons res = null;
316- Cons c2 = null;
317-
318- for(Datum x : d) {
319- if(res == null) {
320- res = c2 = new Cons();
321- c2.setCar(x);
322- } else {
323- Cons c3 = new Cons(x, Nil.NIL);
324- c2.setCdr(c3);
325- c2 = c3;
326- }
327- }
328-
329- if(res == null) {
330- return dot;
331- } else {
332- c2.setCdr(dot);
333- return res;
334- }
335- }
336-
337- /**
338- *
339- * @param d
340- * @return
341- */
342- public static Datum toCons(Iterable<? extends Datum> d) {
343- return toCons(d, Nil.NIL);
344- }
345-
346- /**
347- *
348- * @param d
349310 * @param mesg
350311 * @return
351312 */
@@ -482,30 +443,6 @@
482443 * @param lst
483444 * @return
484445 */
485- public static Datum listDot(Object d, Object... lst) {
486- ConsListBuilder b = new ConsListBuilder();
487-
488- for(Object o : lst) {
489- b.append(toDatum(o));
490- }
491- return b.get(toDatum(d));
492- }
493-
494- /**
495- *
496- * @param lst
497- * @return
498- */
499- public static Datum list(Object... lst) {
500- return listDot(Nil.NIL, lst);
501- }
502-
503- /**
504- *
505- * @param d
506- * @param lst
507- * @return
508- */
509446 public static Datum listDot(Datum d, Datum... lst) {
510447 ConsListBuilder b = new ConsListBuilder();
511448
@@ -525,85 +462,6 @@
525462 }
526463
527464 /**
528- *
529- * @param v1
530- * @param v2
531- * @return
532- */
533- public static boolean equalsVector(LispVector v1, LispVector v2) {
534- if(v1.size() != v2.size()) {
535- return false;
536- } else {
537- for(int i = 0; i < v1.size(); i++) {
538- if(!equal(v1.get(i), v2.get(i))) {
539- return false;
540- }
541- }
542- return true;
543- }
544- }
545-
546- /**
547- *
548- * @param d1
549- * @param d2
550- * @return
551- */
552- /*package*/ static boolean equal(Datum d1, Datum d2) {
553- Datum p = d1;
554- Datum q = d2;
555-
556- while(true) {
557- if(p instanceof Cons) {
558- Cons pc = (Cons)p;
559-
560- if(q instanceof Cons) {
561- Cons qc = (Cons)q;
562-
563- if(equal(pc.getCar(), qc.getCar())) {
564- p = pc.getCdr();
565- q = qc.getCdr();
566- } else {
567- return false;
568- }
569- } else {
570- return false;
571- }
572- } else if(p instanceof LispString) {
573- if(q instanceof LispString) {
574- String s1 = ((LispString)p).getString();
575- String s2 = ((LispString)q).getString();
576-
577- return s1.equals(s2);
578- } else {
579- return false;
580- }
581- } else if(p instanceof LispVector) {
582- if(q instanceof LispVector) {
583- return equalsVector((LispVector)p, (LispVector)q);
584- } else {
585- return false;
586- }
587- } else {
588- return p.isEqv(q);
589- }
590- }
591- }
592-
593- /**
594- * @param lispString
595- * @return
596- */
597- public static Datum stringToList(CharSequence cs) {
598- ConsListBuilder b = new ConsListBuilder();
599-
600- for(int i = 0; i < cs.length(); i++) {
601- b.append(LispCharacter.valueOf(cs.charAt(i)));
602- }
603- return b.get();
604- }
605-
606- /**
607465 * @param charAt
608466 * @return
609467 */
--- trunk/schluessel-nano/src/net/morilib/lisp/nano/LispString.java (revision 368)
+++ trunk/schluessel-nano/src/net/morilib/lisp/nano/LispString.java (revision 369)
@@ -494,13 +494,6 @@
494494 }
495495
496496 /* (non-Javadoc)
497- * @see net.morilib.lisp.collection.LispCollection#toList()
498- */
499- public Datum toList() {
500- return LispUtils.stringToList(value);
501- }
502-
503- /* (non-Javadoc)
504497 * @see net.morilib.lisp.collection.LispSequence#first()
505498 */
506499 public Datum first() {
--- trunk/schluessel-nano/src/net/morilib/lisp/nano/InputPort.java (revision 368)
+++ trunk/schluessel-nano/src/net/morilib/lisp/nano/InputPort.java (revision 369)
@@ -370,185 +370,6 @@
370370 }
371371
372372 /* (non-Javadoc)
373- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#getChar()
374- */
375- public int getChar() throws IOException {
376- if(closed) {
377- throw msg.getError("err.port.closed");
378- } else if(reachedEOF) {
379- return -1;
380- }
381-
382- try {
383- int ch = getc();
384-
385- if(ch < 0) {
386- reachedEOF = true;
387- return ch;
388- } else {
389- return ch;
390- }
391- } catch (IOException e) {
392- throw new LispIOException(e);
393- }
394- }
395-
396- /* (non-Javadoc)
397- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#lookaheadChar()
398- */
399- public int lookaheadChar() throws IOException {
400- return readc();
401- }
402-
403- /* (non-Javadoc)
404- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#getString(int)
405- */
406- public String getString(int n) throws IOException {
407- StringBuilder b = new StringBuilder();
408- int c;
409-
410- if(closed) {
411- throw msg.getError("err.port.closed");
412- } else if(reachedEOF) {
413- return null;
414- } else {
415- for(int i = 0; i < n; i++) {
416- if((c = getChar()) >= 0) {
417- b.appendCodePoint(c);
418- } else if(i == 0) {
419- reachedEOF = true;
420- return null;
421- } else {
422- break;
423- }
424- }
425- return b.toString();
426- }
427- }
428-
429- /* (non-Javadoc)
430- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#getChars(int[], int, int)
431- */
432- public int getChars(int[] buf,
433- int start, int end) throws IOException {
434- int c;
435-
436- if(closed) {
437- throw msg.getError("err.port.closed");
438- } else if(reachedEOF) {
439- return -1;
440- } else {
441- for(int i = start; i < end; i++) {
442- if((c = getChar()) >= 0) {
443- buf[i] = c;
444- } else if(i == start) {
445- reachedEOF = true;
446- return -1;
447- } else {
448- break;
449- }
450- }
451- return end - start;
452- }
453- }
454-
455- /* (non-Javadoc)
456- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#getStringAll()
457- */
458- public String getStringAll() throws IOException {
459- StringBuilder b = new StringBuilder();
460- int c;
461-
462- if(closed) {
463- throw msg.getError("err.port.closed");
464- } else if(reachedEOF) {
465- return null;
466- } else {
467- while(true) {
468- if((c = getChar()) >= 0) {
469- b.appendCodePoint(c);
470- } else if(b.length() == 0) {
471- reachedEOF = true;
472- return null;
473- } else {
474- break;
475- }
476- }
477- return b.toString();
478- }
479- }
480-
481- /* (non-Javadoc)
482- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#getLine()
483- */
484- public String getLine() throws IOException {
485- StringBuilder b = new StringBuilder();
486- int c;
487-
488- if(closed) {
489- throw msg.getError("err.port.closed");
490- } else if(reachedEOF) {
491- return null;
492- } else {
493- while(true) {
494- if((c = getChar()) == '\n') {
495- break;
496- } else if(c >= 0) {
497- b.appendCodePoint(c);
498- } else if(b.length() == 0) {
499- reachedEOF = true;
500- return null;
501- } else {
502- break;
503- }
504- }
505- return b.toString();
506- }
507- }
508-
509- /* (non-Javadoc)
510- * @see net.morilib.lisp.r6rs.io.ILispTextualInputPort#getDatum()
511- */
512- public Datum getDatum() throws IOException {
513- return readS();
514- }
515-
516- /* (non-Javadoc)
517- * @see net.morilib.lisp.r6rs.io.ILispR6RSInputPort#isPortEof()
518- */
519- public boolean isPortEof() {
520- return reachedEOF;
521- }
522-
523- /* (non-Javadoc)
524- * @see net.morilib.lisp.r6rs.io.ILispPort#supportsPosition()
525- */
526- public boolean hasPortPosition() {
527- return false;
528- }
529-
530- /* (non-Javadoc)
531- * @see net.morilib.lisp.r6rs.io.ILispPort#getPortPosition()
532- */
533- public Datum getPortPosition() {
534- throw new UnsupportedOperationException();
535- }
536-
537- /* (non-Javadoc)
538- * @see net.morilib.lisp.r6rs.io.ILispPort#supportsSetPosition()
539- */
540- public boolean hasSetPortPosition() {
541- return false;
542- }
543-
544- /* (non-Javadoc)
545- * @see net.morilib.lisp.r6rs.io.ILispPort#setPortPosition(net.morilib.lisp.Datum)
546- */
547- public void setPortPosition(Datum pos) {
548- throw new UnsupportedOperationException();
549- }
550-
551- /* (non-Javadoc)
552373 * @see net.morilib.lisp.Datum#toDisplayString(java.lang.StringBuilder)
553374 */
554375 @Override
Show on old repository browser