Skip to content

Instantly share code, notes, and snippets.

@dresswithpockets
Created May 12, 2013 02:44
Show Gist options
  • Save dresswithpockets/5562218 to your computer and use it in GitHub Desktop.
Save dresswithpockets/5562218 to your computer and use it in GitHub Desktop.
VSL2NET, Convert VSL to .NET
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
namespace ClassLibrary1
{
public class ExeIO
{
/// <summary>
/// Code that a new ExeIO has been initialized with
/// </summary>
public string[] OriginalCode;
/// <summary>
/// The save path that the database will save the new executable to
/// </summary>
public string SavePath;
/// <summary>
/// The specialized database array from vsltcsnet.db
/// </summary>
public List<string> VslDB;
#region forgottenCode
/*{
get { return VslDB; }
set
{
List<string> parentLevels = new List<string>();
string[] valueToSet = new string[value.Length];
for (int l = 0; l < value.Length; l++)
{
string[] cls = value[l].Split('\t');
parentLevels[l] += cls[cls.Length - 1];
for (int i = 0; i < cls.Length - 1; i++)
{
cls[cls.Length - 1].Insert(cls[cls.Length - 1].LastIndexOf(':'), parentLevels[i].Split(':')[1]);
valueToSet[l] += parentLevels[i].Split(':')[0];
}
valueToSet[l] += cls[cls.Length - 1];
}
}
}*/
#endregion
/// <summary>
/// The C#.Net 4.5 converted version of VSL.fw 1.3
/// </summary>
public string[] ConvertedCode;
/// <summary>
/// ExeIO Initializer
/// </summary>
/// <param name="code">The VSL input that the initialized ExeIO will convert</param>
/// <param name="fpath">The filepath that the executable will be saved to.</param>
public ExeIO(string[] code, string fpath)
{
OriginalCode = code;
VslDB = new List<string>(File.ReadAllLines("dll/stddll.db"));
VslDB.AddRange(File.ReadAllLines("dll/stdio.db"));
VslDB.AddRange(File.ReadAllLines("dll/std.db"));
SavePath = fpath;
ConvertedCode = V2C();
}
public static object _locker1 = new object();
private string[] V2C()
{
lock (_locker1) {
string[] nc = OriginalCode;
bool continueString = false;
for (int i = 0; i < nc.Length; i++)
{
string[] ls = nc[i].Split(new string[] { "\"", "'" }, StringSplitOptions.None);
if (ls.Length % 2 != 0) continueString = !continueString;
for (int x = 0; x < ls.Length; x++)
{
if ((x % 2 == 0 || x == 0) && !continueString)
{
for (int a = 0; a < VslDB.Count; a++)
ls[x].Replace(VslDB[a].Split(':')[0], VslDB[a].Split(':')[1]);
}
else if ((x % 2 == 1 || x == 1) && continueString)
{
for (int a = 0; a < VslDB.Count; a++)
ls[x].Replace(VslDB[a].Split(':')[0], VslDB[a].Split(':')[1]);
}
}
}
return nc;
}
}
public void setSavePath(string fpath)
{
SavePath = fpath;
}
public CompilerErrorCollection C2E(string fpath)
{
//CSharpCodeProvider implements the ICodeCompiler interface and provides access to
//instances of the C# code generator/compilers
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
//Configure the output to be a windows executable with the chosen name at the end of fpath
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = fpath.Split('\\')[fpath.Split('\\').Length - 1];
//Compile the code
CompilerResults results = icc.CompileAssemblyFromSource(parameters, string.Join("", ConvertedCode));
if (results.Errors.Count > 0)
{
return results.Errors;
}
return null;
}
}
}
abs*: abstract
as*: as
bse*: base
btf*: bool
brk*: break
byt*: byte
cse*: case
erc*: catch
chr*: char
chk*: checked
cls*: class
cst*: const
con*: continue
dec*: decimal
def*: default
del*: delegate
do*: do
dub*: double
els*: else
enm*: enum
vnt*: event
xpl*: explicit
xtr*: extern
fls*: false
fin*: finally
fix*: fixed
flt*: float
for*: for
foreach*: foreach
gto*: goto
if*: if
imp*: implicit
in*: in
i32*: int
ntf*: interface
ntnr*: internal
is*: is
lck*: lock
i64*: long
nsp*: namespace
new*: new
nul*: null
obj*: object
opr*: operator
out*: out
ovr*: override
prm*: params
prv*: private
prt*: protected
pub*: public
rdo*: readonly
ref*: ref
ret*: return
sbt*: sbyte
sld*: sealed
i16*: short
szf*: sizeof
alc*: stackalloc
stc*: static
str*: string
stc*: struct
stf*: switch
self*: this
thr*: throw
tru*: true
try*: try
tpf*: typeof
ui32*: uint
ui64*: long
uch*: unchecked
usf*: unsafe
ui16*: ushort
imports*: using
vrt*: virutal
typenull*: void
vol*: volatile
while*: while
stddll:System
.avexcep.data:.AccessViolationException.Data
.avexcep.hl:.AccessViolationException.HelpLink
.avexcep.hr:.AccessViolationException.HResult
.avexcep.innerexcep:.AccessViolationException.InnerException
.avexcep.msg:.AccessViolationException.Message
.avexcep.src:.AccessViolationException.Source
.avexcep.st:.AccessViolationException.StackTrace
.avexcep.targetsite:AccessViolationException.TargetSite
.avexcep.is:AccessViolationException.Equals
.avexcep:.AccessViolationException
.actvatncontxt:.ActivationContext
.actvatr:.Activator
.aggrexcep:.AggregateException
.appdom:.AppDomain
.appdommngr:.AppDomainManager
.appdomsetup:.AppDomainSetup
.appdomunloadedexcep:.AppDomainUnloadedException
.appexcep:.ApplicationException
.appid:.ApplicationId
.appident:.ApplicationIdentity
.argexcep:.ArgumentException
.argnullexcep:.ArgumentNullException
.argoorexcep:.ArgumentOutOfRangeException
.arithexcep:.ArithmeticException
.array:.Array
.arraytypemmexcep:.ArrayTypeMismatchException
.assembldevntargs:.AssemblyLoadEventArgs
.attribute:.Attribute
.attributeusgattribute:.AttributeUsageAttribute
.badimgfrmtexcep:.BadImageFormatException
.b2a2b:.BitConverter
.buffer:.Buffer
.cantunloadappdomexcep:.CannotUnloadAppDomainException
.charenum:.CharEnumerator
.clscompliantattribute:.CLSComplaintAttribute
.con:.Console
.concancelevntargs:.ConsoleCancelEventArgs
.contxtbndobj:.ContextBoundObject
.contxtmarshalexcep:.ContextMarshalException
.contxtstaticattribute:.ContextStaticAttribute
.b2b:.Convert
.datamisalignedexcep:.DataMisalignedException
.dbnull:.DBNull
.delegate:.Delegate
.div0excep:.DivideByZeroException
.dllnfexcep:.DLLNotFoundException
.dupewaitobjexcep:.DuplicateWaitObjectException
.entrypntnfexcep:.EntryPointNotFoundException
.enum:.Enumerator
.enviornment:.Enviornment
.evntargs:.EventArgs
.excep:.Exception
.execengineexcep:.ExecutionEngineException
.fieldaccessexcep:.FieldAccessException
.filestyleuriprsr:.FileStyleUriParser
.flagsattribute:.FlagsAttribute
.formatexcep:.FormatException
.ftpstyleuriprsr:.FtpStyleUriParser
.gc:.GC
.gnricuriprsr:.GenericUriParser
.gphrstyleuriprsr:.GopherStyleUriParser
.httpstyleuriprsr:.HttpStyleUriParser
.indexoorexcep:.IndexOutOfRangeException
.insuffexecstaclexcep:.InsufficientExecutionStackException
.insuffmemexcep:.InsufficientMemoryException
.invalidcastexcep:.InvalidCastException
.invalidopexcep:.InvalidOperationException
.invalidprogramexcep:InvalidProgramException
.invalidtzexcep:.InvalidTimeZoneException
.lazy:.Lazy
.ldapstyleuriprsr:.LdapStyleUriParser
.loaderoptimnattribute:.LoaderOptimizationAttribute
.localdatastrslot:.LocalDataStoreSlot
.marshalrefobj:.MarshalByRefObject
.math:.Math
.memberaccessexcep:.MemberAccessException
.methodaccessexcep:.MethodAccessException
.missfieldexcep:.MissingFieldException
.missmemberexcep:.MissingMemberException
.missingmethodexcep:.MissingMethodException
.mtathrdattribute:.NTAThreadAttribute
.mcdelegate:.MulticastDelegate
.mcnotsupportedexcep:.MulticastNotSupportedException
.netpipestyleuriprsr:.NetPipeStyleUriParser
.nettcpstyleurlprsr:.NetTcpStyleUriParser
.nonserializedattribute:.NonSerializedAttribute
.notfinitenumexcep:.NotFiniteNumberException
.notimplmntdexcep:.NotImplementedException
.notsuppexcep:.NotSupportedException
.nullable:.Nullable
.nullrefexcep:.NullReferenceException
.obj:.Object
.objdisposedexcep:.ObjectDisposedException
.obsattribute:.ObsoleteAttribute
.opsys:.OperatingSystem
.opcanceledexcep:.OperationCanceledException
.oorexcep:.OutOfRangeException
.overflowexcep:.OverflowException
.paramarrayattribute:.ParamArrayException
.pfnotsuppexcep:.PlatformNotSupportedException
.progress:.Progress
.rand:.Random
.rnkexcep:.RankException
.resevntargs:.ResolveEventArgs
.serializableattribute:.SerializableAttribute
.stackoverflowexcep:.StackOverflowException
.stathrdattribute:.STAThreadAttribute
.str:.String
.strcomp:.StringComparer
.sysexcep:.SystemException
.thrdstaticattribute:.ThreadStaticAttribute
.toexcep:.TimeoutException
.tz:.TimeZone
.tzinf:.TimeZoneInfo
.tzinf.adjustrule:.TimeZoneInfo.AdjustmentRule
.tznfexcep:.TimeZoneNotFoundException
.tuple:.Tuple
.type:.Type
.typeaccessexcep:.TypeAccessException
.typeinitexcep:.TypeInitializationException
.typeloadexcep:.TypeLoadException
.typeunloadedexcep:.TypeUnloadedException
.unauthdaccessexcep:.UnauthorizedAccessException
.unhandexcepevntargs:.UnhandledExceptionEventArgs
.uri:.Uri
.uribr:.UriBuilder
.uriformateexcep:.UriFormatException
.uriprsr:.UriParser
.uritmplt:.UriTemplate
.uritmpltequivcomp:.UriTemplateEquivalenceComparer
.uritmpltmatch:.UriTemplateMatch
.uritmpltmatchexcep:.UriTemplateMatchException
.uritmplttable:.UriTemplateTable
.str2uri:.UriTypeConverter
.valtype:.ValueType
.vers:.Version
.weakref:.WeakReference
.winruntimysexcep:.WindowsRuntimeSystemExtensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment