Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "* Convert RxOp, Sig and Unit to MooseX::Declare. That's all o…
…f them. :-)"

This reverts commit f4ddde8.
  • Loading branch information
Audrey Tang committed Jul 20, 2010
1 parent 50423d2 commit 2a2ae2d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 20 deletions.
38 changes: 33 additions & 5 deletions RxOp.pm
@@ -1,24 +1,52 @@
use strict;
use warnings;
use 5.010;
use MooseX::Declare;

use CgOp;

class RxOp {
{
package RxOp;
use Moose;

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

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

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

has text => (isa => 'Str', is => 'ro', required => 1);

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

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

has type => (isa => 'Str', is => 'ro', required => 1);
# ? + * only
# zyg * 1

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

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

# zyg * N

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

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

class Sig::Target {
{
package Sig::Target;
use Moose;

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

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

method binder ($get) {
sub binder {
my ($self, $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;
}

class Sig::Parameter {
{
package Sig::Parameter;
use Moose;

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

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

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

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

class Sig {
{
package Sig;
use Moose;

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

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

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

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

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

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

1;
17 changes: 12 additions & 5 deletions Unit.pm
@@ -1,19 +1,23 @@
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
class Unit {
{
package Unit;
use Moose;
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');

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

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

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

0 comments on commit 2a2ae2d

Please sign in to comment.