169 lines
4.4 KiB
Markdown
169 lines
4.4 KiB
Markdown
# HateLace - A Simple Computer
|
|
|
|
```mermaid
|
|
classDiagram
|
|
class Computer {
|
|
- Memory memory
|
|
- Program program
|
|
+ Computer(Memory Memory)
|
|
+ void load(Program program)
|
|
+ void run()
|
|
}
|
|
class Memory {
|
|
+ abstract Word read(Address address)
|
|
+ abstract int size()
|
|
+ abstract void write(Address address, Word data)
|
|
+ abstract void dump()
|
|
}
|
|
class Program
|
|
class ProgramCounter {
|
|
- int PC
|
|
- int SysTick
|
|
- boolean haltFlag
|
|
+ ProgramCounter()
|
|
+ ProgramCounter(int PC)
|
|
+ int getPC()
|
|
+ int getSysTicks()
|
|
+ int incPC()
|
|
+ int setPC(int PC)
|
|
+ boolean halted()
|
|
+ void halt()
|
|
}
|
|
class Instruction {
|
|
+ abstract void execute(Memory memory, ProgramCounter pc)
|
|
# abstract String opcode()
|
|
# abstract Object[] operands()
|
|
+ abstract String toString()
|
|
}
|
|
class ArrayList
|
|
class Word {
|
|
+ abstract <T> T getValue()
|
|
+ abstract Word add(Word other)
|
|
+ abstract Word subtract(Word other)
|
|
+ abstract Word multiply(Word other)
|
|
+ abstract Word divide(Word other)
|
|
+ abstract String toString()
|
|
+ abstract boolean equals(Object other)
|
|
}
|
|
class Address {
|
|
- int address
|
|
+ Address(int address)
|
|
+ int getAddress()
|
|
+ String toString()
|
|
}
|
|
class LongWord {
|
|
- Long value
|
|
+ LongWord(Long value)
|
|
+ Long getValue()
|
|
+ Word add(Word other)
|
|
+ Word subtract(Word other)
|
|
+ Word multiply(Word other)
|
|
+ Word divide(Word other)
|
|
+ String toString()
|
|
+ boolean equals(Object other)
|
|
}
|
|
class Add {
|
|
- Address src
|
|
- Word imm
|
|
- Address dest
|
|
+ Add(Address src, Word imm, Address dest)
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
class Copy {
|
|
- Word imm
|
|
- Address dest
|
|
+ Copy(Word imm, Address dest)
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
class Halt {
|
|
+ Halt()
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
class Jump {
|
|
- int index
|
|
+ Jump(int index)
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
class JumpEq {
|
|
- int index
|
|
- Address src
|
|
- Word imm
|
|
+ JumpEq(int index, Address src, Word imm)
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
class Mul {
|
|
- Address src1
|
|
- Address src2
|
|
- Address dest
|
|
+ Mul(Address src1, Address src2, Address dest)
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
class Print {
|
|
- Address address
|
|
+ Print(Address address)
|
|
+ void execute(Memory memory, ProgramCounter PC)
|
|
+ String opcode()
|
|
+ Object[] operands()
|
|
+ String toString()
|
|
}
|
|
Memory <|-- LongMemory
|
|
Word <|-- LongWord
|
|
Program <-- ArrayList
|
|
Program --|> Instruction
|
|
Program : +toString()
|
|
Computer --> Memory
|
|
Computer --> Program
|
|
Computer --> ProgramCounter
|
|
ProgramCounter --> Program
|
|
ProgramCounter --> Instruction
|
|
ProgramCounter : +toString()
|
|
Instruction : +toString()
|
|
Instruction <|-- Add
|
|
Instruction <|-- Copy
|
|
Instruction <|-- Halt
|
|
Instruction <|-- Jump
|
|
Instruction <|-- JumpEq
|
|
Instruction <|-- Mul
|
|
Instruction <|-- Print
|
|
Add --> Address
|
|
```
|
|
|
|
```mermaid
|
|
sequenceDiagram
|
|
participant Computer
|
|
participant Program
|
|
participant Memory
|
|
participant ProgramCounter
|
|
participant Instruction
|
|
|
|
Computer -> Program: load(program)
|
|
loop Program Execution
|
|
Program -> Computer: run()
|
|
loop Instructions Execution
|
|
Computer -> ProgramCounter: incPC()
|
|
ProgramCounter -> Program: getPC()
|
|
Program -> Program: executeInstruction()
|
|
Program -> Instruction: execute(memory, PC)
|
|
Instruction -> Memory: read/write(address)
|
|
Program -> ProgramCounter: incPC()
|
|
end
|
|
end
|
|
```
|