aboutsummaryrefslogtreecommitdiff
path: root/interpreter
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2013-01-10 19:34:47 +0100
committerDrahflow <drahflow@gmx.de>2013-01-10 19:34:47 +0100
commitcde514733d2c0c3c070d2452c653cf3a4eea0313 (patch)
tree54bc2dd0c0d4fe644729aaa5d41bb4f80e47556d /interpreter
parent492a35eab4c1c09f5fb9b207e3e36bfa96109236 (diff)
Some code clean- and speedup
Diffstat (limited to 'interpreter')
-rw-r--r--interpreter/ElymasGlobal.pm45
1 files changed, 42 insertions, 3 deletions
diff --git a/interpreter/ElymasGlobal.pm b/interpreter/ElymasGlobal.pm
index 351826b..aace222 100644
--- a/interpreter/ElymasGlobal.pm
+++ b/interpreter/ElymasGlobal.pm
@@ -567,9 +567,15 @@ sub installGlobal2IntFunction {
$global->{$name} = [sub {
my ($data, $scope) = @_;
- my $b = popInt($data);
- my $a = popInt($data);
- push @$data, [&$code($a, $b), 'int'];
+ my $b = pop @$data;
+ unless($b->[1] eq 'int' and $data->[-1]->[1] eq 'int') {
+ die "Not int-typed arguments: " . Dumper($data->[-1], $b);
+ }
+ $data->[-1] = [&$code($data->[-1]->[0], $b->[0]), 'int'];
+
+# my $b = popInt($data);
+# my $a = popInt($data);
+# push @$data, [&$code($a, $b), 'int'];
}, ['func', $name, ['int', 'int'], ['int']], 'active'];
}
@@ -754,4 +760,37 @@ installGlobal2StrFunction('streq', sub { return [($_[0] eq $_[1])? 1: 0, 'int']
# x: Extended Precision -> <TODO: arbitrary precision lib>
# _9: to 9: Constant Functions -> { 9 neg } ... { 9 }
+use Time::HiRes qw(time);
+
+my %timings;
+
+sub takeTimings {
+ my ($scope) = @_;
+
+ foreach my $key (keys %$scope) {
+ next if not ref($scope->{$key}->[1]);
+
+ if($scope->{$key}->[1]->[0] eq 'func') {
+ my $sub = $scope->{$key}->[0];
+ my $name = $scope->{$key}->[1]->[1];
+
+ $scope->{$key}->[0] = sub {
+ my $start = time;
+ &$sub(@_);
+ $timings{$name} += time - $start;
+ }
+ } elsif($scope->{$key}->[1]->[0] eq 'struct') {
+ takeTimings($scope->{$key}->[0]);
+ }
+ }
+}
+
+# takeTimings($global);
+
+END {
+ foreach my $key (sort { $timings{$a} <=> $timings{$b} } keys %timings) {
+ printf "%s: %.6f\n", $key, $timings{$key};
+ }
+}
+
1;