Esempio n. 1
0
variant * interpreter::get_container_variant(const func_binary & fb, int conpos)
{
	variant * v = 0;
	assert(conpos >= 0 && conpos < (int)fb.m_container_addr_list_num);
	const container_addr & ca = fb.m_container_addr_list[conpos];
	bool & err = m_isend;
	USE(err);
	variant * conv = 0;
	do {GET_VARIANT_BY_CMD(fb, m_bp, conv, ca.con);}while(0);
	const variant * keyv = 0;
	do {GET_VARIANT_BY_CMD(fb, m_bp, keyv, ca.key);}while(0);

	if (UNLIKE(m_isend))
	{	
		return 0;
	}

	if (UNLIKE(!(conv->type == variant::ARRAY || conv->type == variant::MAP)))
	{
		m_isend = true;
		seterror(m_fk, efk_run_inter_error, fkgetcurfile(m_fk), fkgetcurline(m_fk), fkgetcurfunc(m_fk), "interpreter get container variant fail, container type error, type %s", vartypetostring(conv->type));
		return 0;
	}
	
	if (conv->type == variant::MAP)
	{
		v = con_map_get(m_fk, conv->data.vm, keyv);
	}
	else if (conv->type == variant::ARRAY)
	{
		v = con_array_get(m_fk, conv->data.va, keyv);
	}

	return v;
}
Esempio n. 2
0
variant * assembler_get_container(fake * fk, variant * conv, variant * keyv)
{
	variant * v = 0;
	if (conv->type == variant::MAP)
	{
		v = con_map_get(fk, conv->data.vm, keyv);
	}
	else if (conv->type == variant::ARRAY)
	{
		v = con_array_get(fk, conv->data.va, keyv);
	}
	return v;
}
Esempio n. 3
0
bool compiler::compile_explicit_value_node_to_variant(explicit_value_node* ev, variant & v)
{
	fake * fk = m_fk;
	
	switch (ev->getvaluetype())
	{
	case explicit_value_node::EVT_TRUE:
		V_SET_REAL((&v), 1);
		break;
	case explicit_value_node::EVT_FALSE:
		V_SET_REAL((&v), 0);
		break;
	case explicit_value_node::EVT_NUM:
		V_SET_REAL((&v), (fkatol(&ev->str)));
		break;
	case explicit_value_node::EVT_STR:
		v = fk->sh.allocsysstr(ev->str.c_str());
		break;
	case explicit_value_node::EVT_FLOAT:
		V_SET_REAL((&v), (fkatof(&ev->str)));
		break;
	case explicit_value_node::EVT_UUID:
		V_SET_UUID((&v), (fkatol(&ev->str)));
		break;
	case explicit_value_node::EVT_MAP:
		{
			const_map_list_value_node * cml = dynamic_cast<const_map_list_value_node *>(ev->v);
			assert(cml);
			variant_map * vm = fk->con.newconstmap();
			for (int i = 0; i < (int)cml->lists.size(); i++)
			{
				const_map_value_node * cmv = dynamic_cast<const_map_value_node *>(cml->lists[i]);
				assert(cmv);
				explicit_value_node * kn = dynamic_cast<explicit_value_node *>(cmv->k);
				explicit_value_node * vn = dynamic_cast<explicit_value_node *>(cmv->v);
				assert(kn);
				assert(vn);
				variant kv;
				variant vv;
				if (!compile_explicit_value_node_to_variant(kn, kv))
				{
					return false;
				}
				if (!compile_explicit_value_node_to_variant(vn, vv))
				{
					return false;
				}
				
				variant * des = con_map_get(fk, vm, &kv);
				*des = vv;
			}
			V_SET_MAP(&v, vm);
		}
		break;
	case explicit_value_node::EVT_ARRAY:
		{
			const_array_list_value_node * cal = dynamic_cast<const_array_list_value_node *>(ev->v);
			assert(cal);
			variant_array * va = fk->con.newconstarray();
			for (int i = 0; i < (int)cal->lists.size(); i++)
			{
				explicit_value_node * vn = dynamic_cast<explicit_value_node *>(cal->lists[i]);
				assert(vn);
				variant kv;
				V_SET_REAL((&kv), i);
				variant vv;
				if (!compile_explicit_value_node_to_variant(vn, vv))
				{
					return false;
				}
				
				variant * des = con_array_get(fk, va, &kv);
				*des = vv;
			}
			V_SET_ARRAY(&v, va);
		}
		break;
	default:
		FKERR("[compiler] compile_explicit_value type error %d %s", ev->getvaluetype(), ev->gettypename());
		compile_seterror(ev, m_fk, efk_compile_explicit_type_error, "compile explicit value type error %d", ev->getvaluetype());
		return false;
	}

	return true;
}