Skip to content

Commit

Permalink
Added Melbourne parser extension.
Browse files Browse the repository at this point in the history
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 committed Jul 20, 2009
1 parent 651d835 commit ad861fe
Show file tree
Hide file tree
Showing 21 changed files with 19,330 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/bin/compile.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions lib/ext/melbourne/build.rb
@@ -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
11 changes: 11 additions & 0 deletions lib/ext/melbourne/extconf.rb
@@ -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

0 comments on commit ad861fe

Please sign in to comment.