Permalink
Browse files

Added Melbourne parser extension.

The basic machinery is in place but the processor is all stubs. Both
String#to_ast and File.to_ast "work". The next steps are:

1. Get a harness in place to run the specs
2. Start adding functionality to the processor methods
3. Fix the arguments passed to processor methods from the visitor
4. Augment the compiler Node classes with additional methods as needed
5. Get all specs passing
6. Remove the dependencies on libmpa, libmquard, libcchash
  • Loading branch information...
Brian Ford
Brian Ford committed Jul 14, 2009
1 parent 651d835 commit ad861fe61a8a93dd6b252b0b29667b3ea2c7afea
View
@@ -75,6 +75,10 @@ def add_include(inc)
@includes << "-I#{inc}"
end
+ def add_pre_compile(block)
+ @block = block
+ end
+
attr_reader :output
def calculate_output
@@ -151,10 +155,14 @@ def link_options
return opts.join(" ")
end
+ def pre_compile
+ @block.call if @block
+ end
+
def compile_files
@objects = []
@files.each do |file|
- out = file.sub /\.c$/, '.o'
+ out = file.sub /\.cpp|\.c$/, '.o'
cmd = "#{compiler} #{compile_options} -c -o #{out} #{file}"
puts cmd if $VERBOSE
@@ -203,8 +211,8 @@ def name(name)
@ec.set_output name
end
- def files(glob)
- Dir[glob].each { |f| @ec.add_file f }
+ def files(*glob)
+ Dir[*glob].each { |f| @ec.add_file f }
end
def flags(*args)
@@ -219,6 +227,10 @@ def includes(*args)
args.each { |a| @ec.add_include a }
end
+ def pre_compile(&block)
+ @ec.add_pre_compile block
+ end
+
def setup
$ec_dsl = self
end
@@ -282,9 +294,10 @@ def extension
Dir.chdir file
load "build.rb"
+ ext.pre_compile
ext.compile
-elsif file.suffix?(".c")
+elsif file.suffix?(".c") or file.suffix?(".cpp")
puts "Compiling extension #{file}..." if $VERBOSE
ext = ExtensionCompiler.new(flags, ARGV)
View
@@ -0,0 +1,14 @@
+extension do |e|
+ e.name 'melbourne'
+ e.files '*.c', '*.cpp'
+ e.includes '.', '../../../vm/external_libs/libbstring',
+ '../../../vm/external_libs/libmquark',
+ '../../../vm/external_libs/libmpa',
+ '../../../vm/external_libs/libcchash'
+
+ e.pre_compile do
+ if File.mtime("grammar.y") > File.mtime("grammar.cpp")
+ system "bison -o grammar.cpp grammar.y"
+ end
+ end
+end
@@ -0,0 +1,11 @@
+require 'rbconfig'
+require 'mkmf'
+
+create_makefile('melbourne')
+
+File.open("Makefile","a+") do |f|
+ f.puts <<END
+grammar.cpp: grammar.y
+ bison -o grammar.cpp grammar.y
+END
+end
Oops, something went wrong.

0 comments on commit ad861fe

Please sign in to comment.