Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: linscan
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 122 lines (75 sloc) 2.237 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
=head1 NAME

TODO - This is the TODO file for a PIR implementation in PGE.

=head1 PARSING

Currently parsing is mostly done. Some areas require particular
attention:

=over 4

=item * C<var_ref>

Currently C<< <id> >> rule is overused. We need to split it into
C<< <id> >> and C<< <var_ref> >> rules to implement checks for
undeclared variables.

=item * C<heredoc>

=item * C<macro>

=back

=head1 OPTIMISING

Optimising isn't started yet. General roadmap:

=over 4

=item *

Implement PASTing.

=item *

Convert PAST to Lambda-lifted form

=item *

Optimise using full power of FP notation.

=over 4

=item *

Dead Code Elimination. E.g. unused variables, etc.

=item *

Constant propagation.

=item *

(Put more stuff here)

=back

=item *

Convert back to PAST using "lambda dropping".

=back

=head1 "Lambda lifting" and "lambda dropping"

To avoid hassles with SSA and Phi function used for analyse imperative
languages I'm going to convert PIR to functional representation.

Consider next PIR fragment:
 
  # Print even values from array
  .sub "foo"
      .param pmc array
      $P0 = iter array
   loop:
      unless $P0 goto done
      $P1 = shift $P0
      $I0 = $P1 % 2
      if $I0 goto loop
      say $P1
      goto loop
   done:
      
  .end

This code can be represented as:

  foo(array) =
    $P0 = iter array
    loop($P0)

  loop($P0) =
    unless $P0 tailcall done()
    $P1 = shift $P0
    $I0 = $P1 % 2
    if $I0 tailcall loop($P0)
    say $P1
    tailcall loop($P0)

  done() =

Every line with assignment statement introduce new "static context". RHS
evaluated in parent static context. LHS bind value in "child" static
context. Which give us next easy ways to optimise out unused variables,
constant propagating, etc.

After optimisation we use lambda-dropping to inline function and convert
it back to PAST for further processing.
    

=head1 PBC Emitting

After (or in parallel with) optimisation implementation we can start
work on emitting PBC directly from POST tree without serialisation to
PIR and invoking IMCC/PIRC. Current Packfile PMCs are robust enough for
generating PBC. What we'll need a some kind of "SerializableSub" for
generate PBC properly without attaching to current interp.

=cut


Something went wrong with that request. Please try again.