<commit_before>! Copyright (C) 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays compiler.units continuations debugger
fuel.pprint io io.streams.string kernel namespaces parser sequences
vectors vocabs.parser ;

IN: fuel.eval

TUPLE: fuel-status manifest restarts ;

SYMBOL: fuel-status-stack
V{ } clone fuel-status-stack set-global

SYMBOL: fuel-eval-error
f fuel-eval-error set-global

SYMBOL: fuel-eval-result
f fuel-eval-result set-global

SYMBOL: fuel-eval-output
f fuel-eval-result set-global

SYMBOL: fuel-eval-res-flag
t fuel-eval-res-flag set-global

: fuel-eval-restartable? ( -- ? )
    fuel-eval-res-flag get-global ;

: fuel-push-status ( -- )
    manifest get clone restarts get-global clone
    fuel-status boa
    fuel-status-stack get push ;

: fuel-pop-restarts ( restarts -- )
    fuel-eval-restartable? [ drop ] [ clone restarts set-global ] if ;

: fuel-pop-status ( -- )
    fuel-status-stack get empty? [
        fuel-status-stack get pop
        [ manifest>> clone manifest set ]
        [ restarts>> fuel-pop-restarts ]
        bi
    ] unless ;

: fuel-forget-error ( -- ) f fuel-eval-error set-global ;
: fuel-forget-result ( -- ) f fuel-eval-result set-global ;
: fuel-forget-output ( -- ) f fuel-eval-output set-global ;
: fuel-forget-status ( -- )
    fuel-forget-error fuel-forget-result fuel-forget-output ;

: fuel-send-retort ( -- )
    fuel-eval-error get-global
    fuel-eval-result get-global
    fuel-eval-output get-global 3array
    fuel-pprint flush nl "<~FUEL~>" write nl flush ;

: (fuel-begin-eval) ( -- )
    fuel-push-status fuel-forget-status ;

: (fuel-end-eval) ( output -- )
    fuel-eval-output set-global fuel-send-retort fuel-pop-status ;

: (fuel-eval) ( lines -- )
    [ [ parse-lines ] with-compilation-unit call( -- ) ] curry
    [ [ fuel-eval-error set-global ] [ print-error ] bi ] recover ;

: (fuel-eval-usings) ( usings -- )
    [ [ use-vocab ] curry [ drop ] recover ] each
    fuel-forget-error fuel-forget-output ;

: (fuel-eval-in) ( in -- )
    [ set-current-vocab ] when* ;

: (fuel-eval-in-context) ( lines in usings -- )
    (fuel-begin-eval)
    [ (fuel-eval-usings) (fuel-eval-in) (fuel-eval) ] with-string-writer
    (fuel-end-eval) ;<commit_msg>fuel.eval: some minor cleanup.<commit_after>! Copyright (C) 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays compiler.units continuations debugger
fuel.pprint io io.streams.string kernel namespaces parser sequences
vectors vocabs.parser ;

IN: fuel.eval

TUPLE: fuel-status manifest restarts ;

SYMBOL: fuel-status-stack
V{ } clone fuel-status-stack set-global

SYMBOL: fuel-eval-error
f fuel-eval-error set-global

SYMBOL: fuel-eval-result
f fuel-eval-result set-global

SYMBOL: fuel-eval-output
f fuel-eval-result set-global

SYMBOL: fuel-eval-res-flag
t fuel-eval-res-flag set-global

: fuel-eval-restartable? ( -- ? )
    fuel-eval-res-flag get-global ;

: fuel-push-status ( -- )
    manifest get clone restarts get-global clone
    fuel-status boa
    fuel-status-stack get push ;

: fuel-pop-restarts ( restarts -- )
    fuel-eval-restartable? [ drop ] [ clone restarts set-global ] if ;

: fuel-pop-status ( -- )
    fuel-status-stack get [
        pop
        [ manifest>> clone manifest set ]
        [ restarts>> fuel-pop-restarts ]
        bi
    ] unless-empty ;

: fuel-forget-error ( -- ) f fuel-eval-error set-global ;
: fuel-forget-result ( -- ) f fuel-eval-result set-global ;
: fuel-forget-output ( -- ) f fuel-eval-output set-global ;
: fuel-forget-status ( -- )
    fuel-forget-error fuel-forget-result fuel-forget-output ;

: fuel-send-retort ( -- )
    fuel-eval-error get-global
    fuel-eval-result get-global
    fuel-eval-output get-global 3array
    fuel-pprint flush nl "<~FUEL~>" write nl flush ;

: (fuel-begin-eval) ( -- )
    fuel-push-status fuel-forget-status ;

: (fuel-end-eval) ( output -- )
    fuel-eval-output set-global fuel-send-retort fuel-pop-status ;

: (fuel-eval) ( lines -- )
    [ [ parse-lines ] with-compilation-unit call( -- ) ] curry
    [ [ fuel-eval-error set-global ] [ print-error ] bi ] recover ;

: (fuel-eval-usings) ( usings -- )
    [ [ use-vocab ] curry [ drop ] recover ] each ;

: (fuel-eval-in) ( in -- )
    [ set-current-vocab ] when* ;

: (fuel-eval-in-context) ( lines in usings -- )
    (fuel-begin-eval)
    [ (fuel-eval-usings) (fuel-eval-in) (fuel-eval) ] with-string-writer
    (fuel-end-eval) ;
{'fraction_non_alphanumeric': 0.14757758428220585, 'fraction_numerical': 0.0022326412145568207, 'mean_word_length': 2.7583892617449663, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '7528370', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1548, 'n_words': 336}