31 lines
825 B
C#
31 lines
825 B
C#
using System;
|
|
using System.IO;
|
|
using TLang.Common;
|
|
|
|
namespace TLang.BytecodeCompiler
|
|
{
|
|
public class PushStringInstruction : Instruction
|
|
{
|
|
public string Value {get;set;}
|
|
public PushStringInstruction(string value)
|
|
{
|
|
Value = value;
|
|
}
|
|
|
|
public override int CalculateLength()
|
|
{
|
|
return System.Text.Encoding.UTF8.GetByteCount(Value) + 5;
|
|
}
|
|
|
|
public override void WriteData(Stream strm)
|
|
{
|
|
strm.WriteByte(PUSH_STRING);
|
|
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(Value);
|
|
var data=BitConverter.GetBytes(bytes.Length);
|
|
if(BitConverter.IsLittleEndian) Array.Reverse(data);
|
|
strm.Write(data,0,data.Length);
|
|
strm.Write(bytes,0,bytes.Length);
|
|
}
|
|
}
|
|
}
|