Ejemplo n.º 1
0
		}//Nibble
		
		/// <summary>
		/// rewrite literal from parsed value buffer/stack to code buffer
		/// </summary>
		protected override void Literal( Opcode op, int top, int start )
		{
			if( op == Opcode.Ident )
			{
				Copy( op, true, top, start );
				return;
			}
			if( (op < Opcode.Ident) || (op == Opcode.Exception) )
			{
				Write( unchecked((byte)op) );
				return;
			}
			var len = top - start;
			if( (op.Kind() <= Opkind.Number) && (unchecked((byte)op) >= unchecked((byte)Opcode.Char)) )
			{
				Debug.Assert( op <= Opcode.Double );
				Debug.Assert( len == op.Numsz() );
				Need( len + 1 );
				Code[CodeAt++] = unchecked((byte)op);
				Array.Copy( Vals, start, Code, CodeAt, len );
				CodeAt += len;
				return;
			}
			Debug.Assert( op == Opcode.String );
			if( len < (1 << 7) )
			{
				Copy( op, true, top, start );
				return;
			}
			if( len < (1 << 14) )
			{
				Need( 3 + len );
				Code[CodeAt++] = unchecked((byte)op);
				Code[CodeAt++] = unchecked((byte)(0x80 | len));
				Code[CodeAt++] = unchecked((byte)(len >> 7));
				Array.Copy( Vals, start, Code, CodeAt, len );
				CodeAt += len;
				return;
			}
			if( len < (1 << 21) )
			{
				Need( 4 + len );
				Code[CodeAt++] = unchecked((byte)op);
				Code[CodeAt++] = unchecked((byte)(0x80 | len));
				Code[CodeAt++] = unchecked((byte)(0x80 | (len >> 7)));
				Code[CodeAt++] = unchecked((byte)(len >> 14));
				Array.Copy( Vals, start, Code, CodeAt, len );
				CodeAt += len;
				return;
			}
			if( len < (1 << 28) )
			{
				Need( 5 + len );
				Code[CodeAt++] = unchecked((byte)op);
				Code[CodeAt++] = unchecked((byte)(0x80 | len));
				Code[CodeAt++] = unchecked((byte)(0x80 | (len >> 7)));
				Code[CodeAt++] = unchecked((byte)(0x80 | (len >> 14)));
				Code[CodeAt++] = unchecked((byte)(len >> 21));
				Array.Copy( Vals, start, Code, CodeAt, len );
				CodeAt += len;
				return;
			}
			throw new InvalidOperationException();
		}//Literal