-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
515 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package compiler | ||
|
||
import "github.com/MontFerret/ferret/pkg/runtime" | ||
|
||
type Emitter struct { | ||
instructions []runtime.Instruction | ||
} | ||
|
||
func NewEmitter() *Emitter { | ||
return &Emitter{ | ||
instructions: make([]runtime.Instruction, 0, 8), | ||
} | ||
} | ||
|
||
func (e *Emitter) Size() int { | ||
return len(e.instructions) | ||
} | ||
|
||
// Emit emits an opcode with no arguments. | ||
func (e *Emitter) Emit(op runtime.Opcode) { | ||
e.EmitABC(op, 0, 0, 0) | ||
} | ||
|
||
// EmitA emits an opcode with a single destination register argument. | ||
func (e *Emitter) EmitA(op runtime.Opcode, dest runtime.Operand) { | ||
e.EmitABC(op, dest, 0, 0) | ||
} | ||
|
||
// EmitAB emits an opcode with a destination register and a single source register argument. | ||
func (e *Emitter) EmitAB(op runtime.Opcode, dest, src1 runtime.Operand) { | ||
e.EmitABC(op, dest, src1, 0) | ||
} | ||
|
||
// EmitABC emits an opcode with a destination register and two source register arguments. | ||
func (e *Emitter) EmitABC(op runtime.Opcode, dest, src1, src2 runtime.Operand) { | ||
e.instructions = append(e.instructions, runtime.Instruction{ | ||
Opcode: op, | ||
Operands: [3]runtime.Operand{dest, src1, src2}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.