module XfOOrth

XfOOrth - the module name space of the fOOrth language system.

Constants

DCC_VAL

The procedure used for dot colon colon instance vals

DCC_VAR

The procedure used for dot colon colon instance vars

DC_VAL

The procedure used for dot colon instance vals

DC_VAR

The procedure used for dot colon instance vars

DegreesPerRadian

The number of degrees in one radian.

Local_Val_Action

The lambda used to define local values. fOOrth language definition is:

[n] val: lv [], lv = n
Local_Var_Action

The lambda used to define local variables. fOOrth language definition is:

[n] var: lv [], lv = [n]
TimeFormat

The user facing format used for date/time display.

VERSION

The version string for fOOrth.

Public Class Methods

add_common_compiler_locals(vm, ctrl) click to toggle source

Set up the common local defns.
Parameters:

  • vm - The current virtual machine instance.

  • ctrl - A list of valid start controls.


Endemic Code Smells

  • :reek:TooManyStatements

# File lib/fOOrth/library/compile_library.rb, line 193
def self.add_common_compiler_locals(vm, ctrl)
  context = vm.context

  #Support for local data.
  context.create_local_method('var:', LocalSpec, [:immediate], &Local_Var_Action)
  context.create_local_method('val:', LocalSpec, [:immediate], &Local_Val_Action)

  #Support for super methods.
  context.create_local_method('super', LocalSpec, [:immediate],
    &lambda {|vm| vm << 'super(vm); ' })

  #The standard end-compile adapter word: ';' semi-colon.
  context.create_local_method(';', LocalSpec, [:immediate], &lambda {|vm|
    vm.clear_cast
    vm.end_compile_mode([ctrl])
  })
end
add_dot_colon_colon_locals(context) click to toggle source

Add locals specific to a dot colon colon methods.

# File lib/fOOrth/library/compile_library.rb, line 180
def self.add_dot_colon_colon_locals(context)
  context.create_local_method('var@:', LocalSpec, [:immediate], &DCC_VAR)
  context.create_local_method('val@:', LocalSpec, [:immediate], &DCC_VAL)
end
add_dot_colon_locals(context) click to toggle source

Add locals specific to a dot colon methods.

# File lib/fOOrth/library/compile_library.rb, line 122
def self.add_dot_colon_locals(context)
  context.create_local_method('var@:', LocalSpec, [:immediate], &DC_VAR)
  context.create_local_method('val@:', LocalSpec, [:immediate], &DC_VAL)
end
announcements() click to toggle source

Display the start-up messages for the interactive session.

# File lib/fOOrth/main.rb, line 57
def self.announcements
  puts "Welcome to fOOrth: fO(bject)O(riented)rth."
  puts "\nfOOrth Reference Implementation Version: #{XfOOrth.version}"
  puts "\nSession began on: #{Time.now.strftime(TimeFormat)}"
end
main() click to toggle source

The starting point for an interactive fOOrth programming session. This method only returns when the session is closed.
Returns:

  • The virtual machine used to run the session.


To launch a fOOrth interactive session, simply use:

XfOOrth::main


Endemic Code Smells

  • :reek:TooManyStatements

# File lib/fOOrth/main.rb, line 19
def self.main
  vm = VirtualMachine.vm('Console')
  running = false

  loop do
    begin
      running ||= start_up(vm)
      vm.process_console

    rescue Interrupt, ForceExit, SilentExit, MiniReadlineEOI => err
      puts "\n#{err.foorth_message}"
      break

    rescue StandardError => err
      vm.display_abort(err)

    rescue Exception => err
      puts "\n#{err.class.to_s.gsub(/.*::/, '')} detected: #{err}"
      puts err.backtrace
      break
    end

    break unless running
  end

  vm
end
name_to_type(name, vm) click to toggle source

Determine the type of method being created. This only applies to non-vm methods as vm methods are all of type VmSpec.
Parameters *name - The name of the method to be created. <Returns>

  • The class of the spec to be used for this method.

# File lib/fOOrth/library/compile_library.rb, line 217
def self.name_to_type(name, vm)
  normal_spec = case name[0]
  when '.'
    TosSpec

  when '~'
    SelfSpec

  when /[0-9A-Z$@#]/
    error "F10: Invalid name for a method: #{name}"

  else
    NosSpec
  end

  vm.get_cast || normal_spec
end
process_command_line_options() click to toggle source

Process the command line arguments. A string is returned containing fOOrth commands to be executed after the dictionary is loaded.
Returns

  • A string of fOOrth commands to be executed after the dictionary is loaded.


Endemic Code Smells

  • :reek:TooManyStatements

# File lib/fOOrth/main.rb, line 69
def self.process_command_line_options
  begin

    defer, found = "", false

    opts = GetoptLong.new(
      [ "--help",  "-h", "-?", GetoptLong::NO_ARGUMENT ],
      [ "--load",  "-l",       GetoptLong::REQUIRED_ARGUMENT ],
      [ "--debug", "-d",       GetoptLong::NO_ARGUMENT ],
      [ "--show",  "-s",       GetoptLong::NO_ARGUMENT ],
      [ "--quit",  "-q",       GetoptLong::NO_ARGUMENT ],
      [ "--words", "-w",       GetoptLong::NO_ARGUMENT ])

    # Translate the parsed options into fOOrth.
    opts.each do |opt, arg|

      unless found
        puts
        found = true
      end

      case opt
      when "--debug"
        defer << ")debug "
      when "--show"
        defer << ")show "
      when "--load"
        defer << ")load#{arg.inspect}"
      when "--quit"
        defer << ")quit "
      when "--words"
        defer << ")words "
      else
        fail SilentExit
      end
    end

    puts if found

  rescue Exception
    puts
    puts "fOOrth available options:"
    puts
    puts "--help  -h  -?          Display this message and exit."
    puts "--load  -l <filename>   Load the specified fOOrth source file."
    puts "--debug -d              Default to debug ON."
    puts "--quit  -q              Quit after processing the command line."
    puts "--show  -s              Default to show results ON."
    puts "--words -w              List the current vocabulary."
    puts
    raise SilentExit
  end

  defer
end
start_up(vm) click to toggle source

Perform one time start-up actions.

# File lib/fOOrth/main.rb, line 48
def self.start_up(vm)
  announcements
  vm.debug = false
  vm.show_stack = false
  vm.process_string(process_command_line_options)
  true
end
validate_string_method(type, target, name) click to toggle source

Check for the case where a string method is created on another class.
Parameters *type - The class of the method to be created. *target - The object that is to receive this method. *name - The name of the method to be created.
Endemic Code Smells

  • :reek:ControlParameter – false positive

# File lib/fOOrth/library/compile_library.rb, line 260
def self.validate_string_method(type, target, name)
  if type == TosSpec && name[-1] == '"' && target != String
    error "F13: Creating a string method #{name} on a #{target.foorth_name}"
  end
end
validate_type(vm, type, name) click to toggle source

Compare the new method's spec against the specs of other methods of the same name. If no specs exist, create one on Object if the new spec is not a virtual machine spec.
Parameters *vm - The current virtual machine. *type - The class of the method to be created. *name - The name of the method to be created.

# File lib/fOOrth/library/compile_library.rb, line 242
def self.validate_type(vm, type, name)
  if (spec = vm.context.map_without_defaults(name))
    if spec.class != type
      error "F90: Spec type mismatch #{spec.foorth_name} vs #{type.foorth_name}"
    end
  else
    Object.create_shared_method(name, type, [:stub]) unless type == VmSpec
  end

end
version() click to toggle source

The version of this module.
Returns

  • A version string; <major>.<minor>.<step>

# File lib/fOOrth.rb, line 36
def self.version
  VERSION
end