Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dim13 committed May 4, 2023
1 parent 22b705b commit 93784ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
11 changes: 5 additions & 6 deletions core.go
Expand Up @@ -17,12 +17,11 @@ type Console interface {

// Core of J1 Forth CPU
//
// 33 deep × 16 bit data stack
// 32 deep × 16 bit return stack
// 13 bit program counter
// memory is 16 bit wide and addressed by bytes
// 0..0x3fff RAM, 0x4000..0x7fff mem-mapped I/O
//
// 33 deep × 16 bit data stack
// 32 deep × 16 bit return stack
// 13 bit program counter
// memory is 16 bit wide and addressed by bytes
// 0..0x3fff RAM, 0x4000..0x7fff mem-mapped I/O
type Core struct {
memory [8192]uint16 // 0..0x3fff RAM, 0x4000..0x7fff mem-mapped I/O
pc uint16 // 13 bit
Expand Down
49 changes: 22 additions & 27 deletions parse.go
Expand Up @@ -33,10 +33,9 @@ type Instruction interface {

// Literal value
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── value
// └─────────────────────────────────────────────── 1
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── value
// └─────────────────────────────────────────────── 1
type Literal uint16

func newLiteral(v uint16) Literal { return Literal(v &^ uint16(1<<15)) }
Expand All @@ -47,10 +46,9 @@ func (v Literal) compile() uint16 { return v.value() | (1 << 15) }

// Jump instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 0 0
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 0 0
type Jump uint16

func newJump(v uint16) Jump { return Jump(v &^ uint16(7<<13)) }
Expand All @@ -61,10 +59,9 @@ func (v Jump) compile() uint16 { return v.value() }

// Conditional jump instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 0 1
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 0 1
type Conditional uint16

func newConditional(v uint16) Conditional { return Conditional(v &^ uint16(7<<13)) }
Expand All @@ -75,10 +72,9 @@ func (v Conditional) compile() uint16 { return v.value() | (1 << 13) }

// Call instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 1 0
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 1 0
type Call uint16

func newCall(v uint16) Call { return Call(v &^ uint16(7<<13)) }
Expand All @@ -89,17 +85,16 @@ func (v Call) compile() uint16 { return v.value() | (2 << 13) }

// ALU instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──┴── dstack ±
// │ │ │ │ │ │ │ │ │ │ │ │ └──┴──────── rstack ±
// │ │ │ │ │ │ │ │ │ │ │ └────────────── unused
// │ │ │ │ │ │ │ │ │ │ └───────────────── N → [T]
// │ │ │ │ │ │ │ │ │ └──────────────────── T → R
// │ │ │ │ │ │ │ │ └─────────────────────── T → N
// │ │ │ │ └──┴──┴──┴────────────────────────── Tʹ
// │ │ │ └────────────────────────────────────── R → PC
// └──┴──┴───────────────────────────────────────── 0 1 1
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──┴── dstack ±
// │ │ │ │ │ │ │ │ │ │ │ │ └──┴──────── rstack ±
// │ │ │ │ │ │ │ │ │ │ │ └────────────── unused
// │ │ │ │ │ │ │ │ │ │ └───────────────── N → [T]
// │ │ │ │ │ │ │ │ │ └──────────────────── T → R
// │ │ │ │ │ │ │ │ └─────────────────────── T → N
// │ │ │ │ └──┴──┴──┴────────────────────────── Tʹ
// │ │ │ └────────────────────────────────────── R → PC
// └──┴──┴───────────────────────────────────────── 0 1 1
type ALU struct {
Opcode uint16
RtoPC bool
Expand Down

0 comments on commit 93784ef

Please sign in to comment.