[stupid-crypto] 4 new revisions pushed by ben@links.org on 2010-06-05 17:15 GMT

1 view
Skip to first unread message

stupid...@googlecode.com

unread,
Jun 5, 2010, 1:15:52 PM6/5/10
to stupi...@googlegroups.com
4 new revisions:

Revision: f24b4dc4c5
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 09:40:17 2010
Log: Fix array deductions.
http://code.google.com/p/stupid-crypto/source/detail?r=f24b4dc4c5

Revision: 0350e24c57
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 09:47:11 2010
Log: Set children's width correctly.
http://code.google.com/p/stupid-crypto/source/detail?r=0350e24c57

Revision: 3cbdda37ab
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 09:52:15 2010
Log: Test was failing for the wrong reason.
http://code.google.com/p/stupid-crypto/source/detail?r=3cbdda37ab

Revision: 856ffff4dd
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 10:05:49 2010
Log: All tests pass.
http://code.google.com/p/stupid-crypto/source/detail?r=856ffff4dd

==============================================================================
Revision: f24b4dc4c5
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 09:40:17 2010
Log: Fix array deductions.
http://code.google.com/p/stupid-crypto/source/detail?r=f24b4dc4c5

Added:
/test2/trivial-array-write.stupid
Modified:
/src/grammar2.y
/src/stupid2.pl

=======================================
--- /dev/null
+++ /test2/trivial-array-write.stupid Sat Jun 5 09:40:17 2010
@@ -0,0 +1,8 @@
+"EXPECT:";
+
+function () test() {
+
+array(int_8u, 1) k = [ 66 ];
+
+k[0] = 65;
+}
=======================================
--- /src/grammar2.y Sat May 29 12:59:33 2010
+++ /src/grammar2.y Sat Jun 5 09:40:17 2010
@@ -174,9 +174,9 @@
;

bitwidth : VALUE
- { new Stupid2::Bitwidth($_[1], 1); }
+ { new Stupid2::Bitwidth($_[1]->value(), 1); }
| UVALUE
- { new Stupid2::Bitwidth($_[1], 0); }
+ { new Stupid2::Bitwidth($_[1]->value(), 0); }
;

arrayval : '[' val_list ']'
=======================================
--- /src/stupid2.pl Sun May 30 06:24:51 2010
+++ /src/stupid2.pl Sat Jun 5 09:40:17 2010
@@ -159,13 +159,17 @@
my $width = shift;
my $signed = shift;

+ $width = new Math::BigInt($width) if ref($width) eq '';
+
my $self = {};
bless $self, $class;

+ confess ref($width) if ref($width) ne 'Math::BigInt';
+
$self->{width} = $width;
$self->{signed} = $signed;

- croak 'Weird width'
+ confess 'Weird width'
if (!defined($self->{width}) && defined($self->{signed}))
|| (defined($self->{width}) && !defined($self->{signed}));

@@ -182,7 +186,7 @@
sub bits {
my $self = shift;

- return $self->{width}->value();
+ return $self->{width};
}

sub asString {
@@ -201,7 +205,7 @@
my $self = shift;
my $other = shift;

- return $self->{width}->value() == $other->{width}->value()
+ return $self->{width} == $other->{width}
&& $self->{signed} == $other->{signed};
}

@@ -209,6 +213,8 @@
my $self = shift;
my $other = shift;

+ croak ref($other) if ref($other) ne 'Stupid2::Bitwidth';
+
$self->{width} = $other->{width} if !defined $self->{width};
$self->{signed} = $other->{signed} if !defined $self->{signed};

@@ -228,6 +234,8 @@
my $count = shift;
my $width = shift;

+ croak ref($width) if ref($width) ne 'Stupid2::Bitwidth';
+
my $self = {};
bless $self, $class;

@@ -247,6 +255,8 @@
my $self = shift;
my $other = shift;

+ croak ref($other) if ref($other) ne 'Stupid2::ArrayWidth';
+
if(ref($other) ne ref($self)) {
croak 'Can\'t merge width of type '.ref($other)
.' with width of type '.ref($self);
@@ -297,6 +307,14 @@
my $self = shift;
my $width = shift;

+ if (!defined $width) {
+ croak "Trying to unset width!" if defined $self->{width};
+ return;
+ }
+
+ confess ref($width) if ref($width) ne 'Stupid2::Bitwidth'
+ && ref($width) ne 'Stupid2::ArrayWidth';
+
if(!defined $self->{width}) {
$self->{width} = $width;
} else {
@@ -337,6 +355,7 @@

use strict;
use base qw(Stupid2::HasWidthWithoutDeduction);
+use Carp;

sub new {
my $class = shift;
@@ -345,7 +364,7 @@
my $self = {};
bless $self, $class;

- $self->{width} = $width;
+ $self->setWidth($width);

return $self;
}
@@ -360,7 +379,7 @@
my $t = new Stupid2::ArrayValue();
foreach my $c (split //, $str) {
$t->append(new Stupid2::DecimalValue(ord($c),
- new Stupid2::Bitwidth(new Stupid2::DecimalValue(8), 0)));
+ new Stupid2::Bitwidth(8, 0)));
}

return $t;
@@ -764,6 +783,48 @@
$a->markAsArgument();
}
}
+
+package Stupid2::DecimalValue;
+
+use strict;
+use base qw(Stupid2::HasWidthWithoutDeduction);
+use Math::BigInt;
+use Carp;
+
+sub new {
+ my $class = shift;
+ my $value = shift;
+ my $width = shift;
+
+ my $self = {};
+ bless $self, $class;
+
+ $self->{value} = new Math::BigInt($value);
+ $self->setWidth($width);
+
+ return $self;
+}
+
+sub value {
+ my $self = shift;
+
+ return $self->{value};
+}
+
+sub setAppropriateWidth {
+ my $self = shift;
+
+ if ($self->{value} >= 0) {
+ if ($self->{value} < 256) {
+ $self->setWidth(new Stupid2::Bitwidth(8, 0));
+ } else {
+ $self->setWidth(new Stupid2::Bitwidth(32, 0));
+ }
+ } else {
+ croak;
+ }
+}
+

package Stupid2::ArrayRef;

@@ -788,6 +849,9 @@
my $self = shift;

$self->{offset}->deduceWidth();
+ if (!defined $self->{offset}->maybeWidth()) {
+ $self->{offset}->setAppropriateWidth();
+ }
$self->maybeSetWidth($self->{array}->memberWidth());
}

@@ -1646,7 +1710,7 @@
sub deduceWidth {
my $self = shift;

- $self->{width} = $self->{type}->width();
+ $self->setWidth($self->{type}->width());
croak if !defined $self->{width};
}

@@ -1695,32 +1759,6 @@

return $self->{value}->bior($right);
}
-
-package Stupid2::DecimalValue;
-
-use strict;
-use base qw(Stupid2::HasWidthWithoutDeduction);
-use Math::BigInt;
-
-sub new {
- my $class = shift;
- my $value = shift;
- my $width = shift;
-
- my $self = {};
- bless $self, $class;
-
- $self->{value} = new Math::BigInt($value);
- $self->{width} = $width;
-
- return $self;
-}
-
-sub value {
- my $self = shift;
-
- return $self->{value};
-}

package Stupid2::ArrayValue;


==============================================================================
Revision: 0350e24c57
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 09:47:11 2010
Log: Set children's width correctly.
http://code.google.com/p/stupid-crypto/source/detail?r=0350e24c57

Modified:
/src/stupid2.pl

=======================================
--- /src/stupid2.pl Sat Jun 5 09:40:17 2010
+++ /src/stupid2.pl Sat Jun 5 09:47:11 2010
@@ -308,7 +308,7 @@
my $width = shift;

if (!defined $width) {
- croak "Trying to unset width!" if defined $self->{width};
+ confess "Trying to unset width!" if defined $self->{width};
return;
}

@@ -1003,10 +1003,9 @@

sub setChildrensWidth {
my $self = shift;
- my $width = shift;
-
- $self->{left}->setWidth($width);
- $self->{right}->setWidth($width);
+
+ $self->{left}->setWidth($self->{width});
+ $self->{right}->setWidth($self->{width});
}

package Stupid2::Set;

==============================================================================
Revision: 3cbdda37ab
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 09:52:15 2010
Log: Test was failing for the wrong reason.
http://code.google.com/p/stupid-crypto/source/detail?r=3cbdda37ab

Modified:
/src/Stupid2/C.pm
/test2/bug-double-declaration.stupid

=======================================
--- /src/Stupid2/C.pm Sat May 29 13:15:22 2010
+++ /src/Stupid2/C.pm Sat Jun 5 09:52:15 2010
@@ -67,6 +67,12 @@
$self->{var}->emitDeclaration($self->{init});
print ";\n";
}
+
+sub Stupid2::Declare::emitArg {
+ my $self = shift;
+
+ $self->{var}->emitArg();
+}

sub Stupid2::Set::emitCode {
my $self = shift;
@@ -234,6 +240,12 @@
if !$self->{isReturn} && !$self->{isArgument};;
print $self->{name};
}
+
+sub Stupid2::Variable::emitArg {
+ my $self = shift;
+
+ $self->{type}->emitArg($self->{name});
+}

sub Stupid2::ArrayRef::emitParameter {
my $self = shift;
=======================================
--- /test2/bug-double-declaration.stupid Sat May 29 08:54:14 2010
+++ /test2/bug-double-declaration.stupid Sat Jun 5 09:52:15 2010
@@ -1,7 +1,8 @@
"EXPECT-BUILD-FAIL:";

function(ostream out) test() {
- out.put(65);
+ "FIXME: should deduce this width";
+ out.put(65_8);
}

function (int_8u i) broken (int_8u x) {

==============================================================================
Revision: 856ffff4dd
Author: Ben Laurie <b...@links.org>
Date: Sat Jun 5 10:05:49 2010
Log: All tests pass.
http://code.google.com/p/stupid-crypto/source/detail?r=856ffff4dd

Modified:
/src/Stupid2/C.pm
/src/stupid2.pl

=======================================
--- /src/Stupid2/C.pm Sat Jun 5 09:52:15 2010
+++ /src/Stupid2/C.pm Sat Jun 5 10:05:49 2010
@@ -27,6 +27,15 @@
$self->{body}->emitCode();
print "}\n";
}
+
+sub Stupid2::Function::emitCall {
+ my $self = shift;
+
+ print $self->{name};
+}
+
+sub Stupid2::Function::maybeAddSelf {
+}

sub Stupid2::StatementList::emitCode {
my $self = shift;
@@ -80,7 +89,7 @@
# special case ... clearly we could do this in full generality,
# e.g f()[8] or f().foo or (a, b) = (c, d) or (a, b) = (b, a)
# [hmmm]
- if(ref($self->{right}) eq 'Stupid::FunctionCall') {
+ if(ref($self->{right}) eq 'Stupid2::FunctionCall') {
$self->{right}->emitCallWithLValue($self->{left});
return;
}
@@ -99,6 +108,18 @@
$self->{args}->emitParameters();
print ");\n";
}
+
+sub Stupid2::FunctionCall::emitCallWithLValue {
+ my $self = shift;
+ my $lvalue = shift;
+
+ $self->{function}->emitCall();
+ print '(';
+ $lvalue->emitPointer();
+ print ', ' if !$self->{args}->isEmpty();
+ $self->{args}->emitParameters();
+ print ");\n";
+}

sub Stupid2::If::emitCode {
my $self = shift;
@@ -186,7 +207,7 @@
# special case ... clearly we could do this in full generality,
# e.g f()[8] or f().foo or (a, b) = (c, d) or (a, b) = (b, a)
# [hmmm]
- if(ref($init) eq 'Stupid::FunctionCall') {
+ if(ref($init) eq 'Stupid2::FunctionCall') {
print ";\n";
$init->emitCallWithLValue($self);
return;
@@ -246,6 +267,13 @@

$self->{type}->emitArg($self->{name});
}
+
+sub Stupid2::Variable::emitPointer {
+ my $self = shift;
+
+ $self->{type}->emitPointer() if !$self->{isReturn};
+ print $self->{name};
+}

sub Stupid2::ArrayRef::emitParameter {
my $self = shift;
=======================================
--- /src/stupid2.pl Sat Jun 5 09:47:11 2010
+++ /src/stupid2.pl Sat Jun 5 10:05:49 2010
@@ -686,6 +686,7 @@
package Stupid2::FunctionCall;

use strict;
+use Carp;

sub new {
my $class = shift;
@@ -708,6 +709,20 @@
# declared.
$self->{args}->deduceWidth();
}
+
+sub maybeWidth {
+ my $self = shift;
+
+ return undef;
+}
+
+sub maybeSetWidth {
+ my $self = shift;
+ my $width = shift;
+
+# FIXME: is this actually wrong?
+# confess "Setting function call width" if defined $width;
+}

package Stupid::MemberRef;

Reply all
Reply to author
Forward
0 new messages