Skip to content

Commit d16bf96

Browse files
committed
Start sketching out compilation of some more of the nodes in QAST::Compiler.
1 parent 6b5c556 commit d16bf96

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

src/QAST/Compiler.nqp

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,50 @@
1-
class QAST::Compiler is HLL::Compiler {
1+
class QAST::Compiler is HLL::Compiler {
2+
# Holds information about the current register usage, for when
3+
# we're allocating tempories.
4+
my class RegAlloc {
5+
has int $!cur_p;
6+
has int $!cur_s;
7+
has int $!cur_i;
8+
has int $!cur_n;
9+
10+
method new($cur?) {
11+
my $obj := nqp::create(self);
12+
$cur ??
13+
$obj.BUILD($cur.cur_p, $cur.cur_s, $cur.cur_i, $cur.cur_n) !!
14+
$obj.BUILD(10, 10, 10, 10);
15+
$obj
16+
}
17+
18+
method BUILD($p, $s, $i, $n) {
19+
$!cur_p := $p;
20+
$!cur_s := $s;
21+
$!cur_i := $i;
22+
$!cur_n := $n;
23+
}
24+
25+
method fresh_p() {
26+
$!cur_p := $!cur_p + 1;
27+
$!cur_p
28+
}
29+
method fresh_s() {
30+
$!cur_s := $!cur_s + 1;
31+
$!cur_s
32+
}
33+
method fresh_i() {
34+
$!cur_i := $!cur_i + 1;
35+
$!cur_i
36+
}
37+
method fresh_n() {
38+
$!cur_n := $!cur_n + 1;
39+
$!cur_n
40+
}
41+
42+
method cur_p() { $!cur_p }
43+
method cur_s() { $!cur_s }
44+
method cur_i() { $!cur_i }
45+
method cur_n() { $!cur_n }
46+
}
47+
248
our $serno;
349
INIT {
450
$serno := 10;
@@ -12,6 +58,46 @@ class QAST::Compiler is HLL::Compiler {
1258
method escape($str) { 'ucs4:"' ~ pir::escape__Ss($str) ~ '"' }
1359
1460
proto method as_post(*@args, *%_) { * }
61+
62+
multi method as_post(QAST::Block $node) {
63+
# Fresh registers.
64+
my $*REGALLOC := RegAlloc.new();
65+
66+
# DO ALL THE STUFFS
67+
}
68+
69+
multi method as_post(QAST::Stmt $node) {
70+
my $orig_reg := $*REGALLOC;
71+
{
72+
my $*REGALLOC := RegAlloc.new($orig_reg);
73+
74+
# COMPILE ALL THE NODES
75+
}
76+
}
77+
78+
multi method as_post(QAST::IVal $node) {
79+
~$node.value
80+
}
81+
82+
multi method as_post(QAST::NVal $node) {
83+
~$node.value
84+
}
85+
86+
multi method as_post(QAST::SVal $node) {
87+
self.escape($node.value)
88+
}
89+
90+
multi method as_post(QAST::WVal $node) {
91+
my $val := $node.value;
92+
my $sc := pir::nqp_get_sc_for_object__PP($val);
93+
my $handle := $sc.handle;
94+
my $idx := $sc.slot_index_for($val);
95+
my $reg := $*REGALLOC.fresh_p();
96+
my $ops := self.post_new('Ops', :result($reg));
97+
$ops.push_pirop('nqp_get_sc_object', $reg, self.escape($handle), ~$idx);
98+
$ops;
99+
}
100+
15101
multi method as_post(QAST::Regex $node) {
16102
my $ops := self.post_new('Ops');
17103
my $prefix := self.unique('rx') ~ '_';

0 commit comments

Comments
 (0)