diff --git a/lib/vaporware/compiler/assembler/elf/section/text.rb b/lib/vaporware/compiler/assembler/elf/section/text.rb index 3f1777b..e660b6e 100644 --- a/lib/vaporware/compiler/assembler/elf/section/text.rb +++ b/lib/vaporware/compiler/assembler/elf/section/text.rb @@ -43,7 +43,7 @@ def opecode(op, *operands) when "ret" [0xc3] else - raise Compiler::Assembler::ERROR + raise Vaporware::Compiler::Assembler::ELF::Error, "yet implemented operations: #{op}" end end @@ -99,16 +99,18 @@ def pop(operands) def reg(r) case r - in "rsp" + when "rsp" 0xec - in "rbp" + when "rbp" 0x5e - in "rax" + when "rax" 0x29 - in "rdi" + when "rdi" 0xf8 - in /\d+/ + when /\d+/ ("%02x" % r).to_i(16) + else + raise Vaporware::Compiler::Assembler::ELF::Error, "yet implemented operand address: #{r}" end end end diff --git a/sig/vaporware/compiler/assembler/elf.rbs b/sig/vaporware/compiler/assembler/elf.rbs index ba3e3cb..dd644c5 100644 --- a/sig/vaporware/compiler/assembler/elf.rbs +++ b/sig/vaporware/compiler/assembler/elf.rbs @@ -1,4 +1,3 @@ class Vaporware::Compiler::Assembler::ELF - class Error - end + Error: singleton(StandardError) end diff --git a/sig/vaporware/compiler/assembler/elf/section/text.rbs b/sig/vaporware/compiler/assembler/elf/section/text.rbs index 26926ac..bc41571 100644 --- a/sig/vaporware/compiler/assembler/elf/section/text.rbs +++ b/sig/vaporware/compiler/assembler/elf/section/text.rbs @@ -3,18 +3,18 @@ class Vaporware::Compiler::Assembler::ELF::Section::Text REGISTER_CODE: Hash[Symbol, Integer] OPECODE: Hash[Symbol, Integer] - @bytes: Array[untyped]? + @bytes: Array[untyped] - attr_reader size: Integer attr_reader offset: Integer def initialize: () -> void def assemble!: (String) -> void def align!: (Integer) -> void + def build: () -> String private - def opecode: ((String | Symbol), Array[String]) -> (Array[Integer] | nil) + def opecode: ((String | Symbol)?, *String) -> Array[Integer] def mov: ((String | Symbol), Array[String]) -> Array[Integer] def calc: ((String | Symbol), Array[String]) -> Array[Integer] def push: (Array[String]) -> Array[Integer]