本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.EmitConvertToPhpNumber方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitConvertToPhpNumber方法的具体用法?C# CodeGenerator.EmitConvertToPhpNumber怎么用?C# CodeGenerator.EmitConvertToPhpNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitConvertToPhpNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitMinus
TypeSymbol EmitMinus(CodeGenerator cg)
{
// Template: 0L - Operand
var il = cg.Builder;
var t = cg.Emit(this.Operand);
switch (t.SpecialType)
{
case SpecialType.System_Double:
// -r8
il.EmitOpCode(ILOpCode.Neg);
return t;
case SpecialType.System_Int32:
// -(i8)i4
il.EmitOpCode(ILOpCode.Conv_i8); // i4 -> i8
il.EmitOpCode(ILOpCode.Neg); // result will fit into long for sure
return cg.CoreTypes.Long;
case SpecialType.System_Int64:
// PhpNumber.Minus(i8) : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Negation_long)
.Expect(cg.CoreTypes.PhpNumber);
default:
if (t != cg.CoreTypes.PhpNumber)
{
cg.EmitConvertToPhpNumber(t, 0);
}
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Negation)
.Expect(cg.CoreTypes.PhpNumber);
}
}
示例2: EmitPlus
TypeSymbol EmitPlus(CodeGenerator cg)
{
// Template: 0L + Operand
// convert value to a number
var il = cg.Builder;
var t = cg.Emit(this.Operand);
switch (t.SpecialType)
{
case SpecialType.System_Double:
case SpecialType.System_Int32:
case SpecialType.System_Int64:
return t;
case SpecialType.System_Boolean:
// (long)(int)bool
il.EmitOpCode(ILOpCode.Conv_i4);
il.EmitOpCode(ILOpCode.Conv_i8);
return cg.CoreTypes.Long;
default:
if (t != cg.CoreTypes.PhpNumber)
{
cg.EmitConvertToPhpNumber(t, 0);
}
return cg.CoreTypes.PhpNumber;
}
}
示例3: EmitMul
internal static TypeSymbol EmitMul(CodeGenerator cg, TypeSymbol xtype, BoundExpression right, TypeSymbol resultTypeOpt = null)
{
var il = cg.Builder;
xtype = cg.EmitConvertIntToLong(xtype); // int|bool -> int64
TypeSymbol ytype;
switch (xtype.SpecialType)
{
case SpecialType.System_Double:
ytype = cg.EmitConvertNumberToDouble(right); // bool|int|long|number -> double
if (ytype.SpecialType == SpecialType.System_Double)
{
// r8 * r8 : r8
il.EmitOpCode(ILOpCode.Mul);
return xtype; // r8
}
else if (ytype == cg.CoreTypes.PhpValue)
{
// r8 * value : r8
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_double_value)
.Expect(SpecialType.System_Double);
}
//
throw new NotImplementedException($"Mul(double, {ytype.Name})");
case SpecialType.System_Int64:
ytype = cg.EmitConvertIntToLong(cg.Emit(right));
if (ytype.SpecialType == SpecialType.System_Int64)
{
// i8 * i8 : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_long)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype.SpecialType == SpecialType.System_Double)
{
// i8 * r8 : r8
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_double)
.Expect(SpecialType.System_Double);
}
else if (ytype == cg.CoreTypes.PhpNumber)
{
// i8 * number : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_number)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype == cg.CoreTypes.PhpValue)
{
// i8 * value : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_long_value)
.Expect(cg.CoreTypes.PhpNumber);
}
//
throw new NotImplementedException($"Mul(int64, {ytype.Name})");
default:
if (xtype == cg.CoreTypes.PhpNumber)
{
ytype = cg.EmitConvertIntToLong(cg.Emit(right));
if (ytype.SpecialType == SpecialType.System_Int64)
{
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_long)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype.SpecialType == SpecialType.System_Double)
{
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_double)
.Expect(cg.CoreTypes.Double);
}
else if (ytype == cg.CoreTypes.PhpNumber)
{
// number * number : number
cg.EmitConvertToPhpNumber(ytype, right.TypeRefMask);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_number)
.Expect(cg.CoreTypes.PhpNumber);
}
else if (ytype == cg.CoreTypes.PhpValue)
{
// number * value : number
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_value)
.Expect(cg.CoreTypes.PhpNumber);
}
else
{
// TODO: unconvertible
// number * number : number
cg.EmitConvertToPhpNumber(ytype, right.TypeRefMask);
return cg.EmitCall(ILOpCode.Call, cg.CoreMethods.PhpNumber.Mul_number_number)
.Expect(cg.CoreTypes.PhpNumber);
}
//
throw new NotImplementedException($"Mul(PhpNumber, {ytype.Name})");
}
else if (xtype == cg.CoreTypes.PhpValue)
{
ytype = cg.EmitConvertIntToLong(cg.Emit(right)); // bool|int -> long
if (ytype == cg.CoreTypes.PhpValue)
{
// value * value : number
//.........这里部分代码省略.........