Skip to content

Commit

Permalink
- Sidef deparser: deparse literal floating-point values more efficien…
Browse files Browse the repository at this point in the history
…tly.

- String.apply_escapes(): fixed an issue that caused binary strings to get inconsistent byte representations during -O1.
  • Loading branch information
trizen committed Mar 13, 2023
1 parent 2a47419 commit ecf99e6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
14 changes: 9 additions & 5 deletions lib/Sidef/Deparse/Sidef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ package Sidef::Deparse::Sidef {
my ($type, $str) = $num->_dump;

state $table = {
'@inf@' => q{Inf},
'-@inf@' => q{Inf.neg},
'@nan@' => q{NaN},
'@inf@' => q{Inf},
'-@inf@' => q{Inf.neg},
'@nan@' => q{NaN},

'inf' => q{Inf},
'-inf' => q{Inf.neg},
'nan' => q{NaN},
};

state $special_values = {
Expand All @@ -193,7 +197,7 @@ package Sidef::Deparse::Sidef {
$str;
}
elsif ($type eq 'float') {
"$str.float";
$str . 'f';
}
elsif (index($str, '/') != -1) {
"Number(\"$str\")";
Expand Down Expand Up @@ -485,7 +489,7 @@ package Sidef::Deparse::Sidef {
. $self->deparse_args($obj->{false}) . ')';
}
elsif ($ref eq 'Sidef::Module::OO') {
$code = '%s' . $self->_dump_string($obj->{module});
$code = '%O' . $self->_dump_string($obj->{module});
}
elsif ($ref eq 'Sidef::Module::Func') {
$code = '%S' . $self->_dump_string($obj->{module});
Expand Down
6 changes: 3 additions & 3 deletions lib/Sidef/Types/String/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ package Sidef::Types::String::String {
my $block = $char;

if ($string ne '') {
$append_arg->(Encode::decode_utf8(Encode::encode_utf8($string)));
$append_arg->($string);
$string = '';
}
$append_arg->($block);
Expand All @@ -1654,13 +1654,13 @@ package Sidef::Types::String::String {
}

if ($string ne '') {
$append_arg->(Encode::decode_utf8(Encode::encode_utf8($string)));
$append_arg->($string);
}

return $expr;
}

$self->new(Encode::decode_utf8(Encode::encode_utf8(CORE::join('', @chars))));
$self->new(CORE::join('', @chars));
}

sub shift_left {
Expand Down
4 changes: 2 additions & 2 deletions scripts/Graphical/fbrowse_tray.sf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Translation of:
# https://github.com/trizen/fbrowse-tray

Perl.eval('use Gtk3 "-init"')
require('File::MimeInfo')
use('Gtk3 -init')
use('File::MimeInfo')

const pkgname = 'fbrowse-tray'
const version = 0.07
Expand Down
2 changes: 1 addition & 1 deletion scripts/Graphical/hello_world_graphical_1.sf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## http://rosettacode.org/wiki/Hello_world/Graphical
#

Perl.eval("use Gtk3 '-init'")
use('Gtk3 -init')
 
var gtk3 = 'Gtk3'.to_caller;
var window = 'Gtk3::Window'.to_caller.new;
Expand Down
2 changes: 1 addition & 1 deletion scripts/Graphical/simple_windowed_application.sf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## http://rosettacode.org/wiki/Simple_windowed_application
#

Perl.eval('use Gtk3 "-init"')
use('Gtk3 -init')

# Window.
var window = %s'Gtk3::Window'.new;
Expand Down
2 changes: 1 addition & 1 deletion scripts/Graphical/user_input.sf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## http://rosettacode.org/wiki/User_input/Graphical
#

Perl.eval("use Gtk3 '-init'")
use('Gtk3 -init')

var Gtk3 = %O'Gtk3'

Expand Down
2 changes: 1 addition & 1 deletion scripts/Graphical/window_creation_1.sf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## http://rosettacode.org/wiki/Window_creation
#

Perl.eval("use Gtk3 '-init'")
use('Gtk3 -init')
var gtk3 = %O'Gtk3'
var window = %O'Gtk3::Window'.new;
window.signal_connect(destroy => func(_) { gtk3.main_quit });
Expand Down
1 change: 1 addition & 0 deletions scripts/Tests/string_encodings.sf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ok(str_3.encode_utf8.bytes.decode, str_3);
ok(str_3.encode('UTF-16').bytes.decode('UTF-16'), str_3);
assert_eq("\37\x8B".bytes, [31, 139])
assert_eq("\37\x8B".bytes_len, 2)
assert_eq("\37\x8B".chars.map{.ord}, [31, 139])
assert_eq([unpack("C*", "\37\x8B")], ["31", "139"])
assert_eq(pack("C*", unpack("C*", "\37\x8B")), "\37\x8B")
Expand Down

0 comments on commit ecf99e6

Please sign in to comment.