Skip to content

Commit b8bee3c

Browse files
committed
amended previous commit
1 parent a8a71db commit b8bee3c

File tree

8 files changed

+39
-24
lines changed

8 files changed

+39
-24
lines changed

samples/dci/js/Dijkstra-alt/Graph.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ function Graph(edges) {
1515
var pairs = this.nodes.get(from);
1616
if (pairs == null) {
1717
pairs = new HashMap();
18-
pairs.add(to, dist);
19-
this.nodes.add(from, pairs);
18+
pairs.put(to, dist);
19+
this.nodes.put(from, pairs);
2020
}
2121
else {
22-
pairs.add(to, dist);
22+
pairs.put(to, dist);
2323
}
2424

25-
this.distances.add(from, Infinity);
25+
this.distances.put(from, Infinity);
2626
}
2727
}

samples/dci/js/Dijkstra-alt/Subgraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var Subgraph = DCI.Context.extend(function() {
3737
}
3838

3939
setAsPreviousOf(node) {
40-
Graph.previous.add(node, self);
40+
Graph.previous.put(node, self);
4141
}
4242

4343
distanceTo(otherNode) {

samples/dci/js/Dijkstra/CalculateShortestPath.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ var CalculateShortestPath = DCI.Context.extend(function() {
2222
//Run the use case
2323
this.run = function() {
2424
Graph.nodes.each(function(node) {
25-
Unvisited.add(node);
26-
Tentative.add(node, Infinity);
25+
Unvisited.put(node);
26+
Tentative.put(node, Infinity);
2727
});
28-
Tentative.add(Initial, 0);
28+
Tentative.put(Initial, 0);
2929

3030
Current = Initial;
3131
Current.markVisited();
@@ -66,8 +66,8 @@ var CalculateShortestPath = DCI.Context.extend(function() {
6666

6767
var alternate = Tentative.get(self) + self.distanceTo(Neighbor);
6868
if (alternate < Tentative.get(Neighbor)) {
69-
Tentative.add(Neighbor, alternate);
70-
Path.add(Neighbor, self);
69+
Tentative.put(Neighbor, alternate);
70+
Path.put(Neighbor, self);
7171
}
7272
});
7373
}

samples/dci/js/Dijkstra/Graph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ function Graph(edges) {
1212

1313
forceMap(this.nodes, to);
1414
var cur = forceMap(this.nodes, from);
15-
cur.add(to, dist);
15+
cur.put(to, dist);
1616
}
1717
}
1818

1919
function forceMap(nodes, node) {
2020
var map = nodes.get(node);
2121
if (map === undefined) {
2222
map = new HashMap();
23-
nodes.add(node, map);
23+
nodes.put(node, map);
2424
}
2525
return map;
2626
}

samples/dci/js/TransferMoney/TransferMoney.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ var TransferMoney = DCI.Context.extend(function () {
1515
var __context = this;
1616
this.__$SourceAccount = { transferOut: //transfer money out of this account and into the destination account
1717
function () {
18-
var methodName = 'withdraw';
19-
__dci_internal.getRoleMember(__context, __context.SourceAccount, "SourceAccount", methodName)();
18+
var withdraw = __dci_internal.getRoleMember(__context, __context.SourceAccount, "SourceAccount", 'withdraw');
19+
withdraw.call(__context.SourceAccount);
2020

2121
//self.withdraw();
22-
methodName = 'deposit';
23-
__dci_internal.getRoleMember(__context, __context.DestinationAccount, "DestinationAccount", methodName)();
24-
//self.withdraw();
25-
//DestinationAccount.deposit();
22+
__context.__$DestinationAccount.deposit.call(__context.DestinationAccount);
2623
}
2724
,withdraw: function () {
2825
if (__context.SourceAccount.getBalance() < __context.Amount) {
@@ -43,9 +40,7 @@ this.__$Amount = {};
4340
};
4441
//Run the use case
4542
this.run = function () {
46-
var methodName = 'transferOut';
47-
__dci_internal.getRoleMember(__context, __context.SourceAccount, "SourceAccount", methodName)();
48-
//SourceAccount.transferOut();
43+
__context.__$SourceAccount.transferOut.call(__context.SourceAccount);
4944
};
5045

5146

samples/dci/js/TransferMoney/TransferMoney.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ var TransferMoney = DCI.Context.extend(function() {
2525
role SourceAccount {
2626
//transfer money out of this account and into the destination account
2727
transferOut() {
28-
self.withdraw();
28+
var withdraw = self['withdraw'];
29+
withdraw.call(self);
30+
31+
//self.withdraw();
2932
DestinationAccount.deposit();
3033
}
3134

samples/dci/typescript/Dijkstra/HashMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HashMap {
2626
return -1;
2727
}
2828

29-
add(key, value) {
29+
put(key, value) {
3030
if (key === undefined && value === undefined) return undefined;
3131

3232
var previous = undefined;

src/compiler/emitter.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ module TypeScript {
643643
this.writeToOutput("__dci_internal.callMethodOnSelf");
644644
//this.writeToOutput("DCI.callMethodOnSelf");
645645
this.writeToOutput("(__context, this, '" + roleName + "'");
646+
647+
//DCI TODO
648+
//Check for dynamic role method call, e.g. this['withdraw'](); or:
649+
// var methodName = 'withdraw';
650+
// this[methodName]();
651+
//
652+
//if (target.nodeType() == NodeType.ElementAccessExpression) {
653+
646654
this.writeToOutput(", '" + operand2.actualText + "'");
647655

648656
if (args && args.members.length) this.writeToOutput(", ");
@@ -1290,11 +1298,20 @@ module TypeScript {
12901298
//This allows us to support calling role methods dynamically, e.g.:
12911299
// var methodName = 'deposit';
12921300
// DestinationAccount[methodName]();
1293-
var isCallToSelf = false;
12941301
var dciContext = this.thisDCIContextNode;
12951302
var potentialRoleIdentifier: Identifier = <Identifier>operand1; //object identifier - potentially a role identifier
12961303
var roleName: string;
12971304

1305+
//DCI TODO
1306+
//Support `this` in addition to `self`
1307+
//
1308+
//Support dynamically retrieving a role method on `self`, e.g.:
1309+
// var withdraw = self['withdraw'];
1310+
// withdraw.call(self);
1311+
if (this.thisRoleNode && potentialRoleIdentifier.actualText == 'self') {
1312+
roleName = this.thisRoleNode.name.actualText;
1313+
}
1314+
12981315
if (!roleName) roleName = potentialRoleIdentifier.actualText;
12991316

13001317
//Is it a role identifier?

0 commit comments

Comments
 (0)