Having to do with issues arising when implementing a programming language.
Questions tagged [language-implementation]
141 questions
9
votes
5 answers
How is Forth LEAVE ... LOOP implemented, since number of LEAVEs is not known beforehand?
The word LOOP is described as "Resolve the destination of all unresolved occurrences of LEAVE". (emphasis mine)
Unlike IF ... ELSE ... THEN, where the number of forward references is always one, LOOP has no constraints on the quantity of LEAVE. How…

shinkarom
- 143
- 6
9
votes
1 answer
Where is it specified whether Unicode identifiers should be allowed in a Haskell implementation?
I wanted to write some educational code in Haskell with Unicode characters (non-Latin) in the identifiers. (So that the identifiers look nice and natural for speakers of a natural language other than English which is not using the Latin characters…

imz -- Ivan Zakharyaschev
- 4,921
- 6
- 53
- 104
9
votes
1 answer
Why can you omit the surrounding parentheses for generators in Python when passing it into a function?
I was just experimenting in Python with different syntax for passing in a generator as an argument to a function, and I realized that although I've been doing this,
>>> sum((j for j in xrange(5)))
10
this works as well:
>>> sum(j for j in…

Darren Yin
- 628
- 3
- 10
8
votes
5 answers
Byte code stack versus three address
When designing a byte code interpreter, is there a consensus these days on whether stack or three address format (or something else?) is better? I'm looking at these considerations:
The objective language is a dynamic language fairly similar to…

rwallace
- 31,405
- 40
- 123
- 242
8
votes
3 answers
How is asynchronous callback implemented?
How do all the languages implements asynchronous callbacks?
For example in C++, one need to have a "monitor thread" to start a std::async. If it is started in main thread, it has to wait for the callback.
std::thread…

SwiftMango
- 15,092
- 13
- 71
- 136
8
votes
1 answer
Brainfuck interpreter in Nimrod
I am toying with nim (at the time of writing still called nimrod), by writing a Brainfuck interpreter in the language. Without loops implemented, I have:
import os, unsigned
const RamSize = 200
type
TRam = array[0..RamSize, int]
var
ram :…

Taylor Skidmore
- 97
- 4
7
votes
2 answers
How is "letrec" implemented without using "set!"?
How can letrec be implemented without using set!?
It seems to me that set! is an imperative programming construct, and that by using it, one loses the benefits of functional programming.

user1059449
- 183
- 6
7
votes
1 answer
Is 'yield' keyword a syntactic sugar ? What is its Implementation
Possible Duplicate:
yield statement implementation
I've seen msdn docs and it says:
The yield keyword signals to the compiler that the method in which it appears is an iterator block. The compiler generates a class to implement the behavior that…

Shekhar_Pro
- 18,056
- 9
- 55
- 79
7
votes
1 answer
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;
…

joeforker
- 40,459
- 37
- 151
- 246
7
votes
7 answers
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…

Ande Turner
- 7,096
- 19
- 80
- 107
6
votes
1 answer
Why is std::same_as implemented in such a weird way?
cppref gives a possible implementation of std::same_as:
namespace detail {
template
concept SameHelper = std::is_same_v;
}
template
concept same_as = detail::SameHelper &&…

xmllmx
- 39,765
- 26
- 162
- 323
6
votes
6 answers
Python: the mechanism behind list comprehension
When using list comprehension or the in keyword in a for loop context, i.e:
for o in X:
do_something_with(o)
or
l=[o for o in X]
How does the mechanism behind in works?
Which functions\methods within X does it call?
If X can comply to more…

Adam Matan
- 128,757
- 147
- 397
- 562
6
votes
1 answer
G-machine, (non-)strict contexts - why case expressions need special treatment
I'm currently reading Implementing functional languages: a tutorial by SPJ and the (sub)chapter I'll be referring to in this question is 3.8.7 (page 136).
The first remark there is that a reader following the tutorial has not yet implemented C…

socumbersome
- 243
- 1
- 6
6
votes
2 answers
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…

Gregg Lind
- 20,690
- 15
- 67
- 81
6
votes
1 answer
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…

John Calsbeek
- 35,947
- 7
- 94
- 101