Skip to content

Commit

Permalink
yield* in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Feb 7, 2025
1 parent 1b40fe8 commit 3b62b98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
21 changes: 3 additions & 18 deletions YantraJS.Core/LinqExpressions/CallStackItemBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@ namespace YantraJS.Core.LinqExpressions
internal static class CallStackItemBuilder
{

static Type type = typeof(CallStackItem);

//static ConstructorInfo _new =
// type.GetConstructor(new Type[] {
// typeof(JSContext),
// typeof(ScriptInfo),
// typeof(int),
// typeof(int),
// typeof(int),
// typeof(int)
// });

static MethodInfo _step =
type.PublicMethod(nameof(CallStackItem.Step), typeof(int), typeof(int));

public static YExpression New(
YExpression context,
YExpression scriptInfo,
Expand All @@ -48,10 +33,10 @@ public static YExpression New(

public static YExpression Step(YExpression target, int line, int column)
{
return YExpression.Call(target,
_step,
return target.CallExpression<CallStackItem, int, int>(() => (x, a, b) => x.Step(a, b),
YExpression.Constant(line),
YExpression.Constant(column));
YExpression.Constant(column)
);
}

}
Expand Down
4 changes: 2 additions & 2 deletions YantraJS.ExpressionCompiler/Expressions/YExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,9 @@ public static YSwitchCaseExpression SwitchCase(YExpression body, IEnumerable<YEx
}


public static YYieldExpression Yield(YExpression arg)
public static YYieldExpression Yield(YExpression arg, bool @delegate = false)
{
return new YYieldExpression(arg);
return new YYieldExpression(arg, @delegate);
}
}
}
8 changes: 7 additions & 1 deletion YantraJS.ExpressionCompiler/Expressions/YYieldExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ namespace YantraJS.Expressions
public class YYieldExpression: YExpression
{
public readonly YExpression Argument;
public readonly bool DelegateYield;

public YYieldExpression(YExpression arg):
public YYieldExpression(YExpression arg, bool @delegate):
base(YExpressionType.Yield, arg.Type)
{
this.Argument = arg;
this.DelegateYield = @delegate;
}

public override void Print(IndentedTextWriter writer)
{
writer.Write("yield ");
if (DelegateYield)
{
writer.Write("*");
}
Argument.Print(writer);
}
}
Expand Down

0 comments on commit 3b62b98

Please sign in to comment.