Skip to content

Commit

Permalink
extend static eval to support jl_tuple_f
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Dec 9, 2012
1 parent e313476 commit effe8e4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
*.creator
*.user
*.orig
*.swp

/usr
2 changes: 1 addition & 1 deletion base/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export copy!,
symv!,
symv

libblas = Base.libblas_name
const libblas = Base.libblas_name

# SUBROUTINE DCOPY(N,DX,INCX,DY,INCY)
for (fname, elty) in ((:dcopy_,:Float64), (:scopy_,:Float32),
Expand Down
2 changes: 1 addition & 1 deletion base/lapack.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## The LAPACK module of interfaces to LAPACK subroutines
module LAPACK

liblapack = Base.liblapack_name
const liblapack = Base.liblapack_name

typealias LapackChar Char
type LapackException <: Exception
Expand Down
2 changes: 1 addition & 1 deletion src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jl_sym_t *const_sym; jl_sym_t *thunk_sym;
jl_sym_t *anonymous_sym; jl_sym_t *underscore_sym;
jl_sym_t *abstracttype_sym; jl_sym_t *bitstype_sym;
jl_sym_t *compositetype_sym; jl_sym_t *type_goto_sym;
jl_sym_t *global_sym;
jl_sym_t *global_sym; jl_sym_t *tuple_sym;

typedef struct {
int64_t a;
Expand Down
12 changes: 6 additions & 6 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,17 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
jl_value_t *ptr=NULL, *rt=NULL, *at=NULL;
Value *jl_ptr=NULL;
JL_GC_PUSH(&ptr, &rt, &at);
//ptr = static_eval(args[1], ctx, true);
//if (ptr == NULL) {
ptr = static_eval(args[1], ctx, true);
if (ptr == NULL) {
jl_value_t *ptr_ty = expr_type(args[1], ctx);
if (jl_is_cpointer_type(ptr_ty)) {
jl_ptr = emit_unbox(T_size, T_psize, emit_unboxed(args[1], ctx));
} else {
ptr = jl_interpret_toplevel_expr_in(ctx->module, args[1],
&jl_tupleref(ctx->sp,0),
jl_tuple_len(ctx->sp)/2);
std::string msg = "in " + ctx->funcName +
": ccall: function argument not a pointer or valid constant";
jl_error(msg.c_str());
}
//}
}
rt = jl_interpret_toplevel_expr_in(ctx->module, args[2],
&jl_tupleref(ctx->sp,0),
jl_tuple_len(ctx->sp)/2);
Expand Down
43 changes: 32 additions & 11 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,41 @@ static jl_value_t *static_eval(jl_value_t *ex, jl_codectx_t *ctx, bool sparams)
if (jl_is_expr(ex)) {
jl_expr_t *e = (jl_expr_t*)ex;
if (e->head == call_sym || e->head == call1_sym) {
if (e->args->length == 3) {
jl_value_t *f = static_eval(jl_exprarg(e,0),ctx,sparams);
if (f && jl_is_function(f)) {
if (((jl_function_t*)f)->fptr == &jl_f_get_field) {
m = (jl_module_t*)static_eval(jl_exprarg(e,1),ctx,sparams);
s = (jl_sym_t*)static_eval(jl_exprarg(e,2),ctx,sparams);
if (m && jl_is_module(m) && s && jl_is_symbol(s)) {
jl_binding_t *b = jl_get_binding(m, s);
if (b && b->constp)
return b->value;
}
jl_value_t *f = static_eval(jl_exprarg(e,0),ctx,sparams);
if (f && jl_is_function(f)) {
jl_fptr_t fptr = ((jl_function_t*)f)->fptr;
if (e->args->length == 3 && fptr == &jl_f_get_field) {
m = (jl_module_t*)static_eval(jl_exprarg(e,1),ctx,sparams);
s = (jl_sym_t*)static_eval(jl_exprarg(e,2),ctx,sparams);
if (m && jl_is_module(m) && s && jl_is_symbol(s)) {
jl_binding_t *b = jl_get_binding(m, s);
if (b && b->constp)
return b->value;
}
} else if (fptr == &jl_f_tuple) {
size_t i;
size_t n = e->args->length-1;
if (n==0) return (jl_value_t*)jl_null;
jl_value_t **v = (jl_value_t**)alloca(n*sizeof(jl_value_t*));
for (i = 0; i < n; i++) {
v[i] = static_eval(jl_exprarg(e,i+1),ctx,sparams);
if (v[i] == NULL)
return NULL;
}
jl_tuple_t *tup = jl_alloc_tuple_uninit(n);
for(i=0; i < n; i++) {
jl_tupleset(tup, i, v[i]);
}
return (jl_value_t*)tup;
}
}
// The next part is probably valid, but it is untested
//} else if (e->head == tuple_sym) {
// size_t i;
// for (i = 0; i < e->args->length; i++)
// if (static_eval(jl_exprarg(e,i), ctx, sparams) == NULL)
// return NULL;
// return ex;
}
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ void jl_init_serializer(void)
jl_symbol("convert"), jl_symbol("typeassert"),
jl_symbol("getfield"), jl_symbol("setfield"),
jl_symbol("tupleref"), jl_symbol("tuplelen"),
jl_symbol("apply_type"), jl_symbol("tuple"),
jl_symbol("apply_type"), tuple_sym,

jl_box_int32(0), jl_box_int32(1), jl_box_int32(2),
jl_box_int32(3), jl_box_int32(4), jl_box_int32(5),
Expand Down
1 change: 1 addition & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2630,4 +2630,5 @@ void jl_init_types(void)
compositetype_sym = jl_symbol("composite_type");
type_goto_sym = jl_symbol("type_goto");
toplevel_sym = jl_symbol("toplevel");
tuple_sym = jl_symbol("tuple");
}
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ extern jl_sym_t *const_sym; extern jl_sym_t *thunk_sym;
extern jl_sym_t *anonymous_sym; extern jl_sym_t *underscore_sym;
extern jl_sym_t *abstracttype_sym; extern jl_sym_t *bitstype_sym;
extern jl_sym_t *compositetype_sym; extern jl_sym_t *type_goto_sym;
extern jl_sym_t *global_sym;
extern jl_sym_t *global_sym; extern jl_sym_t *tuple_sym;

#ifdef __LP64__
#define NWORDS(sz) (((sz)+7)>>3)
Expand Down

0 comments on commit effe8e4

Please sign in to comment.