Live data from Hacker News

My Most Important Project Was a Bytecode Interpreter

gpfault.net

31–40 of 154 posts

Re: My Most Important Project Was a Bytecode Interpreter

#31
post #8

I love the author's meta-idea of refusing to accept that unfamiliar things are black boxes full of magic that can't be touched. A great example of this mindset is the guy who bought a mainframe. [1] Refuse to be placed in a silo. Work your way up and down the stack and you'll be much better placed to solve problems and learn from the patterns that repeat at all levels. [1] https://news.ycombinator.com/item?id=1137671…

Everything is made from smaller components. Understand each of those components better and you'll understand the entire system better.

Sometimes, you can use end-errors to tell which component has the issue. For instance, if a web site gives a 502 error, the problem is likely with the load balancer or lower network stack on the web server. 404 would often be a file system level issue on the web server. 500 is frequently a network issue between web server and database server. 400 is a problem with the site presentation code, or maybe database malforming addresses.

Re: My Most Important Project Was a Bytecode Interpreter

#32
post #28
post #18

Earlier quoted context omitted.

Strong agree on emulator and particularly stack vm. Would add: TCP/IP stack.

mostly curiosity: why a stack vm in particular? (is it because you then need to write the compiler for it?)

Because if you're familiar with conventional real register architectures, the stack VM forces you to rethink it, in a much simpler way. It's a useful simplifying abstraction.

Re: My Most Important Project Was a Bytecode Interpreter

#33
post #22

Earlier quoted context omitted.

I don't get it - what do regexps have to do with compilers and how do they make compilers faster?

The first step in compilation is lexing -- converting a character stream to a stream of semantic "tokens", where a token might be "a number literal" or "the 'while' keyword" or a single character token like "{". This process is usually done via regexs.

I didn't think of lexer rules as regular expressions but I suppose they are of course.

But I can't imagine a lexer would ever be the performance bottleneck in a compiler.

Re: My Most Important Project Was a Bytecode Interpreter

#34
post #27

Two approaches are severely underused in the software world: 1) Domain-specific languages (DSLs) 2) Virtual machines (or just explicit state machines more generally) What I mean is, alot of problems could be solved cleanly, elegantly, more safely, and more powerfully by using one (or both) of the above. The problem is that when people think DSL or VM, they think big (Scheme or JVM) instead of thinking small (printf).…

Yes, can you describe your SPF library? I'd love to learn more about how using a VM / state machine paradigm could help me approach CS problems.

Re: My Most Important Project Was a Bytecode Interpreter

#35

Earlier quoted context omitted.

Every now and then I get interested in demoscene programming. I've never even been able to get a triangle to render on the screen - except with something like XNA. Do you think there's any value in going back to say, DOS based VGA programming? People in #osdev thought I was a bit strange for wanting to write a bootable kernel that only put pixels on the screen, but I really enjoy the idea of starting with plotting pi…

You can write raw pixels to the screen with a HTML canvas and JS - no need to do it with low level code and making your own OS.

I bet you could go from main() to displayBufferOnScreen(unsigned char *buffer) in a couple dozen lines of C using SDL.

Re: My Most Important Project Was a Bytecode Interpreter

#37
post #22

Earlier quoted context omitted.

I don't get it - what do regexps have to do with compilers and how do they make compilers faster?

The first step in compilation is lexing -- converting a character stream to a stream of semantic "tokens", where a token might be "a number literal" or "the 'while' keyword" or a single character token like "{". This process is usually done via regexs.

I think they're usually done with a specific FSM, rather than general regular expressions.

Re: My Most Important Project Was a Bytecode Interpreter

#38

One of the moments where I really started to feel like I was starting to 'see the matrix' was when I was working on a regex engine to try to make my compiler faster (it didn't, but that's another story). The asymptotically fast way to approach regex processing actually involves writing a parser to process the regex, so in order to write a fast compiler, you need to write another fast compiler to process the regexes t…

I mean, the whole point of regexes (not to be confused with PCREs) is that any given regex is isomorphic to some canonical finite state machine. It is, specifically speaking, a tiny description of an FSM over the alphabet of ASCII characters (or whatever charset you're using).

Interestingly, regexes/FSMs are (IIRC) the most powerful class of machines for which equivalence is decidable. So if you give me any two regexes, I can tell you if they match on all the same strings, but this is not true for any more powerful grammar.

Re: My Most Important Project Was a Bytecode Interpreter

#39
I saw the matrix after I first implemented a virtual machine. I recommend everyone does it because it will teach you a lot about how code is executed and transformed from the syntax to the actual assembly/bytecode. A stack based virtual machine is so simple it takes a lot of thinking to understand how they work. (or maybe I'm just not that smart).

It's interesting that he implemented function calls via a jump. In my VM a function is just mapped to a name (variable), so functions are first class. When the VM gets to a CALL instruction, it loads the bytecode from the hash table (via a lookup of the name).

Since this is a procedural language where statements can be executed outside of a function, implementing the functions as a jump would be difficult because there would need to be multiple jumps between the function definition and statements that aren't in a function.

I really wish my CS program had a compilers class, but unfortunately they don't, so I had to learn everything on my own.

Re: My Most Important Project Was a Bytecode Interpreter

#40

Earlier quoted context omitted.

Every now and then I get interested in demoscene programming. I've never even been able to get a triangle to render on the screen - except with something like XNA. Do you think there's any value in going back to say, DOS based VGA programming? People in #osdev thought I was a bit strange for wanting to write a bootable kernel that only put pixels on the screen, but I really enjoy the idea of starting with plotting pi…

You can write raw pixels to the screen with a HTML canvas and JS - no need to do it with low level code and making your own OS.

Or with different desktop GUI toolkits for different languages: C++ w/Qt, C++ w/ wxWidgets, wxPython, Perl/Tk, Python +Tkinter, Delphi, Lazarus, or many other lang/toolkit combos. Even many BASICs have that ability built-in (from the early days of personal computers).
Post reply on HN