diff --git a/.gitignore b/.gitignore index eacf10a3..4a610ba1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,35 +1,5 @@ -MAIN.cs -MAIN.exe -Kernel.dll -Kernel.dll.so -PerlTask.dll -SAFE.dll -SAFE.dll.so -SAFE.cs -SAFE_ast.store -CORE.dll -CORE.dll.so -CORE.cs -CORE_ast.store -Test.dll -Test.dll.so -Test.cs -Test_ast.store -Threads.dll -Threads.dll.so -Threads.cs -Threads_ast.store -MONKEY_TYPING.dll -MONKEY_TYPING.dll.so -MONKEY_TYPING.cs -MONKEY_TYPING_ast.store -RegexEngine.dll -RegexEngine.so -RegexEngine.cs -RegexEngine_ast.store *.swp *.pmc -syml .STD_build_stamp .STD_checkout_stamp STD_checkout diff --git a/CompilerDriver.pm b/CompilerDriver.pm index 7c7dd040..d7f09968 100644 --- a/CompilerDriver.pm +++ b/CompilerDriver.pm @@ -8,7 +8,7 @@ use Sub::Exporter -setup => { }; use Time::HiRes 'time'; - +use File::Basename; use autodie ':all'; open ::NIECZA_OUT, ">&", \*STDOUT; @@ -30,8 +30,21 @@ use Storable; use Niecza::Grammar (); use Niecza::Actions (); -# TODO -my $builddir = File::Spec->curdir; +my $builddir; +{ + my $libdir = dirname($INC{'CompilerDriver.pm'}); + $builddir = File::Spec->catdir($libdir, "build"); +} +File::Path::make_path($builddir); + +sub build_file { File::Spec->catfile($builddir, $_[1]) } + +sub metadata_for { + my ($cl, $unit) = @_; + $unit =~ s/::/./g; + + Storable::retrieve(File::Spec->catfile($builddir, "$unit.store")) +} { package @@ -100,7 +113,7 @@ sub compile { $::UNITNAME =~ s|[\\/]|.|g; $STD::ALL = {}; - $::SETTING_RESUME = retrieve($args{lang} . '.store')->{setting} + $::SETTING_RESUME = CompilerDriver->metadata_for($args{lang})->{setting} unless $args{lang} eq 'NULL'; $::UNITDEPS{$args{lang}} = 1 if $args{lang} ne 'NULL'; @@ -109,6 +122,9 @@ sub compile { my $ast; my $basename = $::UNITNAME || 'MAIN'; + my $csfile = File::Spec->catfile($builddir, "$basename.cs"); + my $outname = File::Spec->catfile($builddir, + $basename . ($args{main} ? ".exe" : ".dll")); my @phases = ( [ 'parse', sub { @@ -124,7 +140,7 @@ sub compile { [ 'to_anf', sub { $ast->to_anf } ], [ 'writecs', sub { - open ::NIECZA_OUT, ">", "$basename.cs"; + open ::NIECZA_OUT, ">", $csfile; binmode ::NIECZA_OUT, ":utf8"; print ::NIECZA_OUT < $::SETTING_RESUME, syml => $::niecza_mod_symbols }; - store $blk, "$basename.store"; + store $blk, File::Spec->catfile($builddir, "$basename.store"); } - $ast = undef; } ], + $ast = undef; + } ], [ 'gmcs', sub { delete $::UNITDEPS{$basename}; - system "gmcs", ($args{main} ? () : ("/target:library")), + my @args = ("gmcs", + ($args{main} ? () : ("/target:library")), + "/lib:$builddir", "/r:Kernel.dll", (map { "/r:$_.dll" } sort keys %::UNITDEPS), - "/out:${basename}." . ($args{main} ? 'exe' : 'dll'), - "${basename}.cs"; } ], + "/out:$outname", + $csfile); + print STDERR "@args\n" if $args{stagetime}; + system @args; + } ], [ 'aot', sub { - system "mono", "--aot", "${basename}." . - ($args{main} ? 'exe' : 'dll'); } ]); + system "mono", "--aot", $outname; + } ]); for my $p (@phases) { next if $p->[0] eq 'aot' && !$args{aot}; diff --git a/Decl.pm b/Decl.pm index f1ddf7dd..42fc4a6d 100644 --- a/Decl.pm +++ b/Decl.pm @@ -482,7 +482,7 @@ use CgOp; sub preinit_code { my ($self, $body) = @_; - my $scope = Storable::retrieve($self->unit . ".store")->{setting}; + my $scope = CompilerDriver->metadata_for($self->unit)->{setting}; CodeGen->know_module($self->unit); CgOp::prog( diff --git a/Niecza.proj b/Niecza.proj index e07a1679..3e5a635f 100644 --- a/Niecza.proj +++ b/Niecza.proj @@ -1,6 +1,6 @@ - + svn @@ -28,9 +28,10 @@ - - + @@ -38,40 +39,50 @@ - + - + OutputAssembly="build\Kernel.dll"/> + - + - + - + - - - + + + - - - + + + - - - + + + @@ -112,9 +123,9 @@ ContinueOnError="true"/> - + diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1 @@ +* diff --git a/niecza_eval b/niecza_eval index b372d55d..ef0f5dd4 100755 --- a/niecza_eval +++ b/niecza_eval @@ -53,7 +53,8 @@ $lang = 'SAFE' if $safe; sub run { compile(main => !$module, stopafter => $stopafter, aot => $aot, stagetime => $stagestats, lang => $lang, safe => $safe, @_); - system 'mono MAIN.exe' if !$module && !$stopafter; + system 'mono', CompilerDriver->build_file('MAIN.exe') + if !$module && !$stopafter; } if (@ARGV) {