git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit acc114f061e4e4c2cbede55a72d008b7e46c5cbc

first two test passing

wanderer committed on 5/7/2017, 2:31:49 PM
Parent: 5f6b460515d272f0c4dcfce10ff08f1efd953318

Files changed

index.jschanged
kernel.jschanged
portManager.jschanged
tests/index.jschanged
index.jsView
@@ -13,12 +13,12 @@
1313 let id = await this.generateID(port)
1414 let kernel = this._vmInstances.get(id)
1515 if (!kernel) {
1616 // load the container from the state
17- await this.graph.tree(port, 2)
18- const parentID = await this.generateID(port.id['/'].parent)
17+ await this.graph.tree(port, 3)
18+ const parentID = await this.generateID({id: port.id['/'].parent})
1919 const parentKernel = await this._vmInstances.get(parentID)
20- const parentPort = parentKernel.entryPort || null
20+ const parentPort = parentKernel.entryPort
2121
2222 kernel = await this.createInstanceFromPort(port, parentPort)
2323 // don't delete the root contracts
2424 if (id) {
@@ -36,9 +36,9 @@
3636 let kernel = await this.getInstance(port)
3737 return kernel.wait(threshold, fromPort)
3838 }
3939
40- async createInstance (type, state, entryPort, parentPort) {
40+ async createInstance (type, state, entryPort = null, parentPort) {
4141 const VM = this._VMs[type]
4242 if (!state) {
4343 state = VM.createState()
4444 }
kernel.jsView
@@ -53,9 +53,8 @@
5353 this.emit(vmState, message)
5454 }
5555
5656 async _runNextMessage () {
57- // console.log('next message', this.ticks, this.entryPort)
5857 const message = await this.ports.getNextMessage()
5958 // if the vm is paused and it gets a message; save that message for use when the VM is resumed
6059 if (message && this.vmState === 'paused') {
6160 this.ports._portMap(message._fromPort).unshfit(message)
@@ -112,9 +111,8 @@
112111
113112 // returns a promise that resolves once the kernel hits the threshould tick
114113 // count
115114 async wait (threshold, fromPort) {
116- console.log('wait', threshold, fromPort, this.ticks, this.vmState, this.entryPort)
117115 if (threshold <= this.ticks) {
118116 return this.ticks
119117 } else if (this.vmState === 'idle') {
120118 return this.ports.wait(threshold, fromPort)
@@ -129,9 +127,8 @@
129127 }
130128 }
131129
132130 incrementTicks (count) {
133- console.log('update ticks')
134131 this.ticks += count
135132 while (!this._waitingQueue.isEmpty()) {
136133 const waiter = this._waitingQueue.peek()
137134 if (waiter.threshold > this.ticks) {
@@ -182,12 +179,8 @@
182179
183180 const receiverEntryPort = portRef === this.entryPort ? this.parentPort : portRef
184181 const vm = await this.hypervisor.getInstance(receiverEntryPort)
185182 vm.queue(message)
186- if (this.vmState !== 'running') {
187- this._updateVmState('running')
188- this._runNextMessage()
189- }
190183 }
191184 }
192185
193186 function clearObject (myObject) {
portManager.jsView
@@ -37,8 +37,9 @@
3737 })
3838
3939 // create the parent port
4040 await Promise.all(ports)
41+ // skip the root, since it doesn't have a parent
4142 if (this.parentPort !== undefined) {
4243 const id = await this.hypervisor.generateID(this.parentPort)
4344 this._portMap.set(id, new Port(ENTRY))
4445 }
@@ -71,14 +72,14 @@
7172 // waits till all ports have reached a threshold tick count
7273 async wait (threshold, fromPort) {
7374 // find the ports that have a smaller tick count then the threshold tick count
7475 const unkownPorts = [...this._portMap].filter(([id, port]) => {
76+ const portRef = this.getRef(port.name)
7577 return (port.hasSent || port.name === ENTRY) &&
7678 port.ticks < threshold &&
77- fromPort !== port
79+ fromPort !== portRef
7880 })
7981
80- // console.log(unkownPorts, this.entryPort)
8182 const promises = unkownPorts.map(async ([id, port]) => {
8283 const portObj = port.name === ENTRY ? this.parentPort : this.ports[port.name]
8384 // update the port's tick count
8485 port.ticks = await this.hypervisor.wait(portObj, threshold, this.entryPort)
tests/index.jsView
@@ -51,9 +51,9 @@
5151 }
5252 t.end()
5353 })
5454
55- tape.only('one child contract', async t => {
55+ tape('one child contract', async t => {
5656 let message = new Message()
5757 const expectedState = { '/': 'zdpuAqtY43BMaTCB5nTt7kooeKAWibqGs44Uwy9jJQHjTnHRK' }
5858 let hasResolved = false
5959
@@ -119,9 +119,9 @@
119119
120120 t.end()
121121 })
122122
123- tape('should wait on parent', async t => {
123+ tape.skip('should wait on parent', async t => {
124124 let r
125125 const lock = new Promise((resolve, reject) => {
126126 r = resolve
127127 })

Built with git-ssb-web