Module: XfOOrth
- Defined in:
- lib/fOOrth.rb,
lib/fOOrth/core.rb,
lib/fOOrth/main.rb,
lib/fOOrth/debug.rb,
lib/fOOrth/library.rb,
lib/fOOrth/version.rb,
lib/fOOrth/compiler.rb,
lib/fOOrth/initialize.rb,
lib/fOOrth/symbol_map.rb,
lib/fOOrth/interpreter.rb,
lib/fOOrth/debug/vm_dump.rb,
lib/fOOrth/library/stubs.rb,
lib/fOOrth/compiler/modes.rb,
lib/fOOrth/compiler/token.rb,
lib/fOOrth/debug/dbg_puts.rb,
lib/fOOrth/compiler/parser.rb,
lib/fOOrth/compiler/source.rb,
lib/fOOrth/compiler/context.rb,
lib/fOOrth/compiler/process.rb,
lib/fOOrth/debug/context_dump.rb,
lib/fOOrth/interpreter/squash.rb,
lib/fOOrth/library/vm_library.rb,
lib/fOOrth/compiler/word_specs.rb,
lib/fOOrth/debug/display_abort.rb,
lib/fOOrth/interpreter/do_loop.rb,
lib/fOOrth/compiler/parser/skip.rb,
lib/fOOrth/core/virtual_machine.rb,
lib/fOOrth/library/hash_library.rb,
lib/fOOrth/library/time_library.rb,
lib/fOOrth/compiler/context/tags.rb,
lib/fOOrth/compiler/modes/nested.rb,
lib/fOOrth/library/array_library.rb,
lib/fOOrth/library/class_library.rb,
lib/fOOrth/library/clone_library.rb,
lib/fOOrth/library/duration/make.rb,
lib/fOOrth/library/fiber_library.rb,
lib/fOOrth/library/mutex_library.rb,
lib/fOOrth/library/queue_library.rb,
lib/fOOrth/library/stack_library.rb,
lib/fOOrth/library/stdio_library.rb,
lib/fOOrth/compiler/modes/delayed.rb,
lib/fOOrth/compiler/modes/suspend.rb,
lib/fOOrth/compiler/parser/normal.rb,
lib/fOOrth/interpreter/data_stack.rb,
lib/fOOrth/library/bundle_library.rb,
lib/fOOrth/library/object_library.rb,
lib/fOOrth/library/string_library.rb,
lib/fOOrth/library/thread_library.rb,
lib/fOOrth/compiler/context/locals.rb,
lib/fOOrth/compiler/modes/compiled.rb,
lib/fOOrth/compiler/modes/deferred.rb,
lib/fOOrth/compiler/parser/special.rb,
lib/fOOrth/compiler/process/string.rb,
lib/fOOrth/compiler/source/console.rb,
lib/fOOrth/interpreter/add_to_hash.rb,
lib/fOOrth/library/command_library.rb,
lib/fOOrth/library/compile_library.rb,
lib/fOOrth/library/complex_library.rb,
lib/fOOrth/library/integer_library.rb,
lib/fOOrth/library/numeric_library.rb,
lib/fOOrth/monkey_patch/exceptions.rb,
lib/fOOrth/library/data_ref_library.rb,
lib/fOOrth/library/duration_library.rb,
lib/fOOrth/library/rational_library.rb,
lib/fOOrth/compiler/context/map_name.rb,
lib/fOOrth/compiler/process/generate.rb,
lib/fOOrth/library/in_stream_library.rb,
lib/fOOrth/library/procedure_library.rb,
lib/fOOrth/compiler/parser/get_string.rb,
lib/fOOrth/compiler/process/get_token.rb,
lib/fOOrth/compiler/process/procedure.rb,
lib/fOOrth/compiler/source/read_point.rb,
lib/fOOrth/library/duration/formatter.rb,
lib/fOOrth/library/duration/intervals.rb,
lib/fOOrth/library/out_stream_library.rb,
lib/fOOrth/compiler/source/file_source.rb,
lib/fOOrth/library/ctrl_struct_library.rb,
lib/fOOrth/library/duration/arithmetic.rb,
lib/fOOrth/library/sync_bundle_library.rb,
lib/fOOrth/compiler/source/string_source.rb,
lib/fOOrth/library/other_value_types_library.rb
Overview
-
library/other_value_types_library.rb - Support for true, false, and nil in
the fOOrth library.
Defined Under Namespace
Modules: ReadPoint, SymbolMap Classes: AbstractSource, AbstractWordSpec, ClassSpec, Console, Context, Duration, FileSource, ForceExit, GlobalVarSpec, InstanceVarSpec, LocalSpec, MacroSpec, NosSpec, Parser, SelfSpec, SilentExit, StringSource, ThreadVarSpec, Token, TosSpec, VirtualMachine, VmSpec, XfOOrthError, XfOOrth_Bundle, XfOOrth_Fiber, XfOOrth_InStream, XfOOrth_OutStream, XfOOrth_SyncBundle
Constant Summary collapse
- TimeFormat =
The user facing format used for date/time display.
'%Y-%m-%d at %I:%M%P'
- VERSION =
The version string for fOOrth.
"0.5.1"
- DegreesPerRadian =
The number of degrees in one radian.
180.0/Math::PI
- Local_Var_Action =
The lambda used to define local variables. fOOrth language definition is:
- n
-
var: lv [], lv = [n]
lambda {|vm| name = vm.parser.get_word() error "F10: Invalid var name #{name}" unless /^[a-z][a-z0-9_]*$/ =~ name symbol = XfOOrth::SymbolMap.add_entry(name) vm << "#{symbol} = [vm.pop]; " #Add a local defn for the local variable. vm.context.create_local_method(name, LocalSpec, [:immediate], &lambda {|vm| vm << "vm.push(#{symbol}); "} ) }
- Local_Val_Action =
The lambda used to define local values. fOOrth language definition is:
- n
-
val: lv [], lv = n
lambda {|vm| name = vm.parser.get_word() error "F10: Invalid val name #{name}" unless /^[a-z][a-z0-9_]*$/ =~ name symbol = XfOOrth::SymbolMap.add_entry(name) vm << "#{symbol} = vm.pop; " #Add a local defn for the local variable. vm.context.create_local_method(name, LocalSpec, [:immediate], &lambda {|vm| vm << "vm.push(#{symbol}); "} ) }
- Inst_Var_Action =
The lambda used to define instance variables. fOOrth language definition is:
- n
-
var@: @iv [], @iv = [n]
lambda { |vm| name = vm.parser.get_word() error "F10: Invalid var name #{name}" unless /^@[a-z][a-z0-9_]*$/ =~ name symbol = XfOOrth::SymbolMap.add_entry(name) vm << "#{'@'+(symbol.to_s)} = [vm.pop]; " #Add a defn for the instance variable. vm.context.recvr.create_shared_method(name, InstanceVarSpec, []) }
- Inst_Val_Action =
The lambda used to define instance values. fOOrth language definition is:
- n
-
val@: @iv [], @iv = n
lambda { |vm| name = vm.parser.get_word() error "F10: Invalid val name #{name}" unless /^@[a-z][a-z0-9_]*$/ =~ name symbol = XfOOrth::SymbolMap.add_entry(name) vm << "#{'@'+(symbol.to_s)} = vm.pop; " #Add a defn for the instance variable. vm.context.recvr.create_shared_method(name, InstanceVarSpec, []) }
Class Method Summary collapse
-
.add_common_compiler_locals(vm, ctrl) ⇒ Object
Set up the common local defns.
-
.announcements ⇒ Object
Display the start-up messages for the interactive session.
-
.main ⇒ Object
The starting point for an interactive fOOrth programming session.
-
.name_to_type(name) ⇒ Object
Determine the type of method being created.
-
.process_command_line_options ⇒ Object
Process the command line arguments.
-
.start_up(vm) ⇒ Object
Perform one time start-up actions.
-
.validate_string_method(type, target, name) ⇒ Object
Check for the case where a string method is created on another class.
-
.validate_type(vm, type, name) ⇒ Object
Compare the new method’s spec against the specs of other methods of the same name.
-
.version ⇒ Object
The version of this module.
Class Method Details
.add_common_compiler_locals(vm, ctrl) ⇒ Object
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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fOOrth/library/compile_library.rb', line 108 def self.add_common_compiler_locals(vm, ctrl) context = vm.context #Support for local variables. context.create_local_method('var:', LocalSpec, [:immediate], &Local_Var_Action) context.create_local_method('val:', LocalSpec, [:immediate], &Local_Val_Action) #Support for instance variables. context.create_local_method('var@:', LocalSpec, [:immediate], &Inst_Var_Action) context.create_local_method('val@:', LocalSpec, [:immediate], &Inst_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.end_compile_mode([ctrl]) }) end |
.announcements ⇒ Object
Display the start-up messages for the interactive session.
57 58 59 60 61 |
# 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 ⇒ Object
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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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.}" 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) ⇒ Object
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.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fOOrth/library/compile_library.rb', line 134 def self.name_to_type(name) case name[0] when '.' TosSpec when '~' SelfSpec when /[0-9A-Z$@#]/ error "F10: Invalid name for a method: #{name}" else NosSpec end end |
.process_command_line_options ⇒ Object
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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/fOOrth/main.rb', line 69 def self. 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 << "\"#{arg}\" .load " 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) ⇒ Object
Perform one time start-up actions.
48 49 50 51 52 53 54 |
# File 'lib/fOOrth/main.rb', line 48 def self.start_up(vm) announcements vm.debug = false vm.show_stack = false vm.process_string() true end |
.validate_string_method(type, target, name) ⇒ Object
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
175 176 177 178 179 |
# File 'lib/fOOrth/library/compile_library.rb', line 175 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) ⇒ Object
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.
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fOOrth/library/compile_library.rb', line 157 def self.validate_type(vm, type, name) if (spec = vm.context.map(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 |