Skip to content

Instantly share code, notes, and snippets.

Created July 4, 2011 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1063742 to your computer and use it in GitHub Desktop.
Save anonymous/1063742 to your computer and use it in GitHub Desktop.
Cannot modify readonly value in '&infix:<=>'
sub make_flipflop($/) {
my $excl_lhs := 0;
my $excl_rhs := 0;
my $sedlike := 0;
if ($/<infix><sym> eq '^ff' || $/<infix><sym> eq '^ff^'
|| $/<infix><sym> eq '^fff' || $/<infix><sym> eq '^fff^') {
$excl_lhs := 1;
}
if ($/<infix><sym> eq 'ff^' || $/<infix><sym> eq '^ff^'
|| $/<infix><sym> eq 'fff^' || $/<infix><sym> eq '^fff^') {
$excl_rhs := 1;
}
if ($/<infix><sym> eq 'fff' || $/<infix><sym> eq '^fff'
|| $/<infix><sym> eq 'fff^' || $/<infix><sym> eq '^fff^') {
$sedlike := 1;
}
my $lhspast := $/[0].ast;
my $rhspast := $/[1].ast;
my $state_var := $lhspast.unique('ff_state');
# define state-saving pir
my $label := $lhspast.unique;
my $get_state := " %r = get_hll_global ['GLOBAL'], '$state_var'
unless null %r goto ff_state_assign_$label
new %r, 'Integer'
assign %r, 0
set_hll_global ['GLOBAL'], '$state_var', %r
ff_state_assign_$label:
%0 = %r";
my $set_state := " set_hll_global ['GLOBAL'], '$state_var', %0";
my $lhsinc := ($excl_lhs) ?? '&postfix:<++>' !! '&prefix:<++>';
my $rhsinc := ($excl_rhs) ?? '&postfix:<++>' !! '&prefix:<++>';
my $past := PAST::Op.new(
:pasttype<stmts>,
PAST::Op.new(
:pasttype('inline'),
:inline($get_state), # state_var exists
PAST::Var.new( :name($state_var), :scope('lexical'), :isdecl(1), :viviself(0) ),
),
PAST::Op.new(:pasttype<unless>,
PAST::Var.new(:name($state_var), :scope<lexical>),
PAST::Op.new(:pasttype<if>,
$lhspast,
PAST::Op.new(:name($lhsinc),
PAST::Var.new(:name($state_var), :scope<lexical>)
)
)
),
PAST::Op.new(:pasttype<if>,
PAST::Var.new(:name($state_var), :scope<lexical>),
PAST::Op.new(:pasttype<if>,
$rhspast,
PAST::Op.new(:name('&infix:<=>'),
PAST::Var.new(:name($state_var), :scope<lexical>),
PAST::Val.new( :value(0) )),
# $*ST.add_constant('Int', 'int', 0)),
PAST::Op.new(:name($rhsinc),
PAST::Var.new(:name($state_var), :scope<lexical>))
)
),
# PAST::Op.new( :inline($set_state), PAST::Var.new( :name($state_var), :scope('lexical') ) ),
);
if $sedlike {
$past.pasttype('unless');
$past.unshift(PAST::Var.new(:name($state_var), :scope<lexical>));
}
$past := PAST::Op.new(
:pasttype<unless>,
$past,
PAST::Val.new( :value('') ),
# $*ST.add_constant('Str', 'str', '')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment