Commit graph

208 commits

Author SHA1 Message Date
Joseph Kogut
d054ae9467 Create flag to compile in freestanding mode 2017-02-12 11:36:35 -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
a4c540f5a0 Merge pull request #30 from ryanpcmcquen/patch-1
Remove trailing slash from INSTALL_PREFIX
2015-02-21 18:27:33 -07:00
Ryan P.C. McQuen
d9fb3065f2 Remove trailing slash from INSTALL_PREFIX
Otherwise '//' occurs.
2015-02-21 09:01:00 -08:00
Joseph
9872f64348 Merge pull request #29 from tekknolagi/master
no need for gotos...
2014-10-14 23:47:54 -07:00
Max Bernstein
de3a679576 no need for gotos... 2014-08-01 18:19:24 +02: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
Joseph Kogut
ca762c48ad Merge branch 'master' of https://github.com/jakogut/tinyvm 2014-06-08 16:38:38 -07:00
Joseph Kogut
2f2d89c4fe Added item to TODO 2014-06-08 16:38:13 -07:00
Joseph
1480d046b9 Make it mildly more difficult for spammers to find me 2014-03-24 14:39:53 -07:00
Joseph
da5ba2816d Added contact information to README 2014-03-24 14:25:34 -07:00
bl0ckeduser
3b5cbac25b Merge pull request #28 from PaytonTurnage/master
Modify htab to have generic function names, and find to be nonredundant.
2014-01-19 14:06:38 -08:00
Payton Turnage
daa02f5082 Fix bug where an outdate node is returned.
If htab_add_core added a node that happened to push the htab past its load
factor, it would return a pointer to where the added node was *before* the
rehash. Now it does not do this.
2014-01-14 20:54:31 -05:00
Payton Turnage
584217a142 Modify htab_add to have a generic core. 2014-01-14 20:03:41 -05: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
Joseph
abea0981ae Merge pull request #27 from PaytonTurnage/master
Implementation for Preprocessor Defines
2014-01-14 07:40:33 -08:00
Payton Turnage
27a090e704 Remove assumption that node is in the bottom of the bucket.
This is the last remaining instance of this assumption.
2014-01-14 00:51:42 -05:00
Payton Turnage
e6d9d92d8c Do not write a value for strings in htab.
The assignment is unnecessary, and was overwriting the first element in the bucket (not the added string's value) in the case of a collision.
2014-01-13 13:50:56 -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
aa57b007c7 Make sure strings are moved into the rehash. 2014-01-13 11:16:00 -05:00
Payton Turnage
7bea39a6b5 Add preprocessor directives to the SYNTAX file.
The preprocessor section of the SYNTAX file has been rewritten to match
the other sections in style, and include both %include and %define
directives. #27
2014-01-13 11:08:12 -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
b208237960 Allow the preprocessor to abort.
If the preprocessor encounters a problem, such as failing to load a source
file or an improperly formatted define, it should be able to abort running
the program.
2014-01-12 21:56:54 -05:00
Payton Turnage
27cde3f429 Warn on redefining. 2014-01-12 21:54:21 -05:00
Payton Turnage
d152751cf8 Free the defines memory earlier.
There is no need to keep this memory for the life of the program.
2014-01-12 21:49:17 -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
1d9659c507 Modified TODO 2014-01-11 15:52:49 -07:00
Joseph Kogut
5719b3a265 Added TODO 2014-01-11 15:48:44 -07:00
bl0ckeduser
07c32b9869 Simplify a structure copy 2013-08-12 18:43:17 -04:00
bl0ckeduser
716936a8eb Fix incorrect truncation of floating-point data
If the entire parenthesized division expression is cast to float, as it
was prior to this commit, C performs truncating integer division before
converting to float, which always leads to a result of zero.  `git-blame'
traces the bug to commit d5ed7e75d9, which
added the faulty parentheses as a matter of style. No parentheses are
necessary, since increments have higher precedence than type-casts,
type-casts have higher precedence than division, and division has
higher precedence than comparison. The operations will execute in the
desired order.
2013-08-12 18:33:08 -04:00
Joseph Kogut
6ca1ec8b05 Added prime sieve example program 2013-03-13 17:59:06 -07:00
Joseph Kogut
f60fb720b6 Fixed filename typo 2013-03-07 14:42:53 -07:00
Joseph Kogut
d5ed7e75d9 * Replaced all instances of malloc with calloc
* Replaced magic number in tvm_htab.c with define
2013-03-07 12:19:03 -07:00
Joseph Kogut
378cc66c0d Removed a dumbass goto. 2013-02-08 20:16:12 -07:00
Joseph Kogut
9be63e849d * Updated SYNTAX to include preprocessor directives
* Added a preprocessor example program
2013-02-08 14:15:36 -07:00
Joseph Kogut
21198a8282 Added preprocessor 2013-02-08 13:51:01 -07:00
Joseph Kogut
7f753d0954 Fixed incorrect path PROF_ARGS used by build target "profile" 2013-02-07 10:57:52 -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
cc39eadc9e Fixed typo in tvm_program.c 2013-02-07 10:13:15 -07:00
Joseph Kogut
e1a6ae6188 Merge branch 'master' of https://github.com/GenTiradentes/tinyvm 2013-02-06 11:48:12 -07:00
Joseph Kogut
25cc724b33 *Updated variable declarations and definitions to C99 standard
*Removed some excessive conditional nesting
2013-02-06 11:47:13 -07:00
Joseph
eb5b168fe7 Merge pull request #24 from bl0ckeduser/fix-tdb
Patch tdb to compile with the new Makefile and gcc 4.6.3
2013-01-28 19:02:38 -08:00
bl0ckeduser
9f563a7cb3 Patch tdb to compile with the new Makefile and gcc 4.6.3 2013-01-28 21:03:23 -05:00
Joseph Kogut
c11e5bccfa Made pointer syntax in TDB more consistent. 2013-01-25 13:05:51 -07:00
Joseph Kogut
451ff4df8e Moved example tvm programs to programs/tinyvm. 2013-01-25 11:40:26 -07:00