Skip to content

Commit

Permalink
a couple more small front-end speedups
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 27, 2014
1 parent 5e949d7 commit f522f8f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
19 changes: 13 additions & 6 deletions src/flisp/flisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static symbol_t **symtab_lookup(symbol_t **ptree, const char *str)
{
int x;

while(*ptree != NULL) {
while (*ptree != NULL) {
x = strcmp(str, (*ptree)->name);
if (x == 0)
return ptree;
Expand Down Expand Up @@ -497,16 +497,18 @@ static value_t relocate(value_t v)
#endif
d = cdr_(v);
car_(v) = TAG_FWD; cdr_(v) = nc;
car_(nc) = relocate(a);
if ((tag(a)&3) == 0 || !ismanaged(a))
car_(nc) = a;
else
car_(nc) = relocate(a);
pcdr = &cdr_(nc);
v = d;
} while (iscons(v));
*pcdr = (d==NIL) ? NIL : relocate(d);
return first;
}

if ((t&3) == 0) return v;
if (!ismanaged(v)) return v;
if ((t&3) == 0 || !ismanaged(v)) return v;
if (isforwarded(v)) return forwardloc(v);

if (t == TAG_VECTOR) {
Expand All @@ -524,8 +526,13 @@ static value_t relocate(value_t v)
forward(v, nc);
if (sz > 0) {
vector_elt(nc,0) = relocate(a);
for(i=1; i < sz; i++)
vector_elt(nc,i) = relocate(vector_elt(v,i));
for(i=1; i < sz; i++) {
a = vector_elt(v,i);
if ((tag(a)&3) == 0 || !ismanaged(a))
vector_elt(nc,i) = a;
else
vector_elt(nc,i) = relocate(a);
}
}
}
return nc;
Expand Down
66 changes: 33 additions & 33 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2886,39 +2886,39 @@ So far only the second case can actually occur.
'(null))
`(call (top typeassert) ,(cadr e) ,(caddr e)))))
((lambda)
(letrec ((args (lam:args e))
(locl (cdr (caddr e)))
(allv (nconc (map arg-name args) locl))
(fv (let* ((fv (diff (free-vars (lam:body e)) allv))
;; add variables referenced in declared types for free vars
(dv (apply nconc (map (lambda (v)
(let ((vi (var-info-for v env)))
(if vi (free-vars (vinfo:type vi)) '())))
fv))))
(append (diff dv fv) fv)))
(glo (declared-global-vars (lam:body e)))
; make var-info records for vars introduced by this lambda
(vi (nconc
(map (lambda (decl) (make-var-info (decl-var decl)))
args)
(map make-var-info locl)))
; captured vars: vars from the environment that occur
; in our set of free variables (fv).
(cv (filter (lambda (v) (and (memq (vinfo:name v) fv)
(not (memq
(vinfo:name v) glo))))
env))
(bod (analyze-vars
(lam:body e)
(append vi
; new environment: add our vars
(filter (lambda (v)
(and
(not (memq (vinfo:name v) allv))
(not (memq (vinfo:name v) glo))))
env))
cv)))
; mark all the vars we capture as captured
(let* ((args (lam:args e))
(locl (cdr (caddr e)))
(allv (nconc (map arg-name args) locl))
(fv (let* ((fv (diff (free-vars (lam:body e)) allv))
;; add variables referenced in declared types for free vars
(dv (apply nconc (map (lambda (v)
(let ((vi (var-info-for v env)))
(if vi (free-vars (vinfo:type vi)) '())))
fv))))
(append (diff dv fv) fv)))
(glo (declared-global-vars (lam:body e)))
;; make var-info records for vars introduced by this lambda
(vi (nconc
(map (lambda (decl) (make-var-info (decl-var decl)))
args)
(map make-var-info locl)))
;; captured vars: vars from the environment that occur
;; in our set of free variables (fv).
(cv (filter (lambda (v) (and (memq (vinfo:name v) fv)
(not (memq
(vinfo:name v) glo))))
env))
(bod (analyze-vars
(lam:body e)
(append vi
;; new environment: add our vars
(filter (lambda (v)
(and
(not (memq (vinfo:name v) allv))
(not (memq (vinfo:name v) glo))))
env))
cv)))
;; mark all the vars we capture as captured
(for-each (lambda (v) (vinfo:set-capt! v #t))
cv)
`(lambda ,args
Expand Down

0 comments on commit f522f8f

Please sign in to comment.