Skip to content

Commit

Permalink
Make Ref private.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleury committed Jan 15, 2024
1 parent eb0f7a5 commit 4be476e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (g *Machine) RunProgram(program []Word) {
g.Run()
}

type Ref struct {
type ref struct {
Name string
Line int
Address Word
Expand Down Expand Up @@ -242,7 +242,7 @@ func (t *symbolTable) lookup(name string) (Word, bool) {

func Assemble(reader io.Reader) ([]Word, error) {
program := []Word{}
refs := []Ref{}
refs := []ref{}
symbols := newSymbolTable()

l, err := lexer.New(reader)
Expand Down Expand Up @@ -289,7 +289,7 @@ func Assemble(reader io.Reader) ([]Word, error) {
return program, nil
}

func assembleOpcodeStatement(stmt *ast.OpcodeStatement, program []Word, refs []Ref) ([]Word, []Ref, error) {
func assembleOpcodeStatement(stmt *ast.OpcodeStatement, program []Word, refs []ref) ([]Word, []ref, error) {
opcode, ok := opcodes[stmt.TokenLiteral()]
if !ok {
return nil, nil, fmt.Errorf("%w: %s at line %d", ErrUndefinedInstruction, stmt.TokenLiteral(), stmt.Token.Line)
Expand All @@ -314,12 +314,12 @@ func assembleOpcodeStatement(stmt *ast.OpcodeStatement, program []Word, refs []R
if !slices.Contains([]Word{OpSETA, OpJUMP, OpJXNZ}, opcode) {
return nil, nil, fmt.Errorf("%w: %s at line %d", ErrInvalidOperand, stmt.TokenLiteral(), stmt.Token.Line)
}
ref := Ref{
rf := ref{
Name: operand.TokenLiteral(),
Line: operand.Token.Line,
Address: Word(len(program)),
}
refs = append(refs, ref)
refs = append(refs, rf)
program = append(program, Word(0))
case *ast.IntegerLiteral:
if !slices.Contains([]Word{OpSETA, OpSETX, OpSETY, OpJUMP}, opcode) {
Expand Down

0 comments on commit 4be476e

Please sign in to comment.