Skip to content

Commit

Permalink
renamed fileRead to fileReadStr. version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldford committed Aug 29, 2024
1 parent 9518867 commit a048b6d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion scripts/replace-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Backup your code before you do this
str='s/SM_FILE_WRITE_EXPR/SM_FILE_WRITESTR_EXPR/g'
str='s/fileRead/fileReadStr/g'
find ../src/ -name "*.c" -exec sed -i -e "$str" {} +
find ../src/ -name "*.h" -exec sed -i -e "$str" {} +
find ../src/ -name "*.y" -exec sed -i -e "$str" {} +
Expand Down
18 changes: 9 additions & 9 deletions src/main/engine/sm_ast_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ inline sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *s
fclose(fptr);
return (sm_object *)sms_true;
}
case SM_FILE_READ_EXPR: {
case SM_FILE_READSTR_EXPR: {
// Evaluate and check if the first argument is a string (file name)
sm_string *fname_str = (sm_string *)eager_type_check(sme, 0, SM_STRING_TYPE, current_cx, sf);
if (fname_str->my_type == SM_ERR_TYPE)
Expand All @@ -1105,7 +1105,7 @@ inline sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *s
if (access(fname_cstr, F_OK) != 0) {
char error_msg[256];
snprintf(error_msg, sizeof(error_msg),
"fileReadStr failed because the file, %s, does not exist.", fname_cstr);
"fileReadStrStr failed because the file, %s, does not exist.", fname_cstr);
sm_symbol *title = sm_new_symbol("fileNotFoundError", strlen("fileNotFoundError"));
sm_string *message = sm_new_string(strlen(error_msg), error_msg);
return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL);
Expand All @@ -1114,7 +1114,7 @@ inline sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *s
FILE *fptr = fopen(fname_cstr, "r");
if (fptr == NULL) {
char error_msg[256];
snprintf(error_msg, sizeof(error_msg), "fileReadStr failed to open: %s", fname_cstr);
snprintf(error_msg, sizeof(error_msg), "fileReadStrStr failed to open: %s", fname_cstr);
sm_symbol *title = sm_new_symbol("fileOpenError", strlen("fileOpenError"));
sm_string *message = sm_new_string(strlen(error_msg), error_msg);
return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL);
Expand All @@ -1124,9 +1124,9 @@ inline sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *s
long len = ftell(fptr);
if (len < 0) {
fclose(fptr);
sm_symbol *title = sm_new_symbol("fileReadError", strlen("fileReadError"));
sm_string *message = sm_new_string(strlen("fileReadStr failed to determine file length"),
"fileReadStr failed to determine file length");
sm_symbol *title = sm_new_symbol("fileReadStrError", strlen("fileReadStrError"));
sm_string *message = sm_new_string(strlen("fileReadStrStr failed to determine file length"),
"fileReadStrStr failed to determine file length");
return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL);
}
// Read the file contents
Expand All @@ -1135,9 +1135,9 @@ inline sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *s
size_t read_count = fread(&(output->content), 1, len, fptr);
if (read_count != len) {
fclose(fptr);
sm_symbol *title = sm_new_symbol("fileReadError", strlen("fileReadError"));
sm_string *message = sm_new_string(strlen("fileReadStr failed during read operation"),
"fileReadStr failed during read operation");
sm_symbol *title = sm_new_symbol("fileReadStrError", strlen("fileReadStrError"));
sm_string *message = sm_new_string(strlen("fileReadStrStr failed during read operation"),
"fileReadStrStr failed during read operation");
return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL);
}
fclose(fptr);
Expand Down
2 changes: 1 addition & 1 deletion src/main/object/sm_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ enum SM_EXPR_TYPE {
SM_CX_IMPORT_EXPR,
SM_CX_MAP_EXPR,
SM_FILE_PARSE_EXPR,
SM_FILE_READ_EXPR,
SM_FILE_READSTR_EXPR,
SM_FILE_RUN_EXPR,
SM_FILE_PART_EXPR,
SM_FILE_EXISTS_EXPR,
Expand Down
2 changes: 1 addition & 1 deletion src/main/parser/sms.l
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ cxReduce {return CX_REDUCE;}

fileParse {return FILE_PARSE;}
fileRun {return FILE_RUN;}
fileRead {return FILE_READ;}
fileReadStr {return FILE_READ;}
filePart {return FILE_PART;}
fileTomem {return FILE_TOMEM;}
fileExists {return FILE_EXISTS;}
Expand Down
4 changes: 2 additions & 2 deletions src/main/parser/sms.y
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ EXPR : SELF { $$ = (sm_expr*)sm_new_self(); }
| F64_ARRAY { }
| UI8_ARRAY { }
| FILE_PARSE '(' EXPR ')' {$$ = sm_new_expr(SM_FILE_PARSE_EXPR,(sm_object*)$3, _note());}
| FILE_READ '(' EXPR ')' {$$ = sm_new_expr(SM_FILE_READ_EXPR,(sm_object*)$3, _note());}
| FILE_RUN '(' EXPR ',' EXPR ')' {$$ = sm_new_expr_2(SM_FILE_READ_EXPR,(sm_object*)$3,(sm_object*)$5, _note());}
| FILE_READ '(' EXPR ')' {$$ = sm_new_expr(SM_FILE_READSTR_EXPR,(sm_object*)$3, _note());}
| FILE_RUN '(' EXPR ',' EXPR ')' {$$ = sm_new_expr_2(SM_FILE_READSTR_EXPR,(sm_object*)$3,(sm_object*)$5, _note());}
| FILE_PART '(' EXPR ',' EXPR ',' EXPR ')' {$$ = sm_new_expr_3(SM_FILE_PART_EXPR,(sm_object*)$3,(sm_object*)$5,(sm_object*)$7, _note());}
| FILE_WRITESTR '(' EXPR ',' EXPR ')' {$$ = sm_new_expr_2(SM_FILE_WRITESTR_EXPR,(sm_object*)$3,(sm_object*)$5, _note());}
| FILE_WRITETGA '(' EXPR ',' EXPR ',' EXPR ',' EXPR ')' {$$ = sm_new_expr_4(SM_FILE_WRITETGA_EXPR,(sm_object*)$3,(sm_object*)$5,(sm_object*)$7,(sm_object*)$9, _note());}
Expand Down
2 changes: 1 addition & 1 deletion src/main/sm_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sm_string *sm_read_file(char *filePath, int filePathLen) {
sm_string *fname_str;
char *fname_cstr = filePath;
if (access(fname_cstr, F_OK) != 0) {
printf("fileReadStr failed because the file, %s ,does not exist.\n", fname_cstr);
printf("fileReadStrStr failed because the file, %s ,does not exist.\n", fname_cstr);
return (sm_string *)sms_false;
}
FILE *fptr = fopen(fname_cstr, "r");
Expand Down
16 changes: 8 additions & 8 deletions src/main/sm_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ char *sm_global_fn_name(uint32_t which) {
"cxImport", // SM_CX_IMPORT_EXPR
"cxMap", // SM_CX_MAP_EXPR
"fileParse", // SM_FILE_PARSE_EXPR
"fileRead", // SM_FILE_READ_EXPR
"fileReadStr", // SM_FILE_READSTR_EXPR
"fileRun", // SM_FILE_RUN_EXPR
"filePart", // SM_FILE_PART_EXPR
"fileExists", // SM_FILE_EXISTS_EXPR
Expand Down Expand Up @@ -256,13 +256,13 @@ char *sm_global_fn_name(uint32_t which) {
// Corresponding string length of the string that would come from the sm_global_fn_name(which)
uint32_t sm_global_fn_name_len(uint32_t which) {
static uint64_t response_len[] = {
8, 4, 4, 5, 4, 2, 2, 3, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 4, 4,
3, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5,
5, 5, 2, 3, 3, 4, 3, 3, 3, 4, 4, 3, 2, 2, 3, 6, 6, 5, 3, 7, 6, 4, 6, 8, 12, 5, 5, 4,
2, 2, 2, 1, 1, 2, 2, 5, 5, 5, 5, 5, 3, 5, 4, 2, 11, 5, 5, 5, 5, 8, 8, 12, 5, 4, 7, 6,
8, 6, 8, 5, 9, 8, 7, 8, 10, 8, 6, 6, 6, 12, 12, 10, 5, 4, 4, 3, 6, 6, 4, 5, 5, 4, 3, 3,
2, 3, 3, 4, 7, 8, 11, 8, 11, 4, 7, 7, 7, 6, 6, 6, 6, 7, 8, 4, 8, 7, 9, 11, 8, 6, 9, 3,
6, 12, 13, 8, 9, 7, 4, 4, 5, 6, 6, 6, 11, 8, 8, 3, 5, 8, 10, 9, 7, 8, 1};
8, 4, 4, 5, 4, 2, 2, 3, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 4, 4,
3, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5,
5, 5, 2, 3, 3, 4, 3, 3, 3, 4, 4, 3, 2, 2, 3, 6, 6, 5, 3, 7, 6, 4, 6, 8, 12, 5, 5, 4,
2, 2, 2, 1, 1, 2, 2, 5, 5, 5, 5, 5, 3, 5, 4, 2, 11, 5, 5, 5, 5, 8, 8, 12, 5, 4, 7, 6,
8, 6, 8, 5, 9, 11, 7, 8, 10, 8, 6, 6, 6, 12, 12, 10, 5, 4, 4, 3, 6, 6, 4, 5, 5, 4, 3, 3,
2, 3, 3, 4, 7, 8, 11, 8, 11, 4, 7, 7, 7, 6, 6, 6, 6, 7, 8, 4, 8, 7, 9, 11, 8, 6, 9, 3,
6, 12, 13, 8, 9, 7, 4, 4, 5, 6, 6, 6, 11, 8, 8, 3, 5, 8, 10, 9, 7, 8, 1};


if (which >= sm_global_num_fns())
Expand Down
2 changes: 1 addition & 1 deletion src/main/sm_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern uint32_t sms_num_symbols;

void sm_init(sm_env *env, int num_args, char **argv) {
// Set version number. Major.Minor.Patch
char *sms_version = "0.21.27";
char *sms_version = "0.21.28";
int sms_version_len = 7;
sm_strncpy(env->version, sms_version, sms_version_len);
env->version_len = sms_version_len;
Expand Down
4 changes: 2 additions & 2 deletions test_zone/file/0.sms
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ # file operations
tests->[
[ fileWrite("test_file_0.txt","str1"),true, "Writing a file"],
[ fileRead("test_file_0.txt"),"str1","Reading the file that was written"],
[ fileWriteStr("test_file_0.txt","str1"),true, "Writing a file"],
[ fileReadStr("test_file_0.txt"),"str1","Reading the file that was written"],
[ fileExists("test_file_0.txt"),true,"Checking the the file exists"],
[ fileExists("random.txt"),false,"random.txt does not exist"],
[ size(fileStat("test_file_0.txt")),16,"Getting stat info for this file."],
Expand Down

0 comments on commit a048b6d

Please sign in to comment.