<commit_before># Copyright (C) 2010, Parrot Foundation.
# $Id$

.sub 'set_up'
    load_bytecode 'PCT.pbc'
    load_bytecode 'PAST/Walker.pbc'
    load_bytecode 'PAST/Transformer.pbc'
    load_bytecode 'Data/Dumper.pbc'
    load_bytecode 'nqp-rx.pbc'
    $P1 = get_class ['PAST'; 'Transformer']
    $P0 = subclass $P1, ['PAST'; 'Transformer'; 'FoldConstants']
.end

.sub main :main
    'set_up'()
    .local pmc dumper, folder, nqp, past, result
    nqp = compreg 'NQP-rx'
    dumper = new ['Data'; 'Dumper']
    past = 'build_past'(nqp)
    folder = new ['PAST'; 'Transformer'; 'FoldConstants']
    
    dumper.'dumper'(past)
    $P0 = nqp.'post'(past)
    $P0 = nqp.'pir'($P0)
    say $P0
    
    say "\nFolding:\n"
    result = folder.'walk'(past)
    dumper.'dumper'(result)
    $P0 = nqp.'post'(result)
    $P0 = nqp.'pir'($P0)
    say $P0
.end

.sub 'build_past'
    .param pmc nqp
    .local pmc result
    .local string source
    source = "say(1+2);"
    result = nqp.'compile'(source, 'target' => 'past')
    .return (result)
.end

.namespace ['PAST'; 'Walker']

.sub 'walk' :multi(['PAST';'Transformer';'FoldConstants'], ['PAST';'Op'])
    .param pmc walker
    .param pmc node
    .local pmc result
    $P0 = node.'pirop'()
    if null $P0 goto end
    unless $P0 == 'add' goto end
    .local int foldable
    $P0 = node[0]
    $P1 = node[1]
    $P2 = $P0.'value'()
    $P3 = $P1.'value'()
    $I0 = isa $P2, 'Integer'
    $I1 = isa $P3, 'Integer'
    foldable = and $I0, $I1
    unless foldable goto end
    say "Foo"
    result = new ['PAST'; 'Val']
    $I0 = $P2
    $I1 = $P3
    $I2 = $I0 + $I1
    result.'value'($I2)
    .return (result)
end:
    result = node
    $P0 = 'walkChildren'(walker, node)
    'replaceChildren'(result, $P0)
    .return (result)
.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:<commit_msg>Removing a debugging 'say "Foo"'.<commit_after># Copyright (C) 2010, Parrot Foundation.
# $Id$

.sub 'set_up'
    load_bytecode 'PCT.pbc'
    load_bytecode 'PAST/Walker.pbc'
    load_bytecode 'PAST/Transformer.pbc'
    load_bytecode 'Data/Dumper.pbc'
    load_bytecode 'nqp-rx.pbc'
    $P1 = get_class ['PAST'; 'Transformer']
    $P0 = subclass $P1, ['PAST'; 'Transformer'; 'FoldConstants']
.end

.sub main :main
    'set_up'()
    .local pmc dumper, folder, nqp, past, result
    nqp = compreg 'NQP-rx'
    dumper = new ['Data'; 'Dumper']
    past = 'build_past'(nqp)
    folder = new ['PAST'; 'Transformer'; 'FoldConstants']
    
    dumper.'dumper'(past)
    $P0 = nqp.'post'(past)
    $P0 = nqp.'pir'($P0)
    say $P0
    
    say "\nFolding:\n"
    result = folder.'walk'(past)
    dumper.'dumper'(result)
    $P0 = nqp.'post'(result)
    $P0 = nqp.'pir'($P0)
    say $P0
.end

.sub 'build_past'
    .param pmc nqp
    .local pmc result
    .local string source
    source = "say(1+2);"
    result = nqp.'compile'(source, 'target' => 'past')
    .return (result)
.end

.namespace ['PAST'; 'Walker']

.sub 'walk' :multi(['PAST';'Transformer';'FoldConstants'], ['PAST';'Op'])
    .param pmc walker
    .param pmc node
    .local pmc result
    $P0 = node.'pirop'()
    if null $P0 goto end
    unless $P0 == 'add' goto end
    .local int foldable
    $P0 = node[0]
    $P1 = node[1]
    $P2 = $P0.'value'()
    $P3 = $P1.'value'()
    $I0 = isa $P2, 'Integer'
    $I1 = isa $P3, 'Integer'
    foldable = and $I0, $I1
    unless foldable goto end
    result = new ['PAST'; 'Val']
    $I0 = $P2
    $I1 = $P3
    $I2 = $I0 + $I1
    result.'value'($I2)
    .return (result)
end:
    result = node
    $P0 = 'walkChildren'(walker, node)
    'replaceChildren'(result, $P0)
    .return (result)
.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
{'fraction_non_alphanumeric': 0.17608236536430835, 'fraction_numerical': 0.025343189017951427, 'mean_word_length': 2.729330708661417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7642295', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1545, 'n_words': 375}