News for hackers. Stuff that matters.
Re:TinyVM – A small and easy to understand virtual machine in C by userbinator on Saturday March 17, 2018 @01:49PM (#16608117)
After seeing C4[1], everything else doesn't seem tiny at all... and maybe it's just me, but this is another one of those projects where I found the directory layout rather confusing, especially for something that claims to be "small and easy to understand." bin/ is empty, there's only a single nearly-empty file in src/, lib/ is also empty, include/tvm is two levels but one is empty, and all the interesting stuff actually appears to be in libtvm/ .

More importantly, even after going through all the files in libtvm/ , I still haven't managed to find the main instruction execution loop nor the decoding switch. Sorry, but I don't think "small and easy to understand" applies, and I've had experience with VMs and interpreters and the like for many years. Compare with this, for example:

https://github.com/tjmerritt/z80

A rule-of-thumb when investigating the source code of a project for the first time: if I have to go more than 2 directories deep to get to the "meat" of the code, my desire to explore further drops significantly.

[1] https://news.ycombinator.com/item?id=8558822

Re:TinyVM – A small and easy to understand virtual machine in C by dfbrown on Saturday March 17, 2018 @04:45PM (#16608982)
C library public headers are commonly two levels deep to so that projects using them can add the "include" directory to their header search path and in their code have #include "<libname>/header.h". It helps avoid filename clashes.
Re:TinyVM – A small and easy to understand virtual machine in C by lmitchell on Saturday March 17, 2018 @05:44PM (#16609228)
I dunno, I find it pretty easy to understand... seems like the main instruction loop is in tvm.c, in the function tvm_vm_run(), which is exactly the first place I looked and seems totally sensible to me.

  for (; vm->prog->instr[*instr_idx] != -0x1; ++(*instr_idx))
    tvm_step(vm, instr_idx);
Re:TinyVM – A small and easy to understand virtual machine in C by spc476 on Saturday March 17, 2018 @06:03PM (#16609284)
Compare that to my 6809 emulator [1]. I have a mc6809_run() function that is pretty much the same, but mc6809_step() is in the same file and not hidden in a header file. There also seems to be a lack of memory operations (like reading or writing) other than PUSH/POP.

[1] https://github.com/spc476/mc6809 [2]

[2] Yes, it lacks a README. I know.

Re:TinyVM – A small and easy to understand virtual machine in C by coldtea on Saturday March 17, 2018 @05:40PM (#16609207)
>bin/ is empty, there's only a single nearly-empty file in src/

Because that's where the generated binary will go.

>lib/ is also empty

Presumably the same for any lib files?

>include/tvm is two levels but one is empty

That's as intended too, poor man's namespacing.

Re:TinyVM – A small and easy to understand virtual machine in C by saagarjha on Sunday March 18, 2018 @12:13AM (#16610433)
> Because that's where the generated binary will go. > Presumably the same for any lib files?

Why is even tracked, then? Surely putting it in .gitignore is a better way to go?

Re:TinyVM – A small and easy to understand virtual machine in C by numpad on Sunday March 18, 2018 @06:32PM (#16614874)
I find leaving them in the repo makes it pretty clear how your have to configure your build process. For GCC, I instantly know I need `-I ./tinyvm/include/` and can use `#include <tvm/tvm.h>` etc.
Re:TinyVM – A small and easy to understand virtual machine in C by acqq on Saturday March 17, 2018 @02:01PM (#16608174)
I’ve found that switch fast, in a few clicks, reading this on my phone:

https://github.com/jakogut/tinyvm/blob/master/include/tvm/tv...

I’ve used the info you provided as the start, of course.

Re:TinyVM – A small and easy to understand virtual machine in C by ben_bai on Saturday March 17, 2018 @03:40PM (#16608666)
In a .h file?

Have to agree with userbinator.

Re:TinyVM – A small and easy to understand virtual machine in C by e12e on Saturday March 17, 2018 @06:15PM (#16609336)
Isn't it odd to have:

/* nop */ case 0x0

Rather than #define NOP 0x0? Namespacing? How about vm_NOP?

Re:TinyVM – A small and easy to understand virtual machine in C by kowdermeister on Saturday March 17, 2018 @05:08PM (#16609066)
"easy to understand" is added by the poster to the title, the repo doesn't make this claim.

With zero explanation and code it's small experiment, but not really educational.

Re:TinyVM – A small and easy to understand virtual machine in C by pankajdoharey on Saturday March 17, 2018 @05:26PM (#16609144)
By C4 you meant C in 4 functions? https://github.com/rswier/c4 here?
Re:TinyVM – A small and easy to understand virtual machine in C by tytytytytytytyt on Saturday March 17, 2018 @05:01PM (#16609041)
Why does he/she have .gitignore files in subdirectories? That seems to make those subdirectories linger for no reason.
Re:TinyVM – A small and easy to understand virtual machine in C by tines on Saturday March 17, 2018 @05:18PM (#16609105)
Usually because a build script depends on their existence or something.
Re:TinyVM – A small and easy to understand virtual machine in C by saagarjha on Sunday March 18, 2018 @12:14AM (#16610434)
Then have the scripts create them?
Re:TinyVM – A small and easy to understand virtual machine in C by coldtea on Saturday March 17, 2018 @05:41PM (#16609211)
>Why does he/she have .gitignore files in subdirectories? That seems to make those subdirectories linger for no reason.

He has it precisely to make them linger. And what "no reason"? It's so subsequent scripts can put results there.

Re:TinyVM – A small and easy to understand virtual machine in C by ori_b on Saturday March 17, 2018 @08:36PM (#16609893)
Better form to just have those scripts create the directories.
Re:TinyVM – A small and easy to understand virtual machine in C by coldtea on Sunday March 18, 2018 @10:50PM (#16615920)
Sure, but it's not like why having them persist is a mystery, or hurts understanding the structure of the repo, as the parent claimed.
Re:TinyVM – A small and easy to understand virtual machine in C by tytytytytytytyt on Tuesday March 20, 2018 @08:42PM (#16634237)