Class: Trith::Compiler Abstract
- Inherits:
-
Object
- Object
- Trith::Compiler
- Defined in:
- lib/trith/compiler.rb,
lib/trith/compiler/java.rb,
lib/trith/compiler/ruby.rb
Overview
A base class for Trith compiler targets.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary (collapse)
- - (Hash{Symbol => Object}) options readonly
Class Method Summary (collapse)
- + (Compiler) compile(program, options = {})
- + (Compiler) compile_files(*filenames)
- + (Class) for(target = nil, &block)
Instance Method Summary (collapse)
- - (Compiler) compile(program, options = {})
- - compile_boolean(operand) protected Abstract
- - compile_decimal(operand) protected Abstract
- - compile_float(operand) protected Abstract
- - compile_integer(operand) protected Abstract
- - compile_nil(operand = nil) protected Abstract
- - compile_number(operand) protected Abstract
- - compile_operand(operand) protected
- - compile_operator(operator) protected Abstract
- - compile_quotation(operand) protected Abstract
- - compile_rational(operand) protected Abstract
- - compile_reference(operand) protected Abstract
- - compile_string(operand) protected Abstract
-
- (Compiler) initialize(options = {})
constructor
A new instance of Compiler.
Constructor Details
- (Compiler) initialize(options = {})
A new instance of Compiler
44 45 46 |
# File 'lib/trith/compiler.rb', line 44 def initialize( = {}) @options = .to_hash.dup end |
Instance Attribute Details
- (Hash{Symbol => Object}) options (readonly)
11 12 13 |
# File 'lib/trith/compiler.rb', line 11 def @options end |
Class Method Details
+ (Compiler) compile(program, options = {})
38 39 40 |
# File 'lib/trith/compiler.rb', line 38 def self.compile(program, = {}) self.new().compile(program, ) end |
+ (Compiler) compile_files(*filenames)
29 30 31 32 |
# File 'lib/trith/compiler.rb', line 29 def self.compile_files(*filenames) = filenames.last.is_a?(Hash) ? filenames.peek : {} self.compile(Reader.read_files(*filenames), ) end |
+ (Class) for(target = nil, &block)
16 17 18 19 20 21 22 23 |
# File 'lib/trith/compiler.rb', line 16 def self.for(target = nil, &block) target = block.call if block_given? case target.to_sym when :ruby then Ruby when :java then Java else nil end end |
Instance Method Details
- (Compiler) compile(program, options = {})
52 53 54 55 56 |
# File 'lib/trith/compiler.rb', line 52 def compile(program, = {}) program = program.respond_to?(:each) ? program : [program] program.each { |op| compile_operand(op) } self end |
- compile_boolean(operand) (protected)
This method returns an undefined value.
111 112 113 |
# File 'lib/trith/compiler.rb', line 111 def compile_boolean(operand) raise NotImplementedError.new("#{self.class}#compile_boolean(#{operand.inspect})") end |
- compile_decimal(operand) (protected)
This method returns an undefined value.
154 155 156 |
# File 'lib/trith/compiler.rb', line 154 def compile_decimal(operand) raise NotImplementedError.new("#{self.class}#compile_decimal(#{operand.inspect})") end |
- compile_float(operand) (protected)
This method returns an undefined value.
146 147 148 |
# File 'lib/trith/compiler.rb', line 146 def compile_float(operand) raise NotImplementedError.new("#{self.class}#compile_float(#{operand.inspect})") end |
- compile_integer(operand) (protected)
This method returns an undefined value.
138 139 140 |
# File 'lib/trith/compiler.rb', line 138 def compile_integer(operand) raise NotImplementedError.new("#{self.class}#compile_integer(#{operand.inspect})") end |
- compile_nil(operand = nil) (protected)
This method returns an undefined value.
103 104 105 |
# File 'lib/trith/compiler.rb', line 103 def compile_nil(operand = nil) raise NotImplementedError.new("#{self.class}#compile_nil") end |
- compile_number(operand) (protected)
This method returns an undefined value.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/trith/compiler.rb', line 119 def compile_number(operand) case operand when Integer compile_integer(operand) when Float compile_float(operand) when BigDecimal compile_decimal(operand) when Rational compile_rational(operand) else raise NotImplementedError.new("#{self.class}#compile_number(#{operand.inspect})") end end |
- compile_operand(operand) (protected)
This method returns an undefined value.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trith/compiler.rb', line 63 def compile_operand(operand) case operand when Symbol compile_operator(operand) when NilClass compile_nil(operand) when TrueClass, FalseClass compile_boolean(operand) when Numeric compile_number(operand) when String compile_string(operand) when URI compile_reference(operand) when Array, SXP::List compile_quotation(operand) when Machine, Function compile_quotation(operand.to_a) else raise NotImplementedError.new("#{self.class}#compile_operand(#{operand.inspect})") end end |
- compile_operator(operator) (protected)
This method returns an undefined value.
90 91 92 93 94 95 96 97 |
# File 'lib/trith/compiler.rb', line 90 def compile_operator(operator) case operator.to_sym when :nil then compile_nil(nil) when :false then compile_boolean(false) when :true then compile_boolean(true) else raise NotImplementedError.new("#{self.class}#compile_operator(#{operator.inspect})") end end |
- compile_quotation(operand) (protected)
This method returns an undefined value.
186 187 188 |
# File 'lib/trith/compiler.rb', line 186 def compile_quotation(operand) raise NotImplementedError.new("#{self.class}#compile_quotation(#{operand.inspect})") end |
- compile_rational(operand) (protected)
This method returns an undefined value.
162 163 164 |
# File 'lib/trith/compiler.rb', line 162 def compile_rational(operand) raise NotImplementedError.new("#{self.class}#compile_rational(#{operand.inspect})") end |
- compile_reference(operand) (protected)
This method returns an undefined value.
178 179 180 |
# File 'lib/trith/compiler.rb', line 178 def compile_reference(operand) raise NotImplementedError.new("#{self.class}#compile_reference(#{operand.inspect})") end |
- compile_string(operand) (protected)
This method returns an undefined value.
170 171 172 |
# File 'lib/trith/compiler.rb', line 170 def compile_string(operand) raise NotImplementedError.new("#{self.class}#compile_string(#{operand.inspect})") end |