Skip to content

Commit

Permalink
Added nqp::p6getlexclient op
Browse files Browse the repository at this point in the history
Find a symbol in client's lexical scope. Works at compile, optimize, and
run times.
  • Loading branch information
vrurg committed Aug 23, 2019
1 parent bba92c0 commit cbce0ed
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/ops.markdown
Expand Up @@ -24,6 +24,7 @@
- [p6decontrv](#p6decontrv)
- [p6definite](#p6definite)
- [p6finddispatcher](#p6finddispatcher)
- [p6getlexclient](#p6getlexclient)
- [p6getouterctx](#p6getouterctx)
- [p6init](#p6init)
- [p6inpre](#p6inpre)
Expand Down Expand Up @@ -162,6 +163,11 @@ Decodes the unix timestamp $epoch into a native int array with six fields contai
## p6finddispatcher
* p6finddispatcher(str $value)

## p6getlexclient
* p6getlexclient(str $symbol)

Takes a name and finds corresponding symbol in lexical scope of [p6clientctx](#p6clientctx).

## p6getouterctx
* p6getouterctx(Mu $closure)

Expand Down
122 changes: 122 additions & 0 deletions src/Perl6/Ops.nqp
Expand Up @@ -186,3 +186,125 @@ _register_op_with_nqp('p6clientcorever', -> $qast {
)
)
});

_register_op_with_nqp( 'p6getlexclient', -> $qast {
my $ctx := QAST::Node.unique('$ctx');
my $PseudoStash := QAST::Node.unique('$PseudoStash');
my $Map := QAST::Node.unique('$Map');
my $stash := QAST::Node.unique('$stash');
QAST::Op.new(
:op<if>,
QAST::Op.new(
:op<isconcrete>,
QAST::VarWithFallback.new(
:name<$*OPTIMIZER-SYMBOLS>,
:fallback(
QAST::WVal.new( :value(Mu) )
),
:scope<contextual>
)
),
QAST::Op.new(
:op<callmethod>,
QAST::Var.new( :name<$*OPTIMIZER-SYMBOLS>, :scope<contextual> ),
QAST::SVal.new( :value<find_symbol> ),
QAST::Op.new(
:op<split>,
QAST::SVal.new( :value<::> ),
$qast[0]
)
),
QAST::Op.new(
:op<if>,
QAST::Op.new(
:op<isconcrete>,
QAST::VarWithFallback.new(
:name<$*W>,
:fallback(
QAST::Op.new( :op<null> )
# QAST::WVal.new( :value(NQPMu) )
),
:scope<contextual>
)
),
QAST::Op.new(
:op<callmethod>,
QAST::Var.new( :name<$*W>, :scope<contextual> ),
QAST::SVal.new( :value<find_symbol> ),
QAST::Op.new(
:op<split>,
QAST::SVal.new( :value<::> ),
$qast[0]
)
),
QAST::Stmts.new(
QAST::Op.new(
:op<bind>,
QAST::Var.new( :name($ctx), :scope<local>, :decl<var> ),
QAST::Op.new( :op<p6clientctx> ),
),
QAST::Op.new(
:op<bind>,
QAST::Var.new( :name($PseudoStash), :scope<local>, :decl<var> ),
QAST::Op.new(
:op<getlexrel>,
QAST::Var.new( :name($ctx), :scope<local> ),
QAST::SVal.new( :value<PseudoStash> )
),
),
QAST::Op.new(
:op<bind>,
QAST::Var.new( :name($Map), :scope<local>, :decl<var> ),
QAST::Op.new(
:op<getlexrel>,
QAST::Var.new( :name($ctx), :scope<local> ),
QAST::SVal.new( :value<Map> )
),
),
QAST::Op.new(
:op<bind>,
QAST::Var.new( :name($stash), :scope<local>, :decl<var> ),
QAST::Op.new(
:op<create>,
QAST::Var.new( :name($PseudoStash), :scope<local> ),
)
),
QAST::Op.new(
:op<bindattr>,
QAST::Var.new( :name($stash), :scope<local> ),
QAST::Var.new( :name($Map), :scope<local> ),
QAST::SVal.new( :value<$!storage> ),
QAST::Op.new(
:op<ctxlexpad>,
QAST::Var.new( :name($ctx), :scope<local> ),
),
),
QAST::Op.new(
:op<bindattr>,
QAST::Var.new( :name($stash), :scope<local> ),
QAST::Var.new( :name($PseudoStash), :scope<local> ),
QAST::SVal.new( :value<$!ctx> ),
QAST::Var.new( :name($ctx), :scope<local> ),
),
QAST::Op.new(
:op<bindattr_i>,
QAST::Var.new( :name($stash), :scope<local> ),
QAST::Var.new( :name($PseudoStash), :scope<local> ),
QAST::SVal.new( :value<$!mode> ),
QAST::IVal.new( :value(1) ) # PseudoStash::STATIC_CHAIN constant value
),
QAST::Op.new(
:op<call>,
QAST::Op.new(
:op<getlexrel>,
QAST::Var.new( :name($ctx), :scope<local> ),
QAST::SVal.new( :value<&INDIRECT_NAME_LOOKUP> )
),
QAST::Var.new( :name($stash), :scope<local> ),
$qast[0]
)
),
),
)
}
);

0 comments on commit cbce0ed

Please sign in to comment.