Skip to main content

Questions tagged [implementation]

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

Filter by
Sorted by
Tagged with
3 votes
0 answers
147 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
  • 253
3 votes
0 answers
197 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
  • 304
4 votes
2 answers
234 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
344 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
1 answer
302 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
422 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
  • 13k
7 votes
1 answer
342 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
426 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
12 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
181 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
252 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
297 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
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
  • 19.7k
2 votes
1 answer
335 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,779
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,083
6 votes
1 answer
260 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
  • 13k
5 votes
0 answers
153 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
39 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
  • 19.7k
2 votes
1 answer
258 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
237 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
729 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
541 views

Why did Objective-C remove `NSZone`?

NSZone is a type representing a memory allocation. NSObject implements the allocWithZone: ...
Bbrk24's user avatar
  • 9,067
8 votes
2 answers
386 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,067
5 votes
1 answer
218 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
310 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,067
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
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
143 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,067
3 votes
2 answers
770 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,359
4 votes
5 answers
848 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
193 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,723
10 votes
1 answer
229 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
255 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
283 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
  • 8,321
8 votes
1 answer
434 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
328 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
  • 19.7k
12 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
185 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
232 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
264 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
  • 19.7k
5 votes
1 answer
172 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
243 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
  • 13k
8 votes
2 answers
164 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,723
6 votes
1 answer
179 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
  • 9,067
6 votes
2 answers
99 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,821
5 votes
2 answers
260 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,613
11 votes
1 answer
198 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