public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, OpChain opChain, bool outputUsed) { if (!outputUsed) { if (opChain.OpToken.Value == "==") { throw new ParserException(opChain.OpToken, "'==' cannot be used like this. Did you mean to use just a single '=' instead?"); } throw new ParserException(opChain, "This expression isn't valid here."); } bcc.CompileExpressionList(parser, buffer, new Expression[] { opChain.Left, opChain.Right }, true); switch (opChain.OpTEMP) { case Ops.EQUALS: case Ops.NOT_EQUALS: buffer.Add(opChain.OpToken, OpCode.EQUALS, opChain.OpTEMP == Ops.EQUALS ? 0 : 1); break; default: buffer.Add(opChain.OpToken, OpCode.BINARY_OP, (int)opChain.OpTEMP); break; } if (!outputUsed) { buffer.Add(null, OpCode.POP); } }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, BooleanCombination boolComb, bool outputUsed) { if (!outputUsed) { throw new ParserException(boolComb, "Cannot have this expression here."); } ByteBuffer rightBuffer = new ByteBuffer(); Expression[] expressions = boolComb.Expressions; bcc.CompileExpression(parser, rightBuffer, expressions[expressions.Length - 1], true); for (int i = expressions.Length - 2; i >= 0; --i) { ByteBuffer leftBuffer = new ByteBuffer(); bcc.CompileExpression(parser, leftBuffer, expressions[i], true); Token op = boolComb.Ops[i]; if (op.Value == "&&") { leftBuffer.Add(op, OpCode.JUMP_IF_FALSE_NO_POP, rightBuffer.Size); } else { leftBuffer.Add(op, OpCode.JUMP_IF_TRUE_NO_POP, rightBuffer.Size); } leftBuffer.Concat(rightBuffer); rightBuffer = leftBuffer; } buffer.Concat(rightBuffer); }
public void SendConnectRequest( NetworkingCommon.ConnectArgs connArgs, string roomName, string userName ) { // Attempt to begin the connection // #POSSIBLE_PROBLEM // We may want to continuously send this until we get responce, since we can never trust udp to arrive.. byte[] userName_raw = Encoding.ASCII.GetBytes(userName); byte[] roomName_raw = Encoding.ASCII.GetBytes(roomName); ByteBuffer namesCombined = new ByteBuffer(); namesCombined.Add(new byte[] { (byte)roomName_raw.Length }); namesCombined.Add(roomName_raw); namesCombined.Add(new byte[] { (byte)userName_raw.Length }); namesCombined.Add(userName_raw); // By default we ask for directly connecting.. //Package package = new Package(1, 0, NetworkingCommon.MESSAGE_TYPE__ConnectRequest, (ushort)userName.Length, userName_raw); Package package = new Package(0, 0, NetworkingCommon.Convert_ConnArgs_To_Byte(connArgs), (ushort)namesCombined.Bytes.Length, namesCombined.Bytes); SendData(package.Buffer.Bytes); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, IfStatement ifStatement) { bcc.CompileExpression(parser, buffer, ifStatement.Condition, true); ByteBuffer trueCode = new ByteBuffer(); bcc.Compile(parser, trueCode, ifStatement.TrueCode); ByteBuffer falseCode = new ByteBuffer(); bcc.Compile(parser, falseCode, ifStatement.FalseCode); if (falseCode.Size == 0) { if (trueCode.Size == 0) { buffer.Add(ifStatement.Condition.FirstToken, OpCode.POP); } else { buffer.Add(ifStatement.Condition.FirstToken, OpCode.JUMP_IF_FALSE, trueCode.Size); buffer.Concat(trueCode); } } else { trueCode.Add(null, OpCode.JUMP, falseCode.Size); buffer.Add(ifStatement.Condition.FirstToken, OpCode.JUMP_IF_FALSE, trueCode.Size); buffer.Concat(trueCode); buffer.Concat(falseCode); } }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- partial void OkButton_TouchUpInside(UIButton sender) { try { double val; if ((sensor.type.code == SensorTypeCodes.Pulse) || (sensor.type.code == SensorTypeCodes.IRDAModem)) { if (double.TryParse(Setting1Field.Text.Replace(" ", "").Replace(".", ","), out val) == true) { nodeValues[2] = val; } if (double.TryParse(Setting2Field.Text.Replace(" ", "").Replace(".", ","), out val) == true) { nodeValues[1] = val; } nodeValues[0] = nodeValues[1] + nodeValues[2]; if (double.TryParse(Setting3Field.Text.Replace(" ", "").Replace(".", ","), out val) == true) { nodeValues[3] = val; } } else if (sensor.type.code == SensorTypeCodes.Pulse2Channel) { if (double.TryParse(Setting1Field.Text.Replace(" ", "").Replace(".", ","), out val) == true) { nodeValues[0] = val; } if (double.TryParse(Setting2Field.Text.Replace(" ", "").Replace(".", ","), out val) == true) { nodeValues[2] = val; } if (double.TryParse(Setting3Field.Text.Replace(" ", "").Replace(".", ","), out val) == true) { nodeValues[1] = val; } nodeValues[3] = nodeValues[1]; } } catch {} ByteBuffer buffer = new ByteBuffer(); foreach (KeyValuePair <byte, double> nodeValue in (Dictionary <byte, double>)nodeValues) { buffer.Add((byte)nodeValue.Key); buffer.Add((double)nodeValue.Value); } DataManager.SheduleSetNodeValuesRequest(sensor.nodeID, buffer, null); DataManager.SheduleGetNodeValuesRequest(sensor.nodeID, DataUpdateCallback); OkButton.SetTitle(OkButton.Title(UIControlState.Normal) + "+", UIControlState.Normal); }
public Package(byte roomID, byte clientID, byte messageType) { Buffer = new ByteBuffer(); Buffer.Add(new byte[1] { roomID }); Buffer.Add(new byte[1] { clientID }); Buffer.Add(new byte[1] { messageType }); }
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(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, DictionaryDefinition dictDef, bool outputUsed) { if (!outputUsed) { throw new ParserException(dictDef, "Cannot have a dictionary all by itself."); } int itemCount = dictDef.Keys.Length; List <Expression> expressionList = new List <Expression>(); for (int i = 0; i < itemCount; ++i) { expressionList.Add(dictDef.Keys[i]); expressionList.Add(dictDef.Values[i]); } bcc.CompileExpressionList(parser, buffer, expressionList, true); List <int> args = new List <int>(); args.Add(itemCount); args.Add(0); if (dictDef.CompilationScope.IsStaticallyTyped) { CastEncoder.EncodeTypeInfoToIntBuffer(args, dictDef.ResolvedKeyType, false); args[1] = args.Count; CastEncoder.EncodeTypeInfoToIntBuffer(args, dictDef.ResolvedValueType, false); } buffer.Add(dictDef.FirstToken, OpCode.DEF_DICTIONARY, args.ToArray()); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, ForEachLoop forEachLoop) { bcc.CompileExpression(parser, buffer, forEachLoop.IterationExpression, true); buffer.Add( forEachLoop.IterationExpression.FirstToken, OpCode.VERIFY_TYPE_IS_ITERABLE, forEachLoop.ListLocalId.ID, forEachLoop.IndexLocalId.ID); ByteBuffer body = new ByteBuffer(); ByteBuffer body2 = new ByteBuffer(); bcc.Compile(parser, body2, forEachLoop.Code); body.Add( forEachLoop.FirstToken, OpCode.ITERATION_STEP, body2.Size + 1, forEachLoop.IterationVariableId.ID, forEachLoop.IndexLocalId.ID, forEachLoop.ListLocalId.ID); body2.Add(null, OpCode.JUMP, -body2.Size - 2); body.Concat(body2); body.ResolveBreaks(); body.ResolveContinues(); buffer.Concat(body); }
public Package(byte roomID, byte clientID, byte messageType, ushort dataLength, byte[] data) { Buffer = new ByteBuffer(); Buffer.Add(new byte[1] { roomID }); Buffer.Add(new byte[1] { clientID }); Buffer.Add(new byte[1] { messageType }); Buffer.Add(BitConverter.GetBytes(dataLength)); Buffer.Add(data); }
/// <summary> /// called on data receive /// </summary> /// <param name="ar"></param> private void ReceiveCallback(IAsyncResult ar) { State myState = (State)ar.AsyncState; //Maybe the connection has been closed or so if (myState._client == null || myState._client.Client == null || myState._client.Connected == false) { return; } try { int read = myState._client.Client.EndReceive(ar); //connection closed if (read == 0) { //eeeek } else { _receiveBuffer.Add(myState._buffer, 0, read); StartReceive(myState); } } catch (Exception e) { _log.Warning("Network Transport error: {0}", e.ToString()); } }
public static void CompileInteger(ParserContext parser, ByteBuffer buffer, IntegerConstant intConst, bool outputUsed) { if (!outputUsed) { throw new ParserException(intConst, "This expression does nothing."); } buffer.Add(intConst.FirstToken, OpCode.LITERAL, parser.GetIntConstant(intConst.Value)); }
public static void CompileFloat(ParserContext parser, ByteBuffer buffer, FloatConstant floatConstant, bool outputUsed) { if (!outputUsed) { throw new ParserException(floatConstant, "This expression doesn't do anything."); } buffer.Add(floatConstant.FirstToken, OpCode.LITERAL, parser.GetFloatConstant(floatConstant.Value)); }
public static void CompileString(ParserContext parser, ByteBuffer buffer, StringConstant stringConstant, bool outputUsed) { if (!outputUsed) { throw new ParserException(stringConstant, "This expression does nothing."); } buffer.Add(stringConstant.FirstToken, OpCode.LITERAL, parser.GetStringConstant(stringConstant.Value)); }
public static void CompileNull(ParserContext parser, ByteBuffer buffer, NullConstant nullConstant, bool outputUsed) { if (!outputUsed) { throw new ParserException(nullConstant, "This expression doesn't do anything."); } buffer.Add(nullConstant.FirstToken, OpCode.LITERAL, parser.GetNullConstant()); }
public static void Compile(ParserContext parser, ByteBuffer buffer, ClassReferenceLiteral classRef, bool outputUsed) { if (!outputUsed) { throw new ParserException(classRef, "This class reference expression does nothing."); } buffer.Add(classRef.FirstToken, OpCode.LITERAL, parser.GetClassRefConstant(classRef.ClassDefinition)); }
public static void Compile(ParserContext parser, ByteBuffer buffer, ThisKeyword thisKeyword, bool outputUsed) { if (!outputUsed) { throw new ParserException(thisKeyword, "This expression doesn't do anything."); } buffer.Add(thisKeyword.FirstToken, OpCode.THIS); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, NegativeSign negativeSign, bool outputUsed) { if (!outputUsed) { throw new ParserException(negativeSign, "This expression does nothing."); } bcc.CompileExpression(parser, buffer, negativeSign.Root, true); buffer.Add(negativeSign.FirstToken, OpCode.NEGATIVE_SIGN); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, WhileLoop whileLoop) { ByteBuffer loopBody = new ByteBuffer(); bcc.Compile(parser, loopBody, whileLoop.Code); ByteBuffer condition = new ByteBuffer(); bcc.CompileExpression(parser, condition, whileLoop.Condition, true); condition.Add(whileLoop.Condition.FirstToken, OpCode.JUMP_IF_FALSE, loopBody.Size + 1); condition.Concat(loopBody); condition.Add(null, OpCode.JUMP, -condition.Size - 1); condition.ResolveBreaks(); condition.ResolveContinues(); buffer.Concat(condition); }
public Package(byte roomID, byte clientID, byte messageType, Transform t) { Buffer = new ByteBuffer(); Buffer.Add(new byte[1] { roomID }); Buffer.Add(new byte[1] { clientID }); Buffer.Add(new byte[1] { messageType }); ushort dataLength = sizeof(float) * 10; Buffer.Add(BitConverter.GetBytes(dataLength)); Buffer.Add(t); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, BooleanNot boolNot, bool outputUsed) { if (!outputUsed) { throw new ParserException(boolNot, "Cannot have this expression here."); } bcc.CompileExpression(parser, buffer, boolNot.Root, true); buffer.Add(boolNot.FirstToken, OpCode.BOOLEAN_NOT); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, BracketIndex bracketIndex, bool outputUsed) { if (!outputUsed) { throw new ParserException(bracketIndex, "This expression does nothing."); } bcc.CompileExpression(parser, buffer, bracketIndex.Root, true); bcc.CompileExpression(parser, buffer, bracketIndex.Index, true); buffer.Add(bracketIndex.BracketToken, OpCode.INDEX); }
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(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, ReturnStatement returnStatement) { if (returnStatement.Owner is ConstructorDefinition) { if (returnStatement.Expression != null) { throw new ParserException(returnStatement, "Cannot return a value from a constructor."); } } if (returnStatement.Expression == null || returnStatement.Expression is NullConstant) { buffer.Add(returnStatement.FirstToken, OpCode.RETURN, 0); } else { bcc.CompileExpression(parser, buffer, returnStatement.Expression, true); buffer.Add(returnStatement.FirstToken, OpCode.RETURN, 1); } }
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); } }
private static void AddDebugSymbolData(ByteBuffer buffer, ParserContext parser, FunctionDefinition funcDef) { if (parser.IncludeDebugSymbols) { foreach (VariableId id in funcDef.Locals.OrderBy(vid => vid.ID)) { int type = id.UsedByClosure ? 2 : 1; int idNum = id.UsedByClosure ? id.ClosureID : id.ID; buffer.Add(null, OpCode.DEBUG_SYMBOLS, id.Name, type, idNum); } } }
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, ForLoop forLoop) { bcc.Compile(parser, buffer, forLoop.Init); ByteBuffer codeBuffer = new ByteBuffer(); bcc.Compile(parser, codeBuffer, forLoop.Code); codeBuffer.ResolveContinues(true); // resolve continues as jump-to-end before you add the step instructions. bcc.Compile(parser, codeBuffer, forLoop.Step); ByteBuffer forBuffer = new ByteBuffer(); bcc.CompileExpression(parser, forBuffer, forLoop.Condition, true); forBuffer.Add(forLoop.Condition.FirstToken, OpCode.JUMP_IF_FALSE, codeBuffer.Size + 1); // +1 to go past the jump I'm about to add. forBuffer.Concat(codeBuffer); forBuffer.Add(null, OpCode.JUMP, -forBuffer.Size - 1); forBuffer.ResolveBreaks(); buffer.Concat(forBuffer); }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, Instantiate instantiate, bool outputUsed) { ClassDefinition cd = instantiate.Class; ConstructorDefinition constructor = cd.Constructor; bcc.CompileExpressionList(parser, buffer, instantiate.Args, true); buffer.Add(instantiate.NameToken, OpCode.CALL_FUNCTION, (int)FunctionInvocationType.CONSTRUCTOR, instantiate.Args.Length, constructor.FunctionID, outputUsed ? 1 : 0, cd.ClassID); }