Skip to content

Commit

Permalink
Start to sketch out infrastructure for halding operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 22, 2012
1 parent 95641b4 commit 2e28049
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class QAST::Compiler is HLL::Compiler {
}

our $serno;
INIT {
INIT {
$serno := 10;
Q:PIR {
$P0 = find_lex '$?CLASS'
Expand Down Expand Up @@ -109,6 +109,10 @@ class QAST::Compiler is HLL::Compiler {
$ops
}

multi method as_post(QAST::Op $node) {
QAST::Operations.compile_op(self, '', $node)
}

multi method as_post(QAST::IVal $node) {
self.post_new('Ops', :result(~$node.value))
}
Expand Down
36 changes: 36 additions & 0 deletions src/QAST/Operations.nqp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class QAST::Operations {
# Maps operations to code that will handle them. Hash of code.
my %core_ops;

# Maps HLL-specific operations to code that will handle them.
# Hash of hash of code.
my %hll_ops;

# Compiles an operation to POST.
method compile_op($qastcomp, $hll, $op) {
my $name := $op.op;
if $hll {
if %hll_ops{$hll} && %hll_ops{$hll}{$name} -> $mapper {
return $mapper($qastcomp, $op);
}
}
if %core_ops{$name} -> $mapper {
return $mapper($qastcomp, $op);
}
pir::die("No registered operation handler for '$name'");
}

# Adds a core op that maps to a PIR op.
method add_core_pir_mapping($op, $pirop, $sig) {
%core_ops{$op} := pirop_mapper($pirop, $sig);
}

# Adds a HLL op that maps to a PIR op.
method add_hll_pir_mapping($hll, $op, $pirop, $sig) {
%hll_ops{$hll} := {} unless %hll_ops{$hll};
%hll_ops{$hll}{$op} := pirop_mapper($pirop, $sig);
}
}

INIT {
}
1 change: 1 addition & 0 deletions tools/build/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ QREGEX_SOURCES = \
src/QAST/Stmts.nqp \
src/QAST/Stmt.nqp \
src/QAST/Block.nqp \
src/QAST/Operations.nqp \
src/QAST/Compiler.nqp \
src/QRegex/NFA.nqp \
src/QRegex/Cursor.nqp \
Expand Down

0 comments on commit 2e28049

Please sign in to comment.