<commit_before>#! /usr/bin/env python
import sys, time, os
from rpython.jit.codewriter.policy import JitPolicy
from rpython.rlib import jit, rpath, objectmodel
from spyvm import model, interpreter, squeakimage, objspace, wrapper, error
from spyvm.plugins.simulation import SIMULATE_PRIMITIVE_SELECTOR
from spyvm.util import system

sys.setrecursionlimit(15000)

def _compile_time_version():
    import subprocess
    return subprocess.check_output(
        ["git", "log", "--format=format:\"%ai %h%d\"", "-n", "1"])
VERSION = _compile_time_version()
BUILD_DATE = "%s +0000" % time.asctime(time.gmtime())

def _usage(argv):
    print """
    Usage: %s <path> [-r|-m|-h] [-naPu] [-jpiS] [-tTslL]
            <path> - image path (default: Squeak.image)

          VM options:
            --[no-]highdpi         - Enable or disable High-DPI support.
                                     (Default: on)

          Execution mode:
            (no flags)             - Image will be normally opened.
            -r|--run <code>        - Code will be compiled and executed in
                                     headless mode, result printed.
            -m|--method <selector> - Selector will be sent to a SmallInteger in
                                     headless mode, result printed.
            -h|--help              - Output this message and exit.

          Headless mode:
            When starting the image without -r or -m, the last running Process
            in the image will be executed. This Process will open the image
            window and initialize the environment. In headless mode, this
            Process is ignored; instead, a new context will be created and
            directly executed. When this context returns, the VM terminates.
            In headless mode certain errors make the VM exit directly. This
            should prevent the image from opening a Debugger when the world is
            not visible. Headless mode is good for benchmarking and quick
            experiments.

          Execution parameters:
            -n|--num <int> - Only with -m or -r. SmallInteger to be used as
                             receiver (default: nil).
            -a|--arg <arg> - Only with -m. Will be used as String argument.
            -P|--process   - Only with -m or -r. Disable headless mode.
                             A high-priority Process for the new context will
                             be created. The last active Process in the image
                             will be started, but then quickly switch to the
                             synthetic high-prio Process.
            -u             - Only with -m or -r. Try to stop UI-process at
                             startup. Can help benchmarking.
            --simulate-numeric-primitives
                           - This flag determines if an attempt is made to run
                             Slang Simulation code for _unimplemented_ numeric
                             primitives. This means that, if an unimplemented
                             numeric primitive is encountered, rather than just
                             failing, we see if the receiver understands
                             """ + SIMULATE_PRIMITIVE_SELECTOR + """.
                             If so, this method is called instead of the fallback
                             code.

          Other parameters:
            -j|--jit <jitargs> - jitargs will be passed to the jit config.
            -p|--poll          - Actively poll for events. Try this if the
                                 image is not responding well.
            -i|--no-interrupts - Disable timer interrupt.
                                 Disables non-cooperative scheduling.
            -S                 - Disable specialized storage strategies.
                                 always use generic ListStrategy.
            --hacks            - Enable Spy hacks. Set display color depth to 8
            --use-plugins      - Directs named primitives to go to the native
                                 Squeak plugins, which must be in the dynamic
                                 linker path.

          Logging parameters:
            -t|--trace       - Output a trace of each message, primitive,
                               return value and process switch.
            -T               - Trace important events: Process switch,
                               stack overflow, sender chain manipulation
            -s|--safe-trace  - If tracing is active, omit printing contents of
                               BytesObjects
            -l|--storage-log - Output a log of storage operations.
            -L               - Output an aggregated storage log at the end of
                               execution.
    """ % argv[0]

def get_parameter(argv, idx, arg):
    if len(argv) < idx + 1:
        raise error.Exit("Missing argument after %s" % arg)
    return argv[idx], idx + 1

def get_int_parameter(argv, idx, arg):
    param, idx = get_parameter(argv, idx, arg)
    try:
        result = int(param)
    except ValueError, e:
        raise error.Exit("Non-int argument after %s" % arg)
    return result, idx

def print_error(str):
    os.write(2, str + os.linesep)

prebuilt_space = objspace.ObjSpace()

def safe_entry_point(argv):
    try:
        return entry_point(argv)
    except error.Exit, e:
        print_error("Exited: %s" % e.msg)
        return -1
    except error.SmalltalkException, e:
        print_error("Unhandled %s. Message: %s" % (e.exception_type, e.msg))
        return -1
    except BaseException, e:
        print_error("Exception: %s" % str(e))
        if not objectmodel.we_are_translated():
            raise
        return -1
    finally:
        prebuilt_space.strategy_factory.logger.print_aggregated_log()

def entry_point(argv):
    jit.set_param(None, "trace_limit", 1000000)
    # == Main execution parameters
    path = None
    selector = None
    code = ""
    number = 0
    have_number = False
    stringarg = None
    headless = True
    # == Other parameters
    poll = False
    interrupts = True
    trace = False
    trace_important = False

    space = prebuilt_space
    idx = 1
    try:
        while idx < len(argv):
            arg = argv[idx]
            idx += 1
            if arg in ["-h", "--help"]:
                _usage(argv)
                return 0
            elif arg == "--no-highdpi":
                space.highdpi.deactivate()
            elif arg == "--highdpi":
                space.highdpi.activate()
            elif arg in ["-j", "--jit"]:
                jitarg, idx = get_parameter(argv, idx, arg)
                jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg)
            elif arg in ["--reader-jit-args"]:
                jitarg, idx = get_parameter(argv, idx, arg)
                squeakimage.set_reader_user_param(jitarg)
            elif arg in ["-n", "--number"]:
                number, idx = get_int_parameter(argv, idx, arg)
                have_number = True
            elif arg in ["-m", "--method"]:
                selector, idx = get_parameter(argv, idx, arg)
            elif arg in ["-t", "--trace"]:
                trace = True
            elif arg in ["-T"]:
                trace_important = True
            elif arg in ["-s", "--safe-trace"]:
                space.omit_printing_raw_bytes.activate()
            elif arg in ["-p", "--poll"]:
                poll = True
            elif arg in ["-a", "--arg"]:
                stringarg, idx = get_parameter(argv, idx, arg)
            elif arg in ["-r", "--run"]:
                code, idx = get_parameter(argv, idx, arg)<commit_msg>print version info<commit_after>#! /usr/bin/env python
import sys, time, os
from rpython.jit.codewriter.policy import JitPolicy
from rpython.rlib import jit, rpath, objectmodel
from spyvm import model, interpreter, squeakimage, objspace, wrapper, error
from spyvm.plugins.simulation import SIMULATE_PRIMITIVE_SELECTOR
from spyvm.util import system

sys.setrecursionlimit(15000)

def _compile_time_version():
    import subprocess
    return subprocess.check_output(
        ["git", "log", "--format=format:\"%ai %h%d\"", "-n", "1"])
VERSION = _compile_time_version()
BUILD_DATE = "%s +0000" % time.asctime(time.gmtime())

def _usage(argv):
    print """
    Usage: %s <path> [-r|-m|-h] [-naPu] [-jpiS] [-tTslL]
            <path> - image path (default: Squeak.image)

          VM options:
            --[no-]highdpi         - Enable or disable High-DPI support.
                                     (Default: on)

          Execution mode:
            (no flags)             - Image will be normally opened.
            -r|--run <code>        - Code will be compiled and executed in
                                     headless mode, result printed.
            -m|--method <selector> - Selector will be sent to a SmallInteger in
                                     headless mode, result printed.
            -h|--help              - Output this message and exit.
            -v|--version           - Print version info and exit.

          Headless mode:
            When starting the image without -r or -m, the last running Process
            in the image will be executed. This Process will open the image
            window and initialize the environment. In headless mode, this
            Process is ignored; instead, a new context will be created and
            directly executed. When this context returns, the VM terminates.
            In headless mode certain errors make the VM exit directly. This
            should prevent the image from opening a Debugger when the world is
            not visible. Headless mode is good for benchmarking and quick
            experiments.

          Execution parameters:
            -n|--num <int> - Only with -m or -r. SmallInteger to be used as
                             receiver (default: nil).
            -a|--arg <arg> - Only with -m. Will be used as String argument.
            -P|--process   - Only with -m or -r. Disable headless mode.
                             A high-priority Process for the new context will
                             be created. The last active Process in the image
                             will be started, but then quickly switch to the
                             synthetic high-prio Process.
            -u             - Only with -m or -r. Try to stop UI-process at
                             startup. Can help benchmarking.
            --simulate-numeric-primitives
                           - This flag determines if an attempt is made to run
                             Slang Simulation code for _unimplemented_ numeric
                             primitives. This means that, if an unimplemented
                             numeric primitive is encountered, rather than just
                             failing, we see if the receiver understands
                             """ + SIMULATE_PRIMITIVE_SELECTOR + """.
                             If so, this method is called instead of the fallback
                             code.

          Other parameters:
            -j|--jit <jitargs> - jitargs will be passed to the jit config.
            -p|--poll          - Actively poll for events. Try this if the
                                 image is not responding well.
            -i|--no-interrupts - Disable timer interrupt.
                                 Disables non-cooperative scheduling.
            -S                 - Disable specialized storage strategies.
                                 always use generic ListStrategy.
            --hacks            - Enable Spy hacks. Set display color depth to 8
            --use-plugins      - Directs named primitives to go to the native
                                 Squeak plugins, which must be in the dynamic
                                 linker path.

          Logging parameters:
            -t|--trace       - Output a trace of each message, primitive,
                               return value and process switch.
            -T               - Trace important events: Process switch,
                               stack overflow, sender chain manipulation
            -s|--safe-trace  - If tracing is active, omit printing contents of
                               BytesObjects
            -l|--storage-log - Output a log of storage operations.
            -L               - Output an aggregated storage log at the end of
                               execution.
    """ % argv[0]

def get_parameter(argv, idx, arg):
    if len(argv) < idx + 1:
        raise error.Exit("Missing argument after %s" % arg)
    return argv[idx], idx + 1

def get_int_parameter(argv, idx, arg):
    param, idx = get_parameter(argv, idx, arg)
    try:
        result = int(param)
    except ValueError, e:
        raise error.Exit("Non-int argument after %s" % arg)
    return result, idx

def print_error(str):
    os.write(2, str + os.linesep)

prebuilt_space = objspace.ObjSpace()

def safe_entry_point(argv):
    try:
        return entry_point(argv)
    except error.Exit, e:
        print_error("Exited: %s" % e.msg)
        return -1
    except error.SmalltalkException, e:
        print_error("Unhandled %s. Message: %s" % (e.exception_type, e.msg))
        return -1
    except BaseException, e:
        print_error("Exception: %s" % str(e))
        if not objectmodel.we_are_translated():
            raise
        return -1
    finally:
        prebuilt_space.strategy_factory.logger.print_aggregated_log()

def entry_point(argv):
    jit.set_param(None, "trace_limit", 1000000)
    # == Main execution parameters
    path = None
    selector = None
    code = ""
    number = 0
    have_number = False
    stringarg = None
    headless = True
    # == Other parameters
    poll = False
    interrupts = True
    trace = False
    trace_important = False

    space = prebuilt_space
    idx = 1
    try:
        while idx < len(argv):
            arg = argv[idx]
            idx += 1
            if arg in ["-h", "--help"]:
                _usage(argv)
                return 0
            elif arg in ["-v", "--version"]:
                print "RSqueakVM %s, built on %s" % (VERSION, BUILD_DATE)
                return 0
            elif arg == "--no-highdpi":
                space.highdpi.deactivate()
            elif arg == "--highdpi":
                space.highdpi.activate()
            elif arg in ["-j", "--jit"]:
                jitarg, idx = get_parameter(argv, idx, arg)
                jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg)
            elif arg in ["--reader-jit-args"]:
                jitarg, idx = get_parameter(argv, idx, arg)
                squeakimage.set_reader_user_param(jitarg)
            elif arg in ["-n", "--number"]:
                number, idx = get_int_parameter(argv, idx, arg)
                have_number = True
            elif arg in ["-m", "--method"]:
                selector, idx = get_parameter(argv, idx, arg)
            elif arg in ["-t", "--trace"]:
                trace = True
            elif arg in ["-T"]:
                trace_important = True
            elif arg in ["-s", "--safe-trace"]:
                space.omit_printing_raw_bytes.activate()
            elif arg in ["-p", "--poll"]:
                poll = True
            elif arg in ["-a", "--arg"]:
                stringarg, idx = get_parameter(argv, idx, arg)
            elif arg in ["-r", "--run"]:
                code, idx = get_parameter(argv, idx, arg)
{'fraction_non_alphanumeric': 0.08649829702461281, 'fraction_numerical': 0.003791530107319581, 'mean_word_length': 1.4740858505564387, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2308679', 'n_tokens_mistral': 4103, 'n_tokens_neox': 3970, 'n_words': 1426}