[stupid-crypto] 5 new revisions pushed by b.clifford on 2010-03-29 19:29 GMT

3 views
Skip to first unread message

stupid...@googlecode.com

unread,
Mar 29, 2010, 3:30:09 PM3/29/10
to stupi...@googlegroups.com
5 new revisions:

Revision: fa1d3e0d7c
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Sun Mar 28 07:17:22 2010
Log: beginings of struct support in Haskell backend
http://code.google.com/p/stupid-crypto/source/detail?r=fa1d3e0d7c

Revision: 566a9fe8ae
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 08:42:38 2010
Log: A simpler ostream test to help with puzzling over generated code.
http://code.google.com/p/stupid-crypto/source/detail?r=566a9fe8ae

Revision: d5c5ff1f8b
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 08:44:19 2010
Log: merge
http://code.google.com/p/stupid-crypto/source/detail?r=d5c5ff1f8b

Revision: 9cac83c85a
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 09:37:10 2010
Log: fix output streams enough for ostream-singlechar to pass.
http://code.google.com/p/stupid-crypto/source/detail?r=9cac83c85a

Revision: 7566b0db61
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 12:27:31 2010
Log: ostream-variable test. As far as I can tell, this should...
http://code.google.com/p/stupid-crypto/source/detail?r=7566b0db61

==============================================================================
Revision: fa1d3e0d7c
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Sun Mar 28 07:17:22 2010
Log: beginings of struct support in Haskell backend
http://code.google.com/p/stupid-crypto/source/detail?r=fa1d3e0d7c

Modified:
/src/Stupid/Haskell.pm

=======================================
--- /src/Stupid/Haskell.pm Tue Mar 2 12:56:58 2010
+++ /src/Stupid/Haskell.pm Sun Mar 28 07:17:22 2010
@@ -22,10 +22,10 @@
}

## FUNCTODO
-sub Stupid::FunctionList::emitCode {
+sub Stupid::TopLevelList::emitCode {
my $self = shift;

- for my $f (@{$self->{functions}}) {
+ for my $f (@{$self->{topLevels}}) {
$f->emitCode();
}
}
@@ -96,6 +96,45 @@
$self->{type}->emitHaskellType();
}

+sub Stupid::Type::Struct::emitCode {
+ my $self = shift;
+
+ print "data Struct$self->{name} = MkStruct$self->{name} { \n";
+ $self->{decls}->emitCode(); # TODO this decls probably do not look
quite like variable declarations
+ print "}\n";
+}
+
+sub Stupid::Type::StructInstance::emitHaskellType {
+ my $self = shift;
+ my $name = shift;
+
+ print " $self->{name} ";
+}
+
+
+sub Stupid::AbstractDeclList::emitCode {
+ my $self = shift;
+
+ my $first = 1;
+ foreach my $decl (@{$self->{decls}}) {
+ if($first) {
+ print " {- nocomma Stupid::AbstractDeclList::emitCode -}\n";
+ $first=0;
+ } else {
+ print ", {- Stupid::AbstractDeclList::emitCode -}\n";
+ }
+ $decl->emitCode();
+ }
+}
+
+sub Stupid::AbstractDeclare::emitCode {
+ my $self = shift;
+
+ print ' ';
+ $self->{type}->emitDeclaration($self->{name});
+}
+
+
# FUNCTODO
sub Stupid::ArgList::emitReturnDecls {
my $self = shift;
@@ -389,6 +428,14 @@
print "Uint32";
}

+sub Stupid::Type::UInt32::emitDeclaration {
+ my $self = shift;
+ my $name = shift;
+
+ print "$name :: Uint32";
+}
+
+
# TODO is this the stupid typename or the target language type name?
sub Stupid::Type::UInt32::typeName {
my $self = shift;

==============================================================================
Revision: 566a9fe8ae
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 08:42:38 2010
Log: A simpler ostream test to help with puzzling over generated code.
http://code.google.com/p/stupid-crypto/source/detail?r=566a9fe8ae

Added:
/test/ostream-singlechar.stupid

=======================================
--- /dev/null
+++ /test/ostream-singlechar.stupid Mon Mar 29 08:42:38 2010
@@ -0,0 +1,5 @@
+"EXPECT:C";
+
+function(ostream out) test() {
+ out.put(67);
+}

==============================================================================
Revision: d5c5ff1f8b
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 08:44:19 2010
Log: merge
http://code.google.com/p/stupid-crypto/source/detail?r=d5c5ff1f8b

==============================================================================
Revision: 9cac83c85a
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 09:37:10 2010
Log: fix output streams enough for ostream-singlechar to pass.
http://code.google.com/p/stupid-crypto/source/detail?r=9cac83c85a

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

=======================================
--- /lib/StupidStuff.hs Tue Mar 2 12:56:58 2010
+++ /lib/StupidStuff.hs Mon Mar 29 09:37:10 2010
@@ -228,7 +228,7 @@
stupidwhile condition body
else
return ()
-
+
writeToOutputStream :: IO Handle -> IO Uint8 -> IO ()
writeToOutputStream hr vr = do
h <- hr
@@ -236,3 +236,5 @@
hPutChar h (chr $ fromIntegral v)
return ()

+ getput = writeToOutputStream
+
=======================================
--- /src/Stupid/Haskell.pm Sun Mar 28 07:17:22 2010
+++ /src/Stupid/Haskell.pm Mon Mar 29 09:37:10 2010
@@ -29,6 +29,16 @@
$f->emitCode();
}
}
+
+sub Stupid::FunctionCall::emitCode {
+ my $self = shift;
+
+ $self->{function}->emitCall();
+ print '(';
+ # $self->{function}->maybeAddSelf(); # do we ever need this? perhaps
not... where is it used? for object-style invocations only, I think, and in
those, the self is passed through a different syntax
+ $self->{args}->emitParameters();
+ print ");\n";
+}

## FUNCTODO
sub Stupid::Function::emitCode {
@@ -95,6 +105,38 @@

$self->{type}->emitHaskellType();
}
+
+# may need to make member references less ambigious if Haskell
+# doesn't like structures with the same name
+#
+# at the moment (supporting ostreams but not structs) this is being
+# used to get an output function, not a user-defined structure entry.
+#
+# however eventually it will be. so should that syntax be carried over
+# into the haskell code or should this translater do something fancy?
+#
+sub Stupid::MemberRef::emitCode {
+ my $self = shift;
+
+ print '(';
+ print 'get';
+ print $self->{member}->{name};
+ print ' (';
+ $self->{owner}->emitCode();
+ print '))';
+}
+
+sub Stupid::MemberRef::emitCall {
+ my $self = shift;
+
+ $self->emitCode();
+}
+
+sub Stupid::MemberRef::maybeAddSelf {
+ my $self = shift;
+
+ $self->{owner}->maybeAddSelf();
+}

sub Stupid::Type::Struct::emitCode {
my $self = shift;
@@ -166,6 +208,19 @@

$self->{var}->emitArg();
}
+
+sub Stupid::Variable::maybeAddSelf {
+ my $self = shift;
+
+ print "$self->{name}, " if $self->{type}->needsSelf();
+}
+
+#sub Stupid::Variable::emitMemberRef {
+# my $self = shift;
+# my $member = shift;
+# print ' XXX {- Variable::emitMemberRef -}';
+# print $member->{name};
+#}

# FUNCTODO
sub Stupid::Variable::emitArg {
@@ -173,6 +228,10 @@
print $self->{name};
# $self->{type}->emitArg($self->{name});
}
+
+sub Stupid::Type::OStream::needsSelf {
+ return 1;
+}

sub Stupid::Type::OStream::emitArg {
my $self = shift;
@@ -271,7 +330,7 @@
my $self = shift;
print "do { ";
for my $s (@{$self->{statements}}) {
- $s->emitCode();
+ $s->emitCode();
}
print " ; return () }";
# TODO for now we always return nothing at all - the only example I've seen
@@ -289,9 +348,14 @@
# if this is only used for parameters to functions, maybe needs
# $< as separator?

+# its not - its used in structs, and in function parameters too...
+# in the haskell backend, those will have different separators -
+# funciton parameters are space-separated, but struct definitions
+# (haskell records) use a , between fields
+
sub Stupid::ExprList::emitCode {
my $self = shift;
-
+print '{- ExprList emitCode -}';
my $first = 1;
for my $expr (@{$self->{expressions}}) {
print " (";
@@ -299,6 +363,19 @@
print ") ";
}
}
+
+sub Stupid::ExprList::emitParameters {
+ my $self = shift;
+
+print '{- ExprList emitParameters -}';
+
+ # my $first = 1;
+ for my $expr (@{$self->{expressions}}) {
+ # print ', ' if !$first;
+ # $first = 0;
+ $expr->emitParameter();
+ }
+}

sub Stupid::If::emitCode {
my $self = shift;
@@ -483,6 +560,13 @@
print ')) ';
}

+sub Stupid::ArrayRef::emitParameter {
+ my $self = shift;
+
+ $self->emitLValue();
+}
+
+
sub Stupid::ArrayRef::emitCode {
my $self = shift;
print '( readIORef $< (';
@@ -506,6 +590,13 @@
# shouldn't need a U on the end of this, but maybe can put in type spec to
force type to be unsigned (either here or higher up)
}

+sub Stupid::DecimalValue::emitParameter {
+ my $self = shift;
+
+ $self->emitCode();
+}
+
+
sub Stupid::ArrayValue::emitCode {
my $self = shift;


==============================================================================
Revision: 7566b0db61
Author: Ben Clifford <be...@hawaga.org.uk>
Date: Mon Mar 29 12:27:31 2010
Log: ostream-variable test. As far as I can tell, this should
work, but it fails to generate both in C and Haskell.
http://code.google.com/p/stupid-crypto/source/detail?r=7566b0db61

Added:
/test/ostream-variable.stupid

=======================================
--- /dev/null
+++ /test/ostream-variable.stupid Mon Mar 29 12:27:31 2010
@@ -0,0 +1,7 @@
+"EXPECT:A";
+
+function (ostream o) test() {
+ uint8 x=65;
+ o.put(x);
+}
+

Reply all
Reply to author
Forward
0 new messages