C-sparse

 view release on metacpan or  search on metacpan

src/sparse-0.4.4/perl/sparse.xs  view on Meta::CPAN

sparsepos
x2()
    PREINIT:
        char *av[3] = {"prog", "test.c", 0};
    CODE:
    OUTPUT:
	RETVAL


sparsectx
sparse(...)
    PREINIT:
	struct string_list *filelist = NULL;
	char *file; char **a = 0; int i; struct symbol *sym; struct symbol_list *symlist;
	struct sparse_ctx *_sctx;
    CODE:
        a = (char **)malloc(sizeof(void *) * (items+2));
	a[0] = "sparse";
        for (i = 0; i < items; i++) {
            a[i+1] = strdup(SvPV_nolen(ST(i)));
	}
        a[items+1] = 0;
	TRACE(printf("sparse_initialize("));
	for (i = 0; i < items+1; i++) {
	    TRACE(printf(" \"%s\"",a[i]));
        }
	TRACE(printf(")\n"));
	New (SPARSE_MALLOC_ID,  _sctx, 1, struct sparse_ctx);
	_sctx = sparse_ctx_init( _sctx);
        _sctx ->ppnoopt = 1;
	_sctx ->symlist = sparse_initialize(sctx_ items+1, a, &_sctx->filelist);
	FOR_EACH_PTR_NOTAG(_sctx->filelist, file) {
            concat_symbol_list(sctx_ sparse(sctx_ file), &_sctx ->symlist);
        } END_FOR_EACH_PTR_NOTAG(file);
	RETVAL = new_sparsectx((sparsectx_t)_sctx);
    OUTPUT:
	RETVAL	

MODULE = C::sparse   PACKAGE = C::sparse::ctx
PROTOTYPES: ENABLE

void
DESTROY (r)
        sparsectx r
    PREINIT:
        struct sparse_ctx *c;
    CODE:
        c = r->m;
        /*TRACE (printf ("%s DESTROY %p\n", sparsectx_class, r);fflush(stdout););*/
        assert_support (sparsectx_count--);
        TRACE_ACTIVE ();

MODULE = C::sparse   PACKAGE = C::sparse
PROTOTYPES: ENABLE

void
streams(p,...)
	sparsectx p
    PREINIT:
    struct token *t; int cnt = 0; SPARSE_CTX_GEN(0); int id = 0; struct stream *s;
    PPCODE:
        SPARSE_CTX_SET((struct sparse_ctx *)p->m);
	while(s = stream_get(sctx_ id)) { 
	    if (GIMME_V == G_ARRAY) {
	        EXTEND(SP, 1);
		PUSHs(bless_stream (s));
            }
            id++; cnt++;
	}
 	if (GIMME_V == G_SCALAR) {
 	    EXTEND(SP, 1);
            PUSHs(sv_2mortal(newSViv(cnt)));
	}

void
symbols(p,...)
	sparsectx p
    PREINIT:
    struct token *t; int i, ns, cnt = 0; SPARSE_CTX_GEN(0); int id = 0; struct ptr_list *ptrlist; void *ptr; struct symbol *sym; struct ident *ident;
    PPCODE:
        SPARSE_CTX_SET((struct sparse_ctx *)p->m);
        if( items > 1 ) {
            ns = SvIV(ST(1));
	    for (i = 0; i < IDENT_HASH_SIZE; i++) {
            	ident = _sctx->hash_table[i];
 		while (ident) {
	            for (sym = ident->symbols; sym; sym = sym->next_id) {
		        if (sym->namespace & ns) {
	                    EXTEND(SP, 1);
		            PUSHs(bless_sym (sym));
		        }
    		    }
		    ident = ident->next;
		}
	    }
        } else {
	    ptrlist = (struct ptr_list *)_sctx ->symlist;
            if (ptrlist) {
    	        FOR_EACH_PTR(ptrlist, ptr) {
	            sym = (struct symbol *) ptr;
	            if (GIMME_V == G_ARRAY) {
	                EXTEND(SP, 1);
		        PUSHs(bless_sym (sym));
                    }
                    cnt++;
	        } END_FOR_EACH_PTR(ptr);
            }
 	    if (GIMME_V == G_SCALAR) {
 	        EXTEND(SP, 1);
                PUSHs(sv_2mortal(newSViv(cnt)));
	    }
	}


MODULE = C::sparse   PACKAGE = C::sparse::tok
PROTOTYPES: ENABLE

void
list(p,...)
	sparsetok p
    PREINIT:
    struct token *t, *e = 0; int cnt = 0; SPARSE_CTX_GEN(0); sparsetok _e;
    PPCODE:
	t = p->m;
        SPARSE_CTX_SET(t->ctx);
	if (items >= 2 && sv_derived_from (ST(1), sparsetok_class)) {
	        _e = SvSPARSE_TOK(ST(1)); e = _e->m;
	}
        while(t != e && !eof_token(t)) {
	        cnt++;
 	    	if (GIMME_V == G_ARRAY) {
		   EXTEND(SP, 1);
		   PUSHs(bless_tok (t));
 		}
		t = t->next;
	}
 	if (GIMME_V == G_SCALAR) {
 	    EXTEND(SP, 1);
            PUSHs(sv_2mortal(newSViv(cnt)));
	}

void
fold(p,...)
	sparsetok p
    PREINIT:
    struct token *t, *e = 0; int cnt = 0; SPARSE_CTX_GEN(0); sparsetok _e;
    PPCODE:
	t = p->m;
        SPARSE_CTX_SET(t->ctx);
	if (items >= 2 && sv_derived_from (ST(1), sparsetok_class)) {
	        _e = SvSPARSE_TOK(ST(1)); e = _e->m;
	}
        while(t != e && !eof_token(t)) {
	        cnt++;
 		t = t->next;
	}

void
tok2str(p,...)
	sparsetok p
    PREINIT:
        struct token *t; int cnt = 0; SPARSE_CTX_GEN(0); 
        int prec = 1; char *separator = ""; char *pre = "", *v;
        const char *n; SV *r;
    PPCODE:
        t = p->m;
        SPARSE_CTX_SET(t->ctx);
	EXTEND(SP, 1);
        n = show_token(sctx_ t);
/*if (t->space && t->space->data) { pre = (char *)t->space->data;}*/
        v = malloc(strlen(n) + strlen(pre) + 1);
        v[0] = 0; strcat(v, pre); strcat(v, n);
        PUSHs(sv_2mortal(newSVpv(v, strlen(v))));
        free(v);

MODULE = C::sparse   PACKAGE = C::sparse::ident
PROTOTYPES: ENABLE

SV *
name(i)
	sparseident i
    PREINIT:
        int len = 0;
    CODE:
        RETVAL = newSVpv(i->m ? i->m->name : "<undef>",i->m ? i->m->len : 7);
    OUTPUT:
	RETVAL

MODULE = C::sparse   PACKAGE = C::sparse::sym
PROTOTYPES: ENABLE

SV *
name(s)
	sparsesym s
    PREINIT:
        int len = 0; struct ident *i; const char *n;
    CODE:
	if (!s->m || !(i = s->m->ident))
	   XSRETURN_UNDEF;
	n = show_ident(s->m->ctx, i);
        RETVAL = newSVpv(n,0);
    OUTPUT:
	RETVAL

MODULE = C::sparse   PACKAGE = C::sparse::sym
PROTOTYPES: ENABLE

SV *
id(s)
	sparsesym s
    PREINIT:
        int len = 0; const char *n; struct symbol *sym;
    CODE:
	if (!s->m || ! (sym = s->m))
	   XSRETURN_UNDEF;
	n = builtin_typename(sym->ctx,sym) ?: show_ident(sym->ctx,sym->ident);
        RETVAL = newSVpv(n,0);
    OUTPUT:
	RETVAL

SV *
typename(s)
	sparsesym s
    PREINIT:
        int len = 0; const char *n; struct symbol *sym;



( run in 1.168 second using v1.01-cache-2.11-cpan-71847e10f99 )