Skip to content

Commit

Permalink
Get variable handling to run...
Browse files Browse the repository at this point in the history
... but do the wrong thing. need to fix lexpad creation/access.
  • Loading branch information
coke committed Jun 18, 2013
1 parent 5c8abfb commit b353cc7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
62 changes: 42 additions & 20 deletions src/Partcl/Actions.pm
Expand Up @@ -294,41 +294,59 @@ class Partcl::Actions is HLL::Actions {
#say(nqp::getcodename(nqp::curcode()) ~ ':' ~ $/);
my $variable;
if $<global> {
$variable := QAST::Var.new( :scope<keyed>,
QAST::Var.new( :name<%GLOBALS>, :scope<package>, :namespace([]) ),
~$<identifier>
);
$variable := QAST::Op.new( :op<atkey>,
QAST::Var.new(
:name<%GLOBALS>,
:scope<package>,
:namespace([])
),
QAST::SVal.new(:value($<identifier>))
);
} else {
$variable := QAST::Var.new( :scope<keyed>,
QAST::Var.new( :name<lexpad>, :scope<register> ),
~$<identifier>
);
}
$variable := QAST::Op.new( :op<atkey>,
QAST::Var.new(
:name<lexpad>,
:scope<lexical>
),
QAST::SVal.new(:value($<identifier>))
);
}
# Array access
if $<key> {
make QAST::SVal.new(:value($<key>[0]));
=begin fixit
make QAST::Op.new( :op<if>,
QAST::Op.new( :op<pir::iseq__ISS>,
QAST::Op.new( :op<pir::typeof__SP>, $variable),
QAST::Op.new( :op<iseq_s>,
QAST::Op.new( :op<what>, $variable),
QAST::Val.new( :value<TclArray>)
),
QAST::Var.new( :scope<keyed>,
QAST::Op.new( :op<atkey>,
$variable,
~$<key>[0]
QAST::SVal.new(:value($<key>[0]))
),
QAST::Op.new( :op<call>, :name<error>,
"can't read \"$<identifier>({$<key>[0]})\": variable isn't array"
)
)
=end fixit
}
else {
# Scalar
make QAST::SVal.new(:value("eek"));
=begin fixit
make QAST::Op.new( :op<unless>,
QAST::Op.new( :op<isnull>, $variable),
QAST::Op.new( :op<unless>,
QAST::Op.new( :op<pir::iseq__ISS>,
QAST::Op.new( :op<pir::typeof__SP>, $variable),
QAST::Op.new( :op<iseq_s>,
QAST::Op.new( :op<what>, $variable),
QAST::Val.new( :value<TclArray>)
),
$variable,
Expand All @@ -340,15 +358,19 @@ class Partcl::Actions is HLL::Actions {
"can't read \"$<identifier>\": no such variable"
)
);
=end fixit
}
}
method variable:sym<escaped>($/) {
#say(nqp::getcodename(nqp::curcode()) ~ ':' ~ $/);
make QAST::Var.new( :scope<keyed>,
QAST::Var.new( :name<lexpad>, :scope<register> ),
~$<identifier>,
:node($/)
make QAST::Op.new( :op<atkey>,
QAST::Var.new(
:name<lexpad>,
:scope<lexical>
),
QAST::SVal.new(:value($<identifier>))
);
}
Expand Down
18 changes: 10 additions & 8 deletions src/Partcl/commands/set.pm
Expand Up @@ -8,31 +8,33 @@ method set(*@args) {
# Does it look like foo(bar) ?
# XXX Can we use the variable term in the grammar for this?
my $result;
if pir::ord__ISI($varname, -1) == 41 && pir::index__ISS($varname, '(' ) != -1 {
say(1);
if nqp::ord($varname, -1) == 41 && nqp::index($varname, '(' ) != -1 {
say(2);
# find the variable name and key name
my $left_paren := pir::index__ISS($varname, '(');
my $right_paren := pir::index__ISS($varname, ')');
my $left_paren := nqp::index($varname, '(');
my $right_paren := nqp::index($varname, ')');
my $keyname := nqp::substr($varname, $left_paren+1, $right_paren-$left_paren-1);
my $arrayname := nqp::substr($varname, 0, $left_paren);

say(3);
if +@args == 2 { # set
my $var := Q:PIR {
.local pmc varname, lexpad
varname = find_lex '$arrayname'
lexpad = find_dynamic_lex '%LEXPAD'
%r = vivify lexpad, varname, ['TclArray']
};
if !pir::isa__IPS($var, 'TclArray') {
if !nqp::istype($var, 'TclArray') {
self.error("can't set \"$varname\": variable isn't array");
}
$var{$keyname} := $value;
$result := $var{$keyname};
} else { # get
my $lexpad := pir::find_dynamic_lex__PS('%LEXPAD');
my $lexpad := nqp::getlexdyn('%LEXPAD');
my $var := $lexpad{$arrayname};
if nqp::isnull($var) {
self.error("can't read \"$varname\": no such variable");
} elsif !pir::isa__IPS($var, 'TclArray') {
} elsif !nqp::istype($var, 'TclArray') {
self.error("can't read \"$varname\": variable isn't array");
} elsif nqp::isnull($var{$keyname}) {
self.error("can't read \"$varname($keyname)\": no such element in array");
Expand All @@ -48,7 +50,7 @@ method set(*@args) {
lexpad = find_dynamic_lex '%LEXPAD'
%r = vivify lexpad, varname, ['Undef']
};
if pir::isa__IPS($result, 'TclArray') {
if nqp::istype($result, 'TclArray') {
self.error("can't set \"$varname\": variable is array");
} elsif nqp::defined($value) {
pir::copy__vPP($result, $value);
Expand Down

0 comments on commit b353cc7

Please sign in to comment.