Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.
Version 2 (modified by asterite, 15 years ago)
--

Porting DMD to Descent

This document explains how the process of porting DMD to Java works.

First, the port status is maintained in this file. This is just a plain text file where the files that are still remaining to port are listed in an informal manner.

The process involves porting the diffs between dmd versions. The files are in the descent.internal.compiler.parser package. Translation from C++ to Java involves more or less this steps:

  • Finding the target function to make the diff. In C++ a function like AddExp::semantic in expression.c will be located in the AddExp?.java file.
  • If the target function doesn't exist, create it. If the function is global, add it as a static to ASTDmdNode since all nodes extend from this class and thus the function can be invoked as it if were global and the resulting code looks more like the original one.
  • Replace "->" with ".". Also remove the "*" stars.
  • Errors in DMD C++ are reported via the function error(...). In the Java port every function that needs to report an error (and also in some other cases) receive an extra parameter of type SemanticContext, normally named "context". Use this context to report errors and access to otherwise global data (like the Object or TypeInfo? declaration).

When there are big differences in the lexer or parser, more actions are needed:

  • If the lexer adds new tokens, they must be added in several places: TOK, ITerminalSymbols, JavaCodeScanner. If the tokens are keywords then they must be added in Lexer::case_ident (ugly, but fast).
  • If the parser adds new nodes, a class must be created in the ported AST, package descent.internal.compiler.parser. Also a node in the public AST must be added: descent.core.dom. A constant must be added in the AST class for this new node, two AstVisitors? must be augmented and their implementation checked. This is almost an automatic process but it's hard to describe, contact Ary in case you need it.

Check the project descent.tests, you can find tests for almost everything: the lexer, the parser, the public AST, formatter, code completion, even semantic. Also check AllNonWorkbenchTests.java and AllWorkbenchTests.java.