Skip to content

Commit

Permalink
minor cleanup and updates to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldford committed Oct 19, 2024
1 parent 4b76467 commit 2b1da2f
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion sms_src/examples/benchmark.sms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/sms -m1g
#!/usr/local/bin/sms -m.5g
#Use this to benchmark something
{
let _errHandler = (x) => {
Expand Down
2 changes: 1 addition & 1 deletion sms_src/examples/benchmark_fastfib.sms
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
return 2 *f(n-3) + f(n-4) + f(n-2) ;
};

benchmark(:f(31));
benchmark(:f(40));
};
6 changes: 4 additions & 2 deletions sms_src/examples/char.sms
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Library function to get a char from the byte number in ascii
# The character is returned as a length 1 string..
# Example: char(55) == "7"
cxLet(parent(_scratch), :char , ( value ) => {
{
let index = round(value);
let chars = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" str+
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" str+
Expand All @@ -20,4 +20,6 @@ cxLet(parent(_scratch), :char , ( value ) => {
"\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF" str+
"\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
strPart(chars, index, 1);
});
# Return this context as a library
self;
};
2 changes: 1 addition & 1 deletion sms_src/examples/clock.sms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/sms -qm32k
#!/usr/local/bin/sms -qm48k
# Simply puts the time every second
{
# Represents a number from 0 to 99
Expand Down
5 changes: 2 additions & 3 deletions sms_src/examples/colorTGA.sms
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
return true;
} else return <tgaWriteErr,"Error: Failed to create TGA file.">;
};

# Expose the write function for usage
cxLet(parent(_scratch), :colorTGA, self);
# Return this context as a library
self;
};

2 changes: 1 addition & 1 deletion sms_src/examples/fire.sms
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/sms
#!/usr/local/bin/sms -qm16
#Draws a fire-like image.
#Must be run in the directory with colorPrint.sms
{
Expand Down
4 changes: 2 additions & 2 deletions sms_src/examples/generateRGBImg.sms
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/local/bin/sms -m1g
#!/usr/local/bin/sms -m1.15g
# Usage: This script demonstrates creating a rainbow gradient using colorTGA.write

{
# Evaluate and include the colorTGA library
eval(fileParse("colorTGA.sms"));
let colorTGA = import "colorTGA.sms";

# Image dimensions
let width = 1920;
Expand Down
2 changes: 1 addition & 1 deletion sms_src/examples/termDraw_saturn.sms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/sms -qm16
#!/usr/local/bin/sms -qm24
# Uses tput to get terminal dimensions,
# Then runs a for loop to fill up the screen with numbers
{
Expand Down
2 changes: 1 addition & 1 deletion sms_src/examples/watch.sms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/sms -qm18k
#!/usr/local/bin/sms -qm64k
#Tiny rendition of the linux 'watch' program
{
let cmd = _args[size(_args) - 1];
Expand Down
17 changes: 7 additions & 10 deletions src/main/engine/sm_ast_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,16 +1702,13 @@ inline sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *s
case SM_PUTLN_EXPR: {
sm_string *str;
sm_object *evaluated;
for (int i = 0; i < sme->size; i++) {
evaluated = eager_type_check(sme, i, SM_STRING_TYPE, current_cx, sf);
if (evaluated->my_type == SM_ERR_TYPE)
return evaluated;
str = (sm_string *)evaluated;
for (uint32_t i = 0; i < str->size; i++)
putchar((&str->content)[i]);
putchar('\n');
putchar('\0');
}
evaluated = eager_type_check(sme, 0, SM_STRING_TYPE, current_cx, sf);
if (evaluated->my_type == SM_ERR_TYPE)
return evaluated;
str = (sm_string *)evaluated;
for (uint32_t i = 0; i < str->size; i++)
putchar((&str->content)[i]);
putchar('\n');
fflush(stdout);
return ((sm_object *)sms_true);
break;
Expand Down
3 changes: 1 addition & 2 deletions src/main/sm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ int main(int num_args, char *argv[]) {
clean_exit(&env, 1);
}
if (env.quiet_mode == false) {
printf("Custom Heap Size: ");
char bytelength_str[16];
sm_sprint_fancy_bytelength(bytelength_str, env.mem_bytes);
printf("%s", bytelength_str);
printf("Custom Heap Size: %s\n", bytelength_str);
}
break;
}
Expand Down

0 comments on commit 2b1da2f

Please sign in to comment.