From: Mike D. Lowis Date: Fri, 9 Oct 2015 20:28:29 +0000 (-0400) Subject: Checkpoint commit X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=1e51c984f180449896b6ff175f08e9ca798564fd;p=proto%2Fsclpl.git Checkpoint commit --- diff --git a/build.rb b/build.rb index 88cedf5..e441e51 100755 --- a/build.rb +++ b/build.rb @@ -50,6 +50,7 @@ base_env = BuildEnv.new do |env| env["CPPPATH"] += Dir['modules/libcds/source/**/'] + [ 'modules/libopts/source', 'source/libparse/', + 'source/sclpl/', ] end diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..190a180 --- /dev/null +++ b/input.txt @@ -0,0 +1 @@ +123 diff --git a/source/sclpl/codegen.c b/source/sclpl/codegen.c index 6968d20..0190d5d 100644 --- a/source/sclpl/codegen.c +++ b/source/sclpl/codegen.c @@ -1,6 +1,4 @@ -#include -#include "codegen.h" -#include "pprint.h" +#include #if 0 static void lift_funcs(vec_t* fnlst, AST* tree) { diff --git a/source/sclpl/codegen.h b/source/sclpl/codegen.h deleted file mode 100644 index c854d43..0000000 --- a/source/sclpl/codegen.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - @file codegen.h - @brief TODO: Describe this file - $Revision$ - $HeadURL$ - */ -#ifndef CODEGEN_H -#define CODEGEN_H - -#include -#include "vec.h" - -void codegen_csource(FILE* file, vec_t* program); - -#endif /* CODEGEN_H */ diff --git a/source/sclpl/log.c b/source/sclpl/log.c index ae0e384..ee9c9b7 100644 --- a/source/sclpl/log.c +++ b/source/sclpl/log.c @@ -4,8 +4,7 @@ $Revision$ $HeadURL$ */ -#include "log.h" -#include +#include void log_error(const char msg[], ...) { va_list args; diff --git a/source/sclpl/log.h b/source/sclpl/log.h deleted file mode 100644 index 90c4637..0000000 --- a/source/sclpl/log.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - @file log.h - @brief TODO: Describe this file - $Revision$ - $HeadURL$ - */ -#ifndef LOG_H -#define LOG_H - -#include - -void log_error(const char msg[], ...); - -#endif /* LOG_H */ diff --git a/source/sclpl/main.c b/source/sclpl/main.c index 51d3815..10b32e5 100644 --- a/source/sclpl/main.c +++ b/source/sclpl/main.c @@ -1,16 +1,4 @@ -#include -#include -#include -#include "opts.h" -#include "str.h" -#include "list.h" -#include "pprint.h" -#include "codegen.h" -#include "sys.h" -#include "log.h" -#include "ops.h" -#include - +#include /* Command Line Options *****************************************************************************/ @@ -36,54 +24,16 @@ void print_usage(void) { exit(1); } -/* Options Helpers - *****************************************************************************/ -bool file_exists(const char* name) { - bool ret = false; - FILE* file = fopen(name,"r"); - if (NULL != file) { - fclose(file); - ret = true; - } - return ret; -} - -list_t* input_files(void) { - list_t* infiles = list_new(); - const char** fvec = opts_arguments(); - const char** files = fvec; - while (NULL != files[0]) { - if (!file_exists(files[0])) { - mem_release(infiles); - log_error("no such file or directory: %s", files[0]); - exit(1); - } - list_push_front(infiles, str_new(files[0])); - files++; - } - free(fvec); - return infiles; -} - /* Driver Modes *****************************************************************************/ static int emit_tokens(void) { - list_t* files = input_files(); - size_t nfiles = list_size(files); - if (0 == nfiles) { - (void)ops_token_file(NULL); - } else if (1 == nfiles) { - str_t* fname = list_front(files)->contents; - mem_release( ops_token_file(fname) ); - } else { - log_error("too many files provided for target mode 'tokens'"); - } - mem_release(files); + (void)ops_token_file(NULL); return 0; } static int emit_tree(void) { int ret = 0; +#if 0 list_t* files = input_files(); size_t nfiles = list_size(files); if (0 == nfiles) { @@ -95,12 +45,13 @@ static int emit_tree(void) { log_error("too many files provided for target mode 'ast'"); } mem_release(files); - +#endif return ret; } static int emit_csource(void) { int ret = 0; +#if 0 list_t* files = input_files(); size_t nfiles = list_size(files); if (0 == nfiles) { @@ -112,10 +63,12 @@ static int emit_csource(void) { log_error("too many files provided for target mode 'csource'"); } mem_release(files); +#endif return ret; } static int exec_repl(void) { +#if 0 Parser* p_parser = parser_new(":> ", stdin); while(!parser_eof(p_parser)) { AST* p_tree = toplevel(p_parser); @@ -130,10 +83,12 @@ static int exec_repl(void) { } } mem_release(p_parser); +#endif return 0; } static int emit_object(void) { +#if 0 list_t* files = input_files(); size_t nfiles = list_size(files); if (0 == nfiles) { @@ -148,6 +103,7 @@ static int emit_object(void) { log_error("too many files provided for target mode 'object'"); } mem_release(files); +#endif return 0; } diff --git a/source/sclpl/ops.c b/source/sclpl/ops.c index 4cc4700..0c7114f 100644 --- a/source/sclpl/ops.c +++ b/source/sclpl/ops.c @@ -4,13 +4,9 @@ $Revision$ $HeadURL$ */ -#include "opts.h" -#include "str.h" -#include "sys.h" -#include "pprint.h" -#include "codegen.h" -#include +#include +#if 0 vec_t* ops_parse_file(str_t* in) { //bool failed = false; //FILE* input = (NULL == in) ? stdin : fopen(str_cstr(in), "r"); @@ -38,9 +34,9 @@ vec_t* ops_deps_file(vec_t* program) { (void)program; return deps; } +#endif -str_t* ops_token_file(str_t* in) { - str_t* ofname = NULL; +char* ops_token_file(str_t* in) { FILE* input = (NULL == in) ? stdin : fopen(str_cstr(in), "r"); FILE* output; if (NULL == in) { @@ -58,9 +54,10 @@ str_t* ops_token_file(str_t* in) { } mem_release(ctx); - return ofname; + return NULL; } +#if 0 str_t* ops_syntax_file(str_t* in) { str_t* ofname = NULL; FILE* output; @@ -118,4 +115,4 @@ str_t* ops_compile_file(str_t* in) { mem_release(command); return ofname; } - +#endif diff --git a/source/sclpl/ops.h b/source/sclpl/ops.h index fd52b17..b66d983 100644 --- a/source/sclpl/ops.h +++ b/source/sclpl/ops.h @@ -7,14 +7,5 @@ #ifndef OPS_H #define OPS_H -#include "str.h" -#include "vec.h" - -vec_t* ops_parse_file(str_t* in); -vec_t* ops_deps_file(vec_t* program); -str_t* ops_token_file(str_t* in); -str_t* ops_syntax_file(str_t* in); -str_t* ops_translate_file(str_t* in); -str_t* ops_compile_file(str_t* in); #endif /* OPS_H */ diff --git a/source/sclpl/pprint.c b/source/sclpl/pprint.c index 236d685..32718ec 100644 --- a/source/sclpl/pprint.c +++ b/source/sclpl/pprint.c @@ -4,12 +4,14 @@ $Revision$ $HeadURL$ */ -#include "pprint.h" +#include +#if 0 static void print_indent(FILE* file, int depth) { for(int i = 0; i < (2 * depth); i++) fprintf(file, "%c", ' '); } +#endif static const char* token_type_to_string(TokType type) { switch(type) { diff --git a/source/sclpl/pprint.h b/source/sclpl/pprint.h deleted file mode 100644 index a60030d..0000000 --- a/source/sclpl/pprint.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - @file pprint.h - @brief TODO: Describe this file - $Revision$ - $HeadURL$ - */ -#ifndef PPRINT_H -#define PPRINT_H - -#include - -void pprint_token_type(FILE* file, Tok* token); - -void pprint_token_value(FILE* file, Tok* token); - -void pprint_token(FILE* file, Tok* token, bool print_loc); - -void pprint_tree(FILE* file, AST* tree, int depth); - -#endif /* PPRINT_H */ diff --git a/source/sclpl/sclpl.h b/source/sclpl/sclpl.h new file mode 100644 index 0000000..bbf6445 --- /dev/null +++ b/source/sclpl/sclpl.h @@ -0,0 +1,51 @@ +/** + @file sclpl.h +*/ +#ifndef SCLPL_H +#define SCLPL_H + +#include +#include +#include +#include +#include "str.h" +//#include "vec.h" +#include "list.h" + +typedef enum { + TOKFILE, + ASTFILE, + CSOURCE, + OBJECT, + PROGRAM, + STATICLIB, + SHAREDLIB +} file_type_t; + +/* Filesystem Routines */ +str_t* sys_bin_dir(void); +str_t* sys_inc_dir(void); +str_t* sys_extension(file_type_t ftype); +str_t* sys_filename(file_type_t ftype, str_t* infile); + +/* Pretty Printing Data Structures */ +void pprint_token_type(FILE* file, Tok* token); +void pprint_token_value(FILE* file, Tok* token); +void pprint_token(FILE* file, Tok* token, bool print_loc); +//void pprint_tree(FILE* file, AST* tree, int depth); + +/* Compiler Driver Operations */ +//vec_t* ops_parse_file(str_t* in); +//vec_t* ops_deps_file(vec_t* program); +str_t* ops_token_file(str_t* in); +//str_t* ops_syntax_file(str_t* in); +//str_t* ops_translate_file(str_t* in); +//str_t* ops_compile_file(str_t* in); + +/* Error Logging */ +void log_error(const char msg[], ...); + +/* Code Generation */ +void codegen_csource(FILE* file, vec_t* program); + +#endif /* SCLPL_H */ diff --git a/source/sclpl/sys.c b/source/sclpl/sys.c index 06301e1..7f6fb14 100644 --- a/source/sclpl/sys.c +++ b/source/sclpl/sys.c @@ -4,10 +4,7 @@ $Revision$ $HeadURL$ */ -#include -#include "sys.h" -#include "opts.h" -#include "log.h" +#include str_t* sys_bin_dir(void) { str_t* bindir = NULL; diff --git a/source/sclpl/sys.h b/source/sclpl/sys.h deleted file mode 100644 index f386bec..0000000 --- a/source/sclpl/sys.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - @file sys.h - @brief TODO: Describe this file - $Revision$ - $HeadURL$ - */ -#ifndef SYS_H -#define SYS_H - -#include "str.h" - -str_t* sys_bin_dir(void); -str_t* sys_inc_dir(void); - -typedef enum { - TOKFILE, - ASTFILE, - CSOURCE, - OBJECT, - PROGRAM, - STATICLIB, - SHAREDLIB -} file_type_t; - -str_t* sys_extension(file_type_t ftype); -str_t* sys_filename(file_type_t ftype, str_t* infile); - -#endif /* SYS_H */