Skip to content

Commit

Permalink
- Switched from Math::Big{Int,Rat,Float} to Math::GMP{z,f,q}, Math::M…
Browse files Browse the repository at this point in the history
…PFR and Math::MPC

- Removed the built-in Char(s), Byte(s) and Grapheme(s) types.
- Major changes and performance improvements.
  • Loading branch information
trizen committed Dec 25, 2015
1 parent 4a35652 commit 445a699
Show file tree
Hide file tree
Showing 61 changed files with 1,820 additions and 2,161 deletions.
9 changes: 7 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ my $builder = Module::Build->new(
'List::Util' => 1.33,
'Math::BigInt' => 0,
'Math::BigRat' => 0,
'Math::BigFloat' => 0,
'Math::Complex' => 0,
#'Math::BigFloat' => 0,
#'Math::Complex' => 0,
'Math::MPFR' => 0,
'Math::MPC' => 0,
'Math::GMPq' => 0,
'Math::GMPf' => 0,
'Math::GMPz' => 0,
'Math::Trig' => 0,
'Socket' => 0,
'Fcntl' => 0,
Expand Down
17 changes: 1 addition & 16 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ lib/Sidef/Types/Block/Try.pm
lib/Sidef/Types/Block/Try.pod
lib/Sidef/Types/Bool/Bool.pm
lib/Sidef/Types/Bool/Bool.pod
lib/Sidef/Types/Byte/Byte.pm
lib/Sidef/Types/Byte/Byte.pod
lib/Sidef/Types/Byte/Bytes.pm
lib/Sidef/Types/Byte/Bytes.pod
lib/Sidef/Types/Char/Char.pm
lib/Sidef/Types/Char/Char.pod
lib/Sidef/Types/Char/Chars.pm
lib/Sidef/Types/Char/Chars.pod
lib/Sidef/Types/Glob/Backtick.pm
lib/Sidef/Types/Glob/Backtick.pod
lib/Sidef/Types/Glob/Dir.pm
Expand All @@ -68,10 +60,6 @@ lib/Sidef/Types/Glob/SocketHandle.pm
lib/Sidef/Types/Glob/SocketHandle.pod
lib/Sidef/Types/Glob/Stat.pm
lib/Sidef/Types/Glob/Stat.pod
lib/Sidef/Types/Grapheme/Grapheme.pm
lib/Sidef/Types/Grapheme/Grapheme.pod
lib/Sidef/Types/Grapheme/Graphemes.pm
lib/Sidef/Types/Grapheme/Graphemes.pod
lib/Sidef/Types/Hash/Hash.pm
lib/Sidef/Types/Hash/Hash.pod
lib/Sidef/Types/Null/Null.pm
Expand All @@ -96,7 +84,7 @@ lib/Sidef/Variable/NamedParam.pm
lib/Sidef/Variable/NamedParam.pod
LICENSE
Makefile.PL
MANIFEST This list of files
MANIFEST This list of files
META.json
META.yml
README.md
Expand Down Expand Up @@ -682,7 +670,6 @@ scripts/Tests/prefix_methods.sf
scripts/Tests/problem_of_apollonius.sf
scripts/Tests/pythagorean_means.sf
scripts/Tests/quicksort.sf
scripts/Tests/quicksort_in_parallel.sf
scripts/Tests/quoted_strings.sf
scripts/Tests/range_objects.sf
scripts/Tests/read_a_configuration_file.sf
Expand Down Expand Up @@ -787,8 +774,6 @@ utils/Concepts/sidef_executor.jl
utils/Concepts/sidef_executor.lua
utils/Concepts/sidef_executor.pl6
utils/Examples/sidef_in_perl.pl
utils/Experiments/bigint.sm
utils/Experiments/bigrat.sm
utils/Experiments/C-inline-function-call.pl
utils/Experiments/Lazy/Lazy.pm
utils/Experiments/operator_precendece.pl
Expand Down
29 changes: 7 additions & 22 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
"File::Spec" : "0",
"Getopt::Std" : "0",
"List::Util" : "1.33",
"Math::BigFloat" : "0",
"Math::BigInt" : "0",
"Math::BigRat" : "0",
"Math::Complex" : "0",
"Math::GMPf" : "0",
"Math::GMPq" : "0",
"Math::GMPz" : "0",
"Math::MPC" : "0",
"Math::MPFR" : "0",
"Math::Trig" : "0",
"Memoize" : "0",
"POSIX" : "0",
Expand All @@ -57,7 +60,7 @@
"provides" : {
"Sidef" : {
"file" : "lib/Sidef.pm",
"version" : "2.13"
"version" : "2.20"
},
"Sidef::Convert::Convert" : {
"file" : "lib/Sidef/Convert/Convert.pm"
Expand Down Expand Up @@ -128,18 +131,6 @@
"Sidef::Types::Bool::Bool" : {
"file" : "lib/Sidef/Types/Bool/Bool.pm"
},
"Sidef::Types::Byte::Byte" : {
"file" : "lib/Sidef/Types/Byte/Byte.pm"
},
"Sidef::Types::Byte::Bytes" : {
"file" : "lib/Sidef/Types/Byte/Bytes.pm"
},
"Sidef::Types::Char::Char" : {
"file" : "lib/Sidef/Types/Char/Char.pm"
},
"Sidef::Types::Char::Chars" : {
"file" : "lib/Sidef/Types/Char/Chars.pm"
},
"Sidef::Types::Glob::Backtick" : {
"file" : "lib/Sidef/Types/Glob/Backtick.pm"
},
Expand Down Expand Up @@ -167,12 +158,6 @@
"Sidef::Types::Glob::Stat" : {
"file" : "lib/Sidef/Types/Glob/Stat.pm"
},
"Sidef::Types::Grapheme::Grapheme" : {
"file" : "lib/Sidef/Types/Grapheme/Grapheme.pm"
},
"Sidef::Types::Grapheme::Graphemes" : {
"file" : "lib/Sidef/Types/Grapheme/Graphemes.pm"
},
"Sidef::Types::Hash::Hash" : {
"file" : "lib/Sidef/Types/Hash/Hash.pm"
},
Expand Down Expand Up @@ -213,6 +198,6 @@
"http://dev.perl.org/licenses/"
]
},
"version" : "2.13",
"version" : "2.20",
"x_serialization_backend" : "JSON::PP version 2.27300"
}
23 changes: 7 additions & 16 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: Sidef
provides:
Sidef:
file: lib/Sidef.pm
version: '2.13'
version: '2.20'
Sidef::Convert::Convert:
file: lib/Sidef/Convert/Convert.pm
Sidef::Deparse::Perl:
Expand Down Expand Up @@ -64,14 +64,6 @@ provides:
file: lib/Sidef/Types/Block/Try.pm
Sidef::Types::Bool::Bool:
file: lib/Sidef/Types/Bool/Bool.pm
Sidef::Types::Byte::Byte:
file: lib/Sidef/Types/Byte/Byte.pm
Sidef::Types::Byte::Bytes:
file: lib/Sidef/Types/Byte/Bytes.pm
Sidef::Types::Char::Char:
file: lib/Sidef/Types/Char/Char.pm
Sidef::Types::Char::Chars:
file: lib/Sidef/Types/Char/Chars.pm
Sidef::Types::Glob::Backtick:
file: lib/Sidef/Types/Glob/Backtick.pm
Sidef::Types::Glob::Dir:
Expand All @@ -90,10 +82,6 @@ provides:
file: lib/Sidef/Types/Glob/SocketHandle.pm
Sidef::Types::Glob::Stat:
file: lib/Sidef/Types/Glob/Stat.pm
Sidef::Types::Grapheme::Grapheme:
file: lib/Sidef/Types/Grapheme/Grapheme.pm
Sidef::Types::Grapheme::Graphemes:
file: lib/Sidef/Types/Grapheme/Graphemes.pm
Sidef::Types::Hash::Hash:
file: lib/Sidef/Types/Hash/Hash.pm
Sidef::Types::Null::Null:
Expand Down Expand Up @@ -127,10 +115,13 @@ requires:
File::Spec: '0'
Getopt::Std: '0'
List::Util: '1.33'
Math::BigFloat: '0'
Math::BigInt: '0'
Math::BigRat: '0'
Math::Complex: '0'
Math::GMPf: '0'
Math::GMPq: '0'
Math::GMPz: '0'
Math::MPC: '0'
Math::MPFR: '0'
Math::Trig: '0'
Memoize: '0'
POSIX: '0'
Expand All @@ -143,5 +134,5 @@ requires:
utf8: '0'
resources:
license: http://dev.perl.org/licenses/
version: '2.13'
version: '2.20'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
7 changes: 5 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ WriteMakefile
'File::Spec' => 0,
'Getopt::Std' => 0,
'List::Util' => '1.33',
'Math::BigFloat' => 0,
'Math::BigInt' => 0,
'Math::BigRat' => 0,
'Math::Complex' => 0,
'Math::GMPf' => 0,
'Math::GMPq' => 0,
'Math::GMPz' => 0,
'Math::MPC' => 0,
'Math::MPFR' => 0,
'Math::Trig' => 0,
'Memoize' => 0,
'POSIX' => 0,
Expand Down
30 changes: 2 additions & 28 deletions bin/sidef
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sub NATIVE () { 0 }
my %args;
if ($#ARGV != -1 and chr ord $ARGV[0] eq '-') {
require Getopt::Std;
Getopt::Std::getopts('e:E:d:Dho:ivHn:WwbcrR:ts:CO:kP:A:M:', \%args);
Getopt::Std::getopts('e:E:d:Dho:ivHWwbcrR:ts:CO:kP:M:', \%args);
}

# Help
Expand Down Expand Up @@ -61,21 +61,11 @@ elsif (defined $args{W}) {
};
}

# Backend for Math::BigInt
if (defined(my $type = $args{n})) {
load_math_backend($type);
}

# Number of spaces for indentation
if (defined(my $num = $args{s})) {
$Sidef::SPACES_INCR = int($num);
}

# Change the Math backend to 'FastCalc' when '-D' or '-d' is specified
if (defined($args{D}) or defined($args{d})) {
load_math_backend('FastCalc');
}

# Interactive help
if (defined $args{H}) {
help_interactive();
Expand Down Expand Up @@ -274,18 +264,6 @@ sub parse_code {
$struct;
}

sub load_math_backend {
my ($type) = @_;

require Math::BigInt;
require Math::BigRat;
require Math::BigFloat;

Math::BigInt->import(lib => $type);
Math::BigFloat->import(lib => $type);
Math::BigRat->import(lib => $type);
}

sub execute_struct {
my ($struct, $return) = @_;
my $deparser = Sidef::Deparse::Perl->new(namespaces => [@Sidef::NAMESPACES], opt => \%args);
Expand All @@ -306,14 +284,11 @@ sub output_usage {
'-O level' => ['perform code optimizations before execution',
'valid levels: [0], 1, 2'],
'-P int' => 'set the precision of floating-point numbers',
'-A int' => 'set the numeric accuracy to a certain number of digits',
'-M mode' => ['set the rounding mode of floating-point numbers',
'valid modes: [even], odd, +inf, -inf, zero, trunc, common'],
'valid modes: [near], zero, +zero, +inf, -inf'],
'-k' => 'keep track of potential unsafe parser interpretations',
'-E program' => 'one line of program',
'-H' => 'interactive help',
'-n type' => ['try to use a specific backend for Math::BigInt',
'valid types: GMP, Pari, FastCalc'],
'-s int' => 'the number of spaces used in code indentation',
'-v' => 'print version number and exit',
'-t' => 'treat all command-line arguments as scripts',
Expand Down Expand Up @@ -591,7 +566,6 @@ sub dump_structure {
};

print {$out_fh} _get_namespaces();
print {$out_fh} "use Math::BigFloat;\n";
print {$out_fh} $requirify->(_get_loaded_modules());
print {$out_fh} Data::Dump::pp($struct) . "\n";
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Sidef.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package Sidef {

use 5.014;
our $VERSION = '2.13';
our $VERSION = '2.20';

our $SPACES = 0; # the current number of spaces
our $SPACES_INCR = 4; # the number of spaces incrementor
Expand All @@ -11,9 +11,9 @@ package Sidef {

our %EVALS; # will contain info required for eval()

use Math::BigInt qw(try GMP);
use Math::BigRat qw(try GMP);
use Math::BigFloat qw(try GMP);
#use Math::BigInt qw(try GMP);
#use Math::BigRat qw(try GMP);
#use Math::BigFloat qw(try GMP);

sub new {
bless {}, __PACKAGE__;
Expand Down
39 changes: 5 additions & 34 deletions lib/Sidef/Convert/Convert.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,33 @@ package Sidef::Convert::Convert {
}

sub to_i {
Sidef::Types::Number::Number->new(Math::BigFloat->new($_[0]->get_value)->as_int);
Sidef::Types::Number::Number->new($_[0])->int;
}

*to_int = \&to_i;

sub to_rat {
Sidef::Types::Number::Number->new(Math::BigRat->new($_[0]->get_value));
Sidef::Types::Number::Number->new($_[0]);
}

*to_rational = \&to_rat;
*to_r = \&to_rat;

sub to_complex {
Sidef::Types::Number::Complex->new($_[0]->get_value);
Sidef::Types::Number::Complex->new($_[0]);
}

*to_c = \&to_complex;

sub to_n {
Sidef::Types::Number::Number->new($_[0]->get_value);
Sidef::Types::Number::Number->new($_[0]);
}

*to_num = \&to_n;
*to_number = \&to_n;

sub to_float {
my ($value) = $_[0]->get_value;
Sidef::Types::Number::Number->new(ref($value) eq 'Math::BigRat' ? $value->as_float : Math::BigFloat->new($value));
Sidef::Types::Number::Number->new($_[0])->float;
}

*to_f = \&to_float;
Expand All @@ -74,34 +73,6 @@ package Sidef::Convert::Convert {

*to_re = \&to_regex;

sub to_byte {
Sidef::Types::Byte::Byte->new(CORE::ord($_[0]->get_value));
}

sub to_bytes {
Sidef::Types::Byte::Bytes->call($_[0]->get_value);
}

sub to_char {
Sidef::Types::Char::Char->call($_[0]->get_value);
}

sub to_chars {
Sidef::Types::Char::Chars->call($_[0]->get_value);
}

sub to_grapheme {
Sidef::Types::Grapheme::Grapheme->call($_[0]);
}

*to_graph = \&to_grapheme;

sub to_graphemes {
Sidef::Types::Grapheme::Graphemes->call($_[0]);
}

*to_graphs = \&to_graphemes;

sub to_array {
Sidef::Types::Array::Array->new($_[0]);
}
Expand Down
Loading

0 comments on commit 445a699

Please sign in to comment.