Skip to content

Commit 2e28049

Browse files
committed
Start to sketch out infrastructure for halding operations.
1 parent 95641b4 commit 2e28049

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/QAST/Compiler.nqp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class QAST::Compiler is HLL::Compiler {
4646
}
4747

4848
our $serno;
49-
INIT {
49+
INIT {
5050
$serno := 10;
5151
Q:PIR {
5252
$P0 = find_lex '$?CLASS'
@@ -109,6 +109,10 @@ class QAST::Compiler is HLL::Compiler {
109109
$ops
110110
}
111111

112+
multi method as_post(QAST::Op $node) {
113+
QAST::Operations.compile_op(self, '', $node)
114+
}
115+
112116
multi method as_post(QAST::IVal $node) {
113117
self.post_new('Ops', :result(~$node.value))
114118
}

src/QAST/Operations.nqp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class QAST::Operations {
2+
# Maps operations to code that will handle them. Hash of code.
3+
my %core_ops;
4+
5+
# Maps HLL-specific operations to code that will handle them.
6+
# Hash of hash of code.
7+
my %hll_ops;
8+
9+
# Compiles an operation to POST.
10+
method compile_op($qastcomp, $hll, $op) {
11+
my $name := $op.op;
12+
if $hll {
13+
if %hll_ops{$hll} && %hll_ops{$hll}{$name} -> $mapper {
14+
return $mapper($qastcomp, $op);
15+
}
16+
}
17+
if %core_ops{$name} -> $mapper {
18+
return $mapper($qastcomp, $op);
19+
}
20+
pir::die("No registered operation handler for '$name'");
21+
}
22+
23+
# Adds a core op that maps to a PIR op.
24+
method add_core_pir_mapping($op, $pirop, $sig) {
25+
%core_ops{$op} := pirop_mapper($pirop, $sig);
26+
}
27+
28+
# Adds a HLL op that maps to a PIR op.
29+
method add_hll_pir_mapping($hll, $op, $pirop, $sig) {
30+
%hll_ops{$hll} := {} unless %hll_ops{$hll};
31+
%hll_ops{$hll}{$op} := pirop_mapper($pirop, $sig);
32+
}
33+
}
34+
35+
INIT {
36+
}

tools/build/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ QREGEX_SOURCES = \
101101
src/QAST/Stmts.nqp \
102102
src/QAST/Stmt.nqp \
103103
src/QAST/Block.nqp \
104+
src/QAST/Operations.nqp \
104105
src/QAST/Compiler.nqp \
105106
src/QRegex/NFA.nqp \
106107
src/QRegex/Cursor.nqp \

0 commit comments

Comments
 (0)