Skip to main content

Questions tagged [implementation]

For questions regarding the implementation of a feature in coding languages.

Filter by
Sorted by
Tagged with
7 votes
1 answer
337 views

What's the rationale behind switch/yield in Java?

After upgrading to Java 21, I realized that the promised switch expression has several surprising properties. The most surprising part is the yield keyword which ...
feldentm's user avatar
  • 2,066
2 votes
0 answers
96 views

Is there a guide for implementing exceptions in languages with explicit memory management?

I'm looking for a guide for implementing exceptions in a language with explicit memory management like C++. However, the language's type system and exception handling semantics are incompatible with C+...
feldentm's user avatar
  • 2,066
2 votes
1 answer
295 views

How is a python namespace implemented in terms of memory under Cpython implementation? [closed]

I am confused about the implementation of a global namespace in python . How are variable names mapped as keys to the objects they reference as values ,since namespace is implemented as a dictionary? ...
Silah's user avatar
  • 23
6 votes
5 answers
2k views

How do languages where multiple files make up a module handle combining them into one translation/compilation unit?

Mainly, I want to know what existing languages/implementations that use this sort of multi-file module structure do. In my language, modules can consist of multiple files. (For now I don't plan on ...
texdr.aft's user avatar
  • 313
3 votes
0 answers
229 views

Is there a downside to using offsets instead of raw pointers in a virtual machine?

Say I'm designing a virtual machine for a bytecode compiler/interpreter, using C as the implementation language. Some kind of “tagged” representation of values is simplest for this language, where ...
texdr.aft's user avatar
  • 313
3 votes
0 answers
220 views

How to implement type checking of generics?

I am implementing a toy language, for learning. As of now, it has a Rust-like syntax and I would like to implement monomorphization of Generic types. After parsing, I have an Abstract Syntax Tree. Now,...
Jonas's user avatar
  • 413
4 votes
2 answers
293 views

What are the cons of inlining then optimizing and then reverse inlining?

In many programming languages, not all functions may be inlined. However, assuming that a language is designed in such a way that all functions may be inlined, what the disadvantages of inlining all ...
ggZQX6YPvD's user avatar
2 votes
1 answer
355 views

How would you implement an auto-correct feature for misspelled class attributes?

Suppose that we are working with an object oriented compiled language, such as somthing C-flavored or Java-flavored. There is a class named string ...
Samuel Muldoon's user avatar
8 votes
2 answers
414 views

Can total (primitive) corecursion be implemented?

I'm trying to understand how to implement corecursion in a total functional context. I've already implemented recursion using standard techniques (for loops) but I ...
Corbin's user avatar
  • 851
11 votes
1 answer
443 views

What's the state of the art for implementing effect handler systems?

Effect systems allowing locally introducing and eliminating effects have started to appear in (more) practical systems recently, but they've always had a reputation as being a major challenge to ...
Michael Homer's user avatar
  • 13.2k
7 votes
1 answer
377 views

How are coroutines implemented in a tree-walking interpreter?

It seems to me that coroutines and derived abstractions like the iterators and generators are implemented the following way: When returning Move the function's stack frame to the heap Save a pointer ...
Matheus Moreira's user avatar
4 votes
2 answers
537 views

What are the implications of NaN-Boxing?

I recently heard about NaN-Boxing as an alternative to tagging for pointers. What would implementing NaN-Boxing really mean for a language? Primarily, I'm wondering whether it would limit the ...
Lucas Stertz's user avatar
14 votes
1 answer
2k views

Async Implementation

I have recently been making my own programming language and I am finding most concepts easy to understand, however I'm not sure how to implement async/await in my language. ATM, I'm using C# to create ...
InvaderIzzy's user avatar
5 votes
9 answers
2k views

Correctness of mixed signed/unsigned arithmetic

I'm implementing signed and unsigned integers in my language. They are represented in C as signed long and unsigned long ...
Matheus Moreira's user avatar
4 votes
2 answers
191 views

Supporting reasonably efficient high-level indexing for strings

I'm designing a language that I intend to be implemented on the .NET platform. To my understanding, the native string representation uses UTF-16, by storing an array of ...
Karl Knechtel's user avatar
10 votes
4 answers
2k views

Do parsers typically need access to all tokens?

Do parsers typically operate on the entire array/list of tokens available in memory, or are the tokens often streamed one by one as they are recognized? What influences the decision?
Lazar Ljubenović's user avatar
31 votes
11 answers
19k views

Why do so many programming languages not have a "built-in" way to do simple math functions?

Note 1: My question is not about the factorial function. It's about "simple math functions" that high-school level pocket calculators can do, but most programming languages cannot do without ...
Nike Dattani's user avatar
5 votes
1 answer
264 views

Earliest implementation of pattern matching as a programming language feature

As far as I can tell pattern matching was first proposed as a language feature by Burstall (1969). However, it was a proposal for a feature in the language ISWIM, which itself never had a completed ...
Daphne Preston-Kendal's user avatar
-1 votes
1 answer
308 views

Look behind in parsers [closed]

If Sandwich's AST generator finds that the first token is an identifier, one of two cases can be true: Function call Variable assignment It stores the identifier and checks if the next token is a = ...
192927376337929292283737373773's user avatar
17 votes
2 answers
3k views

How do lexers/parsers distinguish between nested generics and bitshifts?

The lexical grammar of Java has a special case for the the > character. Normally, tokens are formed based on the longest-match rule, so that an input string of <...
kaya3's user avatar
  • 20.2k
2 votes
1 answer
349 views

Are enum members literals or constants in an IR?

While implementing enums in Tyr, I just realized that enum constants are the only form of literal-like entity that is not represented like a literal in the intermediate representation. The enum ...
feldentm's user avatar
  • 2,066
11 votes
4 answers
1k views

Data structures for scopes and variable shadowing

Let's say I have some code in my target language like: ...
Rob N's user avatar
  • 1,105
6 votes
1 answer
291 views

How do you implement a structural subtyping checker?

In a structurally-typed language, one type is a subtype of another iff it has all of the fields/methods of the other with compatible types, meaning that field or return types are subtypes, parameter ...
Michael Homer's user avatar
  • 13.2k
5 votes
0 answers
154 views

What are some design errors that lead to hard-to-debug code? [closed]

There are some design features in programming languages that make code written in the language difficult to debug (e.g. C's default fallthrough behavior). So it would be helpful to make a list of ...
idk's user avatar
  • 159
40 votes
6 answers
5k views

How to ensure that an optimising compiler will terminate?

An optimising compiler typically applies some set of rewrites to some intermediate representation of the program, replacing terms with other terms which are supposed to be equivalent but more ...
kaya3's user avatar
  • 20.2k
2 votes
1 answer
273 views

Implementing a Array programming language in C. What is the best and most efficient struct for the arrays? [closed]

...
rapasite's user avatar
3 votes
1 answer
249 views

Call-by-value: Left-to-right vs right-to-left

There are three standard evaluation strategies for the lambda calculus: Call-by-value (CBV) Call-by-name Call-by-need There are two variants of CBV that differ on how they behave with respect to ...
user76284's user avatar
  • 159
7 votes
2 answers
762 views

Empirically, what are the implementation-complexity and performance implications of "unboxed" primitives?

I'm designing a Python-like language: bytecode-compiled, brace-free syntax, reference semantics for variables. Among many differences from Python, I want to support a limited form of static typing. I ...
Karl Knechtel's user avatar
12 votes
2 answers
608 views

Why did Objective-C remove `NSZone`?

NSZone is a type representing a memory allocation. NSObject implements the allocWithZone: ...
Bbrk24's user avatar
  • 9,277
8 votes
2 answers
416 views

How to optimize non-tail recursion?

Tail recursion, where a function calls itself as the last step, is straightforward to optimize as to prevent unbounded stack growth: tail call optimization applies. However, this doesn't apply to ...
Bbrk24's user avatar
  • 9,277
5 votes
1 answer
244 views

Built-In Asynchronous Loops (Not Functions) - Do they / could they exist?

When writing a game's event loop, I always rely on a function from an external library, like draw() in ProcessingJS for ...
Quack E. Duck's user avatar
6 votes
2 answers
366 views

Why would Short String Optimization not apply to dynamic arrays?

Short string optimization is the optimization that sufficiently short strings have their data stored inline rather than an external buffer, so the string type ends up being a union. Swift does this, ...
Bbrk24's user avatar
  • 9,277
11 votes
5 answers
1k views

What are the pros and cons of a compiler with a single-pass parser?

Assume you are tasked with writing a compiler for a language that can be parsed in a single pass, like C, but does not necessarily have to be. What are the pros and cons for doing this? Would you do ...
Gavin D. Howard's user avatar
14 votes
3 answers
2k views

What are the pros and cons of single-pass compilers?

Okay, we all know the standard compiler architecture: a batch program with multiple passes for parsing, optimizing, and generating code. Suppose you wanted to go all Turbo Pascal and implement a ...
Gavin D. Howard's user avatar
7 votes
1 answer
164 views

How can task-local variables be implemented?

In some languages, async/await can be simply transformed into callbacks, as if it were syntactical sugar: ...
Bbrk24's user avatar
  • 9,277
4 votes
2 answers
975 views

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

Based on this closed question. Basically, why would one choose a pure interpreter for a language implementation as opposed to a virtual machine/bytecode approach like Java or Python (even if at ...
kouta-kun's user avatar
  • 1,648
4 votes
5 answers
972 views

What are the pros and cons of interpreted programming languages?

Some programming languages are implemented via a source code interpreter instead of a compiler, for example Python, PHP, Ruby and Perl, and these programming languages are very popular. So, this ...
чистов_n's user avatar
3 votes
3 answers
217 views

What are the downsides, if any, of using implicit function purity in an impure language?

An idea I had for one of my languages recently was this: function purity makes it easier to do certain optimizations. However, the language I'm designing is an impure imperative language that has an ...
Seggan's user avatar
  • 2,773
10 votes
1 answer
288 views

How to test a compiler/interpreter?

What are some testing techniques and strategies (in software engineering sense) that are relevant to compilers/interpreters? For example, having a set of complete programs and verifying their runtime ...
Bubbler's user avatar
  • 733
4 votes
1 answer
368 views

How can an abstract-syntax tree be converted into linear three-address code?

I have an abstract-syntax tree (AST) for a language, and I'd like to use some sort of three-address code (TAC) to represent the program in a linear way, before converting it to assembly. How do I do ...
springogeek's user avatar
6 votes
2 answers
346 views

How are C++ style references implemented behind the scenes? Could they be implemented without pointers?

I would not be surprised if C++ style int &y = x; was no more than int *y = &x; behind the scenes and every use of ...
CPlus's user avatar
  • 9,063
8 votes
1 answer
447 views

How are hand-written parsers organised, and how do they work?

Below, we have an example of two extremely simple languages and a relationship between the two languages: Inputlanguage (-1, 0) (0, 1) (1, 0) (0, 1) (0, -1) (1, 0) (1, 0) Outputlanguage "left&...
Samuel Muldoon's user avatar
4 votes
4 answers
385 views

Approaches for implementing weak references

How can weak references (weakrefs) be implemented, and how do the different approaches compare? The most important considerations for implementing weakrefs are: Safety ─ a weakref shouldn't allow ...
kaya3's user avatar
  • 20.2k
12 votes
4 answers
2k views

Why does Python ignore type hints?

In Python, everything is treated as an object. This means that CPython interpreter will decide on the fly, what is the type of each variables or the function return type depending on the current state....
Hemanth Haridas's user avatar
4 votes
2 answers
202 views

How does a compiler know that an identifier in an expression refers to a memory location, or the value stored at that location?

There are situations during compilation when some identifier represents a particular value ("contained" in a variable, etc), but sometimes it references the variable's memory location ...
springogeek's user avatar
11 votes
3 answers
267 views

How are strings, lists and dicts implemented in bytecode?

How do I implement strings, lists and dicts in bytecode? For example, disassembling the bytecode might look like this: LOAD str "hello, world" But how ...
чистов_n's user avatar
13 votes
1 answer
307 views

How to implement a REPL for a compiled language?

Implementing a REPL is relatively straightforward for an interpreted language; the interpreter maintains the program state as normal, and evaluates each separate statement as normal, just using the ...
kaya3's user avatar
  • 20.2k
5 votes
1 answer
188 views

What are the pros and cons of ways to implement the LOAD command in a statically typed VM?

What are the pros and cons of ways to implement the LOAD command in a statically typed VM? There is two ways to implement LOAD ...
чистов_n's user avatar
12 votes
1 answer
327 views

How do I implement coroutines on WebAssembly?

I am building a compiler targeting WebAssembly for a language that makes heavy use of first-class coroutines. WASM doesn't have native coroutine support (yet), so I have to emulate it. Given the ...
Michael Homer's user avatar
  • 13.2k
8 votes
2 answers
171 views

How can I reduce the amount of AST duplication in my code?

I'm working on a language that transpiles to Lua, and writing the transpiler in Kotlin. One problem I'm having is that I simply have too many AST types. I have an untyped AST, a typed AST, and a Lua ...
Seggan's user avatar
  • 2,773