Пример #1
0
static jl_value_t* repl_parse_input_line(char *buf)
{
    if (buf[0] == ';') {
        buf++;
        return call_jl_function_with_string("repl_hook", buf, strlen(buf));
    }
    else if (buf[0] == '?') {
        char *tmpbuf;
        asprintf(&tmpbuf, "@Base.help %s", buf+1);
        jl_value_t *v = jl_parse_input_line(tmpbuf);
        free(tmpbuf);
        return v;
    }
    return jl_parse_input_line(buf);
}
Пример #2
0
void jl_input_line_callback(char *input)
{
    int end=0, doprint=1;
    if (!input || ios_eof(ios_stdin)) {
        end = 1;
        rl_ast = NULL;
    }
    else if (!rl_ast) {
        // In vi mode, it's possible for this function to be called w/o a
        // previous call to return_callback.
        rl_ast = jl_parse_input_line(rl_line_buffer);
    }

    if (rl_ast != NULL) {
        doprint = !ends_with_semicolon(input);
        add_history_permanent(input);
        jl_putc('\n', jl_uv_stdout);
        free(input);
    }

    callback_en = 0;
    rl_callback_handler_remove();
    handle_input(rl_ast, end, doprint);
    rl_ast = NULL;
}
Пример #3
0
DLLEXPORT void *jl_eval_string(char *str)
{
#ifdef COPY_STACKS
    int outside_task = (jl_root_task->stackbase == NULL);
    if (outside_task) {
        JL_SET_STACK_BASE;
    }
#endif
    jl_value_t *r;
    JL_TRY {
        jl_value_t *ast = jl_parse_input_line(str);
        JL_GC_PUSH1(&ast);
        r = jl_toplevel_eval(ast);
        JL_GC_POP();
        jl_exception_clear();
    }
    JL_CATCH {
        //jl_show(jl_stderr_obj(), jl_exception_in_transit);
        r = NULL;
    }
#ifdef COPY_STACKS
    if (outside_task) {
        jl_root_task->stackbase = NULL;
    }
#endif
    return r;
}
Пример #4
0
int true_main(int argc, char *argv[])
{
    if (lisp_prompt) {
        jl_lisp_prompt();
        return 0;
    }

    jl_array_t *args = jl_alloc_cell_1d(argc);
    jl_set_global(jl_current_module, jl_symbol("ARGS"), (jl_value_t*)args);
    int i;
    for (i=0; i < argc; i++) {
        jl_arrayset(args, i, (jl_value_t*)jl_cstr_to_string(argv[i]));
    }
    jl_set_const(jl_current_module, jl_symbol("JULIA_HOME"),
                 jl_cstr_to_string(julia_home));

    // run program if specified, otherwise enter REPL
    if (program) {
        return exec_program();
    }

    init_repl_environment();

    jl_function_t *start_client =
        (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start"));

    if (start_client) {
        jl_apply(start_client, NULL, 0);
        return 0;
    }

    // client event loop not available; use fallback blocking version
    int iserr = 0;
 again:
    ;
    JL_TRY {
        if (iserr) {
            jl_show(jl_exception_in_transit);
            ios_printf(ios_stdout, "\n\n");
            iserr = 0;
        }
        while (1) {
            char *input = read_expr("julia> ");
            if (!input || ios_eof(ios_stdin)) {
                ios_printf(ios_stdout, "\n");
                break;
            }
            jl_value_t *ast = jl_parse_input_line(input);
            jl_value_t *value = jl_toplevel_eval(ast);
            jl_show(value);
            ios_printf(ios_stdout, "\n\n");
        }
    }
    JL_CATCH {
        iserr = 1;
        goto again;
    }

    return 0;
}
Пример #5
0
static int return_callback(int count, int key) {
    add_history_temporary(rl_line_buffer);
    rl_ast = jl_parse_input_line(rl_line_buffer);
    rl_done = !rl_ast || !jl_is_expr(rl_ast) ||
        (((jl_expr_t*)rl_ast)->head != jl_continue_sym);
    if (!rl_done) {
        newline_callback(count, key);
    } else {
        reset_indent();
        rl_point = rl_end;
        rl_redisplay();
    }
    return 0;
}
Пример #6
0
static jl_value_t* repl_parse_input_line(char *buf) {
    if (buf[0] == ';') {
        buf++;
        jl_value_t *f = jl_get_global(jl_base_module,jl_symbol("repl_hook"));
        assert(f);
        jl_value_t **fargs;
        JL_GC_PUSHARGS(fargs, 1);
        fargs[0] = jl_pchar_to_string((char*)buf, strlen(buf));
        jl_value_t *result = jl_apply((jl_function_t*)f, fargs, 1);
        JL_GC_POP();
        return result;
    }
    return jl_parse_input_line(buf);
}
Пример #7
0
void jl_input_line_callback(char *input)
{
    if (input) {
        jl_value_t *ast = jl_parse_input_line(input);
        int line_done = !ast || !jl_is_expr(ast) ||
            (((jl_expr_t*)ast)->head != jl_continue_sym);
        if (line_done) {
            jl_deprep_terminal();
            int doprint = !ends_with_semicolon(input);
            stdin_buf[0] = 0; //also sets input[0] == 0
            stdin_buf_len = 0;
            handle_input(ast, 0, doprint);
        }
    }
}
Пример #8
0
DLLEXPORT void *jl_eval_string(const char *str)
{
    jl_value_t *r;
    JL_TRY {
        jl_value_t *ast = jl_parse_input_line(str);
        JL_GC_PUSH1(&ast);
        r = jl_toplevel_eval(ast);
        JL_GC_POP();
        jl_exception_clear();
    }
    JL_CATCH {
        //jl_show(jl_stderr_obj(), jl_exception_in_transit);
        r = NULL;
    }
    return r;
}
Пример #9
0
JL_DLLEXPORT jl_value_t *jl_eval_string(const char *str)
{
    jl_value_t *r;
    JL_TRY {
        char *filename = "none";
        jl_value_t *ast = jl_parse_input_line(str, strlen(str),
                filename, strlen(filename));
        JL_GC_PUSH1(&ast);
        r = jl_toplevel_eval(ast);
        JL_GC_POP();
        jl_exception_clear();
    }
    JL_CATCH {
        //jl_show(jl_stderr_obj(), jl_exception_in_transit);
        r = NULL;
    }
    return r;
}
Пример #10
0
JL_DLLEXPORT jl_value_t *jl_eval_string(const char *str)
{
    jl_value_t *r;
    JL_TRY {
        const char *filename = "none";
        jl_value_t *ast = jl_parse_input_line(str, strlen(str),
                filename, strlen(filename));
        JL_GC_PUSH1(&ast);
        size_t last_age = jl_get_ptls_states()->world_age;
        jl_get_ptls_states()->world_age = jl_get_world_counter();
        r = jl_toplevel_eval_in(jl_main_module, ast);
        jl_get_ptls_states()->world_age = last_age;
        JL_GC_POP();
        jl_exception_clear();
    }
    JL_CATCH {
        r = NULL;
    }
    return r;
}
Пример #11
0
DLLEXPORT void *jl_eval_string(char *str)
{
#ifdef COPY_STACKS
    jl_root_task->stackbase = (char*)&str;
    if (jl_setjmp(jl_root_task->base_ctx, 1)) {
        jl_switch_stack(jl_current_task, jl_jmp_target);
    }
#endif
    jl_value_t *r;
    JL_TRY {
        jl_value_t *ast = jl_parse_input_line(str);
        JL_GC_PUSH1(&ast);
        r = jl_toplevel_eval(ast);
        JL_GC_POP();
    }
    JL_CATCH {
        //jl_show(jl_stderr_obj(), jl_exception_in_transit);
        r = NULL;
    }
    return r;
}
Пример #12
0
static int return_callback(int count, int key) {
    static int consecutive_returns = 0;
    if (rl_point > prompt_length && rl_point == rl_end &&
        rl_line_buffer[rl_point-prompt_length-1] == '\n')
        consecutive_returns++;
    else
        consecutive_returns = 0;
    add_history_temporary(rl_line_buffer);
    rl_ast = jl_parse_input_line(rl_line_buffer);
    rl_done = !rl_ast || !jl_is_expr(rl_ast) ||
        (((jl_expr_t*)rl_ast)->head != jl_continue_sym) ||
        consecutive_returns > 1;
    if (!rl_done) {
        newline_callback(count, key);
    } else {
        reset_indent();
        rl_point = rl_end;
        rl_redisplay();
    }
    return 0;
}