[stupid-crypto] 9 new revisions pushed by b.clifford on 2010-04-06 15:19 GMT

0 views
Skip to first unread message

stupid...@googlecode.com

unread,
Apr 6, 2010, 11:19:52 AM4/6/10
to stupi...@googlegroups.com
9 new revisions:

Revision: d10ef7466b
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:22:20 2010
Log: prettyprint if statements
http://code.google.com/p/stupid-crypto/source/detail?r=d10ef7466b

Revision: cc517c67cb
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:28:47 2010
Log: -quietbuild option for test rig suppresses output of build script,
giv...
http://code.google.com/p/stupid-crypto/source/detail?r=cc517c67cb

Revision: c037a5c717
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:33:25 2010
Log: get rid of a few tabs used for indenting
http://code.google.com/p/stupid-crypto/source/detail?r=c037a5c717

Revision: 16ef346cb1
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:37:25 2010
Log: array-small test now used
http://code.google.com/p/stupid-crypto/source/detail?r=16ef346cb1

Revision: 42182fb7eb
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 06:27:07 2010
Log: make array-small test work in haskell
http://code.google.com/p/stupid-crypto/source/detail?r=42182fb7eb

Revision: 6d126cc2e4
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 06:29:59 2010
Log: make array-write test actually run
http://code.google.com/p/stupid-crypto/source/detail?r=6d126cc2e4

Revision: c9281832d0
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 06:38:11 2010
Log: Like ostream-funccall, but exercises a different code path (at least
i...
http://code.google.com/p/stupid-crypto/source/detail?r=c9281832d0

Revision: ddc294383d
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 07:45:01 2010
Log: function call with lvalue handling in haskell sufficient to...
http://code.google.com/p/stupid-crypto/source/detail?r=ddc294383d

Revision: 14c6fd607e
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 08:17:25 2010
Log: function calls implemented enough to pass test ostream-funccall
http://code.google.com/p/stupid-crypto/source/detail?r=14c6fd607e

==============================================================================
Revision: d10ef7466b
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:22:20 2010
Log: prettyprint if statements
http://code.google.com/p/stupid-crypto/source/detail?r=d10ef7466b

Modified:
/src/Stupid/Haskell.pm

=======================================
--- /src/Stupid/Haskell.pm Tue Apr 6 05:11:33 2010
+++ /src/Stupid/Haskell.pm Tue Apr 6 05:22:20 2010
@@ -387,16 +387,18 @@
sub Stupid::If::emitCode {
my $self = shift;

- print "do {\n";
- print "xxxifcond <- ";
+ print "${indent}do\n";
+ my $oldindent = $indent;
+ $indent = "$indent ";
+ print "${indent}xxxifcond <- ";
$self->{cond}->emitCode();
- print "; \n if xxxifcond";
+ print "\n${indent}if xxxifcond";
print ' then ';
$self->{then}->emitCode();
print " else ";
$self->{else}->emitCode();
print "\n";
- print "};\n";
+ $indent = $oldindent;
}

sub Stupid::While::emitCode {

==============================================================================
Revision: cc517c67cb
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:28:47 2010
Log: -quietbuild option for test rig suppresses output of build script,
giving a much more concise output that makes it easier to see an overview
of which tests work and which fail
http://code.google.com/p/stupid-crypto/source/detail?r=cc517c67cb

Modified:
/test/test.pl

=======================================
--- /test/test.pl Tue Apr 6 04:13:20 2010
+++ /test/test.pl Tue Apr 6 05:28:47 2010
@@ -11,8 +11,10 @@
$| = 1;

my $language;
-
-croak if !GetOptions("language=s" => \$language);
+my $quietbuild;
+
+croak if !GetOptions("language=s" => \$language,
+ "quietbuild" => \$quietbuild);

opendir(D, '.') || croak "Can't open .: $!";
my @tests = sort grep { /\.stupid$/ } readdir(D);
@@ -32,7 +34,11 @@
my $expect_output = $2;
my $status;
my $output;
- if(system("./build-$language.sh $base")) {
+ my $buildredirect="";
+ if($quietbuild) {
+ $buildredirect=">/dev/null 2>/dev/null";
+ }
+ if(system("./build-$language.sh $base $buildredirect")) {
$status = '-BUILD-FAIL';
$output = '';
} else {

==============================================================================
Revision: c037a5c717
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:33:25 2010
Log: get rid of a few tabs used for indenting
http://code.google.com/p/stupid-crypto/source/detail?r=c037a5c717

Modified:
/src/Stupid/Haskell.pm

=======================================
--- /src/Stupid/Haskell.pm Tue Apr 6 05:22:20 2010
+++ /src/Stupid/Haskell.pm Tue Apr 6 05:33:25 2010
@@ -77,7 +77,7 @@

for my $arg (@{$self->{args}}) {
print ' -> ' if !$first;
- print "IORef ";
+ print "IORef ";
$arg->emitHaskellType();
$first = 0;
}
@@ -626,9 +626,9 @@
print '(do { r <- mapM (\a -> do { nxv <- a ; newIORef nxv }) [ ';
my $first = 1;
foreach my $v (@{$self->value()}) {
- print ', ' if !$first;
- $v->emitCode();
- $first = 0;
+ print ', ' if !$first;
+ $v->emitCode();
+ $first = 0;
}
print ' ] ; return r } )';
}

==============================================================================
Revision: 16ef346cb1
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 05:37:25 2010
Log: array-small test now used
http://code.google.com/p/stupid-crypto/source/detail?r=16ef346cb1

Modified:
/test/array-small.stupid

=======================================
--- /test/array-small.stupid Wed Feb 3 05:16:11 2010
+++ /test/array-small.stupid Tue Apr 6 05:37:25 2010
@@ -1,6 +1,8 @@
-function () test() {
-
-array(uint32, 3) k =
- (0x428a2f98, 0x71374491);
-
-}
+"EXPECT:C";
+
+function (ostream o) test() {
+
+array(uint8, 3) k = [65,66,67];
+
+o.put(k[2]);
+}

==============================================================================
Revision: 42182fb7eb
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 06:27:07 2010
Log: make array-small test work in haskell
http://code.google.com/p/stupid-crypto/source/detail?r=42182fb7eb

Modified:
/src/Stupid/Haskell.pm

=======================================
--- /src/Stupid/Haskell.pm Tue Apr 6 05:33:25 2010
+++ /src/Stupid/Haskell.pm Tue Apr 6 06:27:07 2010
@@ -584,7 +584,7 @@
sub Stupid::ArrayRef::emitParameter {
my $self = shift;

- $self->emitLValue();
+ $self->emitCode();
}

==============================================================================
Revision: 6d126cc2e4
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 06:29:59 2010
Log: make array-write test actually run
http://code.google.com/p/stupid-crypto/source/detail?r=6d126cc2e4

Modified:
/test/array-write.stupid

=======================================
--- /test/array-write.stupid Wed Feb 3 05:16:11 2010
+++ /test/array-write.stupid Tue Apr 6 06:29:59 2010
@@ -1,24 +1,12 @@
-function () test() {
-
-array(uint32, 64) k =
- (0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2);
-
-uint32 x = 0;
-
-k[1] = 0;
-}
+"EXPECT:BAB";
+
+function (ostream o) test() {
+
+array(uint8, 3) k = [ 66, 66, 66 ];
+
+k[1] = 65;
+
+o.put(k[0]);
+o.put(k[1]);
+o.put(k[2]);
+}

==============================================================================
Revision: c9281832d0
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 06:38:11 2010
Log: Like ostream-funccall, but exercises a different code path (at least
in Haskell)
http://code.google.com/p/stupid-crypto/source/detail?r=c9281832d0

Added:
/test/ostream-funccall2.stupid

=======================================
--- /dev/null
+++ /test/ostream-funccall2.stupid Tue Apr 6 06:38:11 2010
@@ -0,0 +1,12 @@
+"EXPECT:A";
+
+function (uint8 l)k() {
+ l=65;
+}
+
+function (ostream o) test() {
+ uint8 x=0;
+ x=k();
+ o.put(x);
+}
+

==============================================================================
Revision: ddc294383d
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 07:45:01 2010
Log: function call with lvalue handling in haskell sufficient to
run ostream-function2 but not ostream-function
http://code.google.com/p/stupid-crypto/source/detail?r=ddc294383d

Modified:
/src/Stupid/Haskell.pm

=======================================
--- /src/Stupid/Haskell.pm Tue Apr 6 06:27:07 2010
+++ /src/Stupid/Haskell.pm Tue Apr 6 07:45:01 2010
@@ -43,6 +43,19 @@
# whats happening for return parameters here?
print "\n";
}
+
+sub Stupid::FunctionCall::emitCallWithLValue() {
+ my $self = shift;
+ my $lvalue = shift;
+ print "$indent";
+ print ' (';
+ $self->{function}->emitCall();
+ print ' $< ';
+ $lvalue->emitLValue();
+ print ') ';
+ $self->{args}->emitParameters();
+ print "\n";
+}

## FUNCTODO
sub Stupid::Function::emitCode {
@@ -70,6 +83,12 @@
$self->{body}->emitCode();
print "\n";
}
+
+sub Stupid::Function::emitCall {
+ my $self = shift;
+
+ print $self->{name};
+}

sub Stupid::ArgList::emitArgTypes {
my $self = shift;
@@ -438,17 +457,24 @@
sub Stupid::Set::emitCode {
my $self = shift;

-# should be able to pull the InST out into its own operator using
-# applicative functor syntax, but I don't have my head around that at
-# the moment...
- print "$indent";
- print '(writeIORefInIO (';
- $self->{left}->emitLValue();
- print ' )) $< ( ';
- $self->{right}->emitCode();
- print ")\n";
-
-
+# There are two styles of assignment that differ very much in their
+# generated code.
+
+# One is assignment where the righthand is a value (or something that
+# produces a value).
+# The other is when the righthand is a procedure call, and so all of the
+# lvalues must be passed as procedure parameters
+
+ if(ref($self->{right}) eq 'Stupid::FunctionCall') {
+ $self->{right}->emitCallWithLValue($self->{left});
+ } else {
+ print "$indent";
+ print '(writeIORefInIO (';
+ $self->{left}->emitLValue();
+ print ' )) $< ( ';
+ $self->{right}->emitCode();
+ print ")\n";
+ }

# print "do { writeInternalVar<-";
# $self->{right}->emitCode();

==============================================================================
Revision: 14c6fd607e
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Tue Apr 6 08:17:25 2010
Log: function calls implemented enough to pass test ostream-funccall
http://code.google.com/p/stupid-crypto/source/detail?r=14c6fd607e

Modified:
/lib/StupidStuff.hs
/src/Stupid/Haskell.pm

=======================================
--- /lib/StupidStuff.hs Mon Mar 29 09:37:10 2010
+++ /lib/StupidStuff.hs Tue Apr 6 08:17:25 2010
@@ -21,6 +21,7 @@
type Uint8 = Word8
type Uint32 = Word32

+
-- operators. these work in the monad, rather than being operators on
-- raw values. this allows the translated language to have expressions
-- that use them directly
=======================================
--- /src/Stupid/Haskell.pm Tue Apr 6 07:45:01 2010
+++ /src/Stupid/Haskell.pm Tue Apr 6 08:17:25 2010
@@ -48,7 +48,7 @@
my $self = shift;
my $lvalue = shift;
print "$indent";
- print ' (';
+ print '(';
$self->{function}->emitCall();
print ' $< ';
$lvalue->emitLValue();
@@ -503,14 +503,34 @@
# skip the type declaration...
# $self->{type}->emitDeclaration($self->{name});

- # now create a STRef for this variable and assign the initial value
- print "$indent";
- print $self->{name};
- print ' <- (newIORef $< ( (';
- $init->emitCode();
- print ') :: IO ';
- $self->{type}->emitHaskellType();
- print "));\n"
+ # sometimes we'll get an initial value for this
+ # at other times, there will be a function to make the initialisation
+ # in which case we need to invoke the function with the new
+ # variable as an lvalue. This is one place where the function is going
+ # to be able to read the variable even though its not initialised
+ # (which perhaps we can later on use the type system to prevent)
+
+ if(ref($init) eq 'Stupid::FunctionCall') {
+ # first create a variable with a default value
+ # for now, 0 is used as default value, which will not make sense
+ # for anything except a numeric type.
+ print "$indent";
+ print $self->{name};
+ print ' <- (newIORef (0 :: ';
+ $self->{type}->emitHaskellType();
+ print "))\n";
+ # and now initialise it with the supplied function call
+ $init->emitCallWithLValue($self);
+ } else {
+ # create a STRef for this variable and assign the initial value
+ print "$indent";
+ print $self->{name};
+ print ' <- (newIORef $< ( (';
+ $init->emitCode();
+ print ') :: IO ';
+ $self->{type}->emitHaskellType();
+ print "))\n"
+ }
# I don't know how to emit types for arrays as they are represented here
# (because of the free variable in STRefs :(

Reply all
Reply to author
Forward
0 new messages