The R Project SVN R

Rev

Rev 33297 | Rev 36820 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33297 Rev 33531
Line 305... Line 305...
305
    else
305
    else
306
	n = -n;
306
	n = -n;
307
 
307
 
308
    if(n < 0)
308
    if(n < 0)
309
	errorcall(R_GlobalContext->call,
309
	errorcall(R_GlobalContext->call,
310
		  _("not that many enclosing environments"));
310
		  _("not that many frames on the stack"));
311
 
311
 
312
    while (cptr->nextcontext != NULL) {
312
    while (cptr->nextcontext != NULL) {
313
	if (cptr->callflag & CTXT_FUNCTION ) {
313
	if (cptr->callflag & CTXT_FUNCTION ) {
314
	    if (n == 0) {  /* we need to detach the enclosing env */
314
	    if (n == 0) {  /* we need to detach the enclosing env */
315
		return cptr->cloenv;
315
		return cptr->cloenv;
Line 320... Line 320...
320
	cptr = cptr->nextcontext;
320
	cptr = cptr->nextcontext;
321
    }
321
    }
322
    if(n == 0 && cptr->nextcontext == NULL)
322
    if(n == 0 && cptr->nextcontext == NULL)
323
	return R_GlobalEnv;
323
	return R_GlobalEnv;
324
    else
324
    else
-
 
325
	errorcall(R_GlobalContext->call,
325
	error(_("sys.frame: not that many enclosing functions"));
326
		  _("not that many frames on the stack"));
326
    return R_NilValue;	   /* just for -Wall */
327
    return R_NilValue;	   /* just for -Wall */
327
}
328
}
328
 
329
 
329
 
330
 
330
/* We need to find the environment that can be returned by sys.frame */
331
/* We need to find the environment that can be returned by sys.frame */
Line 337... Line 338...
337
{
338
{
338
    int j;
339
    int j;
339
    SEXP s;
340
    SEXP s;
340
    if(n <= 0)
341
    if(n <= 0)
341
	errorcall(R_ToplevelContext->call,
342
	errorcall(R_ToplevelContext->call,
342
		  _("only positive arguments are allowed"));
343
		  _("only positive values of 'n' are allowed"));
343
    while (cptr->nextcontext != NULL && n > 1) {
344
    while (cptr->nextcontext != NULL && n > 1) {
344
	if (cptr->callflag & CTXT_FUNCTION )
345
	if (cptr->callflag & CTXT_FUNCTION )
345
	    n--;
346
	    n--;
346
	cptr = cptr->nextcontext;
347
	cptr = cptr->nextcontext;
347
    }
348
    }
Line 380... Line 381...
380
SEXP R_syscall(int n, RCNTXT *cptr)
381
SEXP R_syscall(int n, RCNTXT *cptr)
381
{
382
{
382
    /* negative n counts back from the current frame */
383
    /* negative n counts back from the current frame */
383
    /* positive n counts up from the globalEnv */
384
    /* positive n counts up from the globalEnv */
384
    if (n > 0)
385
    if (n > 0)
385
	n = framedepth(cptr)-n;
386
	n = framedepth(cptr) - n;
386
    else
387
    else
387
	n = - n;
388
	n = - n;
388
    if(n < 0 )
389
    if(n < 0)
389
	errorcall(R_GlobalContext->call, _("invalid frame number"));
390
	errorcall(R_GlobalContext->call, 
-
 
391
		  _("not that many frames on the stack"));
390
    while (cptr->nextcontext != NULL) {
392
    while (cptr->nextcontext != NULL) {
391
	if (cptr->callflag & CTXT_FUNCTION ) {
393
	if (cptr->callflag & CTXT_FUNCTION ) {
392
	    if (n == 0)
394
	    if (n == 0)
393
		return (duplicate(cptr->call));
395
		return (duplicate(cptr->call));
394
	    else
396
	    else
Line 396... Line 398...
396
	}
398
	}
397
	cptr = cptr->nextcontext;
399
	cptr = cptr->nextcontext;
398
    }
400
    }
399
    if (n == 0 && cptr->nextcontext == NULL)
401
    if (n == 0 && cptr->nextcontext == NULL)
400
	return (duplicate(cptr->call));
402
	return (duplicate(cptr->call));
401
    errorcall(R_GlobalContext->call, _("not that many enclosing functions"));
403
    errorcall(R_GlobalContext->call, _("not that many frames on the stack"));
402
    return R_NilValue;	/* just for -Wall */
404
    return R_NilValue;	/* just for -Wall */
403
}
405
}
404
 
406
 
405
SEXP R_sysfunction(int n, RCNTXT *cptr)
407
SEXP R_sysfunction(int n, RCNTXT *cptr)
406
{
408
{
407
    if (n > 0)
409
    if (n > 0)
408
	n = framedepth(cptr) - n;
410
	n = framedepth(cptr) - n;
409
    else
411
    else
410
	n = - n;
412
	n = - n;
411
    if (n < 0 )
413
    if (n < 0)
412
	errorcall(R_GlobalContext->call, _("invalid frame number"));
414
	errorcall(R_GlobalContext->call, 
-
 
415
		  _("not that many frames on the stack"));
413
    while (cptr->nextcontext != NULL) {
416
    while (cptr->nextcontext != NULL) {
414
	if (cptr->callflag & CTXT_FUNCTION ) {
417
	if (cptr->callflag & CTXT_FUNCTION ) {
415
	    if (n == 0)
418
	    if (n == 0)
416
		return duplicate(cptr->callfun);  /***** do we need to DUP? */
419
		return duplicate(cptr->callfun);  /***** do we need to DUP? */
417
	    else
420
	    else
Line 419... Line 422...
419
	}
422
	}
420
	cptr = cptr->nextcontext;
423
	cptr = cptr->nextcontext;
421
    }
424
    }
422
    if (n == 0 && cptr->nextcontext == NULL)
425
    if (n == 0 && cptr->nextcontext == NULL)
423
	return duplicate(cptr->callfun);  /***** do we need to DUP? */
426
	return duplicate(cptr->callfun);  /***** do we need to DUP? */
424
    errorcall(R_GlobalContext->call, _("not that many enclosing functions"));
427
    errorcall(R_GlobalContext->call, _("not that many frames on the stack"));
425
    return R_NilValue;	/* just for -Wall */
428
    return R_NilValue;	/* just for -Wall */
426
}
429
}
427
 
430
 
428
/* some real insanity to keep Duncan sane */
431
/* some real insanity to keep Duncan sane */
429
 
432
 
Line 477... Line 480...
477
	n = asInteger(t);
480
	n = asInteger(t);
478
    }
481
    }
479
    else
482
    else
480
	n = - 1;
483
	n = - 1;
481
 
484
 
482
    if(n == NA_INTEGER)
-
 
483
	errorcall(call, _("invalid number of environment levels"));
-
 
484
    switch (PRIMVAL(op)) {
485
    switch (PRIMVAL(op)) {
485
    case 1: /* parent */
486
    case 1: /* parent */
-
 
487
	if(n == NA_INTEGER)
-
 
488
	    errorcall(call, _("invalid value for 'n'"));
486
	nframe = framedepth(cptr);
489
	nframe = framedepth(cptr);
487
	rval = allocVector(INTSXP,1);
490
	rval = allocVector(INTSXP,1);
488
	i = nframe;
491
	i = nframe;
489
	/* This is a pretty awful kludge, but the alternative would be
492
	/* This is a pretty awful kludge, but the alternative would be
490
	   a major redesign of everything... -pd */
493
	   a major redesign of everything... -pd */
491
	while (n-- > 0)
494
	while (n-- > 0)
492
	    i = R_sysparent(nframe - i + 1, cptr);
495
	    i = R_sysparent(nframe - i + 1, cptr);
493
	INTEGER(rval)[0] = i;
496
	INTEGER(rval)[0] = i;
494
	return rval;
497
	return rval;
495
    case 2: /* call */
498
    case 2: /* call */
-
 
499
	if(n == NA_INTEGER)
-
 
500
	    errorcall(call, _("invalid value for 'which'"));
496
	return R_syscall(n, cptr);
501
	return R_syscall(n, cptr);
497
    case 3: /* frame */
502
    case 3: /* frame */
-
 
503
	if(n == NA_INTEGER)
-
 
504
	    errorcall(call, _("invalid value for 'which'"));
498
	return R_sysframe(n, cptr);
505
	return R_sysframe(n, cptr);
499
    case 4: /* sys.nframe */
506
    case 4: /* sys.nframe */
500
	rval=allocVector(INTSXP,1);
507
	rval = allocVector(INTSXP, 1);
501
	INTEGER(rval)[0]=framedepth(cptr);
508
	INTEGER(rval)[0] = framedepth(cptr);
502
	return rval;
509
	return rval;
503
    case 5: /* sys.calls */
510
    case 5: /* sys.calls */
504
	nframe=framedepth(cptr);
511
	nframe = framedepth(cptr);
505
	PROTECT(rval=allocList(nframe));
512
	PROTECT(rval = allocList(nframe));
506
	t=rval;
513
	t=rval;
507
	for(i=1 ; i<=nframe; i++, t=CDR(t))
514
	for(i = 1; i <= nframe; i++, t = CDR(t))
508
	    SETCAR(t, R_syscall(i,cptr));
515
	    SETCAR(t, R_syscall(i, cptr));
509
	UNPROTECT(1);
516
	UNPROTECT(1);
510
	return rval;
517
	return rval;
511
    case 6: /* sys.frames */
518
    case 6: /* sys.frames */
512
	nframe=framedepth(cptr);
519
	nframe = framedepth(cptr);
513
	PROTECT(rval=allocList(nframe));
520
	PROTECT(rval = allocList(nframe));
514
	t=rval;
521
	t = rval;
515
	for(i=1 ; i<=nframe ; i++, t=CDR(t))
522
	for(i = 1; i <= nframe; i++, t = CDR(t))
516
	    SETCAR(t, R_sysframe(i,cptr));
523
	    SETCAR(t, R_sysframe(i, cptr));
517
	UNPROTECT(1);
524
	UNPROTECT(1);
518
	return rval;
525
	return rval;
519
    case 7: /* sys.on.exit */
526
    case 7: /* sys.on.exit */
520
	if( R_GlobalContext->nextcontext != NULL )
527
	if( R_GlobalContext->nextcontext != NULL)
521
	    return R_GlobalContext->nextcontext->conexit;
528
	    return R_GlobalContext->nextcontext->conexit;
522
	else
529
	else
523
	    return R_NilValue;
530
	    return R_NilValue;
524
    case 8: /* sys.parents */
531
    case 8: /* sys.parents */
525
	nframe=framedepth(cptr);
532
	nframe = framedepth(cptr);
526
	rval=allocVector(INTSXP,nframe);
533
	rval = allocVector(INTSXP, nframe);
527
	for(i=0; i<nframe ; i++ )
534
	for(i = 0; i < nframe; i++)
528
	    INTEGER(rval)[i]= R_sysparent(nframe-i,cptr);
535
	    INTEGER(rval)[i] = R_sysparent(nframe - i, cptr);
529
	return rval;
536
	return rval;
530
    case 9: /* sys.function */
537
    case 9: /* sys.function */
-
 
538
	if(n == NA_INTEGER)
-
 
539
	    errorcall(call, _("invalid value for 'which'"));
531
	return(R_sysfunction(n, cptr));
540
	return(R_sysfunction(n, cptr));
532
    default:
541
    default:
533
	error(_("internal error in do_sys"));
542
	error(_("internal error in 'do_sys'"));
534
	return R_NilValue;/* just for -Wall */
543
	return R_NilValue;/* just for -Wall */
535
    }
544
    }
536
}
545
}
537
 
546
 
538
SEXP do_parentframe(SEXP call, SEXP op, SEXP args, SEXP rho)
547
SEXP do_parentframe(SEXP call, SEXP op, SEXP args, SEXP rho)
Line 544... Line 553...
544
 
553
 
545
    t = eval(CAR(args), rho);
554
    t = eval(CAR(args), rho);
546
    n = asInteger(t);
555
    n = asInteger(t);
547
 
556
 
548
    if(n == NA_INTEGER || n < 1 )
557
    if(n == NA_INTEGER || n < 1 )
549
	errorcall(call, _("invalid number of environment levels"));
558
	errorcall(call, _("invalid value for 'n'"));
550
 
559
 
551
    cptr = R_GlobalContext;
560
    cptr = R_GlobalContext;
552
    t = cptr->sysparent;
561
    t = cptr->sysparent;
553
    while (cptr->nextcontext != NULL){
562
    while (cptr->nextcontext != NULL){
554
	if (cptr->callflag & CTXT_FUNCTION ) {
563
	if (cptr->callflag & CTXT_FUNCTION ) {