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/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["3.0", "3.1", "3.2", "3.3"]
ruby-version: ["3.1", "3.2", "3.3", "3.4"]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["3.0", "3.1", "3.2", "3.3"]
ruby-version: ["3.1", "3.2", "3.3", "3.4"]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sorbet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["3.0", "3.1", "3.2", "3.3"]
ruby-version: ["3.1", "3.2", "3.3", "3.4"]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_gem:
rubocop-shopify: rubocop.yml

require: rubocop-rspec
plugins: rubocop-rspec

AllCops:
Include:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.5
3.4.3
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ group :development do
end

gemspec

gem "tapioca", "~> 0.16.11"
101 changes: 76 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,111 @@ PATH
remote: .
specs:
avruby (0.5.1)
benchmark (~> 0.4.0)
intel_hex (~> 0.6.0)
rdoc (~> 6.13.1)
sorbet-runtime (~> 0.5.3)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
byebug (11.1.3)
diff-lcs (1.5.1)
ast (2.4.3)
benchmark (0.4.0)
byebug (12.0.0)
date (3.4.1)
diff-lcs (1.6.1)
erubi (1.13.1)
intel_hex (0.6.0)
json (2.7.5)
language_server-protocol (3.17.0.3)
parallel (1.26.3)
parser (3.3.5.1)
json (2.11.3)
language_server-protocol (3.17.0.4)
lint_roller (1.1.0)
logger (1.7.0)
netrc (0.11.0)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
prism (1.4.0)
psych (5.2.3)
date
stringio
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.9.2)
rbi (0.3.2)
prism (~> 1.0)
rbs (>= 3.4.4)
sorbet-runtime (>= 0.5.9204)
rbs (3.9.2)
logger
rdoc (6.13.1)
psych (>= 4.0.0)
regexp_parser (2.10.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.68.0)
rspec-support (3.13.2)
rubocop (1.75.4)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.44.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.33.0)
parser (>= 3.3.1.0)
rubocop-rspec (3.2.0)
rubocop (~> 1.61)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.44.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-rspec (3.6.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-shopify (2.9.0)
rubocop (~> 1.33)
ruby-progressbar (1.13.0)
sorbet (0.5.11631)
sorbet-static (= 0.5.11631)
sorbet-runtime (0.5.11631)
sorbet-static (0.5.11631-universal-darwin)
sorbet-static (0.5.11631-x86_64-linux)
unicode-display_width (2.6.0)
sorbet (0.5.12043)
sorbet-static (= 0.5.12043)
sorbet-runtime (0.5.12043)
sorbet-static (0.5.12043-universal-darwin)
sorbet-static (0.5.12043-x86_64-linux)
sorbet-static-and-runtime (0.5.12043)
sorbet (= 0.5.12043)
sorbet-runtime (= 0.5.12043)
spoom (1.6.1)
erubi (>= 1.10.0)
prism (>= 0.28.0)
rbi (>= 0.2.3)
sorbet-static-and-runtime (>= 0.5.10187)
thor (>= 0.19.2)
stringio (3.1.7)
tapioca (0.16.11)
benchmark
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (~> 0.2)
sorbet-static-and-runtime (>= 0.5.11087)
spoom (>= 1.2.0)
thor (>= 1.2.0)
yard-sorbet
thor (1.3.2)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
yard (0.9.37)
yard-sorbet (0.9.0)
sorbet-runtime
yard

PLATFORMS
x86_64-darwin-19
Expand All @@ -71,6 +121,7 @@ DEPENDENCIES
rubocop-rspec
rubocop-shopify (~> 2.9.0)
sorbet
tapioca (~> 0.16.11)

BUNDLED WITH
2.5.19
2 changes: 2 additions & 0 deletions avruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Gem::Specification.new do |s|
s.executables = ["avruby_shell"]
s.require_path = "lib"

s.add_dependency("benchmark", "~> 0.4.0")
s.add_dependency("intel_hex", "~> 0.6.0")
s.add_dependency("rdoc", "~> 6.13.1")
s.add_dependency("sorbet-runtime", "~> 0.5.3")
s.metadata["rubygems_mfa_required"] = "true"
end
18 changes: 9 additions & 9 deletions lib/avr/opcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def self.near_relative_pc
.new(:near_relative_pc)
.formatter { |arg| format(".%+d", 2 * arg.value) }
.validator { |arg| NearRelativePcExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= -64 && arg.value <= 63 }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(-64, 63) }
end

sig { returns(OpcodeArgumentDefinition) }
Expand All @@ -144,7 +144,7 @@ def self.far_relative_pc
.new(:far_relative_pc)
.formatter { |arg| format(".%+d", 2 * arg.value) }
.validator { |arg| FarRelativePcExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= -2048 && arg.value <= 2047 }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(-2048, 2047) }
end

sig { returns(OpcodeArgumentDefinition) }
Expand All @@ -153,23 +153,23 @@ def self.absolute_pc
.new(:absolute_pc)
.formatter { |arg| format("0x%04x", 2 * arg.value) }
.validator { |arg| AbsolutePcExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= 0 && arg.value <= (2**22).to_i - 1 }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(0, (2**22).to_i - 1) }
end

sig { returns(OpcodeArgumentDefinition) }
def self.byte
OpcodeArgumentDefinition
.new(:byte, format: "0x%02x")
.validator { |arg| ByteConstantExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= 0x00 && arg.value <= 0xff }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(0x00, 0xff) }
end

sig { returns(OpcodeArgumentDefinition) }
def self.word
OpcodeArgumentDefinition
.new(:word, format: "0x%04x")
.validator { |arg| WordConstantExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= 0x0000 && arg.value <= 0xffff }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(0x0000, 0xffff) }
end

sig { returns(OpcodeArgumentDefinition) }
Expand Down Expand Up @@ -198,23 +198,23 @@ def self.register_with_bit_number
.new(:register_with_bit_number)
.validator { |arg| RegisterExpected unless arg.register.is_a?(Register) }
.validator { |arg| BitNumberExpected unless arg.bit_number.is_a?(Integer) }
.validator { |arg| ConstantOutOfRange unless arg.bit_number >= 0 && arg.bit_number <= 7 }
.validator { |arg| ConstantOutOfRange unless arg.bit_number.between?(0, 7) }
end

sig { returns(OpcodeArgumentDefinition) }
def self.io_address
OpcodeArgumentDefinition
.new(:io_address, format: "0x%02x")
.validator { |arg| IoAddressExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= 0 && arg.value <= 63 }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(0, 63) }
end

sig { returns(OpcodeArgumentDefinition) }
def self.lower_io_address
OpcodeArgumentDefinition
.new(:lower_io_address, format: "0x%02x")
.validator { |arg| IoAddressExpected unless arg.is_a?(Value) }
.validator { |arg| ConstantOutOfRange unless arg.value >= 0 && arg.value <= 31 }
.validator { |arg| ConstantOutOfRange unless arg.value.between?(0, 31) }
end

sig { returns(OpcodeArgumentDefinition) }
Expand Down Expand Up @@ -316,7 +316,7 @@ def self.stack_push(cpu, byte)
sig { params(cpu: CPU, word: Integer).returns(Integer) }
def self.stack_push_word(cpu, word)
stack_push(cpu, (word & 0xff00) >> 8)
stack_push(cpu, (word & 0x00ff))
stack_push(cpu, word & 0x00ff)
end

sig { params(cpu: CPU).returns(Integer) }
Expand Down
2 changes: 1 addition & 1 deletion lib/avr/opcode/operand_parsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.from_twos_complement(value, bits)
def self.to_twos_complement(value, bits)
return value unless value.negative?

((value.magnitude) ^ ((1 << bits) - 1)) + 1
(value.magnitude ^ ((1 << bits) - 1)) + 1
end

sig { params(k_in: Integer).returns(Integer) }
Expand Down
2 changes: 1 addition & 1 deletion lib/avr/register/register_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def register_values

def print_status
@register_list.each_slice(8) do |slice|
puts slice.map { |name| format("%10s", "#{name}=#{@registers[name].value_hex}") }.join + "\n"
puts slice.map { |name| "#{name}=#{@registers[name].value_hex}" }.join + "\n"
end
end

Expand Down
22 changes: 11 additions & 11 deletions spec/avr/opcode/branch/brbc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

RSpec.describe(AVR::Opcode) do
describe "brbc" do
include_examples "opcode", :brbc
it_behaves_like "opcode", :brbc do
it "branches if the bit is set" do
cpu.sreg.Z = true
cpu.instruction(:brbc, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(1))
cpu.sreg.Z = false # we're not supposed to have changed Z
end

it "branches if the bit is set" do
cpu.sreg.Z = true
cpu.instruction(:brbc, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(1))
cpu.sreg.Z = false # we're not supposed to have changed Z
end

it "does not branch if the bit is clear" do
cpu.instruction(:brbc, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(21))
it "does not branch if the bit is clear" do
cpu.instruction(:brbc, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(21))
end
end
end
end
22 changes: 11 additions & 11 deletions spec/avr/opcode/branch/brbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

RSpec.describe(AVR::Opcode) do
describe "brbs" do
include_examples "opcode", :brbs
it_behaves_like "opcode", :brbs do
it "branches if the bit is set" do
cpu.sreg.Z = true
cpu.instruction(:brbs, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(21))
cpu.sreg.Z = false # we're not supposed to have changed Z
end

it "branches if the bit is set" do
cpu.sreg.Z = true
cpu.instruction(:brbs, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(21))
cpu.sreg.Z = false # we're not supposed to have changed Z
end

it "does not branch if the bit is clear" do
cpu.instruction(:brbs, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(1))
it "does not branch if the bit is clear" do
cpu.instruction(:brbs, AVR::Value.new(cpu.sreg.fetch_bit(:Z)), AVR::Value.new(+20)).execute
expect(cpu.pc).to(eq(1))
end
end
end
end
26 changes: 13 additions & 13 deletions spec/avr/opcode/branch/call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

RSpec.describe(AVR::Opcode) do
describe "call" do
include_examples "opcode", :call
it_behaves_like "opcode", :call do
it "pushes the current PC onto the stack" do
previous_sp = cpu.sp.value
cpu.pc = 0x1122
cpu.instruction(:call, AVR::Value.new(0x1234)).execute
expect(cpu.sp.value).to(eq(previous_sp - 2))
expect(cpu.sram.memory[cpu.sp.value + 1].value).to(eq(0x22 + 2))
expect(cpu.sram.memory[cpu.sp.value + 2].value).to(eq(0x11))
end

it "pushes the current PC onto the stack" do
previous_sp = cpu.sp.value
cpu.pc = 0x1122
cpu.instruction(:call, AVR::Value.new(0x1234)).execute
expect(cpu.sp.value).to(eq(previous_sp - 2))
expect(cpu.sram.memory[cpu.sp.value + 1].value).to(eq(0x22 + 2))
expect(cpu.sram.memory[cpu.sp.value + 2].value).to(eq(0x11))
end

it "sets PC to the specified constant" do
cpu.instruction(:call, AVR::Value.new(0x1234)).execute
expect(cpu.pc).to(eq(0x1234))
it "sets PC to the specified constant" do
cpu.instruction(:call, AVR::Value.new(0x1234)).execute
expect(cpu.pc).to(eq(0x1234))
end
end
end
end
Loading
Loading