Skip to content

Commit

Permalink
incomplete work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
richhickey committed Jun 12, 2010
1 parent 3f74c9f commit c5d0985
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 418 deletions.
5 changes: 5 additions & 0 deletions src/clj/clojure/core_print.clj
Expand Up @@ -242,6 +242,7 @@
(defmethod print-dup java.lang.Double [o w] (print-method o w))
(defmethod print-dup clojure.lang.Ratio [o w] (print-method o w))
(defmethod print-dup java.math.BigDecimal [o w] (print-method o w))
(defmethod print-dup java.math.BigInteger [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentHashMap [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentHashSet [o w] (print-method o w))
(defmethod print-dup clojure.lang.PersistentVector [o w] (print-method o w))
Expand Down Expand Up @@ -278,6 +279,10 @@
(.write w (str b))
(.write w "M"))

(defmethod print-method java.math.BigInteger [b, ^Writer w]
(.write w (str b))
(.write w "N"))

(defmethod print-method java.util.regex.Pattern [p ^Writer w]
(.write w "#\"")
(loop [[^Character c & r :as s] (seq (.pattern ^java.util.regex.Pattern p))
Expand Down
17 changes: 10 additions & 7 deletions src/jvm/clojure/lang/Compiler.java
Expand Up @@ -5391,7 +5391,10 @@ public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
{
if(!(arg instanceof MaybePrimitiveExpr && arg.hasJavaClass() && arg.getJavaClass() == primc))
throw new IllegalArgumentException("recur arg for primitive local: " +
lb.name + " must be matching primitive");
lb.name + " must be matching primitive, had: " +
arg.getJavaClass().getName() +
", needed: " +
primc.getName());
}
catch(Exception e)
{
Expand Down Expand Up @@ -7217,7 +7220,7 @@ public Expr parse(C context, Object frm) throws Exception{
for(Object o : ((Map)args.nth(6)).entrySet())
{
Map.Entry e = (Map.Entry) o;
Integer minhash = (Integer) e.getKey();
Integer minhash = ((Number)e.getKey()).intValue();
MapEntry me = (MapEntry) e.getValue();
Expr testExpr = new ConstantExpr(me.getKey());
tests.put(minhash, testExpr);
Expand All @@ -7243,12 +7246,12 @@ public Expr parse(C context, Object frm) throws Exception{
Var.popThreadBindings();
}

return new CaseExpr((Integer) LINE.deref(),
return new CaseExpr(((Number)LINE.deref()).intValue(),
testexpr,
(Integer)args.nth(1),
(Integer)args.nth(2),
(Integer)args.nth(3),
(Integer)args.nth(4),
((Number)args.nth(1)).intValue(),
((Number)args.nth(2)).intValue(),
((Number)args.nth(3)).intValue(),
((Number)args.nth(4)).intValue(),
defaultExpr,
tests,thens,args.nth(7) != RT.F);

Expand Down
12 changes: 9 additions & 3 deletions src/jvm/clojure/lang/LispReader.java
Expand Up @@ -47,7 +47,7 @@ public class LispReader{
//static Pattern intPat = Pattern.compile("[-+]?[0-9]+\\.?");
static Pattern intPat =
Pattern.compile(
"([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+)|0[0-9]+)");
"([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+)|0[0-9]+)(N)?");
static Pattern ratioPat = Pattern.compile("([-+]?[0-9]+)/([0-9]+)");
static Pattern floatPat = Pattern.compile("([-+]?[0-9]+(\\.[0-9]*)?([eE][-+]?[0-9]+)?)(M)?");
static final Symbol SLASH = Symbol.create("/");
Expand Down Expand Up @@ -327,7 +327,11 @@ private static Object matchNumber(String s){
if(m.matches())
{
if(m.group(2) != null)
return 0;
{
if(m.group(8) != null)
return BigInteger.ZERO;
return new Long(0);
}
boolean negate = (m.group(1).equals("-"));
String n;
int radix = 10;
Expand All @@ -342,7 +346,9 @@ else if((n = m.group(7)) != null)
if(n == null)
return null;
BigInteger bn = new BigInteger(n, radix);
return Numbers.reduce(negate ? bn.negate() : bn);
if(m.group(8) != null)
return negate ? bn.negate() : bn;
return Numbers.reduceBigInteger(negate ? bn.negate() : bn);
}
m = floatPat.matcher(s);
if(m.matches())
Expand Down

0 comments on commit c5d0985

Please sign in to comment.