Class: RMasm::Data

Inherits:
Object show all
Defined in:
lib/rmasm/data_core.rb

Overview

RMasm::Data represents a multiple data declaration in a program. Internally RMasm::Data generate corresponding DataItem directives to the args passed at initialization

Constant Summary collapse

DEFAULT =
DataDefault.new

Class Method Summary collapse

Class Method Details

.default(*args) ⇒ Object



285
286
287
288
289
290
# File 'lib/rmasm/data_core.rb', line 285

def self.default(*args)
  return DEFAULT if args.empty?
  return Report.error(:ARGS, args.length, "1", "data.default") if args.length != 1
  # report an error if any arguments are passed to the data directive
  DEFAULT.value = args[0]
end

.default=(arg) ⇒ Object



292
293
294
# File 'lib/rmasm/data_core.rb', line 292

def self.default=(arg)
  DEFAULT.value = arg
end

.fetch(type, *args) ⇒ Object

Send this directive to the assembler This method can be overriden by a directive in order to fetch several directive to the assembler



274
275
276
277
278
279
280
281
282
283
# File 'lib/rmasm/data_core.rb', line 274

def self.fetch(type, *args)
  result = []
  args.each do |arg|
    # Fetch individually data
    instr = DataItem.fetch(type, arg)
    result << instr
    instr.fetch
  end
  result
end

.try_declare_data(owner, type, *args) ⇒ Object

This method try to find if type is a data_type, and if yes, this command emit a declare data directive and return the data directive otherwise, this command return nil



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/rmasm/data_core.rb', line 299

def self.try_declare_data(owner, type, *args)
  # if owner is not a module, then step back to the class
  if !owner.is_a?(Module)
    owner = owner.class
  end

  # Try to get the constant
  const_found = owner.dyn_const_get type

  # Check that this constant is a DataType
  if !const_found.nil? && const_found.is_a?(Class) && const_found.ancestors.include?(DataType)
    # If yes, then emit a Data directive to the assembler
    return Data.fetch(const_found, *args)
  end
  return nil
end