<commit_before>#include <cport.h>
#include <opsys.h>
#include <strops.h>
#include <cmdline.h>
#include <abcheck.h>
#include <abnorm.h>
#include <abuse.h>
#include <axltop.h>
#include <bloop.h>
#include <ccomp.h>
#include <cmdline.h>
#include <compcfg.h>
#include <debug.h>
#include <emit.h>
#include <file.h>
#include <fint.h>
#include <fintphase.h>
#include <fluid.h>
#include <stab.h>
#include <comsg.h>

extern String compRootDir;
extern Bool   compIsDebug;
extern String cmdOptionArg;

extern void compGLoopInit   (int, char**, FILE*, FileName*, EmitInfo*);
extern void compGLoopEval   (FILE*, FILE*, EmitInfo);
extern int  compGLoopFinish (FileName, EmitInfo);

extern void osSetStreams(FILE*, FILE*, FILE*);

JmpBuf compFintJmpBuf;

static void compFintBreakHandler0(int signo) {
    comsgFPrintf(osStdout, ALDOR_M_FintBreakHandler0);
}

void feval(FILE* fin, FILE* fout, EmitInfo finfo) {
    Stab stab = stabFile();
    // stabPrint(stdout, stab);
    AbSyn ab;
    Foam foam;
    int lineno = 0;

    comsgInit();

    while (!osFEof(fin)) {
        Bool ok;
        intStepNo += 1;
        comsgFini();
        comsgInit();
        car(stab)->isChecked = false;

        if (SetJmp(compFintJmpBuf))
            if (osFEof(fin))
                break;

        osSetBreakHandler(compFintBreakHandler0);
        ab = compFileFront(finfo, stab, fin, &lineno);
        breakSetRoot(ab);

        if (!compIsMoreAfterFront(finfo) || abIsEmptySequence(ab))
            continue;

        ab = (AbSyn) fintWrap(ab, intStepNo);
        foam = compFileMiddle(finfo, stab, ab);

        if (!foam)
            continue;

        ok = fint(foam);
        foamFree(foam);

        if (!ok)
            fprintf(fout, "Unhandled Exception!\n");

        if (fintVerbose && ok)
            fintPrintType(fout, ab);
    }

    comsgFini();
}

void eval(EmitInfo finfo, char* code) {
    String out, err;
    size_t out_size, err_size;

    FILE* fin = fmemopen(code, strlen(code), "r");
    FILE* fout = open_memstream(&out, &out_size);
    FILE* ferr = open_memstream(&err, &err_size);

    osSetStreams(osStdin, fout, ferr);
    feval(fin, fout, finfo);
    //compGLoopEval(fin, fout, finfo);
    osSetStreams(osStdin, osStdout, osStderr);

    fclose(fin);
    fclose(fout);
    fclose(ferr);

    puts("===================");
    puts(out);
    puts("===================");
    puts(err);
    puts("+++++++++++++++++++");
}

void _compGLoopInit(int argc, char **argv, FILE *fout, FileName *pfn, EmitInfo *pfinfo) {
    compInit();

    *pfn = fnameStdin();
    *pfinfo = emitInfoNew(*pfn);

    compFileInit(*pfinfo);
    comsgFini();
    fintInit();
}

void _compGLoopFinish(FileName fn, EmitInfo finfo) {
    fintFini();
    compFileFini(finfo);
    emitAllDone();
    emitInfoFree(finfo);
    fnameFree(fn);
    compFini();
}

void init_interpreter(int argc, char** argv) {
    Bool echo;

    osInit();
    osObtainLicense();

    echo = cmdSubsumeResponseFiles(1, &argc, &argv);

    if (cmdHasRootOption(argc, argv))
        compRootDir = cmdOptionArg;
    if (!compRootDir)
        compRootDir = strCopyIf(osGetEnv("ALDORROOT"));
    //if (!compRootDir)
    //    compRootDir = compRootFromCmdLine(osCurDirName(), argv[0]);

    if (cmdHasCfgFileOption(argc, argv))
        compCfgSetConfigFile(cmdOptionArg);
    if (cmdHasCfgNameOption(argc, argv))
        compCfgSetSysName(cmdOptionArg);
<commit_msg>Comment out echo variable to avoid a warning<commit_after>#include <cport.h>
#include <opsys.h>
#include <strops.h>
#include <cmdline.h>
#include <abcheck.h>
#include <abnorm.h>
#include <abuse.h>
#include <axltop.h>
#include <bloop.h>
#include <ccomp.h>
#include <cmdline.h>
#include <compcfg.h>
#include <debug.h>
#include <emit.h>
#include <file.h>
#include <fint.h>
#include <fintphase.h>
#include <fluid.h>
#include <stab.h>
#include <comsg.h>

extern String compRootDir;
extern Bool   compIsDebug;
extern String cmdOptionArg;

extern void compGLoopInit   (int, char**, FILE*, FileName*, EmitInfo*);
extern void compGLoopEval   (FILE*, FILE*, EmitInfo);
extern int  compGLoopFinish (FileName, EmitInfo);

extern void osSetStreams(FILE*, FILE*, FILE*);

JmpBuf compFintJmpBuf;

static void compFintBreakHandler0(int signo) {
    comsgFPrintf(osStdout, ALDOR_M_FintBreakHandler0);
}

void feval(FILE* fin, FILE* fout, EmitInfo finfo) {
    Stab stab = stabFile();
    // stabPrint(stdout, stab);
    AbSyn ab;
    Foam foam;
    int lineno = 0;

    comsgInit();

    while (!osFEof(fin)) {
        Bool ok;
        intStepNo += 1;
        comsgFini();
        comsgInit();
        car(stab)->isChecked = false;

        if (SetJmp(compFintJmpBuf))
            if (osFEof(fin))
                break;

        osSetBreakHandler(compFintBreakHandler0);
        ab = compFileFront(finfo, stab, fin, &lineno);
        breakSetRoot(ab);

        if (!compIsMoreAfterFront(finfo) || abIsEmptySequence(ab))
            continue;

        ab = (AbSyn) fintWrap(ab, intStepNo);
        foam = compFileMiddle(finfo, stab, ab);

        if (!foam)
            continue;

        ok = fint(foam);
        foamFree(foam);

        if (!ok)
            fprintf(fout, "Unhandled Exception!\n");

        if (fintVerbose && ok)
            fintPrintType(fout, ab);
    }

    comsgFini();
}

void eval(EmitInfo finfo, char* code) {
    String out, err;
    size_t out_size, err_size;

    FILE* fin = fmemopen(code, strlen(code), "r");
    FILE* fout = open_memstream(&out, &out_size);
    FILE* ferr = open_memstream(&err, &err_size);

    osSetStreams(osStdin, fout, ferr);
    feval(fin, fout, finfo);
    //compGLoopEval(fin, fout, finfo);
    osSetStreams(osStdin, osStdout, osStderr);

    fclose(fin);
    fclose(fout);
    fclose(ferr);

    puts("===================");
    puts(out);
    puts("===================");
    puts(err);
    puts("+++++++++++++++++++");
}

void _compGLoopInit(int argc, char **argv, FILE *fout, FileName *pfn, EmitInfo *pfinfo) {
    compInit();

    *pfn = fnameStdin();
    *pfinfo = emitInfoNew(*pfn);

    compFileInit(*pfinfo);
    comsgFini();
    fintInit();
}

void _compGLoopFinish(FileName fn, EmitInfo finfo) {
    fintFini();
    compFileFini(finfo);
    emitAllDone();
    emitInfoFree(finfo);
    fnameFree(fn);
    compFini();
}

void init_interpreter(int argc, char** argv) {
    /*Bool echo;*/

    osInit();
    osObtainLicense();

    /*echo =*/ cmdSubsumeResponseFiles(1, &argc, &argv);

    if (cmdHasRootOption(argc, argv))
        compRootDir = cmdOptionArg;
    if (!compRootDir)
        compRootDir = strCopyIf(osGetEnv("ALDORROOT"));
    //if (!compRootDir)
    //    compRootDir = compRootFromCmdLine(osCurDirName(), argv[0]);

    if (cmdHasCfgFileOption(argc, argv))
        compCfgSetConfigFile(cmdOptionArg);
    if (cmdHasCfgNameOption(argc, argv))
        compCfgSetSysName(cmdOptionArg);

{'fraction_non_alphanumeric': 0.1557532448592679, 'fraction_numerical': 0.0020417092022750475, 'mean_word_length': 3.2229064039408866, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, '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': '1500971', 'n_tokens_mistral': 2541, 'n_tokens_neox': 2481, 'n_words': 529}