Urgent.News

What's breaking now, across thousands of outlets.

Tech

Making a Python interpreter in 1024 bytes

Article URL: https://austinhenley.com/blog/python1024.html Comments URL: https://news.ycombinator.com/item?id=49591876 Points: 224 # Comments: 82

A Python interpreter has been crafted in 1024 bytes of C code without the use of macros or libraries. The resulting interpreter resembles Python, featuring elements such as "def", colons, indentations, and if statements without parentheses. The interpreter includes a recursive descent parser and handles a subset of Python syntax. It operates by using the C program's call stack to manage recursion, keeping the state in global variables, and tokenizing the source code into an abstract syntax tree.

The interpreter is capable of executing basic arithmetic expressions, including addition and if statements. It also supports loops, functions, and conditional expressions. Despite its limited feature set, the interpreter still manages to pass the FizzBuzz test, demonstrating its functionality. The code golfing process resulted in a 1024-byte interpreter, while the original version exceeded 4800 bytes.

The implementation relied on various tricks and optimizations, such as using ASCII values for code length reduction, skipping to the end of a line using specific conditions, and employing clever C constructs to minimize bytes. The final result is an impressive demonstration of what can be achieved with a minimal code size, showcasing the versatility and adaptability of the Python language within such tight constraints.

Written by urgent.news from Hacker News Best's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at austinhenley.com →

More in Tech

Somebody asked for help. Nobody came.

Only real asks count. GitHub tells you who opened an issue: the repo's owner, a member, a collaborator. Keep those, add three weeks of silence and zero replies, and every result is a real person who…

Designing the Risk Engine Behind CIDS

A security system can collect thousands of events. But collecting events is not the difficult part. The difficult part is deciding: Which events actually matter?

Turn a website security finding into a client-ready next step

A scanner can identify an observation. It cannot, by itself, settle every business decision that follows. For an agency managing client websites, a useful report needs to bridge that gap.

  • Focus on specific website observation, not generic insecurity claim
  • Separate consequences from remediation steps in report
  • Assign owners and schedule follow-ups for concrete actions

More from Sunday 6 September →