Skip to content

Commit

Permalink
API for asking whether the compiler supports a certain nqp op
Browse files Browse the repository at this point in the history
This can be used to conditionally compile backend specific code in
modules like NativeCall
  • Loading branch information
niner committed Oct 4, 2021
1 parent bc5e5cb commit 6790b45
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/HLL/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ class HLL::Compiler does HLL::Backend::Default {
nqp::die("The backend { $backend.HOW.name($backend) } doesn't support profiler-snapshot");
}
}

method supports-op($opname) {
self.backend.supports-op($opname)
}
}

my $compiler := HLL::Compiler.new();
Expand Down
4 changes: 4 additions & 0 deletions src/vm/js/HLL/Backend.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ class JavaScriptBackend {
method is_compunit($cuish) {
nqp::isinvokable($cuish) || nqp::iscompunit($cuish);
}

method supports-op($opname) {
0 # NYI, so give the safe answer
}
}

# Role specifying the default backend for this build.
Expand Down
4 changes: 4 additions & 0 deletions src/vm/jvm/HLL/Backend.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class HLL::Backend::JVM {
method compunit_coderefs($cu) {
nqp::compunitcodes($cu)
}

method supports-op($opname) {
0 # NYI, so give the safe answer
}
}

# Role specifying the default backend for this build.
Expand Down
6 changes: 6 additions & 0 deletions src/vm/moar/HLL/Backend.nqp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Backend class for the MoarVM.

use MASTOps;

my sub literal_subst(str $source, str $pattern, $replacement) {
my $where := 0;
my $result := $source;
Expand Down Expand Up @@ -824,6 +826,10 @@ class HLL::Backend::MoarVM {
method compunit_coderefs($cu) {
nqp::compunitcodes($cu)
}

method supports-op($opname) {
nqp::existskey(%MAST::Ops::codes, $opname) # || MAST::ExtOpRegistry.extop_known($opname)
}
}

# Role specifying the default backend for this build.
Expand Down

0 comments on commit 6790b45

Please sign in to comment.