本文整理汇总了C++中JL_GC_POP函数的典型用法代码示例。如果您正苦于以下问题:C++ JL_GC_POP函数的具体用法?C++ JL_GC_POP怎么用?C++ JL_GC_POP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JL_GC_POP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jl_parse_eval_all
// repeatedly call jl_parse_next and eval everything
void jl_parse_eval_all(char *fname)
{
//jl_printf(JL_STDERR, "***** loading %s\n", fname);
int last_lineno = jl_lineno;
jl_lineno=0;
jl_value_t *fn=NULL, *ln=NULL, *form=NULL;
JL_GC_PUSH3(&fn, &ln, &form);
JL_TRY {
// handle syntax error
while (1) {
form = jl_parse_next();
if (form == NULL)
break;
if (jl_is_expr(form)) {
if (((jl_expr_t*)form)->head == jl_continue_sym) {
jl_errorf("syntax: %s", jl_string_data(jl_exprarg(form,0)));
}
if (((jl_expr_t*)form)->head == error_sym) {
jl_interpret_toplevel_expr(form);
}
}
(void)jl_toplevel_eval_flex(form, 1);
}
}
JL_CATCH {
jl_stop_parsing();
fn = jl_pchar_to_string(fname, strlen(fname));
ln = jl_box_long(jl_lineno);
jl_lineno = last_lineno;
jl_rethrow_other(jl_new_struct(jl_loaderror_type, fn, ln,
jl_exception_in_transit));
}
jl_stop_parsing();
jl_lineno = last_lineno;
JL_GC_POP();
}
示例2: JL_GC_PUSH3
// wrap expr in a thunk AST
jl_lambda_info_t *jl_wrap_expr(jl_value_t *expr)
{
// `(lambda () (() () ()) ,expr)
jl_expr_t *le=NULL, *bo=NULL; jl_value_t *vi=NULL;
jl_value_t *mt = jl_an_empty_cell;
JL_GC_PUSH3(&le, &vi, &bo);
le = jl_exprn(lambda_sym, 3);
jl_cellset(le->args, 0, mt);
vi = (jl_value_t*)jl_alloc_cell_1d(3);
jl_cellset(vi, 0, mt);
jl_cellset(vi, 1, mt);
jl_cellset(vi, 2, mt);
jl_cellset(le->args, 1, vi);
if (!jl_is_expr(expr) || ((jl_expr_t*)expr)->head != body_sym) {
bo = jl_exprn(body_sym, 1);
jl_cellset(bo->args, 0, (jl_value_t*)jl_exprn(return_sym, 1));
jl_cellset(((jl_expr_t*)jl_exprarg(bo,0))->args, 0, expr);
expr = (jl_value_t*)bo;
}
jl_cellset(le->args, 2, expr);
jl_lambda_info_t *li = jl_new_lambda_info((jl_value_t*)le, jl_null);
JL_GC_POP();
return li;
}
示例3: jl_lam_body
jl_value_t *jl_interpret_toplevel_thunk_with(jl_lambda_info_t *lam,
jl_value_t **loc, size_t nl)
{
jl_expr_t *ast = (jl_expr_t*)lam->ast;
jl_array_t *stmts = jl_lam_body(ast)->args;
jl_array_t *l = jl_lam_locals(ast);
jl_value_t **names = &((jl_value_t**)l->data)[0];
nl += l->length;
jl_value_t **locals = (jl_value_t**)alloca(nl*2*sizeof(void*));
jl_value_t *r = (jl_value_t*)jl_null;
size_t i=0;
for(i=0; i < l->length; i++) {
locals[i*2] = names[i];
locals[i*2+1] = NULL;
}
for(; i < nl; i++) {
locals[i*2] = loc[(i-l->length)*2];
locals[i*2+1] = loc[(i-l->length)*2+1];
}
JL_GC_PUSHARGS(locals, nl*2);
r = eval_body(stmts, locals, nl, 0);
JL_GC_POP();
return r;
}
示例4: jl_set_typeof
JL_DLLEXPORT jl_module_t *jl_new_module(jl_sym_t *name)
{
jl_module_t *m = (jl_module_t*)jl_gc_allocobj(sizeof(jl_module_t));
jl_set_typeof(m, jl_module_type);
JL_GC_PUSH1(&m);
assert(jl_is_symbol(name));
m->name = name;
m->parent = NULL;
m->constant_table = NULL;
m->call_func = NULL;
m->istopmod = 0;
m->std_imports = 0;
m->uuid = uv_now(uv_default_loop());
htable_new(&m->bindings, 0);
arraylist_new(&m->usings, 0);
if (jl_core_module) {
jl_module_using(m, jl_core_module);
}
// export own name, so "using Foo" makes "Foo" itself visible
jl_set_const(m, name, (jl_value_t*)m);
jl_module_export(m, name);
JL_GC_POP();
return m;
}
示例5: jl_declare_constant
jl_value_t *jl_method_def(jl_sym_t *name, jl_value_t **bp, jl_binding_t *bnd,
jl_tuple_t *argtypes, jl_function_t *f)
{
jl_value_t *gf;
if (bnd) {
jl_declare_constant(bnd);
}
if (*bp == NULL) {
gf = (jl_value_t*)jl_new_generic_function(name);
*bp = gf;
}
else {
gf = *bp;
if (!jl_is_gf(gf))
jl_error("in method definition: not a generic function");
}
JL_GC_PUSH(&gf);
assert(jl_is_function(f));
assert(jl_is_tuple(argtypes));
check_type_tuple(argtypes, name, "method definition");
jl_add_method((jl_function_t*)gf, argtypes, f);
JL_GC_POP();
return gf;
}
示例6: jl_printf
static jl_value_t *jl_vexceptionf(jl_datatype_t *exception_type,
const char *fmt, va_list args)
{
if (exception_type == NULL) {
jl_printf(JL_STDERR, "ERROR: ");
jl_vprintf(JL_STDERR, fmt, args);
jl_printf(JL_STDERR, "\n");
jl_exit(1);
}
char *str = NULL;
int ok = vasprintf(&str, fmt, args);
jl_value_t *msg;
if (ok < 0) { // vasprintf failed
msg = jl_cstr_to_string("internal error: could not display error message");
}
else {
msg = jl_pchar_to_string(str, strlen(str));
free(str);
}
JL_GC_PUSH1(&msg);
jl_value_t *e = jl_new_struct(exception_type, msg);
JL_GC_POP();
return e;
}
示例7: jl_array_isdefined
int jl_array_isdefined(jl_value_t **args0, int nargs)
{
assert(jl_is_array(args0[0]));
jl_value_t **depwarn_args;
JL_GC_PUSHARGS(depwarn_args, 3);
depwarn_args[0] = jl_get_global(jl_base_module, jl_symbol("depwarn"));
depwarn_args[1] = jl_cstr_to_string("isdefined(a::Array, i::Int) is deprecated, use isassigned(a, i) instead");
depwarn_args[2] = (jl_value_t*) jl_symbol("isdefined");
jl_apply(depwarn_args, 3);
JL_GC_POP();
jl_array_t *a = (jl_array_t*)args0[0];
jl_value_t **args = &args0[1];
size_t nidxs = nargs-1;
size_t i=0;
size_t k, stride=1;
size_t nd = jl_array_ndims(a);
for(k=0; k < nidxs; k++) {
if (!jl_is_long(args[k]))
jl_type_error("isdefined", (jl_value_t*)jl_long_type, args[k]);
size_t ii = jl_unbox_long(args[k])-1;
i += ii * stride;
size_t d = k>=nd ? 1 : jl_array_dim(a, k);
if (k < nidxs-1 && ii >= d)
return 0;
stride *= d;
}
for(; k < nd; k++)
stride *= jl_array_dim(a, k);
if (i >= stride)
return 0;
if (a->flags.ptrarray)
return ((jl_value_t**)jl_array_data(a))[i] != NULL;
return 1;
}
示例8: JL_GC_PUSH
jl_tag_type_t *jl_new_tagtype(jl_value_t *name, jl_tag_type_t *super,
jl_tuple_t *parameters)
{
jl_typename_t *tn=NULL;
JL_GC_PUSH(&tn);
if (jl_is_typename(name))
tn = (jl_typename_t*)name;
else
tn = jl_new_typename((jl_sym_t*)name);
jl_tag_type_t *t = (jl_tag_type_t*)newobj((jl_type_t*)jl_tag_kind,
TAG_TYPE_NW);
t->name = tn;
t->super = super;
unbind_tvars(parameters);
t->parameters = parameters;
t->fptr = NULL;
t->env = NULL;
t->linfo = NULL;
if (t->name->primary == NULL)
t->name->primary = (jl_value_t*)t;
JL_GC_POP();
return t;
}
示例9: JL_GC_PUSHARGS
jl_value_t *jl_callback_call(jl_function_t *f,jl_value_t *val,int count,...)
{
if (val != 0)
count += 1;
else
return NULL;
jl_value_t **argv;
JL_GC_PUSHARGS(argv,count);
memset(argv, 0, count*sizeof(jl_value_t*));
jl_value_t *v;
va_list argp;
va_start(argp,count);
int i;
assert(val != 0);
argv[0]=val;
for(i=((val==0)?0:1); i<count; ++i) {
switch(va_arg(argp,int)) {
case CB_PTR:
argv[i] = jl_box_voidpointer(va_arg(argp,void*));
break;
case CB_INT32:
argv[i] = jl_box_int32(va_arg(argp,int32_t));
break;
case CB_INT64:
argv[i] = jl_box_int64(va_arg(argp,int64_t));
break;
default: jl_error("callback: only Ints and Pointers are supported at this time");
//excecution never reaches here
break;
}
}
va_end(argp);
v = jl_apply(f,(jl_value_t**)argv,count);
JL_GC_POP();
return v;
}
示例10: assert
static jl_value_t *copy_ast(jl_value_t *expr, jl_tuple_t *sp, int do_sp)
{
if (jl_is_symbol(expr)) {
if (!do_sp) return expr;
// pre-evaluate certain static parameters to help type inference
for(int i=0; i < jl_tuple_len(sp); i+=2) {
assert(jl_is_typevar(jl_tupleref(sp,i)));
if ((jl_sym_t*)expr == ((jl_tvar_t*)jl_tupleref(sp,i))->name) {
jl_value_t *spval = jl_tupleref(sp,i+1);
if (jl_is_long(spval))
return spval;
}
}
}
else if (jl_is_lambda_info(expr)) {
jl_lambda_info_t *li = (jl_lambda_info_t*)expr;
/*
if (sp == jl_null && li->ast &&
jl_array_len(jl_lam_capt((jl_expr_t*)li->ast)) == 0)
return expr;
*/
// TODO: avoid if above condition is true and decls have already
// been evaluated.
JL_GC_PUSH1(&li);
li = jl_add_static_parameters(li, sp);
// inner lambda does not need the "def" link. it leads to excess object
// retention, for example pointing to the original uncompressed AST
// of a top-level thunk that gets type inferred.
li->def = li;
li->ast = jl_prepare_ast(li, li->sparams);
JL_GC_POP();
return (jl_value_t*)li;
}
else if (jl_typeis(expr,jl_array_any_type)) {
jl_array_t *a = (jl_array_t*)expr;
jl_array_t *na = jl_alloc_cell_1d(jl_array_len(a));
JL_GC_PUSH1(&na);
size_t i;
for(i=0; i < jl_array_len(a); i++)
jl_cellset(na, i, copy_ast(jl_cellref(a,i), sp, do_sp));
JL_GC_POP();
return (jl_value_t*)na;
}
else if (jl_is_expr(expr)) {
jl_expr_t *e = (jl_expr_t*)expr;
jl_expr_t *ne = jl_exprn(e->head, jl_array_len(e->args));
JL_GC_PUSH1(&ne);
if (e->head == lambda_sym) {
jl_exprarg(ne, 0) = copy_ast(jl_exprarg(e,0), sp, 0);
jl_exprarg(ne, 1) = copy_ast(jl_exprarg(e,1), sp, 0);
jl_exprarg(ne, 2) = copy_ast(jl_exprarg(e,2), sp, 1);
}
else {
for(size_t i=0; i < jl_array_len(e->args); i++)
jl_exprarg(ne, i) = copy_ast(jl_exprarg(e,i), sp, 1);
}
JL_GC_POP();
return (jl_value_t*)ne;
}
return expr;
}
示例11: assert
jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
{
assert(ex->head == module_sym);
jl_module_t *last_module = jl_current_module;
int std_imports = (jl_exprarg(ex,0)==jl_true);
jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 1);
if (!jl_is_symbol(name)) {
jl_type_error("module", (jl_value_t*)jl_sym_type, (jl_value_t*)name);
}
jl_module_t *parent_module = jl_current_module;
jl_binding_t *b = jl_get_binding_wr(parent_module, name);
jl_declare_constant(b);
if (b->value != NULL) {
JL_PRINTF(JL_STDERR, "Warning: replacing module %s\n", name->name);
}
jl_module_t *newm = jl_new_module(name);
newm->parent = parent_module;
b->value = (jl_value_t*)newm;
if (parent_module == jl_main_module && name == jl_symbol("Base")) {
jl_old_base_module = jl_base_module;
// pick up Base module during bootstrap
jl_base_module = newm;
}
// export all modules from Main
if (parent_module == jl_main_module)
jl_module_export(jl_main_module, name);
// add standard imports unless baremodule
if (std_imports) {
if (jl_base_module != NULL)
jl_module_using(newm, jl_base_module); // using Base
}
JL_GC_PUSH(&last_module);
jl_current_module = newm;
jl_array_t *exprs = ((jl_expr_t*)jl_exprarg(ex, 2))->args;
JL_TRY {
for(int i=0; i < exprs->length; i++) {
// process toplevel form
jl_value_t *form = jl_cellref(exprs, i);
(void)jl_toplevel_eval_flex(form, 1);
}
}
JL_CATCH {
jl_current_module = last_module;
jl_rethrow();
}
JL_GC_POP();
jl_current_module = last_module;
size_t i;
void **table = newm->bindings.table;
for(i=1; i < newm->bindings.size; i+=2) {
if (table[i] != HT_NOTFOUND) {
jl_binding_t *b = (jl_binding_t*)table[i];
// remove non-exported macros
if (b->name->name[0]=='@' && !b->exportp)
b->value = NULL;
// error for unassigned exports
/*
if (b->exportp && b->owner==newm && b->value==NULL)
jl_errorf("identifier %s exported from %s is not initialized",
b->name->name, newm->name->name);
*/
}
}
return jl_nothing;
}
示例12: jl_get_ptls_states
static jl_value_t *eval(jl_value_t *e, interpreter_state *s)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_code_info_t *src = s==NULL ? NULL : s->src;
if (jl_is_ssavalue(e)) {
ssize_t id = ((jl_ssavalue_t*)e)->id;
if (id >= jl_source_nssavalues(src) || id < 0 || s->locals == NULL)
jl_error("access to invalid SSAValue");
else
return s->locals[jl_source_nslots(src) + id];
}
if (jl_is_slot(e)) {
ssize_t n = jl_slot_number(e);
if (n > jl_source_nslots(src) || n < 1 || s->locals == NULL)
jl_error("access to invalid slot number");
jl_value_t *v = s->locals[n-1];
if (v == NULL)
jl_undefined_var_error((jl_sym_t*)jl_array_ptr_ref(src->slotnames, n - 1));
return v;
}
if (jl_is_globalref(e)) {
jl_sym_t *s = jl_globalref_name(e);
jl_value_t *v = jl_get_global(jl_globalref_mod(e), s);
if (v == NULL)
jl_undefined_var_error(s);
return v;
}
if (jl_is_quotenode(e))
return jl_fieldref(e,0);
jl_module_t *modu = (s == NULL ? ptls->current_module : s->module);
if (jl_is_symbol(e)) { // bare symbols appear in toplevel exprs not wrapped in `thunk`
jl_value_t *v = jl_get_global(modu, (jl_sym_t*)e);
if (v == NULL)
jl_undefined_var_error((jl_sym_t*)e);
return v;
}
if (!jl_is_expr(e))
return e;
jl_expr_t *ex = (jl_expr_t*)e;
jl_value_t **args = (jl_value_t**)jl_array_data(ex->args);
size_t nargs = jl_array_len(ex->args);
if (ex->head == call_sym) {
return do_call(args, nargs, s);
}
else if (ex->head == invoke_sym) {
return do_invoke(args, nargs, s);
}
else if (ex->head == new_sym) {
jl_value_t *thetype = eval(args[0], s);
jl_value_t *v=NULL;
JL_GC_PUSH2(&thetype, &v);
assert(jl_is_structtype(thetype));
v = jl_new_struct_uninit((jl_datatype_t*)thetype);
for(size_t i=1; i < nargs; i++) {
jl_set_nth_field(v, i-1, eval(args[i], s));
}
JL_GC_POP();
return v;
}
else if (ex->head == static_parameter_sym) {
ssize_t n = jl_unbox_long(args[0]);
assert(n > 0);
if (s->sparam_vals && n <= jl_svec_len(s->sparam_vals)) {
jl_value_t *sp = jl_svecref(s->sparam_vals, n - 1);
if (!jl_is_typevar(sp))
return sp;
}
// static parameter val unknown needs to be an error for ccall
jl_error("could not determine static parameter value");
}
else if (ex->head == inert_sym) {
return args[0];
}
else if (ex->head == copyast_sym) {
return jl_copy_ast(eval(args[0], s));
}
else if (ex->head == exc_sym) {
return ptls->exception_in_transit;
}
else if (ex->head == method_sym) {
jl_sym_t *fname = (jl_sym_t*)args[0];
if (jl_is_globalref(fname)) {
modu = jl_globalref_mod(fname);
fname = jl_globalref_name(fname);
}
assert(jl_expr_nargs(ex) != 1 || jl_is_symbol(fname));
if (jl_is_symbol(fname)) {
jl_value_t **bp=NULL;
jl_value_t *bp_owner=NULL;
jl_binding_t *b=NULL;
if (bp == NULL) {
b = jl_get_binding_for_method_def(modu, fname);
bp = &b->value;
bp_owner = (jl_value_t*)modu;
}
jl_value_t *gf = jl_generic_function_def(fname, bp, bp_owner, b);
if (jl_expr_nargs(ex) == 1)
return gf;
}
//.........这里部分代码省略.........
示例13: jl_get_ptls_states
// parse and eval a whole file, possibly reading from a string (`content`)
jl_value_t *jl_parse_eval_all(const char *fname,
const char *content, size_t contentlen,
jl_module_t *inmodule)
{
jl_ptls_t ptls = jl_get_ptls_states();
if (ptls->in_pure_callback)
jl_error("cannot use include inside a generated function");
jl_ast_context_t *ctx = jl_ast_ctx_enter();
fl_context_t *fl_ctx = &ctx->fl;
value_t f, ast, expression;
size_t len = strlen(fname);
f = cvalue_static_cstrn(fl_ctx, fname, len);
fl_gc_handle(fl_ctx, &f);
if (content != NULL) {
JL_TIMING(PARSING);
value_t t = cvalue_static_cstrn(fl_ctx, content, contentlen);
fl_gc_handle(fl_ctx, &t);
ast = fl_applyn(fl_ctx, 2, symbol_value(symbol(fl_ctx, "jl-parse-string-stream")), t, f);
fl_free_gc_handles(fl_ctx, 1);
}
else {
JL_TIMING(PARSING);
assert(memchr(fname, 0, len) == NULL); // was checked already in jl_load
ast = fl_applyn(fl_ctx, 1, symbol_value(symbol(fl_ctx, "jl-parse-file")), f);
}
fl_free_gc_handles(fl_ctx, 1);
if (ast == fl_ctx->F) {
jl_ast_ctx_leave(ctx);
jl_errorf("could not open file %s", fname);
}
fl_gc_handle(fl_ctx, &ast);
fl_gc_handle(fl_ctx, &expression);
int last_lineno = jl_lineno;
const char *last_filename = jl_filename;
size_t last_age = jl_get_ptls_states()->world_age;
jl_lineno = 0;
jl_filename = fname;
jl_module_t *old_module = ctx->module;
ctx->module = inmodule;
jl_value_t *form = NULL;
jl_value_t *result = jl_nothing;
int err = 0;
JL_GC_PUSH2(&form, &result);
JL_TRY {
assert(iscons(ast) && car_(ast) == symbol(fl_ctx, "toplevel"));
ast = cdr_(ast);
while (iscons(ast)) {
expression = car_(ast);
{
JL_TIMING(LOWERING);
if (fl_ctx->T == fl_applyn(fl_ctx, 1, symbol_value(symbol(fl_ctx, "contains-macrocall")), expression)) {
form = scm_to_julia(fl_ctx, expression, inmodule);
form = jl_expand_macros(form, inmodule, NULL, 0);
expression = julia_to_scm(fl_ctx, form);
}
// expand non-final expressions in statement position (value unused)
expression =
fl_applyn(fl_ctx, 1,
symbol_value(symbol(fl_ctx, iscons(cdr_(ast)) ? "jl-expand-to-thunk-stmt" : "jl-expand-to-thunk")),
expression);
}
jl_get_ptls_states()->world_age = jl_world_counter;
form = scm_to_julia(fl_ctx, expression, inmodule);
JL_SIGATOMIC_END();
jl_get_ptls_states()->world_age = jl_world_counter;
if (jl_is_linenode(form))
jl_lineno = jl_linenode_line(form);
else
result = jl_toplevel_eval_flex(inmodule, form, 1, 1);
JL_SIGATOMIC_BEGIN();
ast = cdr_(ast);
}
}
JL_CATCH {
form = jl_pchar_to_string(fname, len);
result = jl_box_long(jl_lineno);
err = 1;
}
jl_get_ptls_states()->world_age = last_age;
jl_lineno = last_lineno;
jl_filename = last_filename;
fl_free_gc_handles(fl_ctx, 2);
ctx->module = old_module;
jl_ast_ctx_leave(ctx);
if (err) {
if (jl_loaderror_type == NULL)
jl_rethrow();
else
jl_rethrow_other(jl_new_struct(jl_loaderror_type, form, result,
ptls->exception_in_transit));
}
JL_GC_POP();
return result;
}
示例14: jl_get_global
static jl_value_t *eval(jl_value_t *e, jl_value_t **locals, size_t nl, size_t ngensym)
{
if (jl_is_symbol(e)) {
jl_value_t *v;
size_t i;
for(i=0; i < nl; i++) {
if (locals[i*2] == e) {
v = locals[i*2+1];
break;
}
}
if (i >= nl) {
v = jl_get_global(jl_current_module, (jl_sym_t*)e);
}
if (v == NULL) {
jl_undefined_var_error((jl_sym_t*)e);
}
return v;
}
if (jl_is_symbolnode(e)) {
return eval((jl_value_t*)jl_symbolnode_sym(e), locals, nl, ngensym);
}
if (jl_is_gensym(e)) {
ssize_t genid = ((jl_gensym_t*)e)->id;
if (genid >= ngensym || genid < 0)
jl_error("access to invalid GenSym location");
else
return locals[nl*2 + genid];
}
if (jl_is_quotenode(e)) {
return jl_fieldref(e,0);
}
if (jl_is_topnode(e)) {
jl_sym_t *s = (jl_sym_t*)jl_fieldref(e,0);
jl_value_t *v = jl_get_global(jl_base_relative_to(jl_current_module),s);
if (v == NULL)
jl_undefined_var_error(s);
return v;
}
if (!jl_is_expr(e)) {
if (jl_is_globalref(e)) {
jl_value_t *gfargs[2] = {(jl_value_t*)jl_globalref_mod(e), (jl_value_t*)jl_globalref_name(e)};
return jl_f_get_field(NULL, gfargs, 2);
}
if (jl_is_lambda_info(e)) {
jl_lambda_info_t *li = (jl_lambda_info_t*)e;
if (jl_boot_file_loaded && li->ast && jl_is_expr(li->ast)) {
li->ast = jl_compress_ast(li, li->ast);
jl_gc_wb(li, li->ast);
}
return (jl_value_t*)jl_new_closure(NULL, (jl_value_t*)jl_emptysvec, li);
}
if (jl_is_linenode(e)) {
jl_lineno = jl_linenode_line(e);
}
if (jl_is_newvarnode(e)) {
jl_value_t *var = jl_fieldref(e,0);
assert(!jl_is_gensym(var));
assert(jl_is_symbol(var));
for(size_t i=0; i < nl; i++) {
if (locals[i*2] == var) {
locals[i*2+1] = NULL;
break;
}
}
return (jl_value_t*)jl_nothing;
}
return e;
}
jl_expr_t *ex = (jl_expr_t*)e;
jl_value_t **args = (jl_value_t**)jl_array_data(ex->args);
size_t nargs = jl_array_len(ex->args);
if (ex->head == call_sym) {
if (jl_is_lambda_info(args[0])) {
// directly calling an inner function ("let")
jl_lambda_info_t *li = (jl_lambda_info_t*)args[0];
if (jl_is_expr(li->ast) && !jl_lam_vars_captured((jl_expr_t*)li->ast) &&
!jl_has_intrinsics((jl_expr_t*)li->ast, (jl_expr_t*)li->ast, jl_current_module)) {
size_t na = nargs-1;
if (na == 0)
return jl_interpret_toplevel_thunk(li);
jl_array_t *formals = jl_lam_args((jl_expr_t*)li->ast);
size_t nreq = jl_array_len(formals);
if (nreq==0 || !jl_is_rest_arg(jl_cellref(formals,nreq-1))) {
jl_value_t **ar;
JL_GC_PUSHARGS(ar, na*2);
for(int i=0; i < na; i++) {
ar[i*2+1] = eval(args[i+1], locals, nl, ngensym);
jl_gc_wb(ex->args, ar[i*2+1]);
}
if (na != nreq) {
jl_error("wrong number of arguments");
}
for(int i=0; i < na; i++) {
jl_value_t *v = jl_cellref(formals, i);
ar[i*2] = (jl_is_gensym(v)) ? v : (jl_value_t*)jl_decl_var(v);
}
jl_value_t *ret = jl_interpret_toplevel_thunk_with(li, ar, na);
JL_GC_POP();
return ret;
//.........这里部分代码省略.........
示例15: assert
jl_value_t *jl_eval_module_expr(jl_expr_t *ex, int *plineno)
{
assert(ex->head == module_sym);
jl_module_t *last_module = jl_current_module;
jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 0);
if (!jl_is_symbol(name)) {
jl_type_error("module", (jl_value_t*)jl_sym_type, (jl_value_t*)name);
}
jl_module_t *parent_module;
if (jl_current_module == jl_core_module ||
jl_current_module == jl_main_module) {
parent_module = jl_root_module;
}
else {
parent_module = jl_current_module;
}
jl_binding_t *b = jl_get_binding_wr(parent_module, name);
jl_declare_constant(b);
if (b->value != NULL) {
JL_PRINTF(JL_STDERR, "Warning: replacing module %s\n", name->name);
}
jl_module_t *newm = jl_new_module(name);
newm->parent = (jl_value_t*)parent_module;
b->value = (jl_value_t*)newm;
if (parent_module == jl_root_module && name == jl_symbol("Base") &&
jl_base_module == NULL) {
// pick up Base module during bootstrap
jl_base_module = newm;
}
JL_GC_PUSH(&last_module);
jl_current_module = newm;
jl_array_t *exprs = ((jl_expr_t*)jl_exprarg(ex, 1))->args;
JL_TRY {
for(int i=0; i < exprs->length; i++) {
// process toplevel form
jl_value_t *form = jl_cellref(exprs, i);
if (jl_is_linenode(form)) {
if (plineno)
*plineno = jl_linenode_line(form);
}
else {
(void)jl_toplevel_eval_flex(form, 1, plineno);
}
}
}
JL_CATCH {
JL_GC_POP();
jl_current_module = last_module;
jl_raise(jl_exception_in_transit);
}
JL_GC_POP();
jl_current_module = last_module;
size_t i;
void **table = newm->bindings.table;
for(i=1; i < newm->bindings.size; i+=2) {
if (table[i] != HT_NOTFOUND) {
jl_binding_t *b = (jl_binding_t*)table[i];
// remove non-exported macros
if (b->name->name[0]=='@' && !b->exportp)
b->value = NULL;
// error for unassigned exports
/*
if (b->exportp && b->owner==newm && b->value==NULL)
jl_errorf("identifier %s exported from %s is not initialized",
b->name->name, newm->name->name);
*/
}
}
return jl_nothing;
}