Will there ever be a possibility in the future to compile from D 2.0 to Javascript?

An experienced C++ programmer (that's me) is venturing into other programming languages and considering the value of learning more about D 2.0. The clean, fresh rewrite of D has caught my eye with its pragmatic and wise choices. Now, I'm eager to delve deeper and explore whether it is possible to:

  1. Write code in D 2.0. (Potentially a well-defined subset of D 2.0.)
  2. Compile the aforementioned code.
  3. Obtain Javascript source code from this compilation process.

In essence, I am seeking a D 2.0 compiler with a capable backend for generating Javascript.

My inquiry consists of two main parts:

  1. Does such a compiler already exist?
  2. If not, and if I were to build one myself, where would be the best starting point?

To provide context, the reason behind my quest is to develop a set of business logic in D 2.0 and then utilize that logic in a purely Javascript-based web application (without involving Flash, Silverlight, or Java).

Update

I have received three responses - two relevant and one unrelated which was disregarded.

@FeepingCreature suggests that it may never happen due to being "incongruous with D's targeted environment." I have inquired further on this aspect.

In contrast, @Nekuromento indicates that it can technically be achieved using LDC followed by the LLVM Javascript backend. After checking out both resources, it seems plausible although there are some optimization and minification issues present. Nevertheless, it appears to be functional enough to serve its purpose.

Update 2

Based on current information, here is the most viable approach:

  1. Utilize LDC as suggested by @Nekuromento since it combines Digital Mars with an LLVM backend.
  2. Channel the output through the LLVM Javascript backend as recommended by @Nekuromento.
  3. Further optimize the output using Closure as proposed by @BCS.

I will select the best solution soon but would appreciate additional informed opinions.

Update 3

To elaborate on the reasoning behind this endeavor:

For instance, one specific project I intend to undertake is a geometric modeling library authored primarily by myself over the course of several years, amounting to around 100,000 lines of code. The goal is to minimize bugs to the greatest extent possible, hence avoiding development in Javascript. It should operate across servers, desktops, and browsers without requiring plugins like Flash, Silverlight, or Java. Given the persistence of Javascript within the browsing landscape, strategies need to be devised accordingly.

Update 4

Although I hoped for more responses, I appreciate all the feedback provided, including the insightful comments from @dsimicha. Disagreements are welcomed in a constructive manner. I have accepted the answer given by @Nekuromento.

Update 5 2018-07-18

With advancements in technology, LDC version 1.11 now supports compiling and linking to WebAssembly. More details available here.

Answer №1

At this time, there is no existing compiler with the capability to generate JavaScript code directly. However, there are ongoing efforts related to a javascript LLVM-backend.

Another option worth considering is LDC, which utilizes the DMD front-end and LLVM. It may be feasible to incorporate JavaScript output into LDC.

Answer №2

Stay tuned to the latest updates on the D forums in the coming days as I am developing something that may pique your interest (or precisely what you are looking for). It is currently capable of compiling:

int bar()
{
    if (false)
    {
        return 7;
    }
}

I aim to release an alpha/beta version within the next week.

Answer №3

Simply put: No.

To elaborate: Absolutely not.

A more serious answer: It would not fit well with D's specific environment.

If you do decide to go ahead with implementing it - well, good luck, but be prepared for a challenge. It might be a good idea to start by familiarizing yourself with the DMD frontend, which is open-source and included in the standard DMD zip file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I configure Express to act as a pass-through proxy server?

How can I set up an express server to act as a proxy? Requirements: Support for both http and https Ability to function behind a corporate proxy Option to provide custom content for specific URLs I have experimented with various modules such as http-pr ...

How to Route in Angular 5 and Pass a String as a Parameter in the URL

I am currently working on an Angular project that focuses on geographic system data. The concept is as follows: I have a component with the route: {path: 'home'}. I aim to pass a geojson URL along with this route, making it look like this: {pat ...

How can `timeout` be activated for `$.ajax({dataType:'jsonp'...` in jQuery? Any viable solutions?

Does anyone know how to enable a timeout for the $.ajax function when using the dataType:'jsonp' option? I have tried setting the timeout to 200 milliseconds but it doesn't seem to work. Here is a reference link: http://jsfiddle.net/laukstei ...

"Exploring the dynamic features of jQuery's mobile listview and

As I work on creating a mobile app using jQuery Mobile, I find myself facing some challenges. Despite my efforts and attempts at different methods, I have not been successful in achieving the desired functionality. Specifically, I am trying to implement a ...

Transmit information from JavaScript to the Controller

I can't seem to retrieve the data from my JavaScript in my Controller, even though I can see the value in my Request Header. This issue has me completely stumped... JavaScript $('#Save').click(function (e) { if (document.forms[0].check ...

I am looking to include query string variables within JSON key-value pairs

On my webpage, I have a .asp page using the following url: page.asp?id=33&album=ourcookout The page.asp file then calls a file.js script. Within the file.js script, there is a line located under a function that reads as follows: url: "post_file.php", M ...

Enhancing Efficiency with Laravel 5: Updating Multiple Data Entries

My Simple Todo App lacks the ability to persist multiple record updates simultaneously. The client-side version can be found here: http://codepen.io/anon/pen/bVVpyN Whenever I perform an action, I send an HTTP request to my Laravel API for data persistenc ...

Updating the button text in Angular 7

Here's a question: <button (click)="activateMotion(1)"> <img class="emotion-icon" id="positive-icon" src="" /> </button> <button (click)="activateMotion(-1)"> <img class="emotion-icon" id="negative-icon" src="" /&g ...

What is the best way to toggle between rendering two components or updating two outlets based on a route in React Router?

There is a React application I am working on that utilizes React-Router. My layout component has the following structure: import React from 'react'; import Header from './components/Header/Header'; import Footer from './components/ ...

Is there a javascript function that performs the reverse action of indexof()?

Is there a JavaScript function that is the opposite of indexOf()? In my code, when you press the button it will display 3 [from indexOf(".")]. However, I am looking for a function that is the opposite of indexOf(), which would show me 2 [decimal]. http: ...

Learn how to capture complete stack traces for errors when using Google Cloud Functions

In the codebase I am currently working on, I came across a backend service that I would like to utilize for logging all errors along with their corresponding Http statuses. If possible, I also want to retrieve the full stack trace of these errors from this ...

Ensuring Input Integrity: Utilizing HTML and Javascript to Block Unfilled Form Submissions

Currently, I am working on developing a registration page using HTML and JavaScript. Although I have added the 'required' tag in HTML to prevent users from submitting empty input fields, I noticed that users can bypass this restriction by simply ...

Removing classes from multiple elements on hover and click in Vue 2

Can Vue be used to remove a class from an element? I am looking to remove the class when hovering over the element, and then add it back once the mouse is no longer on the text. Additionally, I want the class to be removed when the element is clicked. He ...

Iterate over an array of objects to showcase the property values within an HTML tag using JavaScript

I am a beginner in JavaScript and I am currently working on an exercise. My goal is to iterate through an array of objects within another object, map the index values from one object to the id values in another object, and based on that, perform a certain ...

The issue with ng-if not functioning within ng-repeat is that the ng-if directive

My issue is with using ng-if inside an ng-repeat in AngularJS. Despite updating to the latest version on 09/27/2014, I am still unable to make it work properly. The code functions perfectly outside of ng-repeat, and also works fine inside ng-repeat when us ...

When attempting to retrieve data in a server-side component, Next.js encountered an ECONNREFUSED error with ::1:3000

import React from "react"; import axios from "axios"; interface UsersType { id: string; firstName: string; lastName: string; email: string; } interface dataProps { allUsers: UsersType[]; } async function getData() { try { c ...

Update the fuelux treeview after uploading a file

Currently, I am utilizing the jquery fileupload plugin to facilitate the process of uploading a file and then using the data from said file to populate a fuelux treeview. I have configured an ajax call for handling the file data where the information is fe ...

JQuery failing to trigger AJAX function

I'm struggling with what seems like a simple issue and it's driving me crazy. The problem lies in this straightforward section of the website. I have a .js file that uses ajax to save a post into the database when the submit button is clicked. A ...

Mistakes in my async/await workflow: How am I incorrectly loading and injecting this external script?

Encountering a simple problem: some calls to refresh() cause window.grecaptcha to become undefined. It doesn't happen all the time, probably due to network delays. Debugging this issue is proving to be tricky, especially since I'm still new to th ...

The two divs are positioned on top of one another, with the link in the bottom div being unclickable

I am trying to create a unique effect where a tile divides into two on hover, with each tile acting as an individual link. Additionally, I want the background color of the tiles to change on hover. To achieve this, I have stacked two divs (toptile and bot ...