Skip to main content
22 votes
Accepted

What is a Global Interpreter Lock, and why would an interpreter have it?

As the question notes, the specific term “global interpreter lock” is generally associated with CPython, which infamously includes a global mutex that must be acquired whenever any thread interprets ...
Alexis King's user avatar
  • 9,444
17 votes
Accepted

Should a virtual machine stack have a limited size?

given that a stack implemented in a virtual machine interpreter is able to have an infinite size, why would we limit its capacity or not? Great question, let me first nitpick and say that "...
Eric Lippert's user avatar
  • 3,869
13 votes
Accepted

What are the pros and cons of interpreted programming languages?

I'll try to answer from the perspective of a language implementer/designer and as a user. I'll also try to answer as broadly and generally as possible, but disclaimer: these lists may not apply to ...
Gavin D. Howard's user avatar
13 votes

Should a virtual machine stack have a limited size?

Consider what will happen when a user's program has a bug causing infinite recursion. If your call stack has a bounded size, then their program will raise a runtime error due to overflowing the call ...
kaya3's user avatar
  • 20.2k
12 votes

How do I Interpret a Continue/Break Statement in a Loop?

Typically, you need to distinguish between what it means for a statement or expression to "complete normally" or "complete abruptly" (borrowing terminology from the Java Language ...
kaya3's user avatar
  • 20.2k
11 votes

How do I Interpret a Continue/Break Statement in a Loop?

Throw an exception For a simple tree-walking interpreter in a language with catchable exceptions, both break and continue ...
Michael Homer's user avatar
  • 13.2k
10 votes
Accepted

What are the pros/cons of a tree-based interpreter vs a bytecode-VM-based interpreter?

The main reason to write a tree-walking interpreter is that it's easier. If you compile to bytecode and then interpret the bytecode, you are either writing a compiler to an existing bytecode language (...
kaya3's user avatar
  • 20.2k
10 votes
Accepted

Is it possible to bootstrap an interpreted language?

It is obviously impossible for a interpreter to only be able to be interpreted by itself, as that would require a infinite chain of interpreters. Each one would slow down the entire system and require ...
mousetail's user avatar
  • 8,681
9 votes

Is it possible to bootstrap an interpreted language?

It is not possible to create a fully bootstrapped interpreter. However, it is entirely possible to create a bootstrapped compiler that targets some lower language which is then interpreted. For ...
Olive's user avatar
  • 470
7 votes

How to store variables in an interpreted language?

Many dynamic languages have function scope, i.e. a variable is in scope within the whole of the function body that it is declared in, or if it is not declared within a function then it is global. In ...
kaya3's user avatar
  • 20.2k
7 votes
Accepted

Are there any languages interpreted twice?

Many interpreters are written in interpreted languages; this is really a property of the implementation rather than the language. The advantage generally is to be able to use that host language for ...
Michael Homer's user avatar
  • 13.2k
6 votes
Accepted

What are some common ways to optimise an interpreter?

The first option is changing the way you execute the code. Reduce the cache thrashing of the tree walk interpretation by moving the AST nodes being interpreted into a contiguous memory buffer. After ...
ratchet freak's user avatar
6 votes

Organizing a large number of built-in instructions

Fundamentally, all of your builtins have to be in one place at some point. If your concern is source code bloat, you can try to modularize the initialization function into several smaller functions. ...
Silvio Mayolo's user avatar
6 votes

How do interpreters avoid stack buffer overflow-related undefined behavior and exploits?

If you're interested in how these sorts of things were done in ancient times, I wrote the stack probing code for VBScript and JScript back when it was the 1990s. Which was complicated by the fact that ...
Eric Lippert's user avatar
  • 3,869
6 votes

How can I more effectively test for differences between my implementation and the official implementation of a language?

Create a test suite for ><> It seems like there are no standard test suite for ><>. It is always a good time to start making one. Every time you find behavior differences, add a test ...
Eldritch Conundrum's user avatar
5 votes
Accepted

What are the advantages of compiling/interpreting a programming language?

There is no hard line There are various techniques that blend the line between compiled and interpreted languages various techniques blur the line, like: JIT compilation Interpreting bytecode Virtual ...
mousetail's user avatar
  • 8,681
5 votes

Why is it so difficult to implement the first Futamura projection?

If the question is "why isn't this used in practice", I think the answer is twofold: First, specializers are complex tools. It's likely that you'll need to refactor the interpreter at least ...
hugomg's user avatar
  • 1,345
5 votes

Should a virtual machine stack have a limited size?

In the face of language implementations where the stack cannot have unbounded size, algorithms which could otherwise be cleanly expressed become contorted, and must use mechanisms like explicit stacks ...
Moonchild's user avatar
  • 1,066
5 votes

Should a virtual machine stack have a limited size?

Stack limits permit a virtual machine to handle stack overflows within the language. If you don't provide one, then the consequences of a stack overflow can only be handled by the underlying language....
Cort Ammon's user avatar
4 votes

How can I track source spans during parsing and interpretation?

My usual strategy for this is that every parse tree node holds on to the first token of the parse element from which it was constructed, and sometimes the last too. The initial token is definitely ...
Michael Homer's user avatar
  • 13.2k
4 votes

How do I implement branch prediction for JIT?

I thought "branch prediction for JIT" means "branch prediction in JIT", but apparently you want branch prediction outside JIT... Unfortunately, I don't think it will work in terms ...
Alex Chichigin's user avatar
4 votes

Organizing a large number of built-in instructions

If the implementation language supports it, you may wish to use Decorators. Decorators allow you to keep registration of built-ins attached to their definition, which can allow for cleaner, more ...
ATaco's user avatar
  • 615
4 votes
Accepted

Pros and cons of reifying the stack in an interpreter

Reifying the stack makes implementing lexical capture significantly easier, but has real performance costs. It can also enable (relatively) easy extension to coroutines or other language constructs ...
Michael Homer's user avatar
  • 13.2k
4 votes

Pros and cons of reifying the stack in an interpreter

I find recursive evaluation (a.k.a. ones that "piggyback" the host language's call stack) to be more readable and much easier to implement. The obvious disadvantage is that, for a large ...
Olive's user avatar
  • 470
4 votes

Utilising recursion schemes when implementing compilers

Recursion schemes are a coding pattern to factor out recursion. Some people may see them as beneficial, others may not. In the end, this is more about software engineering than anything and you ...
NaCl's user avatar
  • 351
4 votes

Utilising recursion schemes when implementing compilers

Recursion schemes are good ways to refactor out recursions only if these recursions can be translated into type-theoretic eliminators (e.g. the "foldr" or the (co)algebra in the (co)...
ice1000's user avatar
  • 2,634
4 votes

What are the pros/cons of a tree-based interpreter vs a bytecode-VM-based interpreter?

Pros of a tree-walking interpreter: It's often one of the fastest form of interpretation for a case you only execute each statement of your language once. Which is very typical for scripting and ...
SK-logic's user avatar
  • 1,320
4 votes

What are some common ways to optimise an interpreter?

I can only speak to my experience; I have a widely-used interpreter, and I didn't optimize it much. The first thing that I noticed is that executing an AST directly involves a lot of pointer chasing. ...
Gavin D. Howard's user avatar
4 votes

How would you implement a language in which the function-name could be separated from function arguments two different ways?

What you’re really facing here is a parsing issue, rather than a tokenising one. You would tokenise this language the same way that you tokenise any other language — give each of those distinct ...
Michael Homer's user avatar
  • 13.2k
3 votes

What are the pros and cons of interpreted programming languages?

In addition to what was said in the other answers: You'd normally design a language with typically interpreted semantics, as in - some form of a dynamic scoping, dynamic dispatch (probably, duck ...
SK-logic's user avatar
  • 1,320

Only top scored, non community-wiki answers of a minimum length are eligible