Add compile_file function
This commit is contained in:
parent
0620c777bf
commit
abe30ac2b2
3 changed files with 28 additions and 8 deletions
|
@ -613,4 +613,14 @@ sub compile {
|
|||
return $parsed;
|
||||
}
|
||||
|
||||
sub compile_file {
|
||||
my $file = shift;
|
||||
|
||||
open(my $fh, "<", $file) or die "Could not open $file: $!";
|
||||
my $script = do { local $/; <$fh> };
|
||||
close($fh);
|
||||
|
||||
return compile($script);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
17
tool/run.pl
Normal file
17
tool/run.pl
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Minilisp;
|
||||
|
||||
my $scriptfile = shift;
|
||||
|
||||
die "No script file provided." unless defined $scriptfile && -f $scriptfile;
|
||||
|
||||
my $parsed = Minilisp::compile_file($scriptfile);
|
||||
|
||||
$parsed->($ctx);
|
||||
|
||||
exit 0;
|
|
@ -13,14 +13,7 @@ my $scriptfile = shift;
|
|||
|
||||
die "No script file provided." unless defined $scriptfile && -f $scriptfile;
|
||||
|
||||
open(my $fh, "<", $scriptfile) or die "Could not open $scriptfile: $!";
|
||||
my $script = do { local $/; <$fh> };
|
||||
close($fh);
|
||||
|
||||
# Remove shebang
|
||||
$script =~ s/^#!.*\n//;
|
||||
|
||||
my $parsed = Minilisp::compile($script);
|
||||
my $parsed = Minilisp::compile_file($scriptfile);
|
||||
|
||||
my $plan = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue