Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.26.x' ]
go-version: [ '1.27.x' ]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Raised the minimum supported Go version to 1.27 and aligned CI with the new toolchain target
- Adopted Go 1.21+/1.27 standard-library idioms across the codebase (`slices`, `maps`, `min`, `strings.Cut`, `errors.AsType`, range-over-int)
- Split the monolithic parser into focused files (labels, statements, macros, operands, effective addresses) and de-duplicated the size-validation helper

## [1.3.2] - 2026-06-13

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions additional_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func TestFileAndFormatWrappers(t *testing.T) {

elfSrc := ".org 0x1000\nstart:\n.byte 0xAA\nMOVEQ #1,D0\n"
for name, fn := range map[string]func() ([]byte, error){
"AssembleELF": func() ([]byte, error) { return AssembleELF(strings.NewReader(elfSrc)) },
"AssembleBytesELF": func() ([]byte, error) { return AssembleBytesELF([]byte(elfSrc)) },
"AssembleELF": func() ([]byte, error) { return AssembleELF(strings.NewReader(elfSrc)) },
"AssembleBytesELF": func() ([]byte, error) { return AssembleBytesELF([]byte(elfSrc)) },
"AssembleBytesELFWithOptions": func() ([]byte, error) {
return AssembleBytesELFWithOptions([]byte(".org 0x1000\n.byte FOO\n"), opts)
},
"AssembleStringELF": func() ([]byte, error) { return AssembleStringELF(elfSrc) },
"AssembleFileELF": func() ([]byte, error) { return AssembleFileELF(writeTempSource(t, elfSrc)) },
"AssembleStringELF": func() ([]byte, error) { return AssembleStringELF(elfSrc) },
"AssembleFileELF": func() ([]byte, error) { return AssembleFileELF(writeTempSource(t, elfSrc)) },
"AssembleFileELFWithOptions": func() ([]byte, error) {
return AssembleFileELFWithOptions(writeTempSource(t, ".org 0x1000\n.byte FOO\n"), opts)
},
Expand Down
6 changes: 5 additions & 1 deletion canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ func formatIndexRegister(ix instructions.EAIndex) string {
if ix.IsA {
reg = formatAddrRegister(ix.Reg)
}
out := reg + "." + map[bool]string{false: "W", true: "L"}[ix.Long]
width := "W"
if ix.Long {
width = "L"
}
out := reg + "." + width
if ix.Scale > 1 {
out += fmt.Sprintf("*%d", ix.Scale)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jenska/m68kasm

go 1.26
go 1.27
2 changes: 1 addition & 1 deletion internal/asm/asm_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func buildBenchmarkSource(blocks int) string {
sb.Grow(blocks * 64)

sb.WriteString(".org 0\n")
for i := 0; i < blocks; i++ {
for i := range blocks {
sb.WriteString(fmt.Sprintf("label%d: moveq #%d,d0\n", i, i%8))
sb.WriteString("nop\n")

Expand Down
14 changes: 6 additions & 8 deletions internal/asm/assemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package asm
import (
"fmt"
"io"
"slices"

"github.com/jenska/m68kasm/internal/asm/instructions"
)
Expand Down Expand Up @@ -169,14 +170,11 @@ func selectForm(def *instructions.InstrDef, ins *Instr, actual []instructions.Op
return nil, fmt.Errorf("no form matches operands/size for %s", def.Mnemonic)
}

func sizeAllowed(list []instructions.Size, sz instructions.Size) bool {
// Most forms allow 1-3 sizes, so linear search is efficient here
for _, v := range list {
if v == sz {
return true
}
}
return false
// sizeAllowed reports whether sz is permitted by allowed. An empty allowed list
// means the form places no constraint on the size. Forms allow 1-3 sizes, so a
// linear scan is the right call here.
func sizeAllowed(allowed []instructions.Size, sz instructions.Size) bool {
return len(allowed) == 0 || slices.Contains(allowed, sz)
}

func operandKinds(a *instructions.Args) []instructions.OperandKind {
Expand Down
9 changes: 5 additions & 4 deletions internal/asm/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package asm
import (
"encoding/binary"
"fmt"
"slices"
)

const (
Expand Down Expand Up @@ -93,9 +94,9 @@ func FormatELFWithLabels(code []byte, origin uint32, labels []DefinedLabel) []by
entry: origin,
segmentAddr: origin,
textAddr: origin,
textBytes: append([]byte(nil), code...),
textBytes: slices.Clone(code),
textPresent: len(code) > 0,
definedLabels: append([]DefinedLabel(nil), labels...),
definedLabels: slices.Clone(labels),
}
for i := range layout.definedLabels {
layout.definedLabels[i].Section = SectionText
Expand Down Expand Up @@ -123,7 +124,7 @@ func assembleELFLayout(p *Program) (elfLayout, error) {
layout := elfLayout{
entry: p.Origin,
segmentAddr: p.Origin,
definedLabels: append([]DefinedLabel(nil), p.DefinedLabels...),
definedLabels: slices.Clone(p.DefinedLabels),
}

var initializedEnd uint32 = p.Origin
Expand Down Expand Up @@ -436,7 +437,7 @@ func (t *elfStringTable) add(name string) uint32 {
}

func (t *elfStringTable) bytes() []byte {
return append([]byte(nil), t.buf...)
return slices.Clone(t.buf)
}

func elfStInfo(bind, typ byte) byte {
Expand Down
2 changes: 1 addition & 1 deletion internal/asm/elf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func readSectionHeaders(t *testing.T, elf []byte) []elfSectionHeader {
shoff := int(binary.BigEndian.Uint32(elf[32:36]))
shnum := int(binary.BigEndian.Uint16(elf[48:50]))
headers := make([]elfSectionHeader, shnum)
for i := 0; i < shnum; i++ {
for i := range shnum {
base := shoff + i*sectionHeaderSize
headers[i] = elfSectionHeader{
name: binary.BigEndian.Uint32(elf[base:]),
Expand Down
9 changes: 5 additions & 4 deletions internal/asm/instructions/table.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package instructions

import "sync"
import (
"maps"
"sync"
)

// Table is a read-only lookup structure for instruction definitions.
//
Expand Down Expand Up @@ -37,8 +40,6 @@ func (t *Table) Lookup(mnemonic string) *InstrDef {

func cloneDefs(src map[string]*InstrDef) map[string]*InstrDef {
dst := make(map[string]*InstrDef, len(src))
for k, v := range src {
dst[k] = v
}
maps.Copy(dst, src)
return dst
}
Loading
Loading