Skip to content

Instantly share code, notes, and snippets.

@niner
Created March 21, 2022 22:39
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 niner/a73b112bcee35159e6f7e10a03c1bc55 to your computer and use it in GitHub Desktop.
Save niner/a73b112bcee35159e6f7e10a03c1bc55 to your computer and use it in GitHub Desktop.
diff --git a/src/Raku/ast/statements.rakumod b/src/Raku/ast/statements.rakumod
index 7440ff597..4c276e84a 100644
--- a/src/Raku/ast/statements.rakumod
+++ b/src/Raku/ast/statements.rakumod
@@ -1123,6 +1123,9 @@ class RakuAST::Statement::Use is RakuAST::Statement is RakuAST::BeginTime
}
True
}
+ elsif $name eq 'MONKEY-SEE-NO-EVAL' {
+ True
+ }
else {
False
}
diff --git a/src/vm/moar/dispatchers.nqp b/src/vm/moar/dispatchers.nqp
index e0037af5f..6350f33ec 100644
--- a/src/vm/moar/dispatchers.nqp
+++ b/src/vm/moar/dispatchers.nqp
@@ -1561,6 +1561,22 @@ sub simple-args-proto($callee, $capture) {
return nqp::capturehasnameds($capture) ?? $accepts-any-named !! 1;
}
+class DispatchASTNode {
+ has @!args;
+ method push($arg) {
+ nqp::push(@!args, $arg);
+ }
+ method IMPL-TO-QAST(RakuAST::IMPL::QASTContext $context) {
+ QAST::Op.new:
+ :op('dispatch'),
+ QAST::SVal.new( :value('boot-resume') ),
+ QAST::IVal.new( :value(nqp::const::DISP_DECONT) ),
+ |@!args;
+ }
+ method visit-children($visitor) {
+ }
+}
+
# We we invoke a multi with an argument that is a Proxy (or some other non-Scalar
# container), we need to read the value(s) from the Proxy argument(s) and then go
# on with the dispatch. The ProxyReaderFactory produces code objects that do
@@ -1596,27 +1612,12 @@ class ProxyReaderFactory {
}
method !produce-reader($num-args, $has-nameds, $indices) {
- # Create a block taking each positional arg required, adding an
- # slurpy named if needed.
- my $block := QAST::Block.new(:is_thunk);
+# # Produce a dispatch op with the required arguments decontainerized.
+ my $dispatch := DispatchASTNode.new;
my int $i := 0;
- while $i < $num-args {
- $block.push(QAST::Var.new( :name("a$i"), :decl<param>, :scope<local> ));
- $i++;
- }
- if $has-nameds {
- $block.push(QAST::Var.new( :name<n>, :decl<param>, :scope<local>, :named, :slurpy ));
- }
-
- # Produce a dispatch op with the required arguments decontainerized.
- my $dispatch := QAST::Op.new:
- :op('dispatch'),
- QAST::SVal.new( :value('boot-resume') ),
- QAST::IVal.new( :value(nqp::const::DISP_DECONT) );
- $i := 0;
my $decont-index := 0;
while $i < $num-args {
- my $var := QAST::Var.new( :name("a$i"), :scope<local> );
+ my $var := QAST::Var.new( :name("a$i"), :scope<lexical> );
if nqp::atpos_i($indices, $decont-index) == $i {
$dispatch.push(QAST::Op.new( :op<decont>, $var ));
$decont-index++;
@@ -1627,12 +1628,57 @@ class ProxyReaderFactory {
$i++;
}
if $has-nameds {
- $dispatch.push(QAST::Var.new( :name<n>, :scope<local>, :named, :flat ));
+ $dispatch.push(QAST::Var.new( :name<n>, :scope<lexical>, :named, :flat ));
+ }
+
+ # Create a block taking each positional arg required, adding an
+ # slurpy named if needed.
+ my @parameters;
+ $i := 0;
+ while $i < $num-args {
+ #$block.push(QAST::Var.new( :name("a$i"), :decl<param>, :scope<local> ));
+ nqp::push(@parameters,
+ RakuAST::Parameter.new(
+ target => RakuAST::ParameterTarget::Var.new("a$i"),
+ ),
+ );
+ $i++;
}
- $block.push($dispatch);
+ if $has-nameds {
+# $block.push(QAST::Var.new( :name<n>, :decl<param>, :scope<local>, :named, :slurpy ));
+ note("has nameds");
+ nqp::push(@parameters,
+ RakuAST::Parameter::Slurpy.new(
+ target => RakuAST::ParameterTarget::Var.new('n'),
+ names => ['n'],
+ ),
+ );
+ }
+
+ my $block := RakuAST::PointyBlock.new(
+ signature => RakuAST::Signature.new(
+ parameters => @parameters,
+ ),
+ body => RakuAST::Blockoid.new(
+ RakuAST::StatementList.new(
+ RakuAST::Statement::Expression.new(
+ expression => $dispatch,
+ ),
+ ),
+ ),
+ );
+ my $compunit := RakuAST::CompUnit.new(
+ :!eval,
+ :comp-unit-name('proxy-reader'),
+ :statement-list(RakuAST::StatementList.new(
+ RakuAST::Statement::Expression.new(
+ expression => $block,
+ ),
+ ))
+ );
# Compile and return it.
- nqp::getcomp('Raku').compile($block, :from<optimize>)
+ nqp::getcomp('Raku').compile($compunit, :from(nqp::getcomp('Raku').exists_stage('optimize') ?? 'optimize' !! 'ast'))
}
}
my $PROXY-READERS := ProxyReaderFactory.new;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment