diff options
| author | Drahflow <drahflow@gmx.de> | 2013-01-10 19:34:47 +0100 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2013-01-10 19:34:47 +0100 |
| commit | cde514733d2c0c3c070d2452c653cf3a4eea0313 (patch) | |
| tree | 54bc2dd0c0d4fe644729aaa5d41bb4f80e47556d | |
| parent | 492a35eab4c1c09f5fb9b207e3e36bfa96109236 (diff) | |
Some code clean- and speedup
| -rw-r--r-- | compiler/elymasAsm.ey | 14 | ||||
| -rw-r--r-- | compiler/elymasAsmLib.ey | 11 | ||||
| -rw-r--r-- | compiler/elymasGlobal.ey | 2 | ||||
| -rw-r--r-- | interpreter/ElymasGlobal.pm | 45 |
4 files changed, 60 insertions, 12 deletions
diff --git a/compiler/elymasAsm.ey b/compiler/elymasAsm.ey index d3ad34b..3a7ca60 100644 --- a/compiler/elymasAsm.ey +++ b/compiler/elymasAsm.ey @@ -576,7 +576,9 @@ /rsp /rbx xchgqRegMem callStack /rbx movqImmReg /r15 /rbx xchgqRegMem - ] opcodes [ + + opcodes _ len dearray + callStack /rbx movqImmReg /r15 /rbx xchgqRegMem valueStack /rbx movqImmReg @@ -584,13 +586,17 @@ /r15 popqReg /rbx popqReg retn - ] cat cat =opcodes + ] + } /compileOn deff - opcodes arrayToCode _ .base sys .asm .execute - .free + { + compileOn arrayToCode _ .base sys .asm .execute + .free } /executeOn deff { mainStack .base mainCallStack .base executeOn } /execute deff + + { mainStack .base mainCallStack .base compileOn } /compile deff > /assembler defv # vim: syn=elymas diff --git a/compiler/elymasAsmLib.ey b/compiler/elymasAsmLib.ey index 9cea01e..76cb7e7 100644 --- a/compiler/elymasAsmLib.ey +++ b/compiler/elymasAsmLib.ey @@ -497,15 +497,18 @@ sys .asm .peek } /peekImm8 deff + [ /0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /A /B /C /D /E /F ] ==base16singleDigits + [ base16singleDigits { ==first base16singleDigits { first -01 cat } each } each ] ==base16digits + { - [ -01 16 { _ 16 mod -01 16 div } rep -- ] - [ /0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /A /B /C /D /E /F ] * + [ -01 8 { _ 256 mod -01 256 div } rep -- ] + base16digits * reverse |cat fold } /base16encode64 deff { - [ -01 8 { _ 16 mod -01 16 div } rep -- ] - [ /0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /A /B /C /D /E /F ] * + [ -01 4 { _ 256 mod -01 256 div } rep -- ] + base16digits * reverse |cat fold } /base16encode32 deff diff --git a/compiler/elymasGlobal.ey b/compiler/elymasGlobal.ey index 12589e8..a6dcfb8 100644 --- a/compiler/elymasGlobal.ey +++ b/compiler/elymasGlobal.ey @@ -94,7 +94,7 @@ { _ "([^\\n]*)\\n(.*)" regex } { -102 -- tokenize { _ .handle assemblerLibrary .stackDump - assemblerLibrary .globalScopeDump + # assemblerLibrary .globalScopeDump } each } loop } loop } /executeFile deff 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; |
