Add compile_file function

This commit is contained in:
madmaurice 2021-04-04 01:17:18 +02:00
parent 0620c777bf
commit abe30ac2b2
3 changed files with 28 additions and 8 deletions

View file

@ -613,4 +613,14 @@ sub compile {
return $parsed; 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; 1;

17
tool/run.pl Normal file
View 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;

View file

@ -13,14 +13,7 @@ my $scriptfile = shift;
die "No script file provided." unless defined $scriptfile && -f $scriptfile; die "No script file provided." unless defined $scriptfile && -f $scriptfile;
open(my $fh, "<", $scriptfile) or die "Could not open $scriptfile: $!"; my $parsed = Minilisp::compile_file($scriptfile);
my $script = do { local $/; <$fh> };
close($fh);
# Remove shebang
$script =~ s/^#!.*\n//;
my $parsed = Minilisp::compile($script);
my $plan = 0; my $plan = 0;