4 ms·
> That's right. You could. How would that help? I literally just described in code how that could help. Wherever the compiler encounters an instance of a list
by James_K 2y ago
> That's right. You could. How would that help?
I literally just described in code how that could help. Wherever the compiler encounters an instance of a list in the source code that looks like a function, you compile it and put the result in a secret third element. Then, when you have to apply a list, you first check if it has a compiled third element before you do the slower work of interpreting it. Have you ever written a compiler or used one? What I described here is literally just the process of JIT compilation.
- lisper 2y agoJIT compilation only works if functions can't change at run-time, which is true for most languages, but not for Bel.
- James_K 2y agoSome fairly simple escape analysis could likely determine that most functions used in practice do not have their bodies assigned.
- lisper 2y agoThat might work if Bel didn't have threads. But it does, so it doesn't. Also, assigning the body is not the only way to undermine compilation. You can change a function into a non-function (by changing its first or second element) and vice versa. You can change a function's environment. You can change its argument list. You can modify the body of a function while it is being evaluated. You can change anything about a function at any time.
- James_K 2y agoYou can still do escape analysis. You wouldn't even need to be very advanced with it since most code won't do anything close to modifying and expression that's in the process of evaluating.
- lisper 2y agoYou clearly don't know what escape analysis is or how it works. Escape analysis applies only to data allocated at run-time. Programs are generally written before they are run (this is the reason that "run-time" is even a thing) and the functions that comprise them in a Bel program are generally globally bound with DEF. Escape analysis doesn't work on globally bound data. It has already escaped before your program even starts to run.
- James_K 2y agoYou can look at where a name is used, I say "escape analysis" here because that is the technique closest to what you would be doing. It gets the idea across quite well. At the fundamental level, you are analysing a program to see which parts of it access which values. In this case assessing if a piece code bound to a global variable "escapes" into the rest of the program as data. The objectives and techniques are similar. This is quite clearly possible.
- lisper 2y agoEscape analysis is a well-established term of art: https://en.wikipedia.org/wiki/Escape_analysis https://en.wikipedia.org/wiki/Escape_analysis "In compiler optimization, escape analysis is a method for determining the dynamic scope of pointers..." In the case of global bindings, there is nothing to analyze. Global bindings do not have dynamic scope, they have global scope. (Duh.) > This is quite clearly possible. OK, you believe what you want. But I'll bet you $100 that you can't even write a program that reliably determines whether or not a list is a valid Bel function, let alone one that does "escape analysis" on an entire Bel code base (whatever you think that might actually mean). Here, I'll get you started: (def is-a-function? (l) (and (id (car l) 'lit) (id (cadr l) 'clo) ...
- James_K 2y ago> valid Bel function What do you mean by this? Can valid functions produce errors? Does a valid function need to halt? > In the case of global bindings, there is nothing to analyze A global name will be used in the program text a finite number of times. You can treat each usage as an the creation of a new value and do escape analysis on it. Doing this on all usages of a variable can determine that the none of these values escape and therefore the value cannot be passed to a list mutating function and is safe to optimise.