Catching up on enhancements
This commit is contained in:
parent
8bb4145fe0
commit
cba66b015b
|
@ -0,0 +1,84 @@
|
|||
## Copyright (C) 2017 Jeremiah Orians
|
||||
## This file is part of stage0.
|
||||
##
|
||||
## stage0 is free software: you an redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## stage0 is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with stage0. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
* Current
|
||||
** Added
|
||||
Added type promotion to allow progress on mes.c
|
||||
Add support for anonymous unions inside of structs
|
||||
Added support for passing of function pointers via FUNCTION
|
||||
Added support for Local functions
|
||||
Added support for EOF
|
||||
Added additional debug information to M2-Planet
|
||||
Added line numbers and files names for errors in parsing to help debug
|
||||
Added support for close and fclose
|
||||
|
||||
** Changed
|
||||
Improving Documentation to help new programmers get functional
|
||||
|
||||
** Fixed
|
||||
Minor cleanup and removal of unneeded whitespace
|
||||
Fixed outstanding bug when struct foo* foo and foo->bar was used
|
||||
|
||||
** Removed
|
||||
|
||||
* 0.1 - 2018-02-23
|
||||
** Added
|
||||
Added example programs
|
||||
Added first generation libc
|
||||
Added first generation defs.M1
|
||||
added FOR Loop support along with example
|
||||
Added support for assembly statements
|
||||
Added CONSTANT to the language
|
||||
Added support for <. >= and > expressions
|
||||
Added struct support
|
||||
Added unary - and ! support
|
||||
Added additional functionality such as mixed structs, do while loops, gotos and tests for the new functionality
|
||||
Incorporate breaks into loops
|
||||
Became Self-Hosting
|
||||
|
||||
** Changed
|
||||
Tweaked argument processing to help mescc support
|
||||
Isolated global_token to cc.c
|
||||
Moved strings to the bottom of the output
|
||||
Broke out globals
|
||||
Started to move type information out of hard-coded logic
|
||||
Started adding tests instead of examples
|
||||
Put common x86 platform logic in a shared folder to reduce duplicate code
|
||||
Converted from legacy M2-Planet Input.c Output.c to M2-Planet -f input.c ... -f
|
||||
Minor reordering of tests
|
||||
|
||||
** Fixed
|
||||
expanded type support to include integer arrays
|
||||
Reduced the memory churn in string creation
|
||||
fixed Capitalization problems
|
||||
|
||||
** Removed
|
||||
Removed need for enum in bootstrapping
|
||||
Removed need for global output list
|
||||
Eliminated the global stack
|
||||
Reduced library dependencies
|
||||
|
||||
* 0.0 - 2017-07-05
|
||||
** Added
|
||||
Added minimal tokenizer
|
||||
Added minimal string support
|
||||
Added minimal parser
|
||||
|
||||
** Changed
|
||||
|
||||
** Fixed
|
||||
|
||||
** Removed
|
11
cc.c
11
cc.c
|
@ -21,7 +21,7 @@
|
|||
|
||||
/* The core functions */
|
||||
void initialize_types();
|
||||
struct token_list* read_all_tokens(FILE* a, struct token_list* current);
|
||||
struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename);
|
||||
struct token_list* reverse_list(struct token_list* head);
|
||||
struct token_list* program(struct token_list* out);
|
||||
void recursive_output(struct token_list* i, FILE* out);
|
||||
|
@ -42,15 +42,16 @@ int main(int argc, char** argv)
|
|||
}
|
||||
else if(match(argv[i], "-f"))
|
||||
{
|
||||
in = fopen(argv[i + 1], "r");
|
||||
char* name = argv[i + 1];
|
||||
in = fopen(name, "r");
|
||||
if(NULL == in)
|
||||
{
|
||||
file_print("Unable to open for reading file: ", stderr);
|
||||
file_print(argv[i + 1], stderr);
|
||||
file_print(name, stderr);
|
||||
file_print("\x0A Aborting to avoid problems\x0A", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
global_token = read_all_tokens(in, global_token);
|
||||
global_token = read_all_tokens(in, global_token, name);
|
||||
i = i + 2;
|
||||
}
|
||||
else if(match(argv[i], "-o"))
|
||||
|
@ -85,7 +86,7 @@ int main(int argc, char** argv)
|
|||
/* Deal with special case of wanting to read from standard input */
|
||||
if(stdin == in)
|
||||
{
|
||||
global_token = read_all_tokens(in, global_token);
|
||||
global_token = read_all_tokens(in, global_token, "STDIN");
|
||||
}
|
||||
|
||||
if(NULL == global_token)
|
||||
|
|
19
cc.h
19
cc.h
|
@ -46,10 +46,21 @@ struct token_list
|
|||
{
|
||||
struct token_list* next;
|
||||
struct token_list* prev;
|
||||
struct token_list* entry;
|
||||
char* s;
|
||||
struct type* type;
|
||||
struct token_list* arguments;
|
||||
union
|
||||
{
|
||||
struct token_list* entry;
|
||||
char* s;
|
||||
};
|
||||
union
|
||||
{
|
||||
struct type* type;
|
||||
char* filename;
|
||||
};
|
||||
union
|
||||
{
|
||||
struct token_list* arguments;
|
||||
int linenumber;
|
||||
};
|
||||
struct token_list* locals;
|
||||
int temps;
|
||||
};
|
||||
|
|
12
cc_core.c
12
cc_core.c
|
@ -35,6 +35,7 @@ char* postpend_char(char* s, char a);
|
|||
char* prepend_char(char a, char* s);
|
||||
char* prepend_string(char* add, char* base);
|
||||
void require_match(char* message, char* required);
|
||||
void line_error();
|
||||
|
||||
struct token_list* emit(char *s, struct token_list* head)
|
||||
{
|
||||
|
@ -94,6 +95,7 @@ int stack_index(struct token_list* a, struct token_list* function)
|
|||
file_print(" does not exist in function ", stderr);
|
||||
file_print(function->s,stderr);
|
||||
file_print("\x0A",stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -219,6 +221,7 @@ struct token_list* sym_get_value(char *s, struct token_list* out, struct token_l
|
|||
|
||||
file_print(s ,stderr);
|
||||
file_print(" is not a defined symbol\x0A", stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -273,6 +276,7 @@ struct token_list* primary_expr(struct token_list* out, struct token_list* funct
|
|||
file_print("Recieved ", stderr);
|
||||
file_print(global_token->s, stderr);
|
||||
file_print(" in primary_expr\x0A", stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -408,6 +412,7 @@ struct token_list* postfix_expr(struct token_list* out, struct token_list* funct
|
|||
file_print("->", stderr);
|
||||
file_print(global_token->s, stderr);
|
||||
file_print(" does not exist\x0A", stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(0 != i->offset)
|
||||
|
@ -967,7 +972,10 @@ struct token_list* statement(struct token_list* out, struct token_list* function
|
|||
out = emit("\t#C goto label\x0A", out);
|
||||
global_token = global_token->next;
|
||||
}
|
||||
else if((NULL != lookup_type(global_token->s)) || match("struct", global_token->s))
|
||||
else if((NULL == sym_lookup(global_token->s, function->locals)) &&
|
||||
(NULL == sym_lookup(global_token->s, function->arguments)) &&
|
||||
(NULL != lookup_type(global_token->s)) ||
|
||||
match("struct", global_token->s))
|
||||
{
|
||||
out = collect_local(out, function);
|
||||
}
|
||||
|
@ -1007,6 +1015,7 @@ struct token_list* statement(struct token_list* out, struct token_list* function
|
|||
if(NULL == break_target)
|
||||
{
|
||||
file_print("Not inside of a loop or case statement", stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
struct token_list* i = function->locals;
|
||||
|
@ -1139,6 +1148,7 @@ new_type:
|
|||
file_print("Recieved ", stderr);
|
||||
file_print(global_token->s, stderr);
|
||||
file_print(" in program\x0A", stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
24
cc_reader.c
24
cc_reader.c
|
@ -18,10 +18,17 @@
|
|||
#include "cc.h"
|
||||
FILE* input;
|
||||
struct token_list* token;
|
||||
int line;
|
||||
char* file;
|
||||
|
||||
char clearWhiteSpace(char c)
|
||||
{
|
||||
if((32 == c) || (10 == c) || (9 == c)) return clearWhiteSpace(fgetc(input));
|
||||
if((32 == c) || (9 == c)) return clearWhiteSpace(fgetc(input));
|
||||
else if (10 == c)
|
||||
{
|
||||
line = line + 1;
|
||||
return clearWhiteSpace(fgetc(input));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -122,8 +129,13 @@ reset:
|
|||
c = fgetc(input);
|
||||
while(c != '/')
|
||||
{
|
||||
while(c != '*') c = fgetc(input);
|
||||
while(c != '*')
|
||||
{
|
||||
c = fgetc(input);
|
||||
if(10 == c) line = line + 1;
|
||||
}
|
||||
c = fgetc(input);
|
||||
if(10 == c) line = line + 1;
|
||||
}
|
||||
c = fgetc(input);
|
||||
goto reset;
|
||||
|
@ -146,6 +158,8 @@ reset:
|
|||
|
||||
current->prev = token;
|
||||
current->next = token;
|
||||
current->linenumber = line;
|
||||
current->filename = file;
|
||||
token = current;
|
||||
return c;
|
||||
}
|
||||
|
@ -163,12 +177,14 @@ struct token_list* reverse_list(struct token_list* head)
|
|||
return root;
|
||||
}
|
||||
|
||||
struct token_list* read_all_tokens(FILE* a, struct token_list* current)
|
||||
struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename)
|
||||
{
|
||||
input = a;
|
||||
line = 1;
|
||||
file = filename;
|
||||
token = current;
|
||||
int ch =fgetc(input);
|
||||
while(0 <= ch) ch = get_token(ch);
|
||||
while(EOF != ch) ch = get_token(ch);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "cc.h"
|
||||
#include <stdint.h>
|
||||
void line_error();
|
||||
|
||||
/* Initialize default types */
|
||||
void initialize_types()
|
||||
|
@ -189,6 +190,7 @@ struct type* type_name()
|
|||
file_print("Unknown type ", stderr);
|
||||
file_print(global_token->s, stderr);
|
||||
file_print("\x0A", stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if(NULL == ret)
|
||||
|
|
|
@ -15,12 +15,22 @@
|
|||
* along with stage0. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "../cc.h"
|
||||
char* numerate_number(int a);
|
||||
|
||||
void line_error()
|
||||
{
|
||||
file_print("In file: ", stderr);
|
||||
file_print(global_token->filename, stderr);
|
||||
file_print(" On line: ", stderr);
|
||||
file_print(numerate_number(global_token->linenumber), stderr);
|
||||
}
|
||||
|
||||
void require_match(char* message, char* required)
|
||||
{
|
||||
if(!match(global_token->s, required))
|
||||
{
|
||||
file_print(message, stderr);
|
||||
line_error();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
global_token = global_token->next;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
// CONSTANT stdin 0
|
||||
// CONSTANT stdout 1
|
||||
// CONSTANT stderr 2
|
||||
// CONSTANT EOF 0xFFFFFFFF
|
||||
|
||||
int fgetc(FILE* f)
|
||||
{
|
||||
|
@ -88,3 +89,15 @@ FILE* fopen(char* filename, char* mode)
|
|||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
asm("LOAD_EFFECTIVE_ADDRESS_ebx %4"
|
||||
"LOAD_IMMEDIATE_eax %6"
|
||||
"INT_80");
|
||||
}
|
||||
int fclose(FILE* stream)
|
||||
{
|
||||
int error = close(stream);
|
||||
return error;
|
||||
}
|
||||
|
|
|
@ -9,15 +9,15 @@ d27eb315d694324650b11a421d6990eee60ac5921a5625bbccb43d806f09e156 test/results/t
|
|||
8cc38294fb1261843cfc3956fad5a451c95bbc2ed687435d4e2d59df2c4a8567 test/results/test08-binary
|
||||
cc8f252877a85c0d7832094ff574d7173ac33940917bc1591358b8970651a81c test/results/test09-binary
|
||||
3857aee4183de41bd00b014d616a5d73f4bfc57aa60a6073bb4113d6ff2fb8d5 test/results/test10-binary
|
||||
21477d1e283e0ecf4d91b64ce02ca391bbf9b6e4682fc4271028937546bf30b2 test/results/test100-binary
|
||||
cde9093d770a2c9c4b76953006468da02a68d3b5895e6e4a2842bf72b99a3e1b test/results/test100-binary
|
||||
dce2f0b35323cf6a2b01f74a9335100f2d8626028af545832dbdb503573db0e5 test/results/test11-binary
|
||||
88602970fa07b5da7a42b4f2b2486fe03accc6796e05453c4ab934e986790bef test/results/test12-binary
|
||||
c85a57b5b1d65288efd47a3b12c6fca1efade9e7ec91e65efda5531d2c40d293 test/results/test13-binary
|
||||
ef2b0fd3acd8f478f5f1ea51ab165503e2f22a4c330e5db134e162cf8b624cf8 test/results/test14-binary
|
||||
c432555f7b121e07ae80f6216128b0420bc158293048bc29259d6adb94a05cb4 test/results/test15-binary
|
||||
b1de0d8c35068420d8f15d2fea74496e4f86c905f7c1b8601d569cd5c61d2796 test/results/test16-binary
|
||||
ca2c1321cbcbf3f551860fc0857d0a816660ba541987f9ed7f92f8553cd6b06b test/results/test15-binary
|
||||
7b0ae42a9ac9e8387900c1a95b3310e9c7fbe4f244d8d7522285dc1cef2f38ec test/results/test16-binary
|
||||
15f1fc51d559b74d7515d3e978a835f7edc765f0763fdbae328f4b03a6b2b92b test/results/test17-binary
|
||||
f2245dea4a08a26f1f63383acedd5a67e918b8c9d8e484f037aee7b71c7f8a50 test/results/test18-binary
|
||||
6f1331ad820cdf9d45506eaac3053b80f4357fe955c30a113d1ec2bf829d79a2 test/results/test19-binary
|
||||
6405e331d3626c0ed1eca16eecc7fb628d8e1dc54dff3a6106e5f5bb063c896c test/results/test18-binary
|
||||
3beeba3bdf2d0b8a8eb2f113d35c3a79a04dcb4330f97fad817f0c484b7c7b70 test/results/test19-binary
|
||||
6fa44153ee3f27f0df49b282c0bb3017dbfaea906073c8c02b8bf5ad4d4a7860 test/results/test20-binary
|
||||
ba3d9623c6512bc327cf934d994e5327e5fad3f7500896e2d8458467fae9b9e9 test/results/test99-binary
|
||||
|
|
|
@ -1 +1 @@
|
|||
929105510c8469704ae12dda52afb6a9f3c383e323564d6068021ee1059c6061 test/test100/proof
|
||||
5fd665e662487bed6c1f52b9f702e4859da01811b6399ff1faa952fcf38ba163 test/test100/proof
|
||||
|
|
Loading…
Reference in New Issue