!Simulator methodsFor: 'instance initialization'! init args := Arguments new. tasks := Dictionary new. mem := VMemory new: (args algorithm). cmds := CommandQueue new. (args args) do: [ :file | cmds fileIn: file ]. (args args isEmpty) ifTrue: [ cmds fileIn: '-' ]. n := 0. lines := 0. rws := 0. ! ! !Simulator methodsFor: 'task manipulation'! start: pid tasks at: pid put: Task new. ! terminate: pid (tasks at: pid ifAbsent: [ ^self error: 'Trying to remove a non-existant process']) terminate. tasks removeKey: pid. ! ! !Simulator methodsFor: 'variable access'! memory ^mem ! tasks ^tasks ! args ^args ! ! !Simulator methodsFor: 'command aliases'! S: pid (args verbose) ifTrue: [ ('Starting task #%1' bindWith: pid) displayNl. ]. self start: pid. ! T: pid (args verbose) ifTrue: [ ('Killing task #%1' bindWith: pid) displayNl. ]. self terminate: pid. ! R: pid A: addr (args verbose) ifTrue: [ ('Task #%1 reading address %2' bindWith: pid with: addr) displayNl. ]. n := n + 1. (tasks at: pid ifAbsent: [ ^self error: 'Invalid PID']) read: addr ! W: pid A: addr (args verbose) ifTrue: [ ('Task #%1 writing address %2' bindWith: pid with: addr) displayNl. ]. n := n + 1. (tasks at: pid ifAbsent: [ ^self error: 'Invalid PID']) write: addr ! ! !Simulator methodsFor: 'simulation'! printOn: aStream 'Simulation summary' displayOn: aStream. aStream nl. ('Page Size: %1' bindWith: args pagesize) displayOn: aStream. aStream nl. ('# page frames: %1' bindWith: args numpages) displayOn: aStream. aStream nl. ('Replacement Algorithm: %1' bindWith: args algorithm) displayOn: aStream. aStream nl. ('Lines processed: %1' bindWith: lines) displayOn: aStream. aStream nl. ('Memory operations: %1' bindWith: rws) displayOn: aStream. aStream nl. ('Faults: %1' bindWith: mem faults) displayOn: aStream. aStream nl. ! run cmds do: [ :msg | lines := lines + 1. (n=args timestep) ifTrue: [ mem timestep. rws := rws + n. n := 0 ]. msg sendTo: self ]. self printNl. ! !