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 properly parse a JSON file in Node.js?

Utilizing node.js, I have created a webpage (index.html) for visualizing a network graph using the vis.js library. To draw a network graph with this library, it is necessary to provide json arrays for both nodes and edges (see example). // array of nodes ...

`Is there a way to manipulate the timer in JavaScript?`

My current project involves creating a timer in minutes and seconds. The user inputs the desired time in minutes into a textbox named "textbox2". However, when I attempt to retrieve the value of this input using `getElementById.value`, it returns a NULL er ...

Optimizing Require.js File for Efficient Loading

I have successfully implemented require.js with multiple individual files: require(['app/login/Login'], function (app) { new app.Login(); }); Everything is functioning as expected, with each module loading when needed. Recently, I have opti ...

"Encountering a mysterious internal server error 500 in Express JS without any apparent issues in

My express.js routes keep giving me an internal server error 500, and I have tried to console log the variables but nothing is showing up. Here are the express routes: submitStar() { this.app.post("/submitstar", async (req, res) => { ...

Iterate through nested objects in Javascript

I am having trouble extracting only the word from each new instance of the newEntry object. It shows up in the console every time I add a new word, but not when I assign it to .innerHTML. Can someone assist me with this issue? Full code: <style ty ...

The functionality of JavaScript on an icon that is supposed to expand and collapse a table is not functioning properly when the enter

On this particular page, I have a toggleable table of information that expands and collapses when the user clicks on a clickable +/- icon. However, there seems to be an issue where if the user tabs to the icon and tries to expand/collapse it by pressing en ...

Unexpected behavior detected with vue.js

I'm having some trouble with my vue.js code. When I try to run this example, the output in the browser is showing "product" instead of "Boots". <div id="app"> <h2>{{product}}</h2> </div> <script src="https://unpkg.com/& ...

Vuex has reserved this keyword

I am working on a Laravel application with the following code in app.js: require('./bootstrap'); window.Vue = require('vue'); import { store } from './store/store' import Sidebar from './Sidebar' Vue.component(& ...

Validate the date selected in a dropdown menu using JavaScript

I'm still relatively new to Javascript, just working my way through some tutorials. I have three select boxes in my HTML form as shown below. HTML Form: <table> <form id="enrolment" name="enrolment" onsubmit="return datevalidate();" action ...

Step by step guide to verifying email addresses with Selenium WebDriver

A feature in my EXTJS application includes a page with an Email button. When this button is clicked, it generates a link to the page contents and opens the default email client with this link in the body. Upon inspecting the DOM, I found that the Email bu ...

Eliminate unnecessary scrollbar from fancybox iframe

I am trying to display content in an iframe using Fancybox, but I am encountering an issue. Despite all the content being contained within the iframe, horizontal and vertical scroll bars are appearing. When inspecting the element in Firefox, I noticed th ...

How can we convert a mixed-case word into one or more words with initial capital letters?

Is there a way to convert caps and spaces to their normal form? For instance, can the word coreControllerC4a be transformed into Core Controller C4a automatically when a function is triggered? ...

Turning Node.js timestamp into MySQL format

Currently, I am using Node (Express.js) to update a MySQL database with the current date. While it is functional, my code seems to be repetitive. let newDate = new Date(); let yearNow = newDate.getFullYear(); let monthNow = newDate.getMonth(); let dayNow ...

Position the Material-UI AppBar and Tab on the far right of the screen

I am trying to achieve a specific layout where the Links for "Homepage Login Settings and etc.." are placed at the right edge of the AppBar, while keeping the "Website" aligned to the left edge of the screen. Here is what I have: Can someone help me figur ...

Safari browser removes spaces after commas in cookie values

I'm encountering an issue when trying to set a session cookie for storing an Address. It seems that whenever I include a comma followed by a space in the cookie's value, Safari automatically removes the spaces after the commas, causing the format ...

Transform a 3D text rotation JavaScript file into an Angular component tailored TypeScript file

I have a javascript file that rotates text in 3D format, and I need help converting it into an Angular component specific TypeScript file. You can find the codepen for the original JavaScript code here. Below are my Angular files: index.html <!doctyp ...

Assigning a value to an attribute as either a "string" or null within JSON Schema while specifying a maximum length

I'm currently working on crafting a JSON schema that supports a nullable attribute. I am aiming to have the ability for specific JSON structures like this one be considered valid: { "some_name" : null } This is how my schema looks like: { "type" ...

Saving the Auth0 user object in React Context for Typescript in a Next.js environment

I am working on integrating Auth0 user authentication into my React application using the useUser hook and the context API. My goal is to access the user object globally throughout the app by storing it in the userContext.tsx file: import { createContext, ...

JQuery isn't functioning properly on dynamically generated divs from JavaScript

I'm currently tackling an assignment as part of my learning journey with The Odin Project. You can check it out here: Despite creating the divs using JavaScript or jQuery as specified in the project requirements, I am unable to get jQuery's .hov ...

The session in ASP.NET expires during an Ajax request

Many questions have been asked about what to do when a session expires during an Ajax request. One popular workaround is to include a header in the response that triggers a redirect to the login page. On my site, only the first page requires a full postba ...