language-implementation

C pointers in C#

Is this function declaration in C#: void foo(string mystring) the same as this one in C: void foo(char *) i.e. In C#, does the called function receive a pointer behind the scenes? ...

What's a good Common Lisp implementation for Windows?

What's your favourite? See also this related question. ...

Are there any Common Lisp implementations for .Net?

Related to my other CL question. ...

Garbage collection and runtime type information

The fixnum question brought my mind to an other question I've wondered for a long time. Many online material about garbage collection does not tell about how runtime type information can be implemented. Therefore I know lots about all sorts of garbage collectors, but not really about how I can implement them. The fixnum solution is act...

Unexpected list comprehension behaviour in Python.

I believe I'm getting bitten by some combination of nested scoping rules and list comprehensions. Jeremy Hylton's blog post is suggestive about the causes, but I don't really understand CPython's implementation well-enough to figure out how to get around this. Here is an (overcomplicated?) example. If people have a simpler one that d...

How are associative arrays implemented in PHP?

Can someone explain how PHP implements associative arrays? What underlying data structure does PHP use? Does PHP hash the key and store it in some kind of hash map? I am curious because I was wondering what the performance of associative arrays where when inserting and searching for keys. ...

range for integer values of chars in c++

I'm reading The C++ Programming Language and in it Stroustrup states that the int value of a char can range from 0 to 255 or -127 to 127, depending on implementation. Is this correct? It seems like it should be from -128 to 127. If not, why are their only 255 possible values in the second implementation possibility, not 256. ...

Unicode strings in process memory

What is the most preferred format of unicode strings in memory when they are being processed? And why? I am implementing a programming language by producing an executable file image for it. Obviously a working programming language implementation requires a protocol for processing strings. I've thought about using dynamic arrays as the ...

Dynamic linking with smalltalk objects

I plan about implementing a dynamic linking into my smalltalk dialect. The problem is about getting message passing to work with dynamic linking. Message passing itself is as simple as this: message with a selector is sent to the object, the object picks up a method matching with the selector from it's protocol, it then process the data...

write-protected virtual pages, catch write

Does there exist a way to catch a write into write-protected page? I plan doing a self -like object system where you copy the object to instantiate it. (because it sounds simple and compact thing compared to the rest) Obviously, the objects created for this purpose ought be write-protected some way. I've seen there's a way to flag somet...

How is the C++ exception handling runtime implemented?

I am intrigued by how the C++ exception handling mechanism works. Specifically, where is the exception object stored and how does it propagate through several scopes until it is caught? Is it stored in some global area? Since this could be compiler specific could somebody explain this in the context of the g++ compiler suite? ...

How would you re-use C opcode implementations when writing a JIT with LLVM ?

In the llvm tutorials and examples, the compiler outputs LLVM IR by making calls like this return Builder.CreateAdd(L, R, "addtmp"); but many interpreters are written like this: switch (opcode) { case ADD: result = L + R; break; ... How would you extract each of these code snippets to make a JIT ...

How to implement a practical fiber scheduler?

I know the very basics about using coroutines as a base and implementing a toy scheduler. But I assume it's oversimplified view about asynchronous schedulers in whole. There are whole set of holes missing in my thoughts. How to keep the cpu from running a scheduler that's running idle/waiting? Some fibers just sleep, others wait for inp...

How is C++'s multiple inheritance implemented?

Single inheritance is easy to implement. For example, in C, the inheritance can be simulated as: struct Base { int a; } struct Descendant { Base parent; int b; } But with multiple inheritance, the compiler has to arrange multiple parents inside newly constructed class. How is it done? The problem I see arising is: should the parents ...

Private inner class synthesizes unexpected anonymous class

When you compile a Java class with a private inner class, it appears that an anonymous class is automatically synthesized along with it for some reason. This class is sufficient to reproduce it: public class SynthesizeAnonymous { public static void method() { new InnerClass(); } private static class InnerClass {} } ...

What Lisp is better at parsing?

I'd like to implement a Lisp interpreter in a Lisp dialect mainly as a learning exercise. The one thing I'm thrown off by is just how many choices there are in this area. Primarily, I'm a bit more interested in learning about some of the Lisps that have been around a while (like Scheme or Common Lisp). I don't want to use Clojure to d...

C: Behaviour of the `const` keyword

I've been told that if I'm coding in ANSI-C to declare in the order that the variables will be used, assert that pointers are not null and that indices are within bounds, and to initialize just before usage of the variable. If I declare a const can I initialize it after a block of assertions and code ? In Java final initializations must...

IE8 JavaScript: select.options behaviour

I've today discovered some strange behaviour in IE8's implementation of the DOM select element's JavaScript 'options' property. Given the following HTML: <select id="sel"><option value="val">An option</option></select> And the javascript: var sel = document.getElementById('sel'); alert(sel === sel.options); //alerts 'true' in IE8 ...

Java - Why all fields in an interface are implicitly static and final?

I am just trying to understand why all fields defined in an Interface are implicitly static and final. The idea of keeping fields static makes sense to me as you can't have objects of an interface but why they are final (implicitly)? Any one knows why Java designers went with making the fields in an interface static and final? ...

what exactly is a "register machine" ?

From http://code.google.com/p/unladen-swallow/wiki/ProjectPlan I quote: "Using a JIT will also allow us to move Python from a stack-based machine to a register machine, which has been shown to improve performance in other similar languages (Ierusalimschy et al, 2005; Shi et al, 2005)." In college I built a simple compiler for a languag...