本文整理汇总了C++中JL_GC_POP函数的典型用法代码示例。如果您正苦于以下问题:C++ JL_GC_POP函数的具体用法?C++ JL_GC_POP怎么用?C++ JL_GC_POP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JL_GC_POP函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:EvanMisshula,项目名称:julia,代码行数:37,代码来源:toplevel.c
示例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;
}
开发者ID:alsam,项目名称:julia,代码行数:25,代码来源:ast.c
示例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;
}
开发者ID:alepharchives,项目名称:julia,代码行数:24,代码来源:interpreter.c
示例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;
}
开发者ID:codeForSaif,项目名称:julia,代码行数:24,代码来源:module.c
示例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;
}
开发者ID:steerapi,项目名称:julia,代码行数:24,代码来源:builtins.c
示例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;
}
开发者ID:MatthiasJReisinger,项目名称:julia,代码行数:24,代码来源:rtutils.c
示例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;
}
开发者ID:ArchieCall,项目名称:julia,代码行数:36,代码来源:array.c
示例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;
}
开发者ID:alvesjnr,项目名称:julia,代码行数:24,代码来源:alloc.c
示例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;
}
开发者ID:Lanzaa,项目名称:julia,代码行数:36,代码来源:jl_uv.c
示例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;
}
开发者ID:SatoHiroki,项目名称:julia,代码行数:61,代码来源:ast.c
示例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;
}
开发者ID:chaoqing,项目名称:julia,代码行数:69,代码来源:toplevel.c
示例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;
}
//.........这里部分代码省略.........
开发者ID:dpsanders,项目名称:julia,代码行数:101,代码来源:interpreter.c
示例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;
}
开发者ID:ararslan,项目名称:julia,代码行数:96,代码来源:ast.c
示例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;
//.........这里部分代码省略.........
开发者ID:Rory-Finnegan,项目名称:julia,代码行数:101,代码来源:interpreter.c
示例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;
}
开发者ID:fpepin,项目名称:julia,代码行数:72,代码来源:toplevel.c
示例16: jl_tuple_len
jl_array_t *jl_reshape_array(jl_type_t *atype, jl_array_t *data,
jl_tuple_t *dims)
{
size_t i;
jl_array_t *a;
size_t ndims = jl_tuple_len(dims);
int ndimwords = jl_array_ndimwords(ndims);
a = allocobj((sizeof(jl_array_t) + ndimwords*sizeof(size_t) + 15)&-16);
a->type = atype;
a->ndims = ndims;
a->data = NULL;
JL_GC_PUSH(&a);
char *d = data->data;
if (data->ndims == 1) d -= data->offset*data->elsize;
if (d == jl_array_inline_data_area(data)) {
if (data->ndims == 1) {
// data might resize, so switch it to shared representation.
// problem: we'd like to do that, but it might not be valid,
// since the buffer might be used from C in a way that it's
// assumed not to move. for now, just copy the data (note this
// case only happens for sizes <= ARRAY_INLINE_NBYTES)
jl_mallocptr_t *mp = array_new_buffer(data, data->length);
memcpy(mp->ptr, data->data, data->length * data->elsize);
a->data = mp->ptr;
jl_array_data_owner(a) = (jl_value_t*)mp;
a->ismalloc = 1;
//data->data = mp->ptr;
//data->offset = 0;
//data->maxsize = data->length;
//jl_array_data_owner(data) = (jl_value_t*)mp;
}
else {
a->ismalloc = 0;
jl_array_data_owner(a) = (jl_value_t*)data;
}
}
else {
a->ismalloc = data->ismalloc;
jl_array_data_owner(a) = jl_array_data_owner(data);
}
if (a->data == NULL) a->data = data->data;
jl_type_t *el_type = (jl_type_t*)jl_tparam0(atype);
if (jl_is_bits_type(el_type)) {
a->elsize = jl_bitstype_nbits(el_type)/8;
a->ptrarray = 0;
}
else {
a->elsize = sizeof(void*);
a->ptrarray = 1;
}
if (ndims == 1) {
a->length = jl_unbox_long(jl_tupleref(dims,0));
a->nrows = a->length;
a->maxsize = a->length;
a->offset = 0;
}
else {
size_t *adims = &a->nrows;
size_t l=1;
for(i=0; i < ndims; i++) {
adims[i] = jl_unbox_long(jl_tupleref(dims, i));
l *= adims[i];
}
a->length = l;
}
JL_GC_POP();
return a;
}
开发者ID:XelaRellum,项目名称:julia,代码行数:73,代码来源:array.c
示例17: true_main
static NOINLINE int true_main(int argc, char *argv[])
{
if (jl_core_module != NULL) {
jl_array_t *args = (jl_array_t*)jl_get_global(jl_core_module, jl_symbol("ARGS"));
if (args == NULL) {
args = jl_alloc_cell_1d(0);
JL_GC_PUSH1(&args);
jl_set_const(jl_core_module, jl_symbol("ARGS"), (jl_value_t*)args);
JL_GC_POP();
}
assert(jl_array_len(args) == 0);
jl_array_grow_end(args, argc);
int i;
for (i=0; i < argc; i++) {
jl_value_t *s = (jl_value_t*)jl_cstr_to_string(argv[i]);
jl_set_typeof(s,jl_utf8_string_type);
jl_arrayset(args, s, i);
}
}
jl_function_t *start_client = jl_base_module ?
(jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start")) : NULL;
if (start_client) {
jl_apply(&start_client, 1);
return 0;
}
// run program if specified, otherwise enter REPL
if (argc > 0) {
if (strcmp(argv[0], "-")) {
return exec_program(argv[0]);
}
}
ios_puts("WARNING: Base._start not defined, falling back to economy mode repl.\n", ios_stdout);
if (!jl_errorexception_type)
ios_puts("WARNING: jl_errorexception_type not defined; any errors will be fatal.\n", ios_stdout);
while (!ios_eof(ios_stdin)) {
char *volatile line = NULL;
JL_TRY {
ios_puts("\njulia> ", ios_stdout);
ios_flush(ios_stdout);
line = ios_readline(ios_stdin);
jl_value_t *val = (jl_value_t*)jl_eval_string(line);
if (jl_exception_occurred()) {
jl_printf(JL_STDERR, "error during run:\n");
jl_static_show(JL_STDERR, jl_exception_in_transit);
jl_exception_clear();
}
else if (val) {
jl_static_show(JL_STDOUT, val);
}
jl_printf(JL_STDOUT, "\n");
free(line);
line = NULL;
uv_run(jl_global_event_loop(),UV_RUN_NOWAIT);
}
JL_CATCH {
if (line) {
free(line);
line = NULL;
}
jl_printf(JL_STDERR, "\nparser error:\n");
jl_static_show(JL_STDERR, jl_exception_in_transit);
jl_printf(JL_STDERR, "\n");
jlbacktrace();
}
}
return 0;
}
开发者ID:Blisse,项目名称:julia,代码行数:72,代码来源:repl.c
示例18: JL_NARGSV
// ccall(pointer, rettype, (argtypes...), args...)
static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
{
JL_NARGSV(ccall, 3);
jl_value_t *ptr=NULL, *rt=NULL, *at=NULL;
JL_GC_PUSH(&ptr, &rt, &at);
ptr = jl_interpret_toplevel_expr_in(ctx->module, args[1],
&jl_tupleref(ctx->sp,0),
ctx->sp->length/2);
rt = jl_interpret_toplevel_expr_in(ctx->module, args[2],
&jl_tupleref(ctx->sp,0),
ctx->sp->length/2);
if (jl_is_tuple(rt)) {
std::string msg = "in " + ctx->funcName +
": ccall: missing return type";
jl_error(msg.c_str());
}
at = jl_interpret_toplevel_expr_in(ctx->module, args[3],
&jl_tupleref(ctx->sp,0),
ctx->sp->length/2);
void *fptr;
if (jl_is_symbol(ptr)) {
// just symbol, default to JuliaDLHandle
fptr = jl_dlsym(jl_dl_handle, ((jl_sym_t*)ptr)->name);
}
else {
JL_TYPECHK(ccall, pointer, ptr);
fptr = *(void**)jl_bits_data(ptr);
}
JL_TYPECHK(ccall, type, rt);
JL_TYPECHK(ccall, tuple, at);
JL_TYPECHK(ccall, type, at);
jl_tuple_t *tt = (jl_tuple_t*)at;
std::vector<Type *> fargt(0);
std::vector<Type *> fargt_sig(0);
Type *lrt = julia_type_to_llvm(rt, ctx);
if (lrt == NULL) {
JL_GC_POP();
return literal_pointer_val(jl_nothing);
}
size_t i;
bool haspointers = false;
bool isVa = false;
for(i=0; i < tt->length; i++) {
jl_value_t *tti = jl_tupleref(tt,i);
if (jl_is_seq_type(tti)) {
isVa = true;
tti = jl_tparam0(tti);
}
Type *t = julia_type_to_llvm(tti, ctx);
if (t == NULL) {
JL_GC_POP();
return literal_pointer_val(jl_nothing);
}
fargt.push_back(t);
if (!isVa)
fargt_sig.push_back(t);
}
if ((!isVa && tt->length != (nargs-2)/2) ||
( isVa && tt->length-1 > (nargs-2)/2))
jl_error("ccall: wrong number of arguments to C function");
// some special functions
if (fptr == &jl_array_ptr) {
Value *ary = emit_expr(args[4], ctx, true);
JL_GC_POP();
return mark_julia_type(builder.CreateBitCast(emit_arrayptr(ary),T_pint8),
rt);
}
// see if there are & arguments
for(i=4; i < nargs+1; i+=2) {
jl_value_t *argi = args[i];
if (jl_is_expr(argi) && ((jl_expr_t*)argi)->head == amp_sym) {
haspointers = true;
break;
}
}
// make LLVM function object for the target
Function *llvmf =
Function::Create(FunctionType::get(lrt, fargt_sig, isVa),
Function::ExternalLinkage,
"ccall_", jl_Module);
jl_ExecutionEngine->addGlobalMapping(llvmf, fptr);
// save temp argument area stack pointer
Value *saveloc=NULL;
Value *stacksave=NULL;
if (haspointers) {
// TODO: inline this
saveloc = builder.CreateCall(save_arg_area_loc_func);
stacksave =
builder.CreateCall(Intrinsic::getDeclaration(jl_Module,
Intrinsic::stacksave));
}
// emit arguments
Value *argvals[(nargs-3)/2];
int last_depth = ctx->argDepth;
//.........这里部分代码省略.........
开发者ID:ChappedSky,项目名称:julia,代码行数:101,代码来源:ccall.cpp
示例19: kind
/*
Method caches are divided into three parts: one for signatures where
the first argument is a singleton kind (Type{Foo}), one indexed by the
UID of the first argument's type in normal cases, and a fallback
table of everything else.
Note that the "primary key" is the type of the first *argument*, since
there tends to be lots of variation there. The type of the 0th argument
(the function) is always the same for most functions.
*/
static jl_typemap_entry_t *jl_typemap_assoc_by_type_(jl_typemap_entry_t *ml, jl_tupletype_t *types, int8_t inexact, jl_svec_t **penv)
{
size_t n = jl_field_count(types);
while (ml != (void*)jl_nothing) {
size_t lensig = jl_field_count(ml->sig);
if (lensig == n || (ml->va && lensig <= n+1)) {
int resetenv = 0, ismatch = 1;
if (ml->simplesig != (void*)jl_nothing) {
size_t lensimplesig = jl_field_count(ml->simplesig);
int isva = lensimplesig > 0 && jl_is_vararg_type(jl_tparam(ml->simplesig, lensimplesig - 1));
if (lensig == n || (isva && lensimplesig <= n + 1))
ismatch = sig_match_by_type_simple(jl_svec_data(types->parameters), n,
ml->simplesig, lensimplesig, isva);
else
ismatch = 0;
}
if (ismatch == 0)
; // nothing
else if (ml->isleafsig)
ismatch = sig_match_by_type_leaf(jl_svec_data(types->parameters),
ml->sig, lensig);
else if (ml->issimplesig)
ismatch = sig_match_by_type_simple(jl_svec_data(types->parameters), n,
ml->sig, lensig, ml->va);
else if (ml->tvars == jl_emptysvec)
ismatch = jl_tuple_subtype(jl_svec_data(types->parameters), n, ml->sig, 0);
else if (penv == NULL) {
ismatch = jl_type_match((jl_value_
|
请发表评论