Permalink
Browse files

Fix matching on <fun> and <ref> values in ets; if such values were me…

…mber of a tuple in ets, then matching such values on e.g. '$N' did not work. This fixes issue #44 (http://github.com/trifork/erjang/issues/#issue/44)
  • Loading branch information...
1 parent e491687 commit c1f976dc8d7a52394d9a27b30ec615e08b792048 @krestenkrab krestenkrab committed Nov 16, 2010
@@ -41,6 +41,8 @@
import erjang.beam.Compiler;
import erjang.beam.CompilerVisitor;
import erjang.beam.EUtil;
+import erjang.m.ets.EMatchContext;
+import erjang.m.ets.ETermPattern;
public abstract class EFun extends EObject implements Opcodes {
@@ -101,6 +103,11 @@ public EObject invoke(EProc proc, EObject[] args, int off, int len)
return invoke(proc, new_args);
}
+ public boolean match(ETermPattern matcher, EMatchContext r) {
+ return matcher.match(this, r);
+ }
+
+
private static final Type EFUN_TYPE = Type.getType(EFun.class);
private static final String EFUN_NAME = EFUN_TYPE.getInternalName();
private static final Type EFUNHANDLER_TYPE = Type
@@ -21,6 +21,9 @@
import java.io.IOException;
+import erjang.m.ets.EMatchContext;
+import erjang.m.ets.ETermPattern;
+
/**
*
*/
@@ -71,6 +74,11 @@ public ERef(EAtom node, int id, int creation) {
}
@Override
+ public boolean match(ETermPattern matcher, EMatchContext r) {
+ return matcher.match(this, r);
+ }
+
+ @Override
int compare_same(EObject rhs) {
int val = compare_same2(rhs);
@@ -34,6 +34,7 @@
import erjang.EAtom;
import erjang.EBitString;
import erjang.ECons;
+import erjang.EFun;
import erjang.ENumber;
import erjang.EObject;
import erjang.EPID;
@@ -221,6 +222,10 @@ public boolean match(EAtom am, EMatchContext r) {
return am.compareTo(value) == 0;
}
+ public boolean match(EFun fu, EMatchContext r) {
+ return fu.compareTo(value) == 0;
+ }
+
public boolean match(EBitString bits, EMatchContext r) {
return bits.compareTo(value) == 0;
}
@@ -855,6 +860,14 @@ public boolean match(EAtom a, EMatchContext r) {
return true;
}
+ public boolean match(EFun a, EMatchContext r) {
+ return true;
+ }
+
+ public boolean match(ERef a, EMatchContext r) {
+ return true;
+ }
+
public boolean match(ECons c, EMatchContext r) {
return true;
}
@@ -924,6 +937,24 @@ public boolean match(EAtom t, EMatchContext r) {
}
}
+ public boolean match(ERef ref, EMatchContext r) {
+ if (free) {
+ r.vars.put(var_name, ref);
+ return true;
+ } else {
+ return ref.equalsExactly(r.vars.get(var_name));
+ }
+ }
+
+ public boolean match(EFun fu, EMatchContext r) {
+ if (free) {
+ r.vars.put(var_name, fu);
+ return true;
+ } else {
+ return fu.equalsExactly(r.vars.get(var_name));
+ }
+ }
+
public boolean match(ECons t, EMatchContext r) {
if (free) {
r.vars.put(var_name, t);
@@ -31,6 +31,7 @@
import erjang.EAtom;
import erjang.EBitString;
import erjang.ECons;
+import erjang.EFun;
import erjang.EList;
import erjang.ENumber;
import erjang.EObject;
@@ -224,6 +225,24 @@ public boolean match(EAtom t, EMatchContext r) {
}
}
+ public boolean match(EFun fu, EMatchContext r) {
+ if (free) {
+ r.vars.put(name, fu);
+ return true;
+ } else {
+ return fu.equalsExactly(r.vars.get(name));
+ }
+ }
+
+ public boolean match(ERef fu, EMatchContext r) {
+ if (free) {
+ r.vars.put(name, fu);
+ return true;
+ } else {
+ return fu.equalsExactly(r.vars.get(name));
+ }
+ }
+
public boolean match(ECons t, EMatchContext r) {
if (free) {
r.vars.put(name, t);
@@ -347,6 +366,10 @@ public boolean match(EAtom port, EMatchContext r) {
return port.equalsExactly(value);
}
+ public boolean match(EFun fu, EMatchContext r) {
+ return fu.equalsExactly(value);
+ }
+
public boolean match(EBitString port, EMatchContext r) {
return port.equalsExactly(value);
}
@@ -22,10 +22,12 @@
import erjang.EAtom;
import erjang.EBitString;
import erjang.ECons;
+import erjang.EFun;
import erjang.ENumber;
import erjang.EObject;
import erjang.EPID;
import erjang.EPort;
+import erjang.ERef;
import erjang.ETuple;
public abstract class ETermPattern {
@@ -56,4 +58,12 @@ public boolean match(EPort p, EMatchContext r) {
public boolean match(EBitString bs, EMatchContext r) {
return false;
}
+
+ public boolean match(EFun eFun, EMatchContext r) {
+ return false;
+ }
+
+ public boolean match(ERef eRef, EMatchContext r) {
+ return false;
+ }
}

0 comments on commit c1f976d

Please sign in to comment.