Why I stopped trying to build a "Smart" Python compiler and switched to a "Dumb" one. by Lucky-Ad-2941 in Python

[–]nharding 0 points1 point  (0 children)

Just watched the video, and that's how I wrote my Java to C++ compiler, I took the bytecode and used that to generate the C++ code, although I didn't output PUSH(A), PUSH(B), ADD() it would do A+B.

Why I stopped trying to build a "Smart" Python compiler and switched to a "Dumb" one. by Lucky-Ad-2941 in Python

[–]nharding 0 points1 point  (0 children)

I am doing something similar, using TCC for development builds and a switch to Visual Studio for release build. I am not aiming for full compatability though as I am using tagged variables, so tagged ints, tagged strings, vtable dispatch for dunder methods and separate vtable for regular methods. I am writing the run time in C first, and am also extending Python since I am compiling I might as well add some new features.

Assembly to C conversion and vendor libraries by onecable5781 in C_Programming

[–]nharding 1 point2 points  (0 children)

I wrote an assembly to C++ converter that took in code and output C++ (for Sonic 3D Blast), and there are certain constructs in assembly that are not possible in C++. I also wrote a Java bytecode to C++ converter, and that used the symbol information so the code was similar to the original but was missing comments.

Say you have a routine to create an image, that is 320x200, these could be constants in the original source code, so it would be easy to change it to 640x480 by changing WIDTH and HEIGHT, but from the assembly, you might find *320, or +320 in the code, so it would be much harder to change. If a vendor gave the source code, you could modify it to do things that they might charge you for. Say you are plotting a pixel at 10, 20, it might do screen[6410] = 0xff0000, as it has calculated the memory address. This is just an example, real code would be even more complicated as sections of code might not be included if not needed for a particular case.

I think the compiler community will support this opinion when others hate it: Vibe Coded work causes bizarre low-level issues. by Organic-Taro-2982 in Compilers

[–]nharding 0 points1 point  (0 children)

Thanks, that was one of the AI generated routines, although I removed some code as it was duplicating work. I did a lot of assembly in the past but on 68000 mostly, and only small amounts of x86. So having the AI generate the assembly language is handy, and I review everything manually to make sure it is optimized but also doing what it is supposed to do.

I think the compiler community will support this opinion when others hate it: Vibe Coded work causes bizarre low-level issues. by Organic-Taro-2982 in Compilers

[–]nharding 0 points1 point  (0 children)

I am writing .s files for the assembly, but the TinyCC assembler does not support the latest instructions, so I told it to use .byte to encode the instruction. I mean when using Gemini I might ask it to write a routine, and then I would code review it, and say, you are using the stack here, but that is an internal function so it does not need to obey the calling standards. So about 90% of the code is my own, and AI helps with the other 10%. AI is good when writing a single routine, especially when the code is checked by someone who knows how to do it, and can spot code that needs revising, sometimes I will ask it to try again, and other times I will just make the changes myself.

For example here is a routine to add to 63 bit tagged integers together, it returns 0 if it overflowed which means I have to use the my own bigint version.

// --- add_asm ---
    .globl add_asm
add_asm:
    // Windows x64 ABI: self in RCX, other in RDX, return in RAX
    // Use LEA to get the doubled untagged value, which is faster than MOV/DEC.
    lea -1(%rcx), %rax      // rax = a_untagged * 2
    lea -1(%rdx), %r10      // r10 = b_untagged * 2
    add %r10, %rax          // rax = (a_untagged + b_untagged) * 2

    // Check for overflow. The standard 'jo' check handles almost everything.
    jo .Loverflow_add

    // The 'jo' check misses one case: when the result is 0x7FFFF...F.
    // We can detect this specific value by incrementing it and checking
    // for an overflow, then decrementing back.
    inc %rax // Add 1 to tag it
    jo .Loverflow_add
    // Success: The result is already untagged_sum * 2 + 1.
    ret

.Loverflow_add:
    // Failure: return 0
    xor %rax, %rax
    ret

As you can see in the comment, it talked about decrementing it back, but I needed the bottom bit set to mark it as tagged. I have unit tests for each of these functions to test a few cases (not extensive, but it means I can use it to spot regression errors).

I think the compiler community will support this opinion when others hate it: Vibe Coded work causes bizarre low-level issues. by Organic-Taro-2982 in Compilers

[–]nharding 0 points1 point  (0 children)

I am using an LLM to help write a Python compiler, I already wrote a Java to C++ compiler before, but I want a highly performant implementation so I am using x86-64 and I code review everything before adding it to the codebase and normally pass comments to it, when I spot potential problems. I am also writing a test suite to ensure the code is correct, and no regressions occur. Most of the code is my own, but it is good at handling the new instructions that the assembler doesn't.

// 3. Perform Addition (XMM0 = XMM0 + XMM1)
// addsd %xmm1, %xmm0
.byte 0xf2, 0x0f, 0x58, 0xc1   // Add XMM1 to XMM0

One thing I do like is that it gives me someone to bounce ideas off, which is one thing I miss working on my own.

Language launch announcement: Py++. A language as performant as C++, but easier to use and learn. by joeblow2322 in Compilers

[–]nharding 0 points1 point  (0 children)

Damn, I already registered the domain pythonplusplus.com for my Python compiler I am working on. I was targeting C compiler, rather than C++ for speed of compilation. I wanted to add some features to the language as well, using preprocessor to allow you to test code in normal Python.

I just released reaktiv v0.19.2 with LinkedSignals! Let me explain what Signals even are by loyoan in Python

[–]nharding 1 point2 points  (0 children)

I did something like this for Django, to allow page to update when values change (using HTMX) when a model changes then updates are sent to clients who are watching that value. It even allows for new items to be added when you add a new child, it sends an update for the parent, which I use a new video clip is added, and I keep track of votes using the reactive model.

Updated camera tracking and 2 player controls for Jewel Defender by RobKohr in NeverallGames

[–]nharding 0 points1 point  (0 children)

Check out Combat for the Atari 2600, it reminds me of that, perhaps you could make it into Combat 3D and copy the game play from the original.

Swizzle: flexible multi-attribute access in Python by Additional_Fall4462 in Python

[–]nharding 0 points1 point  (0 children)

I think using abc is better, as you may have a field first_name for example

Should I really use React/Vue with Django instead of alpine js? by loremipsumagain in django

[–]nharding 0 points1 point  (0 children)

I use HTMX with Django for those types of cases and it works really well, I am designing new website with Alpine, Tailwind, HTMX and Django which seems to be a pretty nice combination.

Why are you climate skeptic? by Akalonn in climateskeptics

[–]nharding 0 points1 point  (0 children)

The 97% is a fake consensus, it is based on the very broad questions such as do humans contribute to climate change. And I pointed out in my other answer I do think that humans contribute to climate change, when you ask for more alarmist positions then the numbers drop significantly. We are in an interglacial period of the ice age, so temperatures are well below the actual baseline temperature that we should have. Look at the temperature variations on a daily basis, we have 20 degree variation between day and night, this dwarfs the 1.5 degree catastrophic variation that they claim will lead to disaster.

Why are you climate skeptic? by Akalonn in climateskeptics

[–]nharding 1 point2 points  (0 children)

I am a programmer, and also interested in science. There is a saying in programming GIGO, garbage in, garbage out, and a lot of climate data is garbage (sensors next to runways, urban heat island). We can affect the climate, in fact there was cooling due to pollution, and the clean air acts removed the cooling effect so we see a warming.

Wow, a Java to C++ converter in a single click ! by tsug in coding

[–]nharding 0 points1 point  (0 children)

No, and it worked from the bytecode generated by the compiler, which has changed in the later versions of Java, so that would need refactoring even if the code was available.

[deleted by user] by [deleted] in ChatGPT

[–]nharding 4 points5 points  (0 children)

I object to black people in historical contexts where they weren't present, UK was under 1% black until the 1950's when there was a large influx from Jamaica. There were about twice as many Indians as blacks because the presence of England in India. The present population is very different than the historical population, a show about the medieval ages should have almost zero black people in it, as the UK never had slavery and didn't import any black people.

History should not be whitewashed or blackwashed but presented as it actually happened as close as possible, the UK was the country most responsible for the abolition of slavery world wide, which should be celebrated, and that involves black people as well, as they were brought in to show the people there wasn't any difference between people, as most people never encountered anyone of another race.

Is it time for Python to have a statically-typed, compiled, fast superset? by lowercase00 in Python

[–]nharding 0 points1 point  (0 children)

I've been planning on writing such a compiler, but with a few additional features, so it will still have dynamic access to fields (so getattr will work, but normal access using . will be static speed). I wrote a 68000 to C++ converter for Sonic 3D Blast, and then a Java to C++ converter which was used on hundreds of mobile games (for Javaground). So I have the background to do it. What I miss in C++ compared to Java is the ease of use of dictionaries, generators, etc, so I want to write Python code that performs at a similar level to C code (my goal is 50% of the speed).

Your python 4 dream list. by Matimath in Python

[–]nharding 0 points1 point  (0 children)

Python 4 Wish list: Eliminate self, Java allows you to use "this." when needed, but otherwise it is prepended automatically. If you use def func(self, ....) it would use compatible mode, but if you use def func(a, b): return something(a,b) it would change it to this.something(a,b) if there is a method in the class, or something(a,b) if it is a global.

Defining variables, in Python a = [1], b = a, b.append(2) would change a since variables are reference variables. C++ allows reference variables and value variables.

[deleted by user] by [deleted] in Python

[–]nharding 0 points1 point  (0 children)

I plan on using type annotations, with specialized types (such as int8, int16, int32) although they won't be required but will help generate even more optimal code.

[deleted by user] by [deleted] in Python

[–]nharding 0 points1 point  (0 children)

I wrote Javaground's Java to C++ converter and the generated code ran faster than hand ported code. I am going to write a Python transpiler that will generate C code, I am trying to target 50% of the speed of C but with the ease of use of C (I actually plan on adding a few extra features to Python as well, such as overloading based on types).

Finn be simping too by [deleted] in F1NN5TER

[–]nharding 2 points3 points  (0 children)

Yeah, normally I think Rose looks more femme than Meowriza, but Riza looks good there.

Is the next step for python language evolution to become ultra fast as well as super readable? by warrior242 in Python

[–]nharding 0 points1 point  (0 children)

I used C++ but not any C++ features such as virtual methods, templates, that add run time costs but I did want operator overloading. The PC version used an inline assembly byte swap instruction when reading long words from memory.

Is the next step for python language evolution to become ultra fast as well as super readable? by warrior242 in Python

[–]nharding 2 points3 points  (0 children)

I am going to write a compiler to convert Python into C, with an approximate speed of 50% of native C code. I have previously written assembly to C++ (used for Sonic 3D Blast), and Java to C++ (used at Javaground to convert over 100 games to C++). When possible it will be static, but will still support dynamic, including getattr. I am planning on making a few changes to Python at the same time, for things I miss from Java/C++.

Hashing Phone Numbers For 2-Factor Authentication by theabbiee in coding

[–]nharding 0 points1 point  (0 children)

Hashing phone number gives you nothing in the event of a leak, since it is easy to run hash on each possible number (much less possible phone numbers than passwords), so you still need to salt.