Skip to content
This repository
Browse code

allow JavaObjects to be used as EProc arguments

  • Loading branch information...
commit 9fe76d9cc1004404e82c3035e0705d403dc3e55e 1 parent 5e2a0ad
Wolfgang Schell authored August 30, 2011 krestenkrab committed September 22, 2011

Showing 1 changed file with 36 additions and 2 deletions. Show diff stats Hide diff stats

  1. 38  src/main/java/erjang/EProc.java
38  src/main/java/erjang/EProc.java
@@ -30,6 +30,7 @@
30 30
 import kilim.Pausable;
31 31
 import erjang.m.erlang.ErlFun;
32 32
 import erjang.m.erlang.ErlProc;
  33
+import erjang.m.java.JavaObject;
33 34
 
34 35
 /**
35 36
  * An erlang process
@@ -97,6 +98,17 @@
97 98
 	public int sp = 0;
98 99
 // 	double[] fregs = new double[16];
99 100
 	public EDouble[] fregs = new EDouble[16];
  101
+	
  102
+	public EProc(EPID group_leader, EAtom m, EAtom f, Object[] a) {
  103
+		self = new EInternalPID(this);
  104
+
  105
+		// if no group leader is given, we're our own group leader
  106
+		this.group_leader = group_leader == null ? self : group_leader;
  107
+		
  108
+		setTarget(m, f, a);
  109
+		
  110
+		all_tasks.put(key(), this);
  111
+	}
100 112
 
101 113
 	/**
102 114
 	 * @param m
@@ -108,6 +120,30 @@ public EProc(EPID group_leader, EAtom m, EAtom f, ESeq a) {
108 120
 
109 121
 		// if no group leader is given, we're our own group leader
110 122
 		this.group_leader = group_leader == null ? self : group_leader;
  123
+		
  124
+		setTarget(m, f, a);
  125
+		
  126
+		all_tasks.put(key(), this);
  127
+	}
  128
+	
  129
+	protected void setTarget(EAtom m, EAtom f, Object[] args) {
  130
+		// wrap any non-EObject argument in JavaObject
  131
+		EObject[] eargs = new EObject[args.length];
  132
+		for (int i = 0; i < args.length; i++) {
  133
+			Object arg = args[i];
  134
+			if (arg instanceof EObject) {
  135
+				EObject earg = (EObject) arg;
  136
+				eargs[i] = earg;
  137
+			}
  138
+			else {
  139
+				// wrap in JavaObject
  140
+				eargs[i] = JavaObject.box(this, arg);
  141
+			}
  142
+		}
  143
+		setTarget(m, f, ESeq.fromArray(eargs));
  144
+	}
  145
+	
  146
+	protected void setTarget(EAtom m, EAtom f, ESeq a) {
111 147
 		this.spawn_mod = m;
112 148
 		this.spawn_fun = f;
113 149
 		this.spawn_args = a.length();
@@ -140,8 +176,6 @@ public EProc(EPID group_leader, EAtom m, EAtom f, ESeq a) {
140 176
 			this.arg0 = a.head(); a = a.tail();
141 177
 		case 0:
142 178
 		}
143  
-		
144  
-		all_tasks.put(key(), this);
145 179
 	}
146 180
 
147 181
 	private int key() {

0 notes on commit 9fe76d9

Please sign in to comment.
Something went wrong with that request. Please try again.