<commit_before>#!perl
# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test tests => 8;

=head1 NAME

t/op/interp.t - Running the Interpreter

=head1 SYNOPSIS

    % prove t/op/interp.t

=head1 DESCRIPTION

Tests the old and new styles of running the Parrot interpreter and the
C<interpinfo> opcode.

=cut

# we probably shouldn't just run a label, but this catches a potential seggie
pasm_output_is( <<'CODE', <<'OUTPUT', "runinterp - new style" );
    new P0, 'ParrotInterpreter'
    say 'calling'
    # set_addr/invoke ?
    runinterp P0, foo
    say 'ending'
    end
    say 'bad things!'
  foo:
    say 'In 2'
    end
CODE
calling
In 2
ending
OUTPUT

pir_output_is( <<'CODE', <<'OUTPUT', 'runinterp - works with printing' );
.sub 'test' :main
    .local string actual
    .local pmc test_interp
               test_interp = new 'ParrotInterpreter'
    .local pmc stdout
               stdout = getstdout

    print "uno\n"
    runinterp test_interp, pasm
    print "dos\n"
    goto pasm_end

  pasm:
    noop
    end
  pasm_end:
.end
CODE
uno
dos
OUTPUT

# Need to disable GC while trace is on, as there's a non-zero chance that a
# GC sweep would occur, causing a bonus "GC mark" line in the output, which makes
# the test fail.
pasm_output_like(
    <<'CODE', <<'OUTPUT', "restart trace" );
    printerr "ok 1\n"
    sweepoff
    set I0, 1
    trace I0
    dec I0
    trace I0
    sweepon
    printerr "ok 2\n"
    end
CODE
/^ok\s1\n
(?:\s+8.*)?\n
(?:\s+10.*)?\n
ok\s2\n$/x
OUTPUT

# This is the behavior as of Parrot 0.4.3
# RT #46819 Should there be a warning?
pasm_output_is( <<'CODE', 'nada:', 'interp - warnings' );
    new P0, 'Undef'
    set I0, P0
    printerr "nada:"
    warningson 1
    new P1, 'Undef'
    set I0, P1
    end
CODE

pasm_output_is( <<'CODE', <<'OUTPUT', "getinterp" );
    .include "interpinfo.pasm"
    getinterp P0
    print "ok 1\n"
    set I0, P0[.INTERPINFO_ACTIVE_PMCS]
    interpinfo I1, .INTERPINFO_ACTIVE_PMCS
    eq I0, I1, ok2
    print "not "
  ok2:
    print "ok 2\n"
    end
CODE
ok 1
ok 2
OUTPUT<commit_msg>Delete inline comment referring to resolved RT #46819.<commit_after>#!perl
# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test tests => 8;

=head1 NAME

t/op/interp.t - Running the Interpreter

=head1 SYNOPSIS

    % prove t/op/interp.t

=head1 DESCRIPTION

Tests the old and new styles of running the Parrot interpreter and the
C<interpinfo> opcode.

=cut

# we probably shouldn't just run a label, but this catches a potential seggie
pasm_output_is( <<'CODE', <<'OUTPUT', "runinterp - new style" );
    new P0, 'ParrotInterpreter'
    say 'calling'
    # set_addr/invoke ?
    runinterp P0, foo
    say 'ending'
    end
    say 'bad things!'
  foo:
    say 'In 2'
    end
CODE
calling
In 2
ending
OUTPUT

pir_output_is( <<'CODE', <<'OUTPUT', 'runinterp - works with printing' );
.sub 'test' :main
    .local string actual
    .local pmc test_interp
               test_interp = new 'ParrotInterpreter'
    .local pmc stdout
               stdout = getstdout

    print "uno\n"
    runinterp test_interp, pasm
    print "dos\n"
    goto pasm_end

  pasm:
    noop
    end
  pasm_end:
.end
CODE
uno
dos
OUTPUT

# Need to disable GC while trace is on, as there's a non-zero chance that a
# GC sweep would occur, causing a bonus "GC mark" line in the output, which makes
# the test fail.
pasm_output_like(
    <<'CODE', <<'OUTPUT', "restart trace" );
    printerr "ok 1\n"
    sweepoff
    set I0, 1
    trace I0
    dec I0
    trace I0
    sweepon
    printerr "ok 2\n"
    end
CODE
/^ok\s1\n
(?:\s+8.*)?\n
(?:\s+10.*)?\n
ok\s2\n$/x
OUTPUT

pasm_output_is( <<'CODE', 'nada:', 'interp - warnings' );
    new P0, 'Undef'
    set I0, P0
    printerr "nada:"
    warningson 1
    new P1, 'Undef'
    set I0, P1
    end
CODE

pasm_output_is( <<'CODE', <<'OUTPUT', "getinterp" );
    .include "interpinfo.pasm"
    getinterp P0
    print "ok 1\n"
    set I0, P0[.INTERPINFO_ACTIVE_PMCS]
    interpinfo I1, .INTERPINFO_ACTIVE_PMCS
    eq I0, I1, ok2
    print "not "
  ok2:
    print "ok 2\n"
    end
CODE
ok 1
ok 2
OUTPUT
{'fraction_non_alphanumeric': 0.11808809746954077, 'fraction_numerical': 0.02507029053420806, 'mean_word_length': 2.6738382099827884, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 7, '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': '7268575', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1646, 'n_words': 535}