Skip to content

Commit a8df907

Browse files
committed
Add a QAST::InlinePlaceholder to represent a place in the QAST where an argument needs to be filled in when inlining. Implement a first cut of producing a tree with the placeholders substituted in.
1 parent d94369f commit a8df907

File tree

12 files changed

+84
-0
lines changed

12 files changed

+84
-0
lines changed

src/QAST/IVal.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class QAST::IVal is QAST::Node {
22
has int $!value;
33
method value(*@value) { $!value := @value[0] if @value; $!value }
4+
5+
method substitute_inline_placeholders(@fillers) {
6+
self
7+
}
48
}

src/QAST/InlinePlaceholder.nqp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This indicates a place in a QAST tree that has been stashed for later
2+
# inlining where one of the arguments to the inlined routine was used.
3+
class QAST::InlinePlaceholder is QAST::Node {
4+
has int $!position;
5+
6+
method position(*@value) {
7+
@value ?? ($!position := @value[0]) !! $!position
8+
}
9+
10+
method substitute_inline_placeholders(@fillers) {
11+
$!position < +@fillers
12+
?? @fillers[$!position]
13+
!! nqp::die("Inline placeholder index out of range")
14+
}
15+
}

src/QAST/NVal.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class QAST::NVal is QAST::Node {
22
has num $!value;
33
method value(*@value) { $!value := @value[0] if @value; $!value }
4+
5+
method substitute_inline_placeholders(@fillers) {
6+
self
7+
}
48
}

src/QAST/Node.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ class QAST::Node {
100100
(%uniques{$prefix} := 1);
101101
$prefix ~ '_' ~ $id
102102
}
103+
104+
method substitute_inline_placeholders(@fillers) {
105+
nqp::die(self.HOW.name(self) ~ " does not support inlining");
106+
}
103107
}

src/QAST/Op.nqp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ class QAST::Op is QAST::Node {
66
method name(*@value) { $!name := @value[0] if @value; $!name || "" }
77
method op(*@value) { $!op := @value[0] if @value; $!op }
88
method childorder(*@value) { $!childorder := @value[0] if @value; $!childorder || "" }
9+
10+
method substitute_inline_placeholders(@fillers) {
11+
my $result := pir::repr_clone__PP(self);
12+
my $i := 0;
13+
my $elems := +@(self);
14+
while $i < $elems {
15+
$result[$i] := self[$i].substitute_inline_placeholders(@fillers);
16+
$i := $i + 1;
17+
}
18+
$result
19+
}
920
}

src/QAST/SVal.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class QAST::SVal is QAST::Node {
22
has str $!value;
33
method value(*@value) { $!value := @value[0] if @value; $!value }
4+
5+
method substitute_inline_placeholders(@fillers) {
6+
self
7+
}
48
}

src/QAST/Stmt.nqp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@ class QAST::Stmt is QAST::Node {
22
has $!resultchild;
33

44
method resultchild(*@value) { $!resultchild := @value[0] if @value; $!resultchild }
5+
6+
method substitute_inline_placeholders(@fillers) {
7+
my $result := pir::repr_clone__PP(self);
8+
my $i := 0;
9+
my $elems := +@(self);
10+
while $i < $elems {
11+
$result[$i] := self[$i].substitute_inline_placeholders(@fillers);
12+
$i := $i + 1;
13+
}
14+
$result
15+
}
516
}

src/QAST/Stmts.nqp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@ class QAST::Stmts is QAST::Node {
22
has $!resultchild;
33

44
method resultchild(*@value) { $!resultchild := @value[0] if @value; $!resultchild }
5+
6+
method substitute_inline_placeholders(@fillers) {
7+
my $result := pir::repr_clone__PP(self);
8+
my $i := 0;
9+
my $elems := +@(self);
10+
while $i < $elems {
11+
$result[$i] := self[$i].substitute_inline_placeholders(@fillers);
12+
$i := $i + 1;
13+
}
14+
$result
15+
}
516
}

src/QAST/Var.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ class QAST::Var is QAST::Node {
1010
method decl(*@value) { $!decl := @value[0] if @value; $!decl }
1111
method slurpy(*@value) { $!slurpy := @value[0] if @value; $!slurpy }
1212
method default(*@value) { $!default := @value[0] if @value; $!default }
13+
14+
method substitute_inline_placeholders(@fillers) {
15+
self
16+
}
1317
}

src/QAST/WVal.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ class QAST::WVal is QAST::Node does QAST::CompileTimeValue {
44
?? self.set_compile_time_value(@value[0])
55
!! self.compile_time_value()
66
}
7+
8+
method substitute_inline_placeholders(@fillers) {
9+
self
10+
}
711
}

0 commit comments

Comments
 (0)