<commit_before>/*
 * tré – Copyright (c) 2005–2009,2011–2014 <NAME> <<EMAIL>>
 */

/*
 * Use _CAR() and _CDR() to enable debug dumps.
 */

#include "config.h"

#ifdef INTERPRETER

#include <stdio.h>
#include <strings.h>

#include "atom.h"
#include "cons.h"
#include "list.h"
#include "number.h"
#include "print.h"
#include "error.h"
#include "util.h"
#include "eval.h"
#include "io.h"
#include "string2.h"
#include "thread.h"
#include "array.h"
#include "symbol.h"
#include "function.h"

char treprint_marks_cons[NUM_LISTNODES >> 3];
char treprint_marks_atoms[NUM_ATOMS >> 3];

#define TREPRINT_MARK_CONS(i)     TRE_MARK(treprint_marks_cons, i)
#define TREPRINT_GET_MARK_CONS(i) TRE_GETMARK(treprint_marks_cons, i)
#define TREPRINT_MARK_ATOM(i)     TRE_MARK(treprint_marks_atoms, TREPTR_INDEX(i))
#define TREPRINT_GET_MARK_ATOM(i) TRE_GETMARK(treprint_marks_atoms, TREPTR_INDEX(i))

void
treprint_wipe_marks (void)
{
    bzero (treprint_marks_cons, sizeof (treprint_marks_cons));
    bzero (treprint_marks_atoms, sizeof (treprint_marks_atoms));
}

void treprint_indent (treptr p, size_t indent, bool nobracket, char *prepend);

bool treprint_no_nl;

treptr treprint_highlight;

#define TREPRINT_HL(x,txt) \
    if (NOT_NIL(treprint_highlight) && treprint_highlight == x) \
        printf (txt) 

#define TREPRINT_HLOPEN(x) \
    if (NOT_NIL(treprint_highlight) && treprint_highlight == x) \
        printf (" ---> ") 
#define TREPRINT_HLCLOSE(x) \
    if (NOT_NIL(treprint_highlight) && treprint_highlight == x) { \
        printf (" <--- "); \
		treprint_highlight = treptr_nil; \
    }

void treprint_r (treptr);

void
treprint_array (treptr array)
{
    treptr * elts = TREARRAY_VALUES(array);
    size_t   i;

    printf ("#(");

    DOTIMES(i, TREARRAY_SIZE(array)) {
		treprint_no_nl = TRUE;
        if (i)
	    	printf (" ");
        treprint_r (elts[i]);
    }

    printf (")");
}

bool
treprint_chk_atom_mark (treptr atom)
{
    bool mark;

    if (CONSP(atom))
    	return FALSE;

    mark = TREPRINT_GET_MARK_ATOM(atom);
    TREPRINT_MARK_ATOM(atom);
    if (! mark)
    	return FALSE;

    switch (TREPTR_TYPE(atom)) {
       	case TRETYPE_FUNCTION:
       	case TRETYPE_MACRO:
       	case TRETYPE_USERSPECIAL:
        case TRETYPE_ARRAY:
            return TRUE;
    }

    return FALSE;
}

void
treprint_atom (treptr atom, size_t indent)
{
    if (treprint_chk_atom_mark (atom)) {
        printf ("unprintable-circularity");
        return;
    }

    TREPRINT_HLOPEN(atom);

    switch (TREPTR_TYPE(atom)) {
		case TRETYPE_SYMBOL:
	    	if (TRESYMBOL_PACKAGE(atom) != TRECONTEXT_PACKAGE())
                printf ("%s:", TRESYMBOL_NAME(TRESYMBOL_PACKAGE(atom)));
           	printf ("%s", TRESYMBOL_NAME(atom));
	    	break;

		case TRETYPE_BUILTIN:
           	printf ("unprintable-builtin");
            break;

		case TRETYPE_SPECIAL:
           	printf ("unprintable-special-form");
            break;

		case TRETYPE_NUMBER:
	    	if (TRENUMBER_TYPE(atom) == TRENUMTYPE_CHAR) {
				printf ("#\\");
	        	putchar ((int) TRENUMBER_VAL(atom));<commit_msg>Print built-in functions and the interpreter's special forms.<commit_after>/*
 * tré – Copyright (c) 2005–2009,2011–2014 <NAME> <<EMAIL>>
 */

/*
 * Use _CAR() and _CDR() to enable debug dumps.
 */

#include "config.h"

#ifdef INTERPRETER

#include <stdio.h>
#include <strings.h>

#include "atom.h"
#include "cons.h"
#include "list.h"
#include "number.h"
#include "print.h"
#include "error.h"
#include "util.h"
#include "eval.h"
#include "io.h"
#include "string2.h"
#include "thread.h"
#include "array.h"
#include "symbol.h"
#include "function.h"
#include "builtin.h"
#include "special.h"

char treprint_marks_cons[NUM_LISTNODES >> 3];
char treprint_marks_atoms[NUM_ATOMS >> 3];

#define TREPRINT_MARK_CONS(i)     TRE_MARK(treprint_marks_cons, i)
#define TREPRINT_GET_MARK_CONS(i) TRE_GETMARK(treprint_marks_cons, i)
#define TREPRINT_MARK_ATOM(i)     TRE_MARK(treprint_marks_atoms, TREPTR_INDEX(i))
#define TREPRINT_GET_MARK_ATOM(i) TRE_GETMARK(treprint_marks_atoms, TREPTR_INDEX(i))

void
treprint_wipe_marks (void)
{
    bzero (treprint_marks_cons, sizeof (treprint_marks_cons));
    bzero (treprint_marks_atoms, sizeof (treprint_marks_atoms));
}

void treprint_indent (treptr p, size_t indent, bool nobracket, char *prepend);

bool treprint_no_nl;

treptr treprint_highlight;

#define TREPRINT_HL(x,txt) \
    if (NOT_NIL(treprint_highlight) && treprint_highlight == x) \
        printf (txt) 

#define TREPRINT_HLOPEN(x) \
    if (NOT_NIL(treprint_highlight) && treprint_highlight == x) \
        printf (" ---> ") 
#define TREPRINT_HLCLOSE(x) \
    if (NOT_NIL(treprint_highlight) && treprint_highlight == x) { \
        printf (" <--- "); \
		treprint_highlight = treptr_nil; \
    }

void treprint_r (treptr);

void
treprint_array (treptr array)
{
    treptr * elts = TREARRAY_VALUES(array);
    size_t   i;

    printf ("#(");

    DOTIMES(i, TREARRAY_SIZE(array)) {
		treprint_no_nl = TRUE;
        if (i)
	    	printf (" ");
        treprint_r (elts[i]);
    }

    printf (")");
}

bool
treprint_chk_atom_mark (treptr atom)
{
    bool mark;

    if (CONSP(atom))
    	return FALSE;

    mark = TREPRINT_GET_MARK_ATOM(atom);
    TREPRINT_MARK_ATOM(atom);
    if (! mark)
    	return FALSE;

    switch (TREPTR_TYPE(atom)) {
       	case TRETYPE_FUNCTION:
       	case TRETYPE_MACRO:
       	case TRETYPE_USERSPECIAL:
        case TRETYPE_ARRAY:
            return TRUE;
    }

    return FALSE;
}

void
treprint_atom (treptr atom, size_t indent)
{
    if (treprint_chk_atom_mark (atom)) {
        printf ("unprintable-circularity");
        return;
    }

    TREPRINT_HLOPEN(atom);

    switch (TREPTR_TYPE(atom)) {
		case TRETYPE_SYMBOL:
	    	if (TRESYMBOL_PACKAGE(atom) != TRECONTEXT_PACKAGE())
                printf ("%s:", TRESYMBOL_NAME(TRESYMBOL_PACKAGE(atom)));
           	printf ("%s", TRESYMBOL_NAME(atom));
	    	break;

		case TRETYPE_BUILTIN:
           	printf ("{%s}", tre_builtin_names[(size_t) TREATOM(atom)]);
            break;

		case TRETYPE_SPECIAL:
           	printf ("{%s}", tre_special_names[(size_t) TREATOM(atom)]);
            break;

		case TRETYPE_NUMBER:
	    	if (TRENUMBER_TYPE(atom) == TRENUMTYPE_CHAR) {
				printf ("#\\");
	        	putchar ((int) TRENUMBER_VAL(atom));
{'fraction_non_alphanumeric': 0.13244402096236302, 'fraction_numerical': 0.0060346196601556296, 'mean_word_length': 3.4571832979476294, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '3263047', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2411, 'n_words': 460}