Class: Piggly::Compiler::TraceCompiler
- Includes:
- Util::Cacheable
- Defined in:
- lib/piggly/compiler/trace_compiler.rb
Overview
Walks the parse tree, attaching Tag values and rewriting source code to ping them.
Class Method Summary collapse
-
.cache_sources ⇒ Object
Each of these files’ mtimes are used to determine when another file is stale.
Instance Method Summary collapse
- #compile(procedure) ⇒ Object
-
#initialize(config) ⇒ TraceCompiler
constructor
A new instance of TraceCompiler.
-
#stale?(procedure) ⇒ Boolean
Is the cache_path is older than its source path or the other files?.
Methods included from Util::Cacheable
Constructor Details
#initialize(config) ⇒ TraceCompiler
Returns a new instance of TraceCompiler.
10 11 12 |
# File 'lib/piggly/compiler/trace_compiler.rb', line 10 def initialize(config) @config = config end |
Class Method Details
.cache_sources ⇒ Object
Each of these files’ mtimes are used to determine when another file is stale
97 98 99 100 101 |
# File 'lib/piggly/compiler/trace_compiler.rb', line 97 def cache_sources [Parser.grammar_path, Parser.parser_path, Parser.nodes_path] end |
Instance Method Details
#compile(procedure) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/piggly/compiler/trace_compiler.rb', line 21 def compile(procedure) cache = CacheDir.new(cache_path(procedure.source_path(@config))) if stale?(procedure) $stdout.puts "Compiling #{procedure.name}" tree = Parser.parse(IO.read(procedure.source_path(@config))) tree = tree.force! if tree.respond_to?(:thunk?) = [] code = traverse(tree, procedure.oid, ) cache.replace(:tree => tree, :code => code, :tags => ) end cache end |
#stale?(procedure) ⇒ Boolean
Is the cache_path is older than its source path or the other files?
15 16 17 18 19 |
# File 'lib/piggly/compiler/trace_compiler.rb', line 15 def stale?(procedure) Util::File.stale?(cache_path(procedure.source_path(@config)), procedure.source_path(@config), *self.class.cache_sources) end |