line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Language::Farnsworth; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.7.7"; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
25048
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
662
|
use Language::Farnsworth::Evaluate; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Language::Farnsworth::Value; |
12
|
|
|
|
|
|
|
use Language::Farnsworth::Dimension; |
13
|
|
|
|
|
|
|
use Language::Farnsworth::Units; |
14
|
|
|
|
|
|
|
use Language::Farnsworth::FunctionDispatch; |
15
|
|
|
|
|
|
|
use Language::Farnsworth::Variables; |
16
|
|
|
|
|
|
|
use Language::Farnsworth::Output; |
17
|
|
|
|
|
|
|
use Math::Pari; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Data::Dumper; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
shift; #get the class off |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $self = {}; |
26
|
|
|
|
|
|
|
my @modules = @_; #i get passed a list of modules to use for standard stuff; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Math::Pari::setprecision(100); #both of these need to be user configurable! |
29
|
|
|
|
|
|
|
Math::Pari::allocatemem(40_000_000); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if (@modules < 1) |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
@modules = ("Units::Standard", "Functions::Standard", "Functions::StdMath", "Functions::GoogleTranslate", "Units::Currency"); #standard modules to include |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#print Dumper(\@modules); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->{eval} = Language::Farnsworth::Evaluate->new(); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
for my $a (@modules) |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
local $@; |
43
|
|
|
|
|
|
|
eval 'use Language::Farnsworth::'.$a.'; Language::Farnsworth::'.$a.'::init($self->{eval});'; |
44
|
|
|
|
|
|
|
#die $@ if $@; |
45
|
|
|
|
|
|
|
#print "-------FAILED? $a\n"; |
46
|
|
|
|
|
|
|
#print $@; |
47
|
|
|
|
|
|
|
#print "\n"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
bless $self; |
51
|
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub runString |
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
my @torun = @_; # we can run an array |
58
|
|
|
|
|
|
|
my @results; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
push @results, new Language::Farnsworth::Output($self->{eval}{units},$self->{eval}->eval($_), $self->{eval}) for (@torun); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return wantarray ? @results : $results[-1]; #return all of them in array context, only the last in scalar context |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub runFile |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
my $filename = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#my @results; #i should really probably only store them all IF they are needed |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
open(my $fh, "<", $filename) or die "couldn't open: $!"; |
73
|
|
|
|
|
|
|
my $lines; |
74
|
|
|
|
|
|
|
my $first = 1; |
75
|
|
|
|
|
|
|
while(<$fh>) |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
$first=0, next if ($first && $_ =~ /^#!/); #skip a shebang line, not part of the language but makes it possible to have executable .frns files! |
78
|
|
|
|
|
|
|
$lines .= $_; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
close($fh); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#as much as i would like this to work WITHOUT this i need to filter blank lines out #not as sure i need to do this anymore! need tests to check |
83
|
|
|
|
|
|
|
$lines =~ s/\s*\n\s*\n\s*/\n/; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return new Language::Farnsworth::Output($self->{eval}{units},$self->{eval}->eval($lines), $self->{eval}); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# while(<$fh>) |
88
|
|
|
|
|
|
|
# { |
89
|
|
|
|
|
|
|
# chomp; |
90
|
|
|
|
|
|
|
#s|//.*$||; |
91
|
|
|
|
|
|
|
#s|\s*$||; |
92
|
|
|
|
|
|
|
# } |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# close($fh); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#return wantarray ? @results : $results[-1]; #return all of them in array context, only the last in scalar context |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#this will wrap around a lot of the funky code for creating a nice looking output |
100
|
|
|
|
|
|
|
#sub prettyOut |
101
|
|
|
|
|
|
|
#{ |
102
|
|
|
|
|
|
|
# my $self = shift; |
103
|
|
|
|
|
|
|
# my $input = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# return $input->toperl($self->{eval}{units}); |
106
|
|
|
|
|
|
|
#} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |