Commit graph

29 commits

Author SHA1 Message Date
Jeff Epler
75f2a1e43e Move definition of tvm_opcode_map, tvm_register_map out of header
.. the previous arrangement lead to compiler diagnostics when
building with 'scan-build make':

include/tvm/tvm_tokens.h:17:20: error: ‘tvm_register_map’ defined but not used [-Werror=unused-variable]
 static const char *tvm_register_map[] = {
                    ^~~~~~~~~~~~~~~~
include/tvm/tvm_tokens.h:7:20: error: ‘tvm_opcode_map’ defined but not used [-Werror=unused-variable]
 static const char *tvm_opcode_map[] = {
                    ^~~~~~~~~~~~~~
cc1: all warnings being treated as errors
2018-03-17 13:46:24 -05:00
Joseph Kogut
488b88f867 tvm_preprocess: update *src after (re)allocating memory
During preprocessing, we find directives, and if they specify including
other source files, we remove the directive, allocate a new block of
memory, copy the first block, append the new source file, and append the
second block.

Previously, the value of the source pointer was passed into the
preprocessing function. When the memory would be (re)allocated, the
pointer value could change, but the original pointer would not be
updated.

Now, the pointer is passed by address, and updated when the memory it
points to changes.
2017-02-12 11:51:06 -08:00
Joseph Kogut
b6ffbd9a4e tvm_step: use double pointer to args array 2017-02-12 11:38:01 -08:00
Joseph Kogut
ca87b3c5e9 Refactor with a consistent coding style
This commit refactors the project using a single, consistent coding
style, derived from the Linux Kernel Coding Style, available here:

https://www.kernel.org/doc/Documentation/CodingStyle

This includes, but is not limited to:
* Removal of typedefs, especially for structs
* Limiting lines to a reasonable length, 80 characters, mostly
* K&R style braces
* Removal of CamelCase
2016-08-28 20:31:12 -07:00
Joseph Kogut
2c66bad7ab Changed default CC to Clang
Modified source to allow for compiling with both GCC and Clang
2014-06-08 16:49:26 -07:00
Payton Turnage
ae63e45c65 Rename htab functions; rewrite find to be generic.
The htab functions find_str and add_str have been renamed to include _ref in
the places they previously noted _str. These are intended to manage an htab
containing references to any data; string or not.

The htab_find function has been divided up. htab_find_core now handles actually
finding the correct node. htab_find and htab_find_ref are just outward facing
functions for retrieving a specific kind of data from the node, depending on
what the htab is used for.
2014-01-14 19:09:35 -05:00
Payton Turnage
d945c9a3f6 Add a new function to return strings from htab.
The htab_find_str function eliminates the assumption that the string
is in the first place in the bucket.
2014-01-13 11:31:58 -05:00
Payton Turnage
e99a0428f3 Implement defines using the htab structure.
The htab_structure has been modified in two ways, which should not break
compatability with any of its uses.

It includes a void pointer, which is in this commit used to point to a
string for defines, and will in the future be used to point to the address
space for words, bytes, and double words.

It now includes a function htab_add_str specifically for storing strings.
It calls htab_add so as not to be redundant, but makes the node's value
their index for the lexer to fetch using htab_find, and assigns their
void pointer.

The lexer will now use htab_find on all tokens to see if they are a define
string, and if so, substitute them with the appropriate token.

The defines htab is destroyed after lexing, because that memory is done.
2014-01-13 10:20:21 -05:00
Payton Turnage
ed12ce05db Remove all traces of the tvm_tree structure.
It is to be replaced with a htab hash table.
2014-01-13 09:45:27 -05:00
Payton Turnage
c80d6974cb Substitute defines with their strings.
Before allocating space for a token, the lexer will first check to see
if that token is a defined name. If it is, it will allocate space for
the defined string instead.

A test file is included in programs/tinyvm/preprocessor to demonstrate
the behavior. When functioning, the program will print the fibonacci
sequence.
2014-01-12 21:43:57 -05:00
Payton Turnage
23e72a8ca7 Implement preprocessor defines.
This commit adds behavior to the preprocessor which fills a tree with
defines and their replacements. In future commits, the parser will
substitute instances of the defines with their replacements in the
source code.
2014-01-12 21:11:31 -05:00
Payton Turnage
9c9eece4d9 Fix naming conflict. 2014-01-12 21:04:56 -05:00
Payton Turnage
58f11eba57 Enable keeping track of associated values.
The tvm_tree structure should optionally be able to keep track of values
associated with the strings by which its nodes are sorted. In the case of
defines, this is the replacement string. In the case of variables, this
will be a pointer to the variable's location in memory.

Searching should return the value, or NULL.

To opt out of storing a value, pass NULL and 0 as the val and len arguments.
2014-01-12 20:30:04 -05:00
Payton Turnage
62066d614f Add a structure for searching strings.
The tvm_tree structure is a binary search tree. It will be used to hold
preprocessor defines, and variable names for when defining bytes, words,
and double words is implemented.

Each node structure and its own string are stored contiguously (in that
order) so the free's are easier to keep track of, and memory doesn't need to
be a concern when adding a string to the tree.
2014-01-12 20:00:20 -05:00
Joseph Kogut
21198a8282 Added preprocessor 2013-02-08 13:51:01 -07:00
Joseph Kogut
eac3bc4291 *Split parsing functions into their own source files
*Removed unused Makefile variables
2013-02-07 10:54:22 -07:00
Joseph Kogut
3d895e0948 Made hash table naming conventions more consistent 2013-01-24 10:42:40 -07:00
Joseph Kogut
ed3acfd515 Made naming conventions more consistent. 2013-01-23 11:15:07 -07:00
Joseph Kogut
d270cc5706 Made pointer syntax consistent 2013-01-23 11:06:19 -07:00
Joseph Kogut
caf4767696 Inlined tvm_step() and htab_hash(). 2013-01-23 10:41:17 -07:00
Joseph Kogut
86c01acd8c Switched to C99 standard 2013-01-20 14:14:35 -07:00
Bl0ckeduser
bc882e4db3 Hash table: implement load factor / rehash
Based on suggestion from bitbckt:

I  saw  this  in  my feed, and feel it merits comment. I hope you
don't mind the input.

You'll want to monitor the load factor of the hash table and  re-
hash  the  table  on  insert  when it is exceeded. Otherwise, key
lookup will degrade toward linear time for sets of  keys  with  a
high number of collisions.

The  easiest  way  to  implement the load factor is to maintain a
count of allocated nodes in tvm_htab_t and  divide  that  by  the
bucket count to obtain the load factor. Of course, you'd need the
bucket count (HTAB_SIZE) to be dynamic, too.
2012-01-19 17:22:41 -05:00
Bl0ckeduser
e0a387d7de Fix hash collisions (separate chaining) 2012-01-18 12:54:23 -05:00
Bl0ckeduser
313a440342 Implement buffer size limit in tvm_fcopy 2011-11-20 21:36:36 -05:00
Joseph Kogut
72193566b9 Moved program interpretation to explicitly called function 2011-09-25 05:47:31 -07:00
Joseph Kogut
75edb60116 * Fixed a style issue
* Inlined tvm_step()
2011-09-04 18:45:56 -07:00
Patrick Jackson
68d066bd53 Removed the redundancy introduced by tdb_step. 2011-09-04 17:06:08 -04:00
Joseph Kogut
7a128d41ec Added break and step to tdb 2011-09-02 02:05:17 -07:00
Joseph Kogut
15019d041f * Moved TVM code to an independent library
* Moved interpreter code to tvmi.c
2011-08-26 15:30:24 -07:00