private static BFOpcode ParseInstrWithStringLiteralArgs( BFInstruction instr, string stringLiteral, int lineIndex, int opIndex, List<Tuple<string, int>> unresolvedProcs, List<Tuple<string, int>> unresolvedJumps) { switch (instr) { case BFInstruction.BeginProcedure: case BFInstruction.CallProcedure: unresolvedProcs.Add(Tuple.Create(stringLiteral, opIndex)); break; case BFInstruction.CallNative: BFCallNativeType callType; if (!Enum.TryParse(stringLiteral, true, out callType)) throw new BFASMParserException(instr, lineIndex + 1); return new BFOpcode(instr, (int)callType); case BFInstruction.Jump: case BFInstruction.JumpIfFalse: string jumpLabelName = stringLiteral.Split(new char[] { '@', ':' }, StringSplitOptions.RemoveEmptyEntries)[0]; if (jumpLabelName.Length == 0) throw new BFASMParserException(instr, lineIndex + 1); unresolvedJumps.Add(Tuple.Create(jumpLabelName, opIndex)); break; } // actual operand value will be resolved later, so just set it to -1 for now return new BFOpcode(instr, -1); }
private static BFOpcode ParseInstrWithDecimalLiteralArgs(BFInstruction instr, string[] tokens, int lineIndex) { float value; if (!float.TryParse(tokens[1], out value)) throw new BFASMParserException(instr, lineIndex + 1); return new BFOpcode(instr, value); }
internal BFOpcode(BFInstruction instruction, int codeBlockIndex, IConvertible operand) { _instr = (ushort)instruction; _codeBlockIndex = codeBlockIndex; SetOperand(operand); }
private static void VerifyArgCount(BFInstruction instr, string[] tokens, int lineIndex) { switch (instr) { case BFInstruction.PushUInt32: case BFInstruction.PushFloat: case BFInstruction.BeginProcedure: case BFInstruction.CallNative: case BFInstruction.CallProcedure: case BFInstruction.Jump: case BFInstruction.JumpIfFalse: case BFInstruction.PushUInt16: case BFInstruction.PushVariable: case BFInstruction.SetVariable: if (tokens.Length < 2) throw new BFASMParserException(instr, lineIndex + 1); break; } }
public BFOpcode(BFInstruction instruction, IConvertible operand) { _instr = (ushort)instruction; SetOperand(operand); }