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 ...
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 "...
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 ...
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 ...
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 ...
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 ...
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 (...
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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)...
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 ...
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. ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
interpreters × 24compilers × 9
implementation × 7
lexing × 3
parsing × 2
object-oriented × 2
virtual-machine × 2
just-in-time × 2
call-stack × 2
c × 1
optimization × 1
python × 1
loops × 1
stack × 1
variables × 1
tokens × 1
undefined-behavior × 1
high-level-languages × 1
built-ins × 1
pointers × 1
bootstrapping × 1
branch-prediction × 1
constant-expressions × 1
preprocessor × 1
tree-walker × 1