D to Javascript converter (a hacked up dmd)

2012-02-26 Thread Adam D. Ruppe
https://github.com/downloads/adamdruppe/dtojs/dtojs.zip Daniel Murphy's microd fork of dmd, meant to output C, made me realize it'd be fairly easy to use that same method for other languages too. So, I spent some time these last two weekends making it work to put out Javascript. See below for

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Jacob Carlborg
On 2012-02-27 04:51, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip Daniel Murphy's microd fork of dmd, meant to output C, made me realize it'd be fairly easy to use that same method for other languages too. So, I spent some time these last two weekends making it w

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Andrea Fontana
Cool! Can you call custom (external, from 3rd party libs) JS functions from there? You should port jquery syntax sugar :) Il giorno lun, 27/02/2012 alle 09.48 +0100, Jacob Carlborg ha scritto: > On 2012-02-27 04:51, Adam D. Ruppe wrote: > > https://github.com/downloads/adamdruppe/dtojs/dtojs.zi

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Daniel Murphy
"Adam D. Ruppe" wrote in message news:yfmgvgprfpiquakiy...@forum.dlang.org... > https://github.com/downloads/adamdruppe/dtojs/dtojs.zip > > Daniel Murphy's microd fork of dmd, meant to output C, > made me realize it'd be fairly easy to use that same method > for other languages too. > > So, I spe

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread node
Does this mean I can do node.js in D? :) On Monday, 27 February 2012 at 03:51:22 UTC, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip Daniel Murphy's microd fork of dmd, meant to output C, made me realize it'd be fairly easy to use that same method for other languag

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Adam D. Ruppe
On Monday, 27 February 2012 at 09:46:51 UTC, Andrea Fontana wrote: Can you call custom (external, from 3rd party libs) JS functions from there? Yes, just make: extern(js) void function_name_here(...); and you can call it. For jQuery, you'd probably want to define an extern(js) class JQuery {}

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Adam D. Ruppe
On Monday, 27 February 2012 at 11:32:52 UTC, Daniel Murphy wrote: How come you didn't do this as a proper fork/branch of dmd? At first, I downloaded a zip of your fork just to take a look at it - I had no intention of actually modifying it. But, then I started to play around and never cleaned

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Adam D. Ruppe
On Monday, 27 February 2012 at 12:10:17 UTC, node wrote: Does this mean I can do node.js in D? :) Probably. When I did my testing, I ran the code in dmdscript and later, firefox. The javascript it outputs is pretty basic so I imagine it will work in any engine. To access the library, you can d

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Andrea Fontana
Il giorno lun, 27/02/2012 alle 16.09 +0100, Adam D. Ruppe ha scritto: > On Monday, 27 February 2012 at 09:46:51 UTC, Andrea Fontana wrote: > > Can you call custom (external, from 3rd party libs) > > JS functions from there? > > Yes, just make: > > extern(js) void function_name_here(...); Good

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Adam D. Ruppe
On Monday, 27 February 2012 at 15:39:50 UTC, Andrea Fontana wrote: About jquery: i mean what about a d function similar to $() jquery function for better elements handling (instead of getElementById() ) Have you seen my dom library? :P It's all server side but it is just awesome. Lots of con

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Andrea Fontana
Il giorno lun, 27/02/2012 alle 16.55 +0100, Adam D. Ruppe ha scritto: > On Monday, 27 February 2012 at 15:39:50 UTC, Andrea Fontana wrote: > > About jquery: i mean what about a d function similar to $() > > jquery > > function for better elements handling (instead of > > getElementById() ) > >

Re: D to Javascript converter (a hacked up dmd)

2012-02-27 Thread Daniel Murphy
"Adam D. Ruppe" wrote in message news:cjalubgkkdpdacsig...@forum.dlang.org... > On Monday, 27 February 2012 at 11:32:52 UTC, Daniel Murphy wrote: >> How come you didn't do this as a proper fork/branch of dmd? > > At first, I downloaded a zip of your fork just to take a > look at it - I had no int

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Don Clugston
On 27/02/12 16:16, Adam D. Ruppe wrote: On Monday, 27 February 2012 at 11:32:52 UTC, Daniel Murphy wrote: How come you didn't do this as a proper fork/branch of dmd? At first, I downloaded a zip of your fork just to take a look at it - I had no intention of actually modifying it. But, then I

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Adam D. Ruppe
On Tuesday, 28 February 2012 at 09:30:41 UTC, Don Clugston wrote: CTFE is entirely implemented in interpret.c. Treatment of the runtime part of (__ctfe) is in the glue layer, that's probably what you saw. Outstanding! As a side note, I've been looking at dmdscript when I want a detailed refe

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Piotr Szturmaj
Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip Daniel Murphy's microd fork of dmd, meant to output C, made me realize it'd be fairly easy to use that same method for other languages too. So, I spent some time these last two weekends making it work to put out Javasc

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Adam D. Ruppe
On Tuesday, 28 February 2012 at 19:27:57 UTC, Piotr Szturmaj wrote: Can it compile a function to native code and JS simultaneously? I want to execute the same code on both client and server side. You'd have to run dmd twice because it exits before getting to the backend when doing js. But you

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Chad J
Fuck. Yes. Combined with HTML5 and such, this might be an awesome way to write web-based games. Please do more!

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Piotr Szturmaj
Adam D. Ruppe wrote: On Tuesday, 28 February 2012 at 19:27:57 UTC, Piotr Szturmaj wrote: Can it compile a function to native code and JS simultaneously? I want to execute the same code on both client and server side. You'd have to run dmd twice because it exits before getting to the backend wh

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 02:42:38 UTC, Piotr Szturmaj wrote: 44 KB - that's not bad! It actually gets better: 9kb if you trim the mangled names down to size (I've written a mangle name trimmer and an unused function cutter; hello world is about 200 bytes.). The reason it didn't work

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Piotr Szturmaj
Adam D. Ruppe wrote: The reason it didn't work before wasn't just dollar, but also ref params. This was a bit of a pain.. without pointers, how can I implement this? After thinking on it for almost an hour, I decided on passing lambdas instead: void a(ref b) { b = 10; } int c = 5; a(c); assert

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 03:24:17 UTC, Piotr Szturmaj wrote: What about passing values within object? Yeah, that's one of the first things I thought of, but what about a more complex thing: d = a(c) + 4; where will the c=wrapper.value go? It can't go at the end of the function call

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Piotr Szturmaj
Adam D. Ruppe wrote: On Wednesday, 29 February 2012 at 03:24:17 UTC, Piotr Szturmaj wrote: What about passing values within object? Yeah, that's one of the first things I thought of, but what about a more complex thing: d = a(c) + 4; where will the c=wrapper.value go? It can't go at the end

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 04:02:54 UTC, Piotr Szturmaj wrote: but this implies that all value variables must be initialized with new Wrapper(x). Yeah. I don't like that because it means you pay for something that you aren't necessarily going to use. Now, it could follow the variable an

Re: D to Javascript converter (a hacked up dmd)

2012-02-28 Thread sclytrack
On 02/28/2012 08:56 PM, Adam D. Ruppe wrote: On Tuesday, 28 February 2012 at 19:27:57 UTC, Piotr Szturmaj wrote: Can it compile a function to native code and JS simultaneously? I want to execute the same code on both client and server side. You'd have to run dmd twice because it exits before g

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Robert Clipsham
On 29/02/2012 03:11, Adam D. Ruppe wrote: On Wednesday, 29 February 2012 at 02:42:38 UTC, Piotr Szturmaj wrote: 44 KB - that's not bad! It actually gets better: 9kb if you trim the mangled names down to size (I've written a mangle name trimmer and an unused function cutter; hello world is abou

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Robert Clipsham
On 29/02/2012 09:18, Robert Clipsham wrote: On 29/02/2012 03:11, Adam D. Ruppe wrote: On Wednesday, 29 February 2012 at 02:42:38 UTC, Piotr Szturmaj wrote: 44 KB - that's not bad! It actually gets better: 9kb if you trim the mangled names down to size (I've written a mangle name trimmer and a

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 09:27:53 UTC, Robert Clipsham wrote: Pretty impressive! It did spit out 86 warnings though... A lot of it is probably the same kind of thing my "linker" does. (I call it that, but it doesn't actually *link* anything.) I get down to 6 KB running it through that

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
I found the std.algorithm problem. I skipped outputting templated structs because it crashes my compiler. For some reason. microd.d(130): Error: variable t forward declaration Segmentation fault. Poo. Function templates work fine, though.

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Bystroushaak
> Daniel Murphy's microd fork of dmd, meant to output C Link please.

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Robert Clipsham
On 29/02/2012 16:56, Bystroushaak wrote: Daniel Murphy's microd fork of dmd, meant to output C Link please. https://github.com/yebblies/dmd/tree/microd -- Robert http://octarineparrot.com/

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Andrei Alexandrescu
On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interesting. So the idea is to make an entire subset of D convertible to Javascript? What use cases do you have in mind? Andrei

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Alex Rønne Petersen
On 29-02-2012 18:32, Andrei Alexandrescu wrote: On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interesting. So the idea is to make an entire subset of D convertible to Javascript? What use cases do you have in mind? Andrei A

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 15:46:40 UTC, Adam D. Ruppe wrote: microd.d(130): Error: variable t forward declaration Segmentation fault. And that's fixed... and handling if(__ctfe)... and boom! It worked. Generated 70 KB of javascript though, a lot of it is obvious garbage - global variab

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 17:32:42 UTC, Andrei Alexandrescu wrote: So the idea is to make an entire subset of D convertible to Javascript? What use cases do you have in mind? Andrei

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Piotr Szturmaj
Adam D. Ruppe wrote: But, wrapping might be fun. I could probably do & 0xff if and only if D otherwise forces it to be a ubyte. But, what about the bit pattern of negative numbers? Take a look at WebGL's Typed Arrays. They allow explicit size integers and binary operators. The disadvantage is

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Nick Sabalausky
"Alex Rønne Petersen" wrote in message news:jilnie$1fsr$1...@digitalmars.com... > On 29-02-2012 18:32, Andrei Alexandrescu wrote: >> On 2/26/12 9:51 PM, Adam D. Ruppe wrote: >>> https://github.com/downloads/adamdruppe/dtojs/dtojs.zip >> [snip] >> >> That's interesting. So the idea is to make an e

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
Sorry if I sent twice, it is so easy to hit the wrong button on things. On Wednesday, 29 February 2012 at 17:32:42 UTC, Andrei Alexandrescu wrote: So the idea is to make an entire subset of D convertible to Javascript? Yeah, and I'm pretty much there - I just built a little sort program with

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Bystroushaak
Thx. On 29.2.2012 18:03, Robert Clipsham wrote: > On 29/02/2012 16:56, Bystroushaak wrote: >>> Daniel Murphy's microd fork of dmd, meant to output C >> >> Link please. > > https://github.com/yebblies/dmd/tree/microd >

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Dmitry Olshansky
On 29.02.2012 21:58, Adam D. Ruppe wrote: [...] 4) This is an insane idea, but one that came to mind. I'm testing this by piping the generated JS into dmdscript. dmd runs insanely fast when compiling this code. Phobos is kinda slow to compile, but you don't have to use it here. Write D1 style c

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
On Wednesday, 29 February 2012 at 19:10:27 UTC, Dmitry Olshansky wrote: If you are serious about dmd I would recommend it, as I've spent weeks to figure out proper try/catch/finally implementation and fix closures that were broken. Indeed, I still have a copy of your zip from before. I tried

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Dmitry Olshansky
On 29.02.2012 23:40, Adam D. Ruppe wrote: On Wednesday, 29 February 2012 at 19:10:27 UTC, Dmitry Olshansky wrote: If you are serious about dmd I would recommend it, as I've spent weeks to figure out proper try/catch/finally implementation and fix closures that were broken. Indeed, I still have

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Adam D. Ruppe
I probably should have been working today but instead spent a good amount of time on this again. New zip: https://github.com/downloads/adamdruppe/dtojs/dtojs-0.3.zip (I haven't cleaned up the github fork yet) To give you an idea of what is working, check out my tests.d file: http://arsdne

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Jacob Carlborg
On 2012-03-01 06:20, Adam D. Ruppe wrote: I probably should have been working today but instead spent a good amount of time on this again. BTW, how do you fit D's class based object model in JavaScript's prototype based object model? -- /Jacob Carlborg

Re: D to Javascript converter (a hacked up dmd)

2012-02-29 Thread Mikael Lindsten
2012/2/29 Adam D. Ruppe > 4) This is an insane idea, but one that came to mind. > I'm testing this by piping the generated JS into > dmdscript. > > dmd runs insanely fast when compiling this code. Phobos > is kinda slow to compile, but you don't have to use it > here. Write D1 style code and dmd

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Daniel Murphy
I love how this started as interesting and turned into awesome. Web programming... might actually become non-horrible?

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Daniel Murphy
"Bystroushaak" wrote in message news:mailman.239.1330541205.24984.digitalmars-d-annou...@puremagic.com... > Thx. > > On 29.2.2012 18:03, Robert Clipsham wrote: >> On 29/02/2012 16:56, Bystroushaak wrote: Daniel Murphy's microd fork of dmd, meant to output C >>> >>> Link please. >> >> https:

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 07:14:02 UTC, Jacob Carlborg wrote: BTW, how do you fit D's class based object model in JavaScript's prototype based object model? Short answer is each D object in JS has a virtual function array and implements array as properties attached to the object. The JS cons

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Marco Leise
Am 29.02.2012, 18:32 Uhr, schrieb Andrei Alexandrescu : On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interesting. So the idea is to make an entire subset of D convertible to Javascript? What use cases do you have in mind? A

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Robert Clipsham
On 01/03/2012 05:20, Adam D. Ruppe wrote: I probably should have been working today but instead spent a good amount of time on this again. New zip: https://github.com/downloads/adamdruppe/dtojs/dtojs-0.3.zip (I haven't cleaned up the github fork yet) To give you an idea of what is working

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 16:29:10 UTC, Robert Clipsham wrote: Perhaps it would be better to have a dedicated function for that though. eval() :) I considered doing asm {} for javascript, but that'd be a pretty invasive change to the compiler, so I decided against it; I want to keep most th

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Andrei Alexandrescu
On 2/29/12 11:58 AM, Adam D. Ruppe wrote: Sorry if I sent twice, it is so easy to hit the wrong button on things. On Wednesday, 29 February 2012 at 17:32:42 UTC, Andrei Alexandrescu wrote: So the idea is to make an entire subset of D convertible to Javascript? Yeah, and I'm pretty much there

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Ary Manzana
On 2/29/12 2:34 PM, Alex Rønne Petersen wrote: On 29-02-2012 18:32, Andrei Alexandrescu wrote: On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interesting. So the idea is to make an entire subset of D convertible to Javascript? W

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Timon Gehr
On 03/01/2012 07:04 PM, Ary Manzana wrote: I think it's cool you can convert D to JS, but I don't see why anyone would want to do it. 1. JS is a superior language: [snip.] Nope.

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Alex Rønne Petersen
On 01-03-2012 19:04, Ary Manzana wrote: On 2/29/12 2:34 PM, Alex Rønne Petersen wrote: On 29-02-2012 18:32, Andrei Alexandrescu wrote: On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interesting. So the idea is to make an entire

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 18:56:07 UTC, Alex Rønne Petersen wrote: Valid argument. Maybe we can make the D -> JS converter help in some way here? I don't know yet. assert() in your D code, while a far cry from a real debugger, does have the decency to give file and line number in your browse

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 17:35:02 UTC, Andrei Alexandrescu wrote: The motivation sounds great. I think one area of focus going forward might be defining precisely the subset of D supported (e.g. I suppose pointer semantics would be difficult). Right. I'm not sure exactly what is and is not

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 18:04:35 UTC, Ary Manzana wrote: 6. Javascript objects have some built-in properties that are different from D. So implementing those in D would make their performance worse (but you can always hard-code those functions into the compiler and translate them directly

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Jacob Carlborg
On 2012-03-01 16:07, Adam D. Ruppe wrote: On Thursday, 1 March 2012 at 07:14:02 UTC, Jacob Carlborg wrote: BTW, how do you fit D's class based object model in JavaScript's prototype based object model? Short answer is each D object in JS has a virtual function array and implements array as pro

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Bill Baxter
On Thu, Mar 1, 2012 at 11:13 AM, Adam D. Ruppe wrote: > > Some integer semantics might be hard too. ubyte is ok, but byte > is different because 127+1 isn't as simple as x & 0xff > > I'll have to think about that. Again, it surely *can* > be done, but I'd rather than an error than it generating > h

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Jacob Carlborg
On 2012-03-01 19:04, Ary Manzana wrote: On 2/29/12 2:34 PM, Alex Rønne Petersen wrote: On 29-02-2012 18:32, Andrei Alexandrescu wrote: On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interesting. So the idea is to make an entire

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Jacob Carlborg
On 2012-03-01 19:56, Alex Rønne Petersen wrote: On 01-03-2012 19:04, Ary Manzana wrote: 3. With JS you don't have to compile and run your code (well, I guess you could make something smart in D for that). ? The D -> JS converter just translates it. It's no different from running e.g. the Coffe

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Bystroushaak
I've played with gdc, but it's pretty complicated. I have few ADM 5120 routers with debwrt and it would be nice to be able compile D2 code there, but so far, it was just fail. C run pretty much everywhere and metacompiler D2C would be nice.. On 1.3.2012 09:05, Daniel Murphy wrote: > "Bystroushaak

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 19:49:46 UTC, Bill Baxter wrote: Might TypedArrays help you implement some number type semantics? Yeah, I think so. I do have compatibility concerns though; it'd be a pity of something taking a ubyte means it doesn't work in IE8 anymore. I'll have to play with it t

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Daniel Murphy
"Bystroushaak" wrote in message news:mailman.281.1330632834.24984.digitalmars-d-annou...@puremagic.com... > I've played with gdc, but it's pretty complicated. I have few ADM 5120 > routers with debwrt and it would be nice to be able compile D2 code > there, but so far, it was just fail. > > C run

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Adam D. Ruppe
On Thursday, 1 March 2012 at 08:01:07 UTC, Daniel Murphy wrote: Web programming... might actually become non-horrible? hehe. I already found it ok though; I've been using D on the server for... will be two years in a couple weeks. Javascript isn't bad if you use it sparingly, and in the last y

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Jean-Bernard Pellerin
This will go nicely with the web framework I'm building in D. I'm borrowing heavily from silverlight. Here's a teaser (sorry, neglected to comment the code...) Here's a sample code file (CGI script for apache, I'm new to these web technologies): http://pastebin.com/SpfmfpmS and here's what t

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Nick Sabalausky
"Ary Manzana" wrote in message news:jiodnj$ric$1...@digitalmars.com... > > I think it's cool you can convert D to JS, but I don't see why anyone > would want to do it. > > 1. JS is a superior language: variables are dynamic and are not bound to > just one single type during their lifetime. JS o

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Nick Sabalausky
"Adam D. Ruppe" wrote in message news:uvagboafiyjrhvywp...@forum.dlang.org... > > but I'd rather than an error than it generating > horribly inefficient javascript for simple operations. > You make it sound as if there's another kind of JS.

Re: D to Javascript converter (a hacked up dmd)

2012-03-01 Thread Jacob Carlborg
On 2012-02-29 18:46, Nick Sabalausky wrote: "Alex Rønne Petersen" wrote in message news:jilnie$1fsr$1...@digitalmars.com... On 29-02-2012 18:32, Andrei Alexandrescu wrote: On 2/26/12 9:51 PM, Adam D. Ruppe wrote: https://github.com/downloads/adamdruppe/dtojs/dtojs.zip [snip] That's interest

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Jacob Carlborg
On 2012-03-02 03:28, Adam D. Ruppe wrote: On Thursday, 1 March 2012 at 08:01:07 UTC, Daniel Murphy wrote: Web programming... might actually become non-horrible? As far as I can tell, we have variable lifetime! (JS's garbage collector is still a question, and some of the variables are global -

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Johannes Pfau
Am Thu, 01 Mar 2012 21:13:41 +0100 schrieb Bystroushaak : > I've played with gdc, but it's pretty complicated. I have few ADM 5120 > routers with debwrt and it would be nice to be able compile D2 code > there, but so far, it was just fail. > ADM 5120 is MIPS, right? Are you trying to build a cro

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Alix Pexton
On 02/03/2012 02:28, Adam D. Ruppe wrote: 3) The JS language doesn't have block scoping like D. Have you considered faking scopes in JS using anonymous functions? var foo; (function(a, b){ var foo; // not the same as the foo outside the func! // do stuff }(x, y)); // inv

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Daniel Murphy
"Jacob Carlborg" wrote in message news:jipus9$v81$1...@digitalmars.com... > On 2012-03-02 03:28, Adam D. Ruppe wrote: >> On Thursday, 1 March 2012 at 08:01:07 UTC, Daniel Murphy wrote: >>> Web programming... might actually become non-horrible? >> >> As far as I can tell, we have variable lifetime

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Jacob Carlborg
On 2012-03-02 10:57, Daniel Murphy wrote: "Jacob Carlborg" wrote in message news:jipus9$v81$1...@digitalmars.com... On 2012-03-02 03:28, Adam D. Ruppe wrote: On Thursday, 1 March 2012 at 08:01:07 UTC, Daniel Murphy wrote: Web programming... might actually become non-horrible? As far as I ca

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Daniel Murphy
"Jacob Carlborg" wrote in message news:jiq8kb$1ht0$1...@digitalmars.com... >> >> CommaExp's containing Declarations > > Is he saying "var a, b, c;" is invalid JavaScript code? > > -- > /Jacob Carlborg It's invalid if it's a comma expression. eg. auto x = (auto a = 3, a); Which dmd creates _e

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Adam D. Ruppe
On Friday, 2 March 2012 at 05:58:03 UTC, Nick Sabalausky wrote: You make it sound as if there's another kind of JS. Horribly inefficient relative to the environment :P I just don't want 100 kb of crap to download just to write a hello world. A lot of people prefer to use gzipped sizes, but I

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Bystroushaak
I think once you get past the horror that is building gcc for your target > platform, the big issue remaining is that druntime needs to be ported. There is actually gdc package in debwrt, but it is D1 :( You'll hit the same issue with a D->C translator, so it might be better just to work on th

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Adam D. Ruppe
On Friday, 2 March 2012 at 09:33:44 UTC, Alix Pexton wrote: Have you considered faking scopes in JS using anonymous functions? Yeah, though right now I'm trusting the D compiler to keep it straight, and it is doing a pretty good job while being really simple to code. What happens is all the lo

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Adam D. Ruppe
Here's one of the nicer things to do: http://arsdnet.net/dtojs/game.d http://arsdnet.net/dtojs/game.html we can do little browser games in D. If you look at game.js: http://arsdnet.net/dtojs/game.js you can see it is similar in size to the original D file (this is after running tools/gcfunctio

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Bystroushaak
> ADM 5120 is MIPS, right? Are you trying to build a cross compiler or a > compiler running on the MIPS itself? Compiler running on the MIPS. > And MIPS is probably also affected by GDC issue 120, so you have to > configure like this: > DFLAGS="-fno-section-anchors" ./configure [configure argume

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Nick Sabalausky
"Jacob Carlborg" wrote in message news:jiptfu$qrg$1...@digitalmars.com... > On 2012-02-29 18:46, Nick Sabalausky wrote: >> "Alex Rønne Petersen" wrote in message >> news:jilnie$1fsr$1...@digitalmars.com... >>> On 29-02-2012 18:32, Andrei Alexandrescu wrote: On 2/26/12 9:51 PM, Adam D. Ruppe

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Nick Sabalausky
"Adam D. Ruppe" wrote in message news:arowwzayimwhzmqah...@forum.dlang.org... > On Friday, 2 March 2012 at 05:58:03 UTC, Nick Sabalausky wrote: >> You make it sound as if there's another kind of JS. > > Horribly inefficient relative to the environment :P > > I just don't want 100 kb of crap to do

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Adam D. Ruppe
On Friday, 2 March 2012 at 18:28:15 UTC, Nick Sabalausky wrote: Suggestion: Allow all D features even if it requires...inefficient-er...boilerplate, BUT then have a system [...] Eh. A problem there is those pragmas or whatever would be unrecognized by the real dmd. A command line switch, maybe

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Nick Sabalausky
"Adam D. Ruppe" wrote in message news:wplwmjdlvvqcokxyk...@forum.dlang.org... > Here's one of the nicer things to do: > > http://arsdnet.net/dtojs/game.d > http://arsdnet.net/dtojs/game.html > > we can do little browser games in D. > > If you look at game.js: > http://arsdnet.net/dtojs/game.js >

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Marco Leise
Am 29.02.2012, 04:11 Uhr, schrieb Adam D. Ruppe : sort can be a wrapper of Array.prototype.sort() from Javascript, thus letting us leave out the implementation. Odds are the native method will be faster anyway. That's right, although at least Google tries to implement the predefined functions

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Daniel Murphy
"Adam D. Ruppe" wrote in message news:omhitgvibquioulpc...@forum.dlang.org... > > If I add a way to instead put those var declarations in > function scope, it is cleaner - no globals - and the same > thing Javascript itself would do anyway! > > > I'll have to redo the string buffering to make tha

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 00:56:48 UTC, Daniel Murphy wrote: Something like this should work: Awesome, it does! Thanks.

Re: D to Javascript converter (a hacked up dmd)

2012-03-02 Thread Nick Sabalausky
"Adam D. Ruppe" wrote in message news:sazpaicrjwzchqcfw...@forum.dlang.org... > On Friday, 2 March 2012 at 18:28:15 UTC, Nick Sabalausky wrote: >> Suggestion: Allow all D features even if it >> requires...inefficient-er...boilerplate, BUT then have a system [...] > > Eh. A problem there is those

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Jacob Carlborg
On 2012-03-02 15:57, Adam D. Ruppe wrote: On Friday, 2 March 2012 at 09:33:44 UTC, Alix Pexton wrote: Have you considered faking scopes in JS using anonymous functions? Yeah, though right now I'm trusting the D compiler to keep it straight, and it is doing a pretty good job while being really

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Jacob Carlborg
On 2012-03-02 15:38, Adam D. Ruppe wrote: On Friday, 2 March 2012 at 05:58:03 UTC, Nick Sabalausky wrote: You make it sound as if there's another kind of JS. Horribly inefficient relative to the environment :P I just don't want 100 kb of crap to download just to write a hello world. A lot of

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Alix Pexton
On 03/03/2012 12:12, Jacob Carlborg wrote: On 2012-03-02 15:57, Adam D. Ruppe wrote: On Friday, 2 March 2012 at 09:33:44 UTC, Alix Pexton wrote: Have you considered faking scopes in JS using anonymous functions? Yeah, though right now I'm trusting the D compiler to keep it straight, and it is

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Jacob Carlborg
On 2012-03-02 19:13, Nick Sabalausky wrote: "Jacob Carlborg" wrote in message news:jiptfu$qrg$1...@digitalmars.com... On 2012-02-29 18:46, Nick Sabalausky wrote: "Alex Rønne Petersen" wrote in message news:jilnie$1fsr$1...@digitalmars.com... On 29-02-2012 18:32, Andrei Alexandrescu wrote:

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Jacob Carlborg
On 2012-03-03 06:56, Nick Sabalausky wrote: "Adam D. Ruppe" wrote in message news:sazpaicrjwzchqcfw...@forum.dlang.org... On Friday, 2 March 2012 at 18:28:15 UTC, Nick Sabalausky wrote: Suggestion: Allow all D features even if it requires...inefficient-er...boilerplate, BUT then have a system

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Daniel Murphy
"Jacob Carlborg" wrote in message news:jit2r7$rlu$2...@digitalmars.com... >> I thought unrecognized pragmas were supposed to just be ignored? (Or >> maybe I >> have it backwards?) >> >> > > No, they're not: > > "Compilers must diagnose an error for unrecognized Pragmas, even if they > are vendo

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 12:12:53 UTC, Jacob Carlborg wrote: Wouldn't you save a lot of characters by properly scoping the variables instead of using unique names? There's no such thing as proper scoping in Javascript. The next best thing is the nested functions, but that's really just tra

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 12:10:47 UTC, Jacob Carlborg wrote: No, we don't want to do it like Dart: 17260 lines of code for Hello World. Wow. I thought I was a bit on the bloated side with ~100 lines of boilerplate (before running the unused function stripper). $ ../dmd -md object.d DMD v2.

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 16:29:25 UTC, Adam D. Ruppe wrote: There's no such thing as proper scoping in Javascript. Let me expand a bit. consider this D: if(1) { int a = 3; } In JS, right now, that'd output: if(1) { var mangled_a = 3; } which, to the interpreter, is: var mangled

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Jacob Carlborg
On 2012-03-03 17:29, Adam D. Ruppe wrote: On Saturday, 3 March 2012 at 12:12:53 UTC, Jacob Carlborg wrote: Wouldn't you save a lot of characters by properly scoping the variables instead of using unique names? There's no such thing as proper scoping in Javascript. The next best thing is the n

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread James Miller
On 4 March 2012 05:40, Adam D. Ruppe wrote: > On Saturday, 3 March 2012 at 12:10:47 UTC, Jacob Carlborg wrote: >> >> No, we don't want to do it like Dart: >> 17260 lines of code for Hello World. > > > Wow. I thought I was a bit on the bloated side with > ~100 lines of boilerplate (before running t

Re: D to Javascript converter (a hacked up dmd)

2012-03-03 Thread Andrej Mitrovic
On 3/3/12, Adam D. Ruppe wrote: > Oh another thing: global variables in D are module scoped. Could export help?

  1   2   >