How can C++ compilers support C++11 atomic, but not support C++11 memory model

One of the issues is the definition of “memory location”, that allows (and forces the compiler to support) locking different structure members by different locks. There is a discussion about a RL problem caused by this. Basically the issue is that having a struct defined like this: struct x { long a; unsigned int b1; … Read more

How can I see parse tree, intermediate code, optimization code and assembly code during COMPILATION?

While you can use the -fdump-tree-all and -fdump-rtl-all options in gcc, I don’t think that their output is very useful to a compiler student. FWIW, I started working on gcc as part of my PhD studies, having already completed two undergraduate courses, and I found gcc and its debug files to be opaque and hard … Read more

How do Haskell compilers decide whether to allocate on the heap or the stack?

When you call a function like this f 42 (g x y) then the runtime behaviour is something like the following: p1 = malloc(2 * sizeof(Word)) p1[0] = &Tag_for_Int p1[1] = 42 p2 = malloc(3 * sizeof(Word)) p2[0] = &Code_for_g_x_y p2[1] = x p2[2] = y f(p1, p2) That is, arguments are usually passed as … Read more

How to emit and execute Java bytecode at runtime?

Here is a working “hello world” made with ObjectWeb ASM (a library which I recommend): package hello; import java.lang.reflect.Method; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; public class HelloWorldASM implements Opcodes { public static byte[] compile(String name) { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, “hello/HelloWorld”, null, “java/lang/Object”, null); cw.visitSource(“HelloWorld.java”, … Read more

Different maven compiler versions for test and main

If you want to set compliance to the relevant Java version, you can configure the compiler plugin for each execution. Assuming Maven is using a JDK at least as current as the highest version you specify. By using properties you can override that configuration on the commandline or in a child if needed: <plugin> <groupId>org.apache.maven.plugins</groupId> … Read more

What are the stages of compilation of a C++ program?

Are the stages of compilation of a C++ program specified by the standard? Yes and no. The C++ standard defines 9 “phases of translation”. Quoting from the N3242 draft (10MB PDF), dated 2011-02-28 (prior to the release of the official C++11 standard), section 2.2: The precedence among the syntax rules of translation is specified by … Read more

Algorithm for implementing C# yield statement

The particular code sample you are looking at involves a series of transformations. Please note that this is an approximate description of the algorithm. The actual names used by the compiler and the exact code it generates may be different. The idea is the same, however. The first transformation is the “foreach” transformation, which transforms … Read more

Is there a need for a “use strict” Python compiler?

Well, I’m not much of a python programmer, but I’d say that the answer is ‘YES’. Any dynamic language that lets you create a variable with any name at any time, could use a ‘strict’ pragma. Strict vars (one of the options for strict in Perl, ‘use strict’ turns them all on at once) in … Read more

Are there Lisp native code compilers?

Many Lisp compilers compile to ‘native’ code. ‘Native’ means here ‘machine code’ (x86 in 32bit or 64bit mode, PowerPC, SPARC, …). Other questions: can ‘non-native code’ compilers generate single file executables? -> Yes. can ‘native code’ compilers generate single file executables? -> Yes. how ‘native’ is ‘native’? -> Lisp system will most of the time … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)