Skip to content

Commit

Permalink
Methods optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Feb 9, 2025
1 parent aae5461 commit 724fa40
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
13 changes: 7 additions & 6 deletions YantraJS.Core/LinqExpressions/JSGeneratorFunctionBuilderV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
using SwitchCase = YantraJS.Expressions.YSwitchCaseExpression;
using GotoExpression = YantraJS.Expressions.YGoToExpression;
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
using YantraJS.Core.LambdaGen;

namespace YantraJS.ExpHelper
{
public class JSGeneratorFunctionBuilderV2
{
private static Type type = typeof(JSGeneratorFunctionV2);

private static ConstructorInfo _New =
type.Constructor(
typeof(JSGeneratorDelegateV2), StringSpanBuilder.RefType, StringSpanBuilder.RefType);

public static Expression New(Expression @delegate, Expression name, Expression code)
{
return Expression.New(_New, @delegate, name, code);
return NewLambdaExpression.NewExpression<JSGeneratorFunctionV2>(() =>
() => new JSGeneratorFunctionV2((JSGeneratorDelegateV2)null, "", "")
,@delegate
,name
,code);
// return Expression.New(_New, @delegate, name, code);
}
}
}
15 changes: 9 additions & 6 deletions YantraJS.Core/LinqExpressions/JSNullBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
using SwitchCase = YantraJS.Expressions.YSwitchCaseExpression;
using GotoExpression = YantraJS.Expressions.YGoToExpression;
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
using YantraJS.Core.LambdaGen;

namespace YantraJS.ExpHelper
{
public class JSNullBuilder
{

public static Expression Value =
Expression.TypeAs(
Expression.Field(
null,
typeof(JSNull)
.GetField(nameof(JSNull.Value))),
typeof(JSValue));
// Expression.TypeAs(
NewLambdaExpression.StaticFieldExpression<JSValue>(() => () => JSNull.Value)
//, Expression.Field(
// null,
// typeof(JSNull)
// .GetField(nameof(JSNull.Value))),
// typeof(JSValue))
;
}
}
51 changes: 30 additions & 21 deletions YantraJS.Core/LinqExpressions/JSNumberBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,64 @@
using SwitchCase = YantraJS.Expressions.YSwitchCaseExpression;
using GotoExpression = YantraJS.Expressions.YGoToExpression;
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
using YantraJS.Core.LambdaGen;

namespace YantraJS.ExpHelper
{
public class JSNumberBuilder
{
static Type type = typeof(JSNumber);
// static Type type = typeof(JSNumber);

public static Expression NaN =
Expression.Field(null, type.GetField(nameof(JSNumber.NaN)));
NewLambdaExpression.StaticFieldExpression<JSNumber>(() => () => JSNumber.NaN);
// Expression.Field(null, type.GetField(nameof(JSNumber.NaN)));

public static Expression Zero =
Expression.Field(null, type.GetField(nameof(JSNumber.Zero)));
NewLambdaExpression.StaticFieldExpression<JSNumber>(() => () => JSNumber.Zero);
// Expression.Field(null, type.GetField(nameof(JSNumber.Zero)));

public static Expression One =
Expression.Field(null, type.GetField(nameof(JSNumber.One)));
NewLambdaExpression.StaticFieldExpression<JSNumber>(() => () => JSNumber.One);
// Expression.Field(null, type.GetField(nameof(JSNumber.One)));

public static Expression MinusOne =
Expression.Field(null, type.GetField(nameof(JSNumber.MinusOne)));
NewLambdaExpression.StaticFieldExpression<JSNumber>(() => () => JSNumber.MinusOne);
// Expression.Field(null, type.GetField(nameof(JSNumber.MinusOne)));

public static Expression Two =
Expression.Field(null, type.GetField(nameof(JSNumber.Two)));
NewLambdaExpression.StaticFieldExpression<JSNumber>(() => () => JSNumber.Two);
// Expression.Field(null, type.GetField(nameof(JSNumber.Two)));

private static FieldInfo _Value =
type.InternalField(nameof(Core.JSNumber.value));
//private static FieldInfo _Value =
// type.InternalField(nameof(Core.JSNumber.value));

public static Expression Value(Expression ex)
{
return Expression.Field(ex, _Value);
}
//public static Expression Value(Expression ex)
//{
// return Expression.Field(ex, _Value);
//}

private static ConstructorInfo _NewDouble
= type.Constructor(typeof(double));
//private static ConstructorInfo _NewDouble
// = type.Constructor(typeof(double));

public static Expression New(Expression exp)
{
if (exp.Type != typeof(double))
{
exp = Expression.Convert(exp, typeof(double));
}
return Expression.TypeAs(Expression.New(_NewDouble, exp), typeof(JSValue));
return Expression.TypeAs(
NewLambdaExpression.NewExpression<JSNumber>(() => () => new JSNumber((double)0), exp)
, typeof(JSValue));
// return Expression.TypeAs(Expression.New(_NewDouble, exp), typeof(JSValue));
}

private static MethodInfo _AddValue =
type.InternalMethod(nameof(Core.JSValue.AddValue), typeof(Core.JSValue));
//private static MethodInfo _AddValue =
// type.InternalMethod(nameof(Core.JSValue.AddValue), typeof(Core.JSValue));

public static Expression AddValue(Expression target, Expression value)
{
return Expression.Call(target, _AddValue, value);
}
//public static Expression AddValue(Expression target, Expression value)
//{
// return Expression.Call(target, _AddValue, value);
//}


}
Expand Down

0 comments on commit 724fa40

Please sign in to comment.