public static void Compile(ParserContext parser, ByteBuffer buffer, FunctionReference funcRef, bool outputUsed) { ByteCodeCompiler.EnsureUsed(funcRef, outputUsed); FunctionDefinition funcDef = funcRef.FunctionDefinition; int classIdStaticCheck = 0; int type = 0; if (funcDef.Owner is ClassDefinition) { if (funcDef.Modifiers.HasStatic) { classIdStaticCheck = ((ClassDefinition)funcDef.Owner).ClassID; type = 2; } else { type = 1; } } buffer.Add(funcRef.FirstToken, OpCode.PUSH_FUNC_REF, funcDef.FunctionID, type, classIdStaticCheck); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, NullCoalescer nullCoalescer, bool outputUsed) { ByteCodeCompiler.EnsureUsed(nullCoalescer, outputUsed); bcc.CompileExpression(parser, buffer, nullCoalescer.PrimaryExpression, true); ByteBuffer secondaryExpression = new ByteBuffer(); bcc.CompileExpression(parser, secondaryExpression, nullCoalescer.SecondaryExpression, true); buffer.Add(nullCoalescer.FirstToken, OpCode.POP_IF_NULL_OR_JUMP, secondaryExpression.Size); buffer.Concat(secondaryExpression); }
public static void Compile(ParserContext parser, ByteBuffer buffer, BaseMethodReference baseMethodReference, bool outputUsed) { ByteCodeCompiler.EnsureUsed(baseMethodReference, outputUsed); int baseClassId = baseMethodReference.ClassToWhichThisMethodRefers.ClassID; buffer.Add( baseMethodReference.DotToken, OpCode.PUSH_FUNC_REF, baseMethodReference.FunctionDefinition.FunctionID, 1, // instance method 0); }
public static void Compile( ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, CoreFunctionInvocation coreFuncInvocation, Expression[] argsOverrideOrNull, Token tokenOverrideOrNull, bool outputUsed) { Token token = tokenOverrideOrNull ?? coreFuncInvocation.FirstToken; Expression[] args = argsOverrideOrNull ?? coreFuncInvocation.Args; if (coreFuncInvocation.FunctionId == (int)CoreFunctionID.TYPE_IS) { ByteCodeCompiler.EnsureUsed(coreFuncInvocation, outputUsed); bcc.CompileExpression(parser, buffer, args[0], true); int typeCount = args.Length - 1; int[] actualArgs = new int[typeCount + 3]; actualArgs[0] = coreFuncInvocation.FunctionId; actualArgs[1] = 1; // output used actualArgs[2] = typeCount; for (int i = typeCount - 1; i >= 0; --i) { IntegerConstant typeArg = args[args.Length - 1 - i] as IntegerConstant; if (typeArg == null) { throw new ParserException(coreFuncInvocation, "typeis requires type enum values."); } actualArgs[3 + i] = typeArg.Value + 1; } buffer.Add(token, OpCode.CORE_FUNCTION, actualArgs); return; } foreach (Expression arg in args) { bcc.CompileExpression(parser, buffer, arg, true); } if (coreFuncInvocation.FunctionId == (int)CoreFunctionID.INT_QUEUE_WRITE_16) { buffer.Add(token, OpCode.CORE_FUNCTION, coreFuncInvocation.FunctionId, outputUsed ? 1 : 0, args.Length - 1); return; } buffer.Add(token, OpCode.CORE_FUNCTION, coreFuncInvocation.FunctionId, outputUsed ? 1 : 0); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, Ternary ternary, bool outputUsed) { ByteCodeCompiler.EnsureUsed(ternary, outputUsed); bcc.CompileExpression(parser, buffer, ternary.Condition, true); ByteBuffer trueBuffer = new ByteBuffer(); bcc.CompileExpression(parser, trueBuffer, ternary.TrueValue, true); ByteBuffer falseBuffer = new ByteBuffer(); bcc.CompileExpression(parser, falseBuffer, ternary.FalseValue, true); trueBuffer.Add(null, OpCode.JUMP, falseBuffer.Size); buffer.Add(ternary.Condition.FirstToken, OpCode.JUMP_IF_FALSE, trueBuffer.Size); buffer.Concat(trueBuffer); buffer.Concat(falseBuffer); }
public static void Compile(ParserContext parser, ByteBuffer buffer, FieldReference fieldRef, bool outputUsed) { ByteCodeCompiler.EnsureUsed(fieldRef, outputUsed); if (fieldRef.Field.Modifiers.HasStatic) { buffer.Add( fieldRef.FirstToken, OpCode.DEREF_STATIC_FIELD, ((ClassDefinition)fieldRef.Field.Owner).ClassID, fieldRef.Field.StaticMemberID); } else { buffer.Add( fieldRef.FirstToken, OpCode.DEREF_INSTANCE_FIELD, fieldRef.Field.MemberID); } }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, Lambda lambda, bool outputUsed) { ByteCodeCompiler.EnsureUsed(lambda, outputUsed); ByteBuffer tBuffer = new ByteBuffer(); List <int> offsetsForOptionalArgs = new List <int>(); Expression[] argDefaultValues_allRequired = new Expression[lambda.Args.Length]; FunctionDefinitionEncoder.CompileFunctionArgs(bcc, parser, tBuffer, lambda.Args, argDefaultValues_allRequired, offsetsForOptionalArgs, lambda.ArgVarIds); bcc.Compile(parser, tBuffer, lambda.Code); List <int> args = new List <int>() { lambda.Args.Length, // min number of args required lambda.Args.Length, // max number of args supplied lambda.LocalScopeSize, tBuffer.Size, offsetsForOptionalArgs.Count }; args.AddRange(offsetsForOptionalArgs); VariableId[] closureIds = lambda.ClosureIds; args.Add(closureIds.Length); foreach (VariableId closureVarId in closureIds) { args.Add(closureVarId.ClosureID); } buffer.Add( lambda.FirstToken, OpCode.LAMBDA, args.ToArray()); buffer.Concat(tBuffer); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, ListSlice listSlice, bool outputUsed) { ByteCodeCompiler.EnsureUsed(listSlice, outputUsed); bcc.CompileExpression(parser, buffer, listSlice.Root, true); Expression step = listSlice.Items[2]; bool isStep1 = step is IntegerConstant && ((IntegerConstant)step).Value == 1; int serializeThese = isStep1 ? 2 : 3; for (int i = 0; i < serializeThese; ++i) { Expression item = listSlice.Items[i]; if (item != null) { bcc.CompileExpression(parser, buffer, item, true); } } bool firstIsPresent = listSlice.Items[0] != null; bool secondIsPresent = listSlice.Items[1] != null; buffer.Add(listSlice.BracketToken, OpCode.LIST_SLICE, new int[] { firstIsPresent ? 1 : 0, secondIsPresent ? 1 : 0, isStep1 ? 0 : 1 }); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, IsComparison isComp, bool outputUsed) { ByteCodeCompiler.EnsureUsed(isComp.IsToken, outputUsed); bcc.CompileExpression(parser, buffer, isComp.Expression, true); buffer.Add(isComp.IsToken, OpCode.IS_COMPARISON, isComp.ClassDefinition.ClassID); }