cvsuser 01/09/26 20:46:05
Modified: . assemble.pl
Log:
This patch makes integer constants of the form 0b[01]+ work with perl 5.005. The
oct function in versions of perl before 5.6 did not handle the 0b numeric prefix;
therefore, it was returning 0. To fix this, I added a from_binary function that would
take a binary string and return its decimal representation. Now, instead of blindly
calilng oct, it makes a distinction between 0/0x numbers and 0b numbers.
Revision Changes Path
1.48 +16 -3 parrot/assemble.pl
Index: assemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/assemble.pl,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -w -r1.47 -r1.48
--- assemble.pl 2001/09/26 18:30:43 1.47
+++ assemble.pl 2001/09/27 03:46:05 1.48
@@ -65,7 +65,7 @@
# %equate maps assembler directives to their replacements.
my %equate=('*'=>sub { return $pc },
'__DATE__'=>'"'.scalar(localtime).'"',
- '__VERSION__'=>'" $Revision: 1.47 $ "',
+ '__VERSION__'=>'" $Revision: 1.48 $ "',
'__LINE__' => sub { return $line },
'__FILE__' => sub { return "\"$file\"" });
@@ -126,7 +126,7 @@
}
if($options{'version'}) {
- print $0,'Version $Id: assemble.pl,v 1.47 2001/09/26 18:30:43 thgibbs Exp $
',"\n";
+ print $0,'Version $Id: assemble.pl,v 1.48 2001/09/27 03:46:05 thgibbs Exp $
',"\n";
exit;
}
@@ -616,8 +616,13 @@
$args[$_] =~ s/[\[\]]//g;
}
else {
- $args[$_] = oct($args[$_]) if($args[$_]=~/^0[xb]?[0-9a-f]*$/);
+ if ($args[$_] =~ /^0b[01]+$/) {
+ $args[$_] = from_binary( $args[$_] );
}
+ elsif ($args[$_] =~ /^0x?[0-9a-f]*$/) {
+ $args[$_] = oct($args[$_]);
+ }
+ }
$pc += sizeof($rtype);
$bytecode .= pack_arg($rtype, $args[$_]);
}
@@ -628,6 +633,14 @@
# adds a line to the listing string.
sub add_line_to_listing {
$listing .= $_[0];
+}
+
+# from_binary
+# convert a string of the form 0b[01]+ to a decimal number
+sub from_binary {
+ my ($pow, $final) = (0,0);
+ $final += $_ * 2 ** $pow++ for split //, reverse substr( shift, 2 );
+ return $final;
}
# error