Skip to content

Commit

Permalink
hacky harness for turning FieldRef off/on
Browse files Browse the repository at this point in the history
  • Loading branch information
ihnorton committed Apr 28, 2015
1 parent 4bb6a90 commit 0302c39
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ jl_value_t *jl_load_file_string(const char *text, char *filename)
return jl_parse_eval_all(filename);
}

DLLEXPORT jl_value_t* jl_toggle_fieldref() {
value_t e = fl_applyn(0, symbol_value(symbol("jl-toggle-fieldref")));
return scm_to_julia(e,0);
}

// returns either an expression or a thunk
jl_value_t *jl_expand(jl_value_t *expr)
{
Expand Down
8 changes: 7 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,13 @@ jl_value_t *jl_static_eval(jl_value_t *ex, void *ctx_, jl_module_t *mod,
}
else if (jl_array_dim0(e->args) == 3 && fptr == &jl_f_get_field) {
m = (jl_module_t*)jl_static_eval(jl_exprarg(e,1),ctx,mod,sp,ast,sparams,allow_alloc);
s = (jl_sym_t*)jl_static_eval(jl_exprarg(e,2),ctx,mod,sp,ast,sparams,allow_alloc);
if (jl_is_datatype(jl_exprarg(e,2)) &&
((jl_datatype_t*)jl_exprarg(e,2))->name == jl_fieldref_type->name) {
jl_value_t *frv = jl_svecref(((jl_datatype_t*)jl_exprarg(e,2))->parameters, 0);
s = (jl_sym_t*)jl_static_eval(frv,ctx,mod,sp,ast,sparams,allow_alloc);
} else {
s = (jl_sym_t*)jl_static_eval(jl_exprarg(e,2),ctx,mod,sp,ast,sparams,allow_alloc);
}
if (m && jl_is_module(m) && s && jl_is_symbol(s)) {
jl_binding_t *b = jl_get_binding(m, s);
if (b && b->constp)
Expand Down
4 changes: 4 additions & 0 deletions src/jlfrontend.scm
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@
e
(expand-toplevel-expr e))))))))))

(define *fieldref* #f)
(define (jl-toggle-fieldref)
(set! *fieldref* (eq? *fieldref* #f)))

(define (jl-parser-current-lineno)
(input-port-line (ts:port current-token-stream)))

Expand Down
6 changes: 5 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,11 @@

'|.|
(lambda (e)
`(call (top getfield) ,(expand-forms (cadr e)) ,(expand-forms (caddr e))))
(cond
((eq? *fieldref* #f)
`(call (top getfield) ,(expand-forms (cadr e)) ,(expand-forms (caddr e))))
(else
`(call (top getfield) ,(expand-forms (cadr e)) (call (top apply_type) (top FieldRef) ,(expand-forms (caddr e)))))))

'in
(lambda (e)
Expand Down
2 changes: 2 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ DLLEXPORT int add_library_mapping(char *lib, void *hnd);
DLLEXPORT const char *jl_lookup_soname(const char *pfx, size_t n);
#endif

DLLEXPORT jl_value_t* jl_toggle_fieldref();

// compiler
void jl_compile(jl_function_t *f);
DLLEXPORT jl_value_t *jl_toplevel_eval(jl_value_t *v);
Expand Down

0 comments on commit 0302c39

Please sign in to comment.