Skip to content

Commit

Permalink
* Convert RxOp, Sig and Unit to MooseX::Declare. That's all of them. :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
Audrey Tang committed Jul 20, 2010
1 parent 4dc75bb commit f4ddde8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 82 deletions.
38 changes: 5 additions & 33 deletions RxOp.pm
@@ -1,52 +1,24 @@
use strict;
use warnings;
use 5.010;
use MooseX::Declare;

use CgOp;

{
package RxOp;
use Moose;

class RxOp {
has zyg => (isa => 'ArrayRef[RxOp]', is => 'ro');

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package RxOp::String;
use Moose;
extends 'RxOp';

class RxOp::String extends RxOp {
has text => (isa => 'Str', is => 'ro', required => 1);

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package RxOp::Quantifier;
use Moose;
extends 'RxOp';

class RxOp::Quantifier extends RxOp {
has type => (isa => 'Str', is => 'ro', required => 1);
# ? + * only
# zyg * 1

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package RxOp::Sequence;
use Moose;
extends 'RxOp';

class RxOp::Sequence extends RxOp {
# zyg * N

__PACKAGE__->meta->make_immutable;
no Moose;
}

1;
47 changes: 10 additions & 37 deletions Sig.pm
@@ -1,44 +1,30 @@
use strict;
use warnings;
use 5.010;
use MooseX::Declare;

{
package Sig::Target;
use Moose;

class Sig::Target {
has slot => (is => 'ro', isa => 'Maybe[Str]', required => 1);
has list => (is => 'ro', isa => 'Bool', default => 0);

sub used_slots {
my $self = shift;
method used_slots () {
if ($self->slot) { [ $self->slot, $self->list ] } else { () }
}

sub binder {
my ($self, $get) = @_;
method binder ($get) {
if ($self->slot) {
# TODO: implement ro, etc
CgOp::bind(0, CgOp::scopedlex($self->slot), $get);
} else {
CgOp::noop;
}
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Sig::Parameter;
use Moose;

class Sig::Parameter {
has target => (is => 'ro', isa => 'Sig::Target', required => 1,
handles => [ 'used_slots' ]);
has slurpy => (is => 'ro', isa => 'Bool', default => 0);

sub binder {
my ($self, $ixp) = @_;

method binder ($ixp) {
if ($self->slurpy) {
$self->target->binder(
CgOp::let(CgOp::rawnew('DynObject', CgOp::getfield('klass',
Expand All @@ -59,32 +45,22 @@ use 5.010;
$self->target->binder(CgOp::pos($$ixp++));
}
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Sig;
use Moose;

class Sig {
has params => (isa => 'ArrayRef[Sig::Parameter]', is => 'ro', required => 1);

sub for_method {
my $self = shift;
method for_method () {
my $sp = Sig::Parameter->new(target =>
Sig::Target->new(slot => 'self'));
Sig->new(params => [ $sp, @{ $self->params } ]);
}

sub used_slots {
my $self = shift;
method used_slots () {
map { $_->used_slots } @{ $self->params };
}

sub binder {
my ($self) = @_;

method binder () {
# TODO: Error checking.
my $ix = 0;
my @p;
Expand All @@ -93,9 +69,6 @@ use 5.010;
}
CgOp::prog(@p);
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

1;
17 changes: 5 additions & 12 deletions Unit.pm
@@ -1,23 +1,19 @@
use strict;
use warnings;
use 5.010;
use MooseX::Declare;

# A Unit generates a CLR class with a BOOT member
# All used Units except for the setting go into Niecza.Kernel.Units
# The main program generates a main class, which sets up Units and runs the
# setting
# BOOT subs take one argument, the outer protopad
{
package Unit;
use Moose;
class Unit {
has mainline => (isa => 'Body', is => 'ro', required => 1);
has name => (isa => 'Str', is => 'ro', required => 1);
has code => (isa => 'CodeGen', is => 'ro', init_arg => undef, lazy => 1,
builder => 'gen_code');
has setting => (isa => 'Body', is => 'ro');

sub gen_code {
my ($self) = @_;
method gen_code () {
$self->mainline->outer($self->setting) if $self->setting;
CodeGen->new(name => 'BOOT', entry => 1,
ops => CgOp::prog(
Expand All @@ -30,8 +26,7 @@ use 5.010;
CgOp::protosub($self->mainline))))));
}

sub write {
my ($self) = @_;
method write () {
#say STDERR (YAML::XS::Dump($self));
print ::NIECZA_OUT <<EOH;
public class @{[ $self->name ]} {
Expand All @@ -40,8 +35,6 @@ EOH
$self->mainline->write;
print ::NIECZA_OUT "}\n"
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

1;

0 comments on commit f4ddde8

Please sign in to comment.