Questions tagged [implementation]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
307 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 ...
Theodore Shepard's user avatar
8 votes
1 answer
218 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
  • 841
11 votes
1 answer
380 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
  • 12.1k
7 votes
1 answer
317 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
3 votes
2 answers
374 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
11 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
1k 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
171 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
1k 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
30 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
4 votes
1 answer
244 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
287 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 = ...
The_AH's user avatar
  • 17
16 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
  • 18.4k
2 votes
1 answer
327 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
  • 1,759
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,073
6 votes
1 answer
247 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
  • 12.1k
5 votes
0 answers
150 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
36 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
  • 18.4k
2 votes
1 answer
246 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
222 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
6 votes
2 answers
708 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
430 views

Why did Objective-C remove `NSZone`?

NSZone is a type representing a memory allocation. NSObject implements the allocWithZone: ...
Bbrk24's user avatar
  • 8,907
8 votes
2 answers
379 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
  • 8,907
5 votes
1 answer
212 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
5 votes
2 answers
280 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
  • 8,907
11 votes
5 answers
936 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
13 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
132 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
  • 8,907
3 votes
2 answers
599 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,349
4 votes
5 answers
775 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
188 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,643
10 votes
1 answer
208 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
  • 713
3 votes
1 answer
183 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
254 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
  • 7,861
7 votes
1 answer
410 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
2 votes
4 answers
169 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
  • 18.4k
11 votes
4 answers
1k 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
174 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
194 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
230 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
  • 18.4k
5 votes
1 answer
158 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
200 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
  • 12.1k
8 votes
2 answers
159 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,643
6 votes
1 answer
160 views

How do I implement branch prediction for JIT?

I have a language with a working interpreter, and I am trying to add just-in-time compilation (JIT) to it. For ease of implementation, only individual branches are compiled, while control flow ...
Bbrk24's user avatar
  • 8,907
6 votes
2 answers
96 views

Organizing a large number of built-in instructions

I am currently writing a Funge-98 interpreter in Go following the Funge-98 specification and need to handle all of its built-in instructions. However, this is proving to be unwieldy, because there's ...
bigyihsuan's user avatar
  • 1,791
5 votes
2 answers
189 views

How can I implement a control flow graph?

A Control-Flow-Graph is: In computer science, a control-flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution. The ...
FireTheLost's user avatar
  • 1,603
10 votes
1 answer
183 views

How is fixpoint of type exponentiation implemented?

Fixpoint of type addition or type multiplication is no big deal. You just need to store data in heap. Haskell does this well for lists for example: ...
Dannyu NDos's user avatar
8 votes
1 answer
127 views

How can runtime type checks be implemented?

Most if not all OO languages have some way to determine whether an object belongs to a given class at runtime. In some languages -- both interpreted (like JS) and compiled (like Objective-C) -- ...
Bbrk24's user avatar
  • 8,907
5 votes
5 answers
515 views

How could fixed-point be implemented?

Fixed point is essentially storing a number of units of a certain size instead of storing a significand and an exponent. However, if the units could be of any size, how big would the fixed-point units ...
CPlus's user avatar
  • 7,861
9 votes
1 answer
196 views

How are generators implemented?

Several languages, such as JavaScript, C#, and Python, have "generator" methods that lazily yield a series of values rather than returning a single one: ...
Bbrk24's user avatar
  • 8,907