コード例 #1
0
ファイル: ast.c プロジェクト: Dominick-A/julia
value_t fl_invoke_julia_macro(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
    if (nargs < 1)
        argcount(fl_ctx, "invoke-julia-macro", nargs, 1);
    jl_lambda_info_t *mfunc = NULL;
    jl_value_t **margs;
    // Reserve one more slot for the result
    JL_GC_PUSHARGS(margs, nargs + 1);
    int i;
    for(i=1; i < nargs; i++) margs[i] = scm_to_julia(fl_ctx, args[i], 1);
    jl_value_t *result = NULL;

    JL_TRY {
        margs[0] = scm_to_julia(fl_ctx, args[0], 1);
        margs[0] = jl_toplevel_eval(margs[0]);
        mfunc = jl_method_lookup(jl_gf_mtable(margs[0]), margs, nargs, 1);
        if (mfunc == NULL) {
            JL_GC_POP();
            jl_method_error((jl_function_t*)margs[0], margs, nargs);
            // unreachable
        }
        margs[nargs] = result = jl_call_method_internal(mfunc, margs, nargs);
    }
    JL_CATCH {
        JL_GC_POP();
        value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
        *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = jl_exception_in_transit;
        return fl_list2(fl_ctx, jl_ast_ctx(fl_ctx)->error_sym, opaque);
    }
    // protect result from GC, otherwise it could be freed during future
    // macro expansions, since it will be referenced only from scheme and
    // not julia.
    // all calls to invoke-julia-macro happen under `jl_macroexpand`,
    // `jl_expand` or `jl_parse_eval_all` so the preserved array is rooted there.
    assert(result != NULL);
    jl_ast_preserve(fl_ctx, result);
    value_t scm = julia_to_scm(fl_ctx, result);
    fl_gc_handle(fl_ctx, &scm);
    value_t scmresult;
    jl_module_t *defmod = mfunc->def->module;
    if (defmod == NULL || defmod == jl_current_module) {
        scmresult = fl_cons(fl_ctx, scm, fl_ctx->F);
    }
    else {
        value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
        *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod;
        scmresult = fl_cons(fl_ctx, scm, opaque);
    }
    fl_free_gc_handles(fl_ctx, 1);

    JL_GC_POP();
    return scmresult;
}
コード例 #2
0
ファイル: ast.c プロジェクト: GlenHertz/julia
value_t fl_invoke_julia_macro(value_t *args, uint32_t nargs)
{
    if (nargs < 1)
        argcount("invoke-julia-macro", nargs, 1);
    jl_function_t *f = NULL;
    jl_value_t **margs = alloca(nargs * sizeof(jl_value_t*));
    int i;
    for(i=0; i < nargs; i++) margs[i] = NULL;
    JL_GC_PUSHARGS(margs, nargs);
    for(i=1; i < nargs; i++) margs[i] = scm_to_julia(args[i]);
    jl_value_t *result;

    JL_TRY {
        jl_register_toplevel_eh();

        margs[0] = scm_to_julia(args[0]);
        f = (jl_function_t*)jl_toplevel_eval(margs[0]);
        result = jl_apply(f, &margs[1], nargs-1);
    }
    JL_CATCH {
        JL_GC_POP();
        value_t opaque = cvalue(jvtype, sizeof(void*));
        *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = jl_exception_in_transit;
        return fl_list2(symbol("error"), opaque);
    }
    // protect result from GC, otherwise it could be freed during future
    // macro expansions, since it will be referenced only from scheme and
    // not julia.
    // all calls to invoke-julia-macro happen under a single call to jl_expand,
    // so the preserved value stack is popped there.
    jl_gc_preserve(result);
    value_t scm = julia_to_scm(result);
    fl_gc_handle(&scm);
    value_t scmresult;
    jl_module_t *defmod = f->linfo->module;
    if (defmod == jl_current_module) {
        scmresult = fl_cons(scm, FL_F);
    }
    else {
        value_t opaque = cvalue(jvtype, sizeof(void*));
        *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod;
        scmresult = fl_cons(scm, opaque);
    }
    fl_free_gc_handles(1);

    JL_GC_POP();
    return scmresult;
}
コード例 #3
0
ファイル: ast.c プロジェクト: RZEWa60/julia
static value_t julia_to_scm(jl_value_t *v)
{
    if (jl_is_symbol(v)) {
        return symbol(((jl_sym_t*)v)->name);
    }
    if (v == jl_true) {
        return FL_T;
    }
    if (v == jl_false) {
        return FL_F;
    }
    if (jl_is_expr(v)) {
        jl_expr_t *ex = (jl_expr_t*)v;
        value_t args = array_to_list(ex->args);
        fl_gc_handle(&args);
        value_t hd = julia_to_scm((jl_value_t*)ex->head);
        value_t scmv = fl_cons(hd, args);
        fl_free_gc_handles(1);
        return scmv;
    }
    if (jl_typeis(v, jl_linenumbernode_type)) {
        return fl_cons(julia_to_scm((jl_value_t*)line_sym),
                       fl_cons(julia_to_scm(jl_fieldref(v,0)),
                               FL_NIL));
    }
    if (jl_typeis(v, jl_labelnode_type)) {
        return fl_cons(julia_to_scm((jl_value_t*)label_sym),
                       fl_cons(julia_to_scm(jl_fieldref(v,0)),
                               FL_NIL));
    }
    if (jl_typeis(v, jl_gotonode_type)) {
        return fl_cons(julia_to_scm((jl_value_t*)goto_sym),
                       fl_cons(julia_to_scm(jl_fieldref(v,0)),
                               FL_NIL));
    }
    if (jl_typeis(v, jl_quotenode_type)) {
        return fl_cons(julia_to_scm((jl_value_t*)quote_sym),
                       fl_cons(julia_to_scm(jl_fieldref(v,0)),
                               FL_NIL));
    }
    if (jl_typeis(v, jl_topnode_type)) {
        return fl_cons(julia_to_scm((jl_value_t*)top_sym),
                       fl_cons(julia_to_scm(jl_fieldref(v,0)),
                               FL_NIL));
    }
    if (jl_is_long(v) && fits_fixnum(jl_unbox_long(v))) {
        return fixnum(jl_unbox_long(v));
    }
    if (jl_typeis(v,jl_array_any_type)) {
        return array_to_list((jl_array_t*)v);
    }
    value_t opaque = cvalue(jvtype, sizeof(void*));
    *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = v;
    return opaque;
}
コード例 #4
0
int main(int argc, char* argv[])
{
	srand(time(NULL));
	apvector<apstring> yourdeck(numofcards,"0");
	apvector<type> cvalue(numofcards,land);
	apvector<int> cast(numofcards,0);
	apvector<int> clife(numofcards,0);
	apmatrix<int> castcost(numofcards,2,0);
	apvector<int> castcostco(numofcards,0);
	apvector<fly> fornot(numofcards,notflying);
	apvector<int> num(numofcards,1);
	apvector<int> cnum(numofcards,1);
	apvector<int> yhand(11,-1);
	apvector<int> chand(11,-1);
	apvector<int> table(1,-1);
	filldeck(yourdeck,cvalue,cast,clife,castcost,castcostco,fornot,num);
	cnum=num;
	firstdrow(yhand,num,cvalue);
	firstdrow(chand,cnum,cvalue);
	for(int u=0;u<11;u++)
	{
		cout<<u+1<<","<<yourdeck[yhand[u]];
		if(cvalue[yhand[u]]==land)
			cout<<" land"<<endl;
		else
			cout<<" Creature"<<endl;

	}
	int ypoints=20,cpoints=20,z=0;
	char the;
	while(the!='n'&&ypoints>0&&cpoints>0)
	{
		putdown(yhand,table,yourdeck);
		the=drawtwo(yhand,num);
		if(the!='n')
		{
			cout<<"\nhand\n-------\n";
			for(z=0;z<yhand.length();z++)
			{
				cout<<z+1<<","<<yourdeck[yhand[z]]<<endl;
			}
			cout<<"\nTabel\n-------\n";
			for(int k=0;k<table.length();k++)
			{
				cout<<k+1<<","<<yourdeck[table[k]]<<endl;
			}
		}
		
	}

	return 0;
}
コード例 #5
0
ファイル: apache_reply.cpp プロジェクト: Klaim/falcon
void ApacheReply::commitHeader( const Falcon::String& name, const Falcon::String& value )
{
   Falcon::AutoCString cvalue( value );

   if ( name.compareIgnoreCase( "Content-Type" ) == 0 )
   {
      m_request->content_type = apr_pstrdup ( m_request->pool, cvalue.c_str() );
   }
   else
   {
      Falcon::AutoCString cname( name );
      apr_table_add( m_request->headers_out, cname.c_str(), cvalue.c_str() );
   }
}
コード例 #6
0
ファイル: ast.c プロジェクト: Dominick-A/julia
static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v)
{
    if (jl_is_symbol(v))
        return symbol(fl_ctx, jl_symbol_name((jl_sym_t*)v));
    if (v == jl_true)
        return jl_ast_ctx(fl_ctx)->true_sym;
    if (v == jl_false)
        return jl_ast_ctx(fl_ctx)->false_sym;
    if (v == jl_nothing)
        return fl_cons(fl_ctx, jl_ast_ctx(fl_ctx)->null_sym, fl_ctx->NIL);
    if (jl_is_expr(v)) {
        jl_expr_t *ex = (jl_expr_t*)v;
        value_t args = fl_ctx->NIL;
        fl_gc_handle(fl_ctx, &args);
        array_to_list(fl_ctx, ex->args, &args);
        value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)ex->head);
        if (ex->head == lambda_sym && jl_expr_nargs(ex)>0 && jl_is_array(jl_exprarg(ex,0))) {
            value_t llist = fl_ctx->NIL;
            fl_gc_handle(fl_ctx, &llist);
            array_to_list(fl_ctx, (jl_array_t*)jl_exprarg(ex,0), &llist);
            car_(args) = llist;
            fl_free_gc_handles(fl_ctx, 1);
        }
        value_t scmv = fl_cons(fl_ctx, hd, args);
        fl_free_gc_handles(fl_ctx, 1);
        return scmv;
    }
    // GC Note: jl_fieldref(v, 0) allocate for LabelNode, GotoNode
    //          but we don't need a GC root here because julia_to_list2
    //          shouldn't allocate in this case.
    if (jl_typeis(v, jl_labelnode_type))
        return julia_to_list2(fl_ctx, (jl_value_t*)label_sym, jl_fieldref(v,0));
    if (jl_typeis(v, jl_linenumbernode_type))
        return julia_to_list2(fl_ctx, (jl_value_t*)line_sym, jl_fieldref(v,0));
    if (jl_typeis(v, jl_gotonode_type))
        return julia_to_list2(fl_ctx, (jl_value_t*)goto_sym, jl_fieldref(v,0));
    if (jl_typeis(v, jl_quotenode_type))
        return julia_to_list2(fl_ctx, (jl_value_t*)inert_sym, jl_fieldref(v,0));
    if (jl_typeis(v, jl_newvarnode_type))
        return julia_to_list2(fl_ctx, (jl_value_t*)newvar_sym, jl_fieldref(v,0));
    if (jl_is_long(v) && fits_fixnum(jl_unbox_long(v)))
        return fixnum(jl_unbox_long(v));
    if (jl_is_ssavalue(v))
        jl_error("SSAValue objects should not occur in an AST");
    if (jl_is_slot(v))
        jl_error("Slot objects should not occur in an AST");
    value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
    *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = v;
    return opaque;
}
コード例 #7
0
ファイル: ast.c プロジェクト: RZEWa60/julia
DLLEXPORT void jl_init_frontend(void)
{
    fl_init(2*512*1024);
    value_t img = cvalue(iostreamtype, sizeof(ios_t));
    ios_t *pi = value2c(ios_t*, img);
    ios_static_buffer(pi, flisp_system_image, sizeof(flisp_system_image));
    
    if (fl_load_system_image(img)) {
        JL_PRINTF(JL_STDERR, "fatal error loading system image\n");
        jl_exit(1);
    }

    fl_applyn(0, symbol_value(symbol("__init_globals")));

    jvtype = define_opaque_type(symbol("julia_value"), sizeof(void*),
                                NULL, NULL);

    assign_global_builtins(julia_flisp_ast_ext);
}
コード例 #8
0
ファイル: ast.c プロジェクト: SatoHiroki/julia
value_t fl_current_julia_module(value_t *args, uint32_t nargs)
{
    value_t opaque = cvalue(jvtype, sizeof(void*));
    *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)jl_current_module;
    return opaque;
}
コード例 #9
0
ファイル: geodata.c プロジェクト: carriercomm/ngx_geo_mod
int geo_find2(geo_ctx_t* geo_ctx, uint32_t ip, geo_result_t* result)
{
	assert(geo_ctx->ptr != NULL);
	geo_head_t* geo_head = (geo_head_t*)geo_ctx->ptr;
	geo_item_t* items = (geo_item_t*)(geo_ctx->ptr + geo_head->geo_item_offset);
	/**
	printf("### geo_head: const_count:%u,"
		"const_table_offset:%u,"
		"geo_item_count:%u,"
		"geo_item_offset:%u\n"
		"filesize: %u\n", 
				geo_head->const_count, geo_head->const_table_offset,
				geo_head->geo_item_count, geo_head->geo_item_offset,
				geo_head->filesize); 
	**/
	if(geo_head->filesize != geo_ctx->size){
		printf("INFO: geo data file changed! filesize(%u) change to : %u\n",
					geo_ctx->size, geo_head->filesize);
		geo_ctx->size = geo_head->filesize;
	}
	
	int size = geo_head->geo_item_count;
	if(size < 1){
		return -1;
	}
	int High = size - 1;
	int Low = 0;
	int M;

#define IP_EQ(ip, node) (ip>=node.ip_begin && ip <=node.ip_end)
	geo_item_t* find_item = NULL;
	while(Low<=High)
	{
		M = (Low + High)/2;
		if(ip<items[M].ip_begin){
			High = M-1; 
		}else if(ip>items[M].ip_end){ 
			Low = M+1; 
		}else if(IP_EQ(ip, items[M]))
		{
			find_item = &items[M];
			break;
		}
	}
	
	if(find_item == NULL){
		return -1;
	}

	result->ip_begin = find_item->ip_begin;
	result->ip_end = find_item->ip_end;
	const_index_t* indexs = (const_index_t*)(geo_ctx->ptr + sizeof(geo_head_t));
	const char* buf = geo_ctx->ptr + geo_head->const_table_offset;
	result->province = cvalue(indexs, buf, find_item->province);
	result->province_len = clength(indexs, find_item->province)-1;
	result->city= cvalue(indexs, buf, find_item->city);
	result->city_len = clength(indexs, find_item->city)-1;
	result->isp = cvalue(indexs, buf, find_item->isp);
	result->isp_len = clength(indexs, find_item->isp)-1;
	
	return 0;
}
コード例 #10
0
ファイル: ast.c プロジェクト: Dominick-A/julia
value_t fl_current_julia_module(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
    value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
    *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)jl_current_module;
    return opaque;
}
コード例 #11
0
ファイル: test_config.cpp プロジェクト: prepare/gameswf
// This source code has been donated to the Public Domain.  Do
// whatever you want with it.

// Test for engine config stuff.


#include <stdio.h>
#include <string.h>

#include <engine/config.h>
#include <engine/utility.h>


cfloat test_cfloat( "test_cfloat", 55.f );
cvalue c10("return 10");
cvar test_cvar( "test_cvar", cvalue( "return 'string bobo'" ) );

// cvalue("poly(vec3(10,10,10), vec3(20,10,10), vec3(10,20,10))");

// cvar("test_float", cfloat(55.f));	// declares global Lua var "test_cfloat"


namespace actorprefs {
	cvar	jumpheight("actorprefs.jumpheight");
	cvar	runspeed("actorprefs.runspeed");
	cvar	color("actorprefs.color");
};


extern "C" int luaSDL_initialize(lua_State *L);