From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1PiBG2-0005V1-3b for garchives@archives.gentoo.org; Wed, 26 Jan 2011 19:42:22 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DB927E0A98; Wed, 26 Jan 2011 19:40:41 +0000 (UTC) Received: from mail-ew0-f53.google.com (mail-ew0-f53.google.com [209.85.215.53]) by pigeon.gentoo.org (Postfix) with ESMTP id 75F75E0A98 for ; Wed, 26 Jan 2011 19:40:41 +0000 (UTC) Received: by ewy6 with SMTP id 6so489669ewy.40 for ; Wed, 26 Jan 2011 11:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=4mzVdgJZHmgCeR/fTHlzuIS3Kd54kb5E256GxORhA7A=; b=OmvQ5HtA6751XiLSp4rhxA8Gf1aVwqoib/BKOr2xdyyH7GsrTtkdOnQeVOzb8r5E3t f18w0dEshLbJS/uTDPaVp/4qAAFNObKU8K9cuqQUcLCJnQW5/vGZNUmgMhn40wMUhbJa 6iwqAvMLbwm/99HKbZAgrJQdg6PrvDlT8uabc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=fuxCgbg+oihMOFop+LV7DCm/eIHlk6yaJvPyJcpBWAiqtGPU2c9oM1e7Hef5xovuKH 4qPicZ2Szg+mMQyigtjm9d8pzeHQ9oreY3w/dAIvx60n/QoCwL6h/IB+wMiu6bBz1lFb lGFmHi5epbUKSfr85f/agDI/7eZVktZxidCW4= Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Received: by 10.216.0.140 with SMTP id 12mr915836web.29.1296070839595; Wed, 26 Jan 2011 11:40:39 -0800 (PST) Received: by 10.216.16.21 with HTTP; Wed, 26 Jan 2011 11:40:39 -0800 (PST) In-Reply-To: <4D406C3D.3010503@orlitzky.com> References: <4D3F75A4.7070100@orlitzky.com> <4D406C3D.3010503@orlitzky.com> Date: Wed, 26 Jan 2011 11:40:39 -0800 Message-ID: Subject: Re: [gentoo-user] [OT] - Code translation tools? From: Mark Knecht To: gentoo-user@lists.gentoo.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 07cb382f241ed7767e66e9f44fac5e6d On Wed, Jan 26, 2011 at 10:47 AM, Michael Orlitzky w= rote: > On 01/26/2011 12:56 PM, Mark Knecht wrote: >> Michael, >> =C2=A0 =C2=A0Thanks for the inputs. It gives me more to think about. >> >> =C2=A0 =C2=A0In this case the input language is interpreted, not compile= d. The >> trading platform interprets the program and internally turns it into >> buy & sell operations. (Not the piece of code I supplied - that was >> just a small function.) Unfortunately, as the language is proprietary >> to the trading platform there isn't a way to go to any common >> low-level language. >> >> =C2=A0 =C2=A0The 'battery of tests' would be, I think, the trading progr= am being >> executed on a certain market, producing a certainly list of buy & sell >> operations and a specific gain or loss. It would be quite easy to >> compare the outcome because it's nothing more than a list of trades. >> If the translated code generates the same list then it works. If not, >> I dig into why. This part of the task seems relatively straight >> forward to me. >> >> =C2=A0 =C2=A0I was mainly hoping to find a tool that might generate _rea= sonable_ >> C code, even if it's not perfect. If the C code compiles and runs then >> I could determine what works, what doesn't, and start fixing things. >> I'm not a C programmer and haven't touched that language in at least >> 15 years so anything that moves me forward would be helpful. >> >> =C2=A0 =C2=A0Again, I do appreciate your inputs. If this extra info give= s you >> any new ideas please let me know. > > If you don't even have a common low-level language, what you're > essentially doing is creating a compiler for EasyLanguage. Take a small > example, adding two integers in E.L. I won't pretend to know the syntax, > but let's just assume that you have two integers (or numbers or > whatever) 'a' and 'b' declared. > > How do you translate "a+b" to C code? You can declare two ints 'a' and > 'b' in C, of course. But these are 32- or 64-bit integers. So if 'a' and > 'b' are large, "a+b" will overflow. Do EasyLanguage integers work that > way? Probably not... > > How about "a/b"? Does EasyLanguage do integer division, or does it treat > them like floats? If it does treat them like floats, do the rounding and > precision agree with C floats? Probably not, so floats are out too. > > If you try to fix all of these problems, what you'll end up with is > something like a struct EasyLanguageInteger {...} with associated > functions add_easylanguage_integers, divide_easylanguage_integers, etc. > Then, you can translate "a+b" into add_easylanguage_integers(a, b) where > 'a' and 'b' are now structs instead of just ints or floats. > > Then, you'll have to write a parser that understands the rules of > precedence, looping constructs, functions, and everything else so that > they can be converted into the appropriate structs and function calls. > At the end, if it works, you'll have an EasyLanguage compiler. > > Without a spec (the language is proprietary?), you'd have to guess at > most of that stuff anyway, so the chances you'd get it all right are > about zero. > > Your best bet[1] is to create a ton of test data, and feed it to the > E.L. program. Make sure the test data triggers any edge cases. Then you > can attempt to rewrite the code in C, and compare the output. You as a > human who understands what the code does can take a lot of shortcuts > that a translator couldn't. > > > [1] I'm assuming you want to do this for a relatively small number of > programs, and that writing a compiler would not actually be less > time-consuming. > > OK - this is probably WAY too off topic for this list. If folks strongly want me to stop the thread I will but I appreciate the technical adeptness of folks on this list quite a lot and the eventual outcome would be the use of this thing on Gentoo, so I hope folks won't mind too much if we continue a little further. REALLY great points about the math issues. Thanks. As for testing it _may_ be a slight bit easier than having to get to that level. There is a library in portage called ta-lib which implements lots of standard technical analysis constructs. After it's installed I don't seem to have the C code for the actual functions anymore. What I have is a compiled library as well as some header files to look at. I suspect I can install the library again using portage bt not getting rid of the functions which I could then use as an example for my coding. I have not used this library myself, but I've read enough on the web to be reasonably sure it's results are very consistent with what TradeStation functions of the same type do. For a simple function call like a moving average EasyLanguage would write: Inputs: Price(Close), Length(10) ; variable: MA1(0) ; MA1 =3D Average(Price,Length); Here is what I see for a similar moving average function from ta-lib: /* * TA_MA - Moving average * * Input =3D double * Output =3D double * * Optional Parameters * ------------------- * optInTimePeriod:(From 1 to 100000) * Number of period * * optInMAType: * Type of Moving Average * * */ TA_RetCode TA_MA( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, /* From 1 to 100000 */ TA_MAType optInMAType, int *outBegIdx, int *outNBElement, double outReal[] ); TA_RetCode TA_S_MA( int startIdx, int endIdx, const float inReal[], int optInTimePeriod, /* From 1 to 100000 */ TA_MAType optInMAType, int *outBegIdx, int *outNBElement, double outReal[] ); int TA_MA_Lookback( int optInTimePeriod, /* From 1 to 100000 */ TA_MAType optInMAType ); Maybe I could use the definitions of these functions as a basis for understanding what might be a reasonable set of guesses? From my point of view, a good start at translation would be to use whatever is available in ta-lib whenever possible and only have to deal with other stuff like If/Else, Switch, etc. Just thinking. Thanks, Mark