Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup directory structure a bit, and fix bootstrapping bug (minor e…
…Char issue).
- Loading branch information
Charles Lowe
committed
Sep 17, 2008
1 parent
03ed737
commit 758634c
Showing
15 changed files
with
277 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
= About | ||
|
||
Briefly what OMeta is | ||
Briefly what OMeta is, some links to the ometajs stuff. | ||
|
||
= TODO | ||
|
||
* finish bootstrapping. | ||
* add in optimization pass by default, with some flags. | ||
* perhaps cache compiled rb files as "#{ometa_filename}.rb.cache" or | ||
similar, and use them based on mtime / flag combination. | ||
* try to optimize some more. profile wasn't particularly illuminating. | ||
|
||
* then write some actual tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
$:.unshift File.dirname(__FILE__) + '/lib' | ||
require 'ometa' | ||
|
||
module Bootstrap | ||
class BootstrapError < StandardError | ||
end | ||
|
||
BOOTSTRAP_GRAMMARS = %w[ | ||
null_opt.ometa | ||
andor_opt.ometa | ||
ometa_opt.ometa | ||
bsruby_parser.ometa | ||
bsruby_translator.ometa | ||
ometa_parser.ometa | ||
ometa_translator.ometa | ||
] | ||
|
||
module_function | ||
|
||
class V0 < Object | ||
end | ||
|
||
def single root=V0 | ||
puts "bootstrapping ometa using #{root.inspect}" | ||
all = '' | ||
|
||
BOOTSTRAP_GRAMMARS.each do |filename| | ||
puts " - #{filename}" | ||
grammar = File.read(File.dirname(__FILE__) + '/ometa/' + filename) | ||
ast = root.const_get('OMetaParser').matchAllwith(grammar, 'grammar') | ||
ast = root.const_get('OMetaOptimizer').matchwith(ast, 'optimizeGrammar') | ||
str = root.const_get('RubyOMetaTranslator').matchwith(ast, 'trans') | ||
# this hack remains at the moment... | ||
str.gsub! /initialize/, 'initialize_hook' | ||
# test its evaluable | ||
obj = eval(str) | ||
# that gives us its name | ||
name = obj.instance_variable_get :@name | ||
all << "#{name} = " << str << "\n\n" | ||
end | ||
|
||
all | ||
end | ||
|
||
# we could also check for AST equivalence, but for now source equivalence will do. | ||
# note that we create the bootstrapped objects within the Bootstrap module, not as | ||
# anonymous objects as they refer to each other by name. anonymous module didn't | ||
# seem to work, but maybe i was doing something wrong... | ||
def bootstrap | ||
v1 = single | ||
eval "module V1; #{v1}; end" | ||
v2 = single V1 | ||
eval "module V2; #{v2}; end" | ||
v3 = single V2 | ||
eval "module V3; #{v3}; end" | ||
raise BootstrapError, 'second and third builds not equivalent' unless v2 == v3 | ||
v3 | ||
end | ||
end | ||
|
||
desc 'rebuild bootstrap.rb from the core ometa grammar files' | ||
task :bootstrap do | ||
# this is kind of like make bootstrap in gcc. the idea is to go through | ||
# the whole "compilation" of ometa -> rb 3 times, and ensure that the | ||
# 2nd and 3rd produce the same results. then we replace with our new | ||
# bootstrap code. | ||
begin | ||
str = Bootstrap.bootstrap | ||
rescue Bootstrap::BootstrapError | ||
puts "unable to bootstrap - #{$!}" | ||
exit 1 | ||
end | ||
puts 'bootstrap successful!' | ||
open File.dirname(__FILE__) + '/lib/ometa/bootstrap.rb', 'w' do |f| | ||
f.puts <<-end | ||
# | ||
# this file was automatically generated by `rake bootstrap' at #{Time.now}. | ||
# do not modify | ||
# | ||
end | ||
f.puts str | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'ometa/runtime' | ||
require 'ometa/bootstrap' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.