Beispiel #1
0
/**
 * Write U from userdef.
 * This function defines which settings a template will override for the user preferences.
 */
void BKE_blender_userdef_app_template_data_swap(UserDef *userdef_a, UserDef *userdef_b)
{
	/* TODO:
	 * - keymaps
	 * - various minor settings (add as needed).
	 */

#define DATA_SWAP(id) \
	SWAP(userdef_a->id, userdef_b->id);

#define LIST_SWAP(id) { \
	SWAP(ListBase, userdef_a->id, userdef_b->id); \
} ((void)0)

	/* for some types we need custom free functions */
	LIST_SWAP(addons);
	LIST_SWAP(user_keymaps);

	LIST_SWAP(uistyles);
	LIST_SWAP(uifonts);
	LIST_SWAP(themes);
	LIST_SWAP(addons);
	LIST_SWAP(user_keymaps);

	DATA_SWAP(light);

	DATA_SWAP(font_path_ui);
	DATA_SWAP(font_path_ui_mono);

#undef SWAP_TYPELESS
#undef LIST_SWAP
#undef DATA_SWAP
}
Beispiel #2
0
/**
 * Write U from userdef.
 * This function defines which settings a template will override for the user preferences.
 */
void BKE_blender_userdef_app_template_data_swap(UserDef *userdef_a, UserDef *userdef_b)
{
  /* TODO:
   * - various minor settings (add as needed).
   */

#define DATA_SWAP(id) \
  { \
    UserDef userdef_tmp; \
    memcpy(&(userdef_tmp.id), &(userdef_a->id), sizeof(userdef_tmp.id)); \
    memcpy(&(userdef_a->id), &(userdef_b->id), sizeof(userdef_tmp.id)); \
    memcpy(&(userdef_b->id), &(userdef_tmp.id), sizeof(userdef_tmp.id)); \
  } \
  ((void)0)

#define LIST_SWAP(id) \
  { \
    SWAP(ListBase, userdef_a->id, userdef_b->id); \
  } \
  ((void)0)

#define FLAG_SWAP(id, ty, flags) \
  { \
    CHECK_TYPE(&(userdef_a->id), ty *); \
    const ty f = flags; \
    const ty a = userdef_a->id; \
    const ty b = userdef_b->id; \
    userdef_a->id = (userdef_a->id & ~f) | (b & f); \
    userdef_b->id = (userdef_b->id & ~f) | (a & f); \
  } \
  ((void)0)

  LIST_SWAP(uistyles);
  LIST_SWAP(uifonts);
  LIST_SWAP(themes);
  LIST_SWAP(addons);
  LIST_SWAP(user_keymaps);

  DATA_SWAP(font_path_ui);
  DATA_SWAP(font_path_ui_mono);
  DATA_SWAP(keyconfigstr);

  DATA_SWAP(gizmo_flag);
  DATA_SWAP(app_flag);

  /* We could add others. */
  FLAG_SWAP(uiflag, int, USER_SAVE_PROMPT);

#undef SWAP_TYPELESS
#undef DATA_SWAP
#undef LIST_SWAP
#undef FLAG_SWAP
}
Beispiel #3
0
int  EgThread_Run(EgThread* e)
{
	int exit_code=0;
	eg_thread_cur=e;
	if(e->t_fstack==NULL)
	{
		return EG_THREAD_EXIT_NORMAL;
	}

	EgThread* eg=e;

	register GrObject** dstack=eg->t_dstack;


	/* used for temp compute */
	register u_int8_t cur_code=0;	/* instruction register*/
	register u_int32_t rd=0; 		/* data register */
	u_int32_t rs=0; 				/* status register */
	register GrObject* acc=NULL;		
	register GrObject* r0=NULL;
	register GrObject* r1=NULL;
	register GrObject* r2=NULL;




	/* frame relative */
	register size_t pc=0;
	register size_t sp=0;
	register u_int8_t* codes=0;
	register GrScope* scope=0;
	GrModule* cur_module=0;
	GrObject** consts_pool=0;
	GrObject** symbols_pool=0;
	GrObject** opcodes_pool=0;
	GrObject** attrs_pool=0;
	EgSframe* cur_frame=0;


	/* make sure use cur frame */

	cur_frame=eg->t_fstack;
	EG_THREAD_USE_FRAME(cur_frame);
	EG_THREAD_CLR_FLAGS(eg,EG_THREAD_FLAGS_FRAME_CHANGE);

next_instruct:

	BUG_ON(sp>=(EG_THREAD_DEFALUT_DATA_SIZE-100),"sp=%d",sp);

	if(GrExcept_Happened())
	{
		/* FIXME Now i hava write code to handle except
		 * When Exception happend just clear all stack frame 
		 */
		eg->t_fstack=NULL;
		exit_code=EG_THREAD_EXIT_EXCEPTION;
		goto over;
	}
	if(eg->t_flags)
	{
		if(EG_THREAD_HAS_FLAGS(eg,EG_THREAD_FLAGS_FRAME_CHANGE))
		{
			cur_frame=eg->t_fstack;
			if(cur_frame==NULL)
			{
				assert(sp==0);
				exit_code=EG_THREAD_EXIT_NORMAL;
				goto over;
			}
			EG_THREAD_USE_FRAME(cur_frame);
			EG_THREAD_CLR_FLAGS(eg,EG_THREAD_FLAGS_FRAME_CHANGE);
		}
		if(EG_THREAD_HAS_FLAGS(eg,EG_THREAD_FLAGS_GC_WORK))
		{
			EG_THREAD_CLR_FLAGS(eg,EG_THREAD_FLAGS_GC_WORK);
			EG_THREAD_SAVE_FRAME(cur_frame);
			eg->t_sp=sp;
			GrGc_CleanGarbage();
			EG_THREAD_SET_FLAGS(eg,EG_THREAD_FLAGS_FRAME_CHANGE);
			cur_module=NULL;

			goto next_instruct;
		}
	}
	/*
	   fprintf(stderr,"sp=%d,pc=%d,module=%s,code_name=%s\n",
	   sp,pc,cur_module->m_name->s_value,
	   cur_frame->f_codes->o_name->s_value);
	   */

	//printf("pc=%d\n",pc);
	cur_code=codes[pc++];
	if(cur_code>=OP_NEED_PARAM2)
	{
		rd=((u_int32_t)(codes[pc++])<<8);
		rd|=(codes[pc++]);
	}

	switch(cur_code)
	{
		case OP_CALL:
			UNPACK_TWO_OP;
			eg->t_sp=sp;
			eg->t_pc=pc;
			acc=GrObject_Call(r0,Gr_Object_Nil,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_CALL_WITH_HOST:
			UNPACK_THREE_OP;
			eg->t_sp=sp;
			eg->t_pc=pc;
			acc=GrObject_Call(r1,r0,r2);
			ACC_PUSH;
			goto next_instruct;
		case OP_SET_ITEM:
			UNPACK_THREE_OP;
			GrObject_SetItem(r1,r2,r0);
			goto next_instruct;
		case OP_GET_ITEM:
			UNPACK_TWO_OP;
			acc=GrObject_GetItem(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_POSITIVE:
			UNPACK_ONE_OP;
			acc=GrObject_Positive(r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_NEGATIVE:
			UNPACK_ONE_OP;
			acc=GrObject_Negative(r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_NEGATED:
			UNPACK_ONE_OP;
			acc=GrObject_Negated(r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_MUL:
			UNPACK_TWO_OP;
			acc=GrObject_Mul(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_DIV:
			UNPACK_TWO_OP;
			acc=GrObject_Div(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_MOD:
			UNPACK_TWO_OP;
			acc=GrObject_Mod(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_PLUS:
			UNPACK_TWO_OP;
			acc=GrObject_Plus(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_MINUS:
			UNPACK_TWO_OP;
			acc=GrObject_Minus(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_LSHIFT:
			UNPACK_TWO_OP;
			acc=GrObject_LShift(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_RSHIFT:
			UNPACK_TWO_OP;
			acc=GrObject_RShift(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_AND:
			UNPACK_TWO_OP;
			acc=GrObject_And(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_XOR:
			UNPACK_TWO_OP;
			acc=GrObject_Xor(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_OR:
			UNPACK_TWO_OP;
			acc=GrObject_Or(r0,r1);
			ACC_PUSH;
			goto next_instruct;
		case OP_LT:
			UNPACK_TWO_OP;
			acc=GrObject_Lt(r0,r1)?Gr_True:Gr_False;
			ACC_PUSH;
			goto next_instruct;
		case OP_LE:
			UNPACK_TWO_OP;
			acc=GrObject_Le(r0,r1)?Gr_True:Gr_False;
			ACC_PUSH;
			goto next_instruct;
		case OP_EQ:
			UNPACK_TWO_OP;
			acc=GrObject_Eq(r0,r1)?Gr_True:Gr_False;
			ACC_PUSH;
			goto next_instruct;
		case OP_NE:
			UNPACK_TWO_OP;
			acc=GrObject_Ne(r0,r1)?Gr_True:Gr_False;
			ACC_PUSH;
			goto next_instruct;
		case OP_GE:
			UNPACK_TWO_OP;
			acc=GrObject_Ge(r0,r1)?Gr_True:Gr_False;
			ACC_PUSH;
			goto next_instruct;
		case OP_GT:
			UNPACK_TWO_OP;
			acc=GrObject_Gt(r0,r1)?Gr_True:Gr_False;
			ACC_PUSH;
			goto next_instruct;
		case OP_BOOL_NOTAKE:
			REF_ONE_OP;
			rs=GrObject_Bool(r0);
			goto next_instruct;
		case OP_BOOL:
			UNPACK_ONE_OP;
			rs=GrObject_Bool(r0);
			goto next_instruct;
		case OP_LOGIC_NOT:
			UNPACK_ONE_OP;
			rs=GrObject_Bool(r0);
			acc=rs?Gr_False:Gr_True;
			ACC_PUSH;
			goto next_instruct;
		case OP_PRINT:
			UNPACK_ONE_OP;
			GrObject_Print(r0,stderr,GR_PRINT_SPACE);
			goto next_instruct;
		case OP_PRINT_LN:
			fprintf(stderr,"\n");
			goto next_instruct;
		case OP_ITER:
			UNPACK_ONE_OP;
			acc=GrObject_Iter(r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_ITER_NEXT:
			REF_ONE_OP;
			acc=GrObject_IterNext(r0);
			if(GrExcept_Happened())
			{
				if(GrExcept_Type()==Gr_Except_Iter_Stop)
				{
					GrExcept_Clr();
					goto next_instruct;
				}
			}
			else
			{
				pc+=3;
			}
			ACC_PUSH;
			goto next_instruct;

		case OP_ARRAY_BEGIN:
			acc=(GrObject*)GrArray_GcNew();
			ACC_PUSH;
			goto next_instruct;
		case OP_ARRAY_PUSH:
			UNPACK_TWO_OP;
			GrArray_Push((GrArray*)r0,r1);
			R0_PUSH;
			goto next_instruct;
		case OP_ARRAY_END:
			goto next_instruct;

		case OP_FUNC_BEGIN:
			acc=(GrObject*)GrFunc_GcNew();
			if(acc==NULL) goto next_instruct;
			GrFunc_SetScope((GrFunc*)acc,scope);
			ACC_PUSH;
			goto next_instruct;
		case OP_FUNC_DEFALUT_ARGS:
			REF_TWO_OP;
			GrFunc_SetDefaultArgs((GrFunc*)r0,(GrArray*)r1);
			sp--;
			goto next_instruct;
		case OP_CLASS_INHERIT:
			REF_TWO_OP;
			GrClass_SetInherit((GrClass*)r0,r1);
			sp--;
			goto next_instruct;

			/* Data op */
		case OP_LOAD_NIL:
			acc=Gr_Object_Nil;
			ACC_PUSH;
			goto next_instruct;
		case OP_DISCARD:
			sp--;
			goto next_instruct;
		case OP_DUP_DATA1:
			REF_ONE_OP;
			R0_PUSH;
			goto next_instruct;
		case OP_DUP_DATA2:
			REF_TWO_OP;
			R0_PUSH;
			R1_PUSH;
			goto next_instruct;
		case OP_DUP_DATA3:
			REF_THREE_OP;
			R0_PUSH;
			R1_PUSH;
			R2_PUSH;
			goto next_instruct;
		case OP_DATA_SWAP0_1:
			DATA_SWAP(0,1);
			goto next_instruct;
		case OP_DATA_SWAP0_2:
			DATA_SWAP(0,2);
			goto next_instruct;
		case OP_DATA_SWAP0_3:
			DATA_SWAP(0,3);
			goto next_instruct;
		case OP_SET_HOST:
			assert(0);
			goto next_instruct;

			/* frame op */
		case OP_EXIT:
			assert(0);
			goto over;
		case OP_RETURN:
			UNPACK_ONE_OP;
			if(cur_frame->f_relval==NULL)
			{
				cur_frame->f_relval=r0;
			}
			EgThread_SFrameReturn(eg);
			goto next_instruct;
		case OP_RETURN_NIL:
			if(cur_frame->f_relval==NULL)
			{
				cur_frame->f_relval=Gr_Object_Nil;
			}
			EgThread_SFrameReturn(eg);
			goto next_instruct;

			/* OP_NEED_PARAM2 OPCODE */
		case OP_GET_ATTR:
			UNPACK_ONE_OP;
			r1=symbols_pool[rd];
			acc=GrObject_GetAttr(r0,r1,cur_frame->f_host==r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_SET_ATTR:
			UNPACK_TWO_OP;
			r2=symbols_pool[rd];
			GrObject_SetAttr(r1,r2,r0,cur_frame->f_host==r1);
			goto next_instruct;
		case OP_CLASS_BEGIN:
			acc=(GrObject*)GrClass_GcNew();
			GrClass_SetName((GrClass*)acc,(GrString*)(symbols_pool[rd]));
			ACC_PUSH;
			goto next_instruct;
		case OP_CLASS_TEMPLATE:
			REF_TWO_OP;
			r2=attrs_pool[rd];
			GrClass_TemplateAdd((GrClass*)r0,r2,r1);
			sp--;
			goto next_instruct;

		case OP_CLASS_ATTR:
			REF_TWO_OP;
			r2=attrs_pool[rd];
			GrClass_AddAttr((GrClass*)r0,r2,r1);
			sp--;
			goto next_instruct;

		case OP_FUNC_OPCODE:
			REF_ONE_OP;
			GrFunc_SetOpcode((GrFunc*)r0,(GrOpcode*)(opcodes_pool[rd]));
			goto next_instruct;

		case  OP_LOAD_CONST:
			dstack[sp++]=consts_pool[rd];
			goto next_instruct;
		case OP_LOAD_SYMBOL:
			r0=symbols_pool[rd];
			acc=GrScope_Lookup(scope,r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_LOAD_U_SYMBOL:
			r0=symbols_pool[rd];
			acc=GrScope_LookupUpper(scope,r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_STORE_SYMBOL:
			UNPACK_ONE_OP;
			r1=symbols_pool[rd];
			GrScope_Map(scope,r1,r0);
			goto next_instruct;
		case OP_STORE_U_SYMBOL:
			UNPACK_ONE_OP;
			r1=symbols_pool[rd];
			GrScope_MapUpper(scope,r1,r0);
			goto next_instruct;
		case OP_IMPORT:
			eg->t_sp=sp;
			eg->t_pc=pc;
			r0=symbols_pool[rd];
			acc=(GrObject*)EgCodger_ImportModule((GrString*)r0);
			ACC_PUSH;
			goto next_instruct;
		case OP_EXPORT:
			UNPACK_ONE_OP;
			r1=symbols_pool[rd];
			GrModule_AddAttr(cur_module,r1,r0);
			goto next_instruct;





			/* flow control op */
		case OP_BREAK:
			assert(0);
		case OP_CONTINUE:
			assert(0);

		case OP_JUMPR_FORWARD:
			pc+=rd-3;
			goto next_instruct;
		case OP_JUMPR_BACK:
			pc-=rd+3;
			goto next_instruct;
		case OP_JUMPR_FALSE_FORWARD:
			if(!rs) pc+=rd-3;
			goto next_instruct;
		case OP_JUMP_FALSE_BACK:
			if(!rs) pc-=rd+3;
			goto next_instruct;
		case OP_JUMPR_TRUE_FORWARD:
			if(rs) pc+=rd-3;
			goto next_instruct;
		case OP_JUMP_TRUE_BACK:
			if(rs) pc-=rd+3;
			goto next_instruct;

		case OP_TEMP_IF3:
			assert(0);




	}

	if(cur_code<OP_CODE_NUM)
	{
		printf("Not Implement %s\n",GrOpcode_Name(cur_code));
	}
	else
	{
		BUG("Unkown instruction<%d>",cur_code);
	}

over:

//	fprintf(stderr,"EgThread With Code(%d) sp=%d\n",exit_code,sp);
	eg->t_sp=0;
	eg->t_pc=0;
	return exit_code;
}