public override PValue Run(StackContext sctx, PValue[] args) { if (args.Length < CallingConventionArgumentsCount) throw new PrexoniteException( "Id of macro implementation, effect flag, call type and/or context missing."); var entityRef = _getMacroRef(sctx, args[0]); //Parse arguments var context = _getContext(args[1]); var call = _getCallType(args[2]); var justEffect = _getEffectFlag(args[3]); // Prepare macro var target = _loader.FunctionTargets[context.Function]; var argList = Call.FlattenArguments(sctx, args, CallingConventionArgumentsCount); _detectRuntimeValues(argList); var inv = new AstExpand(context.Invocation.Position, entityRef, call); inv.Arguments.AddRange(argList.Select(p => (AstExpr) p.Value)); //Execute the macro MacroSession macroSession = null; try { macroSession = target.AcquireMacroSession(); return sctx.CreateNativePValue( macroSession.ExpandMacro(inv, justEffect)); } finally { if (macroSession != null) target.ReleaseMacroSession(macroSession); } }
public override AstGetSet GetCopy() { var copy = new AstExpand(Position, Entity, Call); CopyBaseMembers(copy); return copy; }
private static AstExpr _getMacroSpecExpr(MacroContext context, AstExpand proto) { return EntityRefTo.ToExpr(context.Factory, context.Invocation.Position, proto.Entity); }