@@ -5,20 +5,17 @@ import Mailbox from './mailbox'
55import Process from './process'
66import States from './states'
77import Scheduler from './scheduler'
8- import * as ErlangTypes from 'erlang-types'
8+ import { PID , Reference , Tuple } from 'erlang-types'
99
1010class ProcessSystem {
11- pids : Map < ErlangTypes . PID , Process >
12- mailboxes : Map < ErlangTypes . PID , Mailbox >
13- names : Map < any , ErlangTypes . PID >
14- links : Map < ErlangTypes . PID , Set < ErlangTypes . PID > >
15- monitors : Map <
16- ErlangTypes . Reference ,
17- { monitor : ErlangTypes . PID ; monitee : ErlangTypes . PID }
18- >
11+ pids : Map < PID , Process >
12+ mailboxes : Map < PID , Mailbox >
13+ names : Map < any , PID >
14+ links : Map < PID , Set < PID > >
15+ monitors : Map < Reference , { monitor : PID ; monitee : PID } >
1916 current_process : Process | null
2017 scheduler : Scheduler
21- suspended : Map < ErlangTypes . PID , Function >
18+ suspended : Map < PID , Function >
2219 main_process_pid : Process
2320
2421 constructor ( ) {
@@ -78,12 +75,12 @@ class ProcessSystem {
7875 }
7976 }
8077
81- link ( pid : ErlangTypes . PID ) {
78+ link ( pid : PID ) {
8279 this . links . get ( this . pid ( ) ) . add ( pid )
8380 this . links . get ( pid ) . add ( this . pid ( ) )
8481 }
8582
86- unlink ( pid : ErlangTypes . PID ) {
83+ unlink ( pid : PID ) {
8784 this . links . get ( this . pid ( ) ) . delete ( pid )
8885 this . links . get ( pid ) . delete ( this . pid ( ) )
8986 }
@@ -103,7 +100,7 @@ class ProcessSystem {
103100 }
104101 }
105102
106- monitor ( pid : ErlangTypes . PID ) {
103+ monitor ( pid : PID ) {
107104 const real_pid = this . pidof ( pid )
108105 const ref = this . make_ref ( )
109106
@@ -117,13 +114,13 @@ class ProcessSystem {
117114 } else {
118115 this . send (
119116 this . current_process . pid ,
120- new ErlangTypes . Tuple ( 'DOWN' , ref , pid , real_pid , Symbol . for ( 'noproc' ) )
117+ new Tuple ( 'DOWN' , ref , pid , real_pid , Symbol . for ( 'noproc' ) )
121118 )
122119 return ref
123120 }
124121 }
125122
126- demonitor ( ref : ErlangTypes . Reference ) {
123+ demonitor ( ref : Reference ) {
127124 if ( this . monitors . has ( ref ) ) {
128125 this . monitors . delete ( ref )
129126 return true
@@ -149,7 +146,7 @@ class ProcessSystem {
149146 linked : boolean ,
150147 monitored : boolean
151148 ) {
152- let newpid = new ErlangTypes . PID ( )
149+ let newpid = new PID ( )
153150 let mailbox = new Mailbox ( )
154151 let newproc = new Process ( newpid , fun , args , mailbox , this )
155152
@@ -169,7 +166,7 @@ class ProcessSystem {
169166 return newproc
170167 }
171168
172- remove_proc ( pid : ErlangTypes . PID , exitreason : any ) {
169+ remove_proc ( pid : PID , exitreason : any ) {
173170 this . pids . delete ( pid )
174171 this . unregister ( pid )
175172 this . scheduler . removePid ( pid )
@@ -184,7 +181,7 @@ class ProcessSystem {
184181 }
185182 }
186183
187- register ( name : any , pid : ErlangTypes . PID ) {
184+ register ( name : any , pid : PID ) {
188185 if ( ! this . names . has ( name ) ) {
189186 this . names . set ( name , pid )
190187 } else {
@@ -200,7 +197,7 @@ class ProcessSystem {
200197 return this . names . keys ( )
201198 }
202199
203- unregister ( pid : ErlangTypes . PID ) {
200+ unregister ( pid : PID ) {
204201 for ( let name of this . names . keys ( ) ) {
205202 if ( this . names . has ( name ) && this . names . get ( name ) === pid ) {
206203 this . names . delete ( name )
@@ -213,7 +210,7 @@ class ProcessSystem {
213210 }
214211
215212 pidof ( id : any ) {
216- if ( id instanceof ErlangTypes . PID ) {
213+ if ( id instanceof PID ) {
217214 return this . pids . has ( id ) ? id : null
218215 } else if ( id instanceof Process ) {
219216 return id . pid
@@ -274,14 +271,14 @@ class ProcessSystem {
274271 }
275272 }
276273
277- schedule ( fun : ( ) => any , pid ?: ErlangTypes . PID ) : void {
274+ schedule ( fun : ( ) => any , pid ?: PID ) : void {
278275 if ( this . current_process ) {
279276 const the_pid = pid != null ? pid : this . current_process . pid
280277 this . scheduler . schedule ( the_pid , fun )
281278 }
282279 }
283280
284- exit ( one : ErlangTypes . PID | any , two ?: any ) : void {
281+ exit ( one : PID | any , two ?: any ) : void {
285282 let pid = null
286283 let reason = null
287284 let process = null
@@ -298,7 +295,7 @@ class ProcessSystem {
298295 ) {
299296 this . mailboxes
300297 . get ( process . pid )
301- . deliver ( new ErlangTypes . Tuple ( States . EXIT , this . pid ( ) , reason ) )
298+ . deliver ( new Tuple ( States . EXIT , this . pid ( ) , reason ) )
302299 } else {
303300 process . signal ( reason )
304301 }
@@ -318,13 +315,7 @@ class ProcessSystem {
318315 if ( mons ) {
319316 this . send (
320317 mons [ 'monitor' ] ,
321- new ErlangTypes . Tuple (
322- 'DOWN' ,
323- ref ,
324- mons [ 'monitee' ] ,
325- mons [ 'monitee' ] ,
326- reason
327- )
318+ new Tuple ( 'DOWN' , ref , mons [ 'monitee' ] , mons [ 'monitee' ] , reason )
328319 )
329320 }
330321 }
@@ -395,12 +386,12 @@ class ProcessSystem {
395386 return real_pid != null
396387 }
397388
398- list ( ) : ErlangTypes . PID [ ] {
389+ list ( ) : PID [ ] {
399390 return Array . from ( this . pids . keys ( ) )
400391 }
401392
402- make_ref ( ) : ErlangTypes . Reference {
403- return new ErlangTypes . Reference ( )
393+ make_ref ( ) : Reference {
394+ return new Reference ( )
404395 }
405396}
406397
0 commit comments