Sha256: e5c4a3af4c5ce7a57432291c9e2876ccb6d56492e02773e4cb4ef9ae9ef854c7

Contents?: true

Size: 564 Bytes

Versions: 1

Compression:

Stored size: 564 Bytes

Contents

# frozen_string_literal: true

require_relative '../command'
require_relative '../assembler/translator'

module Hackasm
  module Commands
    class Asm2Binary < Hackasm::Command
      FILE_NAME = "a.hack".freeze

      def initialize(file, options)
        @file = file
        @options = options
      end

      def execute(input: $stdin, output: $stdout)
        assembler_code = File.read(@file)

        binary = Assembler::Translator.new(assembler_code).translate

        output.puts binary
        File.write(FILE_NAME, binary)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackasm-0.1.0 lib/hackasm/commands/asm2binary.rb