/** * Copyright (c) Rich Hickey. All rights reserved. * The use and distribution terms for this software are covered by the * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) * which can be found in the file CPL.TXT at the root of this distribution. * By using this software in any fashion, you are agreeing to be bound by * the terms of this license. * You must not remove this notice, or any other, from this software. **/ /* rich Mar 25, 2006 4:28:27 PM */ using System; using System.Collections; using System.IO; namespace org.clojure.runtime { public class RT { public static Symbol T = Symbol.intern("t"); public static Object[] EMPTY_ARRAY = new Object[0]; static public readonly Object[] chars; static RT(){ chars = new Object[256]; for(int i=0;i= 0; --i) ret = cons(a[i], ret); return ret; } static public int length(ISeq list) { int i = 0; for(ISeq c = list; c != null; c = c.rest()) { i++; } return i; } static public int boundedLength(ISeq list, int limit) { int i = 0; for(ISeq c = list; c != null && i <= limit; c = c.rest()) { i++; } return i; } ///////////////////////////////// reader support //////////////////////////////// static Object readRet(int ret){ if(ret == -1) return null; return box((char) ret); } static public Object readChar(TextReader r) { int ret = r.Read(); return readRet(ret); } static public Object peekChar(TextReader r) { return readRet(r.Peek()); } static public int getLineNumber(TextReader r) { if (r is LineNumberingTextReader) return ((LineNumberingTextReader)r).getLineNumber(); return 0; } static public TextReader getLineNumberingReader(TextReader r) { if (isLineNumberingReader(r)) return r; return new LineNumberingTextReader(r); } static public bool isLineNumberingReader(TextReader r) { return r is LineNumberingTextReader; } /*-------------------------------- values --------------*/ static public Object setValues(ThreadLocalData tld, Object arg1) { if(tld == null) tld = ThreadLocalData.get(); tld.mvCount = 1; tld.mvArray[0] = arg1; return arg1; } static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2) { if(tld == null) tld = ThreadLocalData.get(); tld.mvCount = 2; tld.mvArray[0] = arg1; tld.mvArray[1] = arg2; return arg1; } static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3) { if(tld == null) tld = ThreadLocalData.get(); tld.mvCount = 3; tld.mvArray[0] = arg1; tld.mvArray[1] = arg2; tld.mvArray[2] = arg3; return arg1; } static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4) { if(tld == null) tld = ThreadLocalData.get(); tld.mvCount = 4; tld.mvArray[0] = arg1; tld.mvArray[1] = arg2; tld.mvArray[2] = arg3; tld.mvArray[3] = arg4; return arg1; } static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { if(tld == null) tld = ThreadLocalData.get(); tld.mvCount = 5; tld.mvArray[0] = arg1; tld.mvArray[1] = arg2; tld.mvArray[2] = arg3; tld.mvArray[3] = arg4; tld.mvArray[4] = arg5; return arg1; } static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq args) /**/ { if(tld == null) tld = ThreadLocalData.get(); tld.mvCount = 5; tld.mvArray[0] = arg1; tld.mvArray[1] = arg2; tld.mvArray[2] = arg3; tld.mvArray[3] = arg4; tld.mvArray[4] = arg5; for(int i = 5; args != null && i < ThreadLocalData.MULTIPLE_VALUES_LIMIT; i++, args = args.rest()) { tld.mvArray[i] = args.first(); } if(args != null) throw new ArgumentException("Too many arguments to values (> ThreadLocalData.MULTIPLE_VALUES_LIMIT)"); return arg1; } } }