Achieving a higher-level of polymorphism in Code
A while ago, I tried writing a polymorphism engine. I got fairly far using powerful engines such as the beaengine and x86 JIT libraries. However I noticed the primary method of implementing "polymorphic" code was to decompose the instructions into more primitive instructions, reorganize the ones independant of their sibling instructions, and then to compile some of them into single more high-level instructions if possible. The problem is, x86 code is expressed in a linear fashion, you don't know (without a lot of complex logic - and even then it is impossible when you are dealing with bodies of memory) what order operations can be performed in - how you can decompose an entire function mix it with its caller etc. Programming languages like C & C++ don't allow the programmer to express the details required to create truely polymorphic code. There is no way of expressing which operations can be performed in a parallel manner, and which operations need to be performed in sequence.
I tried to look into a more powerful form of polymorphism - sort of put it aside for a while.
Now that I am doing hardware & digital circuit design, I came accross a programming language called verilog - which illustrates a very atomic programming language. If you've programmed in verilog, you'll know what I mean. For example, this is a verilog application that will count X up from 0 through 10 and y up from 0 through 20. As these are state-machines, they will need to be put into an initial state.
As you can see, fundementally, C++ and C (and any software programming language) is _very_ different from verilog or any hardware descriptor language - however hardware descriptive languages are significantly more descriptive in terms of atomic implementation which makes it suitable for polymorphic code.
The idea is that, if we were to work off of a language like this to create a different programming language that would be more suitable for development of polymorphic code, we could create a more powerful level of polymorphism.
I tried to look into a more powerful form of polymorphism - sort of put it aside for a while.
Now that I am doing hardware & digital circuit design, I came accross a programming language called verilog - which illustrates a very atomic programming language. If you've programmed in verilog, you'll know what I mean. For example, this is a verilog application that will count X up from 0 through 10 and y up from 0 through 20. As these are state-machines, they will need to be put into an initial state.
As you can see, fundementally, C++ and C (and any software programming language) is _very_ different from verilog or any hardware descriptor language - however hardware descriptive languages are significantly more descriptive in terms of atomic implementation which makes it suitable for polymorphic code.
Code:
module adder(
clk1hz,
reset,
x,
y);
output [4:0] x;
output [4:0] y;
input clk1hz;
input reset;
reg [7:0] count; //8 bits for our counter
always @(posedge clk1hz or posedge reset)
begin
if(reset)
count <= 0;
else
begin
//This operation is performed parallel to any other operations because it uses the parallel assignment operator <=
count <= (count + 1) % 200;
//so if I were to go (not that 'z' exists)
z <= 15;
//Either the first or second assignment operator can be executed first - or both at the same time (if possible)
end
end
//These 'wires' or signals are to constantly equal to these expressions. I.e, if one of their dependant variables change, they must also change.
assign x = count % 11;
assign y = count / 10;
endmodule
The idea is that, if we were to work off of a language like this to create a different programming language that would be more suitable for development of polymorphic code, we could create a more powerful level of polymorphism.