TinyVM is a virtual machine with the goal of having a small footprint. Low memory usage, a small amount of code, and a small binary. Building can be accomplished on UNIX-like systems with make and GCC. There are no external dependencies, save the C standard library. Building can be accomplished using "make," or "make rebuild". To build a debug version, add "DEBUG=yes" after "make". To build a binary with profiling enabled, add "PROFILE=yes" after "make". I can be reached at "joseph.kogut(at)gmail.com"
TinyVM is a small, fast, lightweight virtual machine written in pure ANSI C.
This addresses @GenTiradentes' note at the end of #27. It's relatively small.
- htab_find_core is a static method that finds a node based on the key and returns a pointer to the node or NULL
- htab_ find calls this and returns the value of that node, or -1 if it was not found
- htab_find_ref calls this and returns the valptr of that node, or NULL if it was not found
I've done some work on the defines item in the TODO. It is a big pull request, and I mostly did it this way so that all the changes were easily viewable. I can isolate changes and provide patch files where needed if this fork is to be merged.
Valgrind ~~likes~~ fails to reject it, and a test file is included in programs/tinyvm/preprocessor, linked here.
What I've been doing for my tests is
make clean && make DEBUG=yes valgrind --leak-check=full -v bin/tvmi programs/tinyvm/preprocessor/define.vm
in case recreating those steps is necessary in figuring something out.
I was rather unsure of the decision to make an entirely new structure for storing strings, but my intention, if you like this direction, was to also use it for storing variable names when adding the feature to define bytes, words, and double words.
Thanks ahead of time for taking a look! This has been a fun virtual machine to learn assembly on.
my environment is macos , when i make.
clang src/tvmi.c -ltvm -Wall -pipe -Iinclude/ -std=gnu11 -Werror -pedantic -pedantic-errors -O3 -Llib/ -o bin/tvmi
ld: library not found for -ltvm
clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [tvmi] Error 1
I read about hashtables in K&R. It seems avoiding collisions is fairly easy.
I have used the technique of "Separate chaining" here (http://en.wikipedia.org/wiki/Hash_table#Separate_chaining).
(that might be exactly the same as the technique shown in K&R, I'm not sure).
I hope you find the code isn't too messy :)
I've tested it by running a program that actually hash-collided on my machine, and also by changing the hash function to always return the same hash.
The included program contains two labels that should hash to the same value on x86 or amd64 (i.e. 32-bit or 64-bit PC hardware).
Running it with the original hash table code prints out the error "Label 'verdict' defined twice".
With some editors, these actual tab characters are implicitly replaced with spaces, causing the lexer to break on the next compilation. These changes may need to be applied to the other branches.
without modifying one line of codes. https://github.com/chillancezen/ZeldaOS/tree/master/application/tinyvm
I do realize how portable the code written with ANSI C is. much appreciated!
I have successfully build the program , but how can I run it. I am on linux mint. Every time I try ./tvmi it gives the following error File was not found, or does not exist. Unable to interpret.
This fixes a number of diagnostics which were shown with
scan-build makeon a Debian Stretch system (clang version 3.8.1-24).
Testing performed: at each ref, the software compiles, and
./bin/tvmi programs/tinyvm/euler/euler1.vmproduces the same output.
Removed filename parameter in tvm_vm_create() definition (its declaration doesn't contain this parameter). Fixed possible NULL pointer dereferencing in tvm_vm_create() function.
Program objects will now track defines. The htab for defines will be passed to the parser module in future committs, which will scan and replace any instances of the defined string.
Possible modifications in future commits:
- Do not use an htab for defines; rather a list of structs with a key/val
- Use the integer value allocated for htab elements as a pointer to the value string instead of an integer.
Even the newer C++ standards have lareayd decided the preprocessor for C is now just "part of the language" Maybe find a way to integrate that?
Changed: process_defines now uses a calloc'd tempstr like process_includes. Using a variable-length array was the only barrier for the MS compiler.
Added Visual Studio solution and project files.
Please comment this code. It looks like a really excellent project for learning about virtual machines but people wont use it that way if its a pain to figure out whats going on.
If not comments then please provide documentation.