-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from lf-lang/ts-multiport
Added support for connecting multiports and started reorganizing the code base to be more modular.
- Loading branch information
Showing
40 changed files
with
1,887 additions
and
1,201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Bank , Reactor, App, Timer, Triggers, Args, Present, OutPort, InPort, TimeValue } from "../src/core/internal"; | ||
|
||
class Periodic extends Reactor { | ||
|
||
t: Timer = new Timer(this, 0, TimeValue.sec(1)); | ||
o: OutPort<number> = new OutPort(this) | ||
constructor(parent: Reactor) { | ||
super(parent) | ||
this.addReaction( | ||
new Triggers(this.t), | ||
new Args(this.t), | ||
function (this) { | ||
console.log(this.getBankIndex()); | ||
} | ||
); | ||
} | ||
} | ||
|
||
class Generic<T extends Present> extends Reactor { | ||
input: InPort<T> = new InPort(this); | ||
} | ||
|
||
describe('Check bank index', () => { | ||
|
||
class myApp extends App { | ||
b = new Bank(this, 3, Periodic, this) | ||
c = new Bank<Generic<number>, [Reactor]>(this, 2, Generic, this); | ||
constructor() { | ||
super(); | ||
test('contained bank member name', () => { | ||
expect(this.b.get(0)._getFullyQualifiedName()).toBe("myApp.b[0]") | ||
expect(this.b.get(1)._getFullyQualifiedName()).toBe("myApp.b[1]") | ||
expect(this.b.get(2)._getFullyQualifiedName()).toBe("myApp.b[2]") | ||
}) | ||
it('contained bank member index', () => { | ||
expect(this.b.get(0).getBankIndex()).toBe(0); | ||
expect(this.b.get(1).getBankIndex()).toBe(1); | ||
expect(this.b.get(2).getBankIndex()).toBe(2); | ||
}); | ||
|
||
it('generic bank', () => { | ||
this.c.all().forEach(r => expect(typeof r.input == "number")) | ||
}); | ||
var foo = this.b.port((member) => member.o) | ||
var bar = [this.b.get(0).o, this.b.get(1).o, this.b.get(2).o] | ||
it('select port', () => { | ||
for (let i=0; i < foo.length; i++) { | ||
expect(foo[i]).toBe(bar[i]); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
new myApp(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Reactor, App, Triggers, Args, State, OutPort, InPort, TimeUnit, TimeValue } from '../src/core/internal'; | ||
|
||
describe('Check canConnect', () => { | ||
class Source extends Reactor { | ||
out: OutPort<number> = new OutPort(this) | ||
} | ||
class Destination extends Reactor { | ||
in: InPort<number> = new InPort(this) | ||
out: InPort<number> = new InPort(this) | ||
} | ||
|
||
class TestApp extends App { | ||
source: Source | ||
destination: Destination | ||
|
||
constructor() { | ||
super() | ||
this.source = new Source(this) | ||
this.destination = new Destination(this) | ||
|
||
it('canConnect success out->in', () => { | ||
expect(this.canConnect(this.source.out, this.destination.in)).toBe(true) | ||
}) | ||
|
||
it('canConnect success out->out', () => { | ||
expect(this.canConnect(this.source.out, this.destination.out)).toBe(true) | ||
}) | ||
|
||
it('canConnect failure', () => { | ||
expect(this.canConnect(this.destination.in, this.source.out)).toBe(false) | ||
}) | ||
} | ||
} | ||
var testApp = new TestApp() | ||
}) | ||
|
||
describe('Check _connect', () => { | ||
jest.setTimeout(5000); | ||
|
||
class Source extends Reactor { | ||
out: OutPort<number> = new OutPort(this) | ||
constructor(container: Reactor) { | ||
super(container); | ||
this.addReaction( | ||
new Triggers(this.startup), | ||
new Args(this.writable(this.out)), | ||
function(this, __out) { | ||
__out.set(100); | ||
|
||
} | ||
); | ||
} | ||
} | ||
class Destination extends Reactor { | ||
in: InPort<number> = new InPort(this) | ||
received: State<number> = new State(0) | ||
constructor(container: Reactor) { | ||
super(container) | ||
this.addReaction( | ||
new Triggers(this.in), | ||
new Args(this.in, this.received), | ||
function(this, __in, __received) { | ||
let tmp = __in.get(); | ||
try | ||
{ | ||
if(tmp) | ||
{ | ||
__received.set(tmp) | ||
} | ||
} finally { | ||
|
||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
class TestApp extends App { | ||
source: Source | ||
destination: Destination | ||
|
||
constructor(timeout: TimeValue, success?: () => void, fail?: () => void) { | ||
super(timeout, false, false, success, fail) | ||
this.source = new Source(this) | ||
this.destination = new Destination(this) | ||
this._connect(this.source.out, this.destination.in) | ||
} | ||
} | ||
|
||
it("_connect success", done => { | ||
function fail() { | ||
throw new Error("Test has failed."); | ||
}; | ||
|
||
let testApp = new TestApp(TimeValue.withUnits(1,TimeUnit.nsec), done, fail) | ||
testApp._start() | ||
expect(testApp.destination.received.get()).toBe(100) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.