aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/step1_read_print.c2
-rw-r--r--c/step2_eval.c2
-rw-r--r--c/step3_env.c2
-rw-r--r--c/step4_if_fn_do.c4
-rw-r--r--c/step5_tco.c4
-rw-r--r--c/step6_file.c15
-rw-r--r--c/step7_quote.c15
-rw-r--r--c/step8_macros.c15
-rw-r--r--c/step9_interop.c15
-rw-r--r--c/stepA_more.c16
10 files changed, 63 insertions, 27 deletions
diff --git a/c/step1_read_print.c b/c/step1_read_print.c
index d28439e..264528d 100644
--- a/c/step1_read_print.c
+++ b/c/step1_read_print.c
@@ -64,7 +64,7 @@ int main()
// Set the initial prompt
snprintf(prompt, sizeof(prompt), "user> ");
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(NULL, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step2_eval.c b/c/step2_eval.c
index 5d24ff0..39b2789 100644
--- a/c/step2_eval.c
+++ b/c/step2_eval.c
@@ -134,7 +134,7 @@ int main()
snprintf(prompt, sizeof(prompt), "user> ");
init_repl_env();
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step3_env.c b/c/step3_env.c
index 7c36b38..2f41bc0 100644
--- a/c/step3_env.c
+++ b/c/step3_env.c
@@ -159,7 +159,7 @@ int main()
snprintf(prompt, sizeof(prompt), "user> ");
init_repl_env();
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step4_if_fn_do.c b/c/step4_if_fn_do.c
index 87e1241..84fb760 100644
--- a/c/step4_if_fn_do.c
+++ b/c/step4_if_fn_do.c
@@ -178,7 +178,7 @@ void init_repl_env() {
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -197,7 +197,7 @@ int main()
snprintf(prompt, sizeof(prompt), "user> ");
init_repl_env();
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step5_tco.c b/c/step5_tco.c
index 6938e47..3a46bd2 100644
--- a/c/step5_tco.c
+++ b/c/step5_tco.c
@@ -187,7 +187,7 @@ void init_repl_env() {
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -206,7 +206,7 @@ int main()
snprintf(prompt, sizeof(prompt), "user> ");
init_repl_env();
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step6_file.c b/c/step6_file.c
index ae48693..d73acfe 100644
--- a/c/step6_file.c
+++ b/c/step6_file.c
@@ -182,12 +182,12 @@ MalVal *RE(Env *env, char *prompt, char *str) {
// Setup the initial REPL environment
Env *repl_env;
-void init_repl_env() {
+void init_repl_env(int argc, char *argv[]) {
repl_env = new_env(NULL, NULL, NULL);
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -195,6 +195,13 @@ void init_repl_env() {
env_set(repl_env, "eval",
malval_new_function((void*(*)(void *))do_eval, 1));
+ MalVal *_argv = _listX(0);
+ for (i=2; i < argc; i++) {
+ MalVal *arg = malval_new_string(argv[i]);
+ g_array_append_val(_argv->val.array, arg);
+ }
+ env_set(repl_env, "*ARGV*", _argv);
+
// core.mal: defined using the language itself
RE(repl_env, "", "(def! not (fn* (a) (if a false true)))");
RE(repl_env, "",
@@ -209,7 +216,7 @@ int main(int argc, char *argv[])
// Set the initial prompt and environment
snprintf(prompt, sizeof(prompt), "user> ");
- init_repl_env();
+ init_repl_env(argc, argv);
if (argc > 1) {
char *cmd = g_strdup_printf("(load-file \"%s\")", argv[1]);
@@ -217,7 +224,7 @@ int main(int argc, char *argv[])
return 0;
}
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step7_quote.c b/c/step7_quote.c
index ac17955..b66bde6 100644
--- a/c/step7_quote.c
+++ b/c/step7_quote.c
@@ -218,12 +218,12 @@ MalVal *RE(Env *env, char *prompt, char *str) {
// Setup the initial REPL environment
Env *repl_env;
-void init_repl_env() {
+void init_repl_env(int argc, char *argv[]) {
repl_env = new_env(NULL, NULL, NULL);
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -231,6 +231,13 @@ void init_repl_env() {
env_set(repl_env, "eval",
malval_new_function((void*(*)(void *))do_eval, 1));
+ MalVal *_argv = _listX(0);
+ for (i=2; i < argc; i++) {
+ MalVal *arg = malval_new_string(argv[i]);
+ g_array_append_val(_argv->val.array, arg);
+ }
+ env_set(repl_env, "*ARGV*", _argv);
+
// core.mal: defined using the language itself
RE(repl_env, "", "(def! not (fn* (a) (if a false true)))");
RE(repl_env, "",
@@ -245,7 +252,7 @@ int main(int argc, char *argv[])
// Set the initial prompt and environment
snprintf(prompt, sizeof(prompt), "user> ");
- init_repl_env();
+ init_repl_env(argc, argv);
if (argc > 1) {
char *cmd = g_strdup_printf("(load-file \"%s\")", argv[1]);
@@ -253,7 +260,7 @@ int main(int argc, char *argv[])
return 0;
}
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step8_macros.c b/c/step8_macros.c
index 93c83fa..e7aebf2 100644
--- a/c/step8_macros.c
+++ b/c/step8_macros.c
@@ -257,12 +257,12 @@ MalVal *RE(Env *env, char *prompt, char *str) {
// Setup the initial REPL environment
Env *repl_env;
-void init_repl_env() {
+void init_repl_env(int argc, char *argv[]) {
repl_env = new_env(NULL, NULL, NULL);
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -270,6 +270,13 @@ void init_repl_env() {
env_set(repl_env, "eval",
malval_new_function((void*(*)(void *))do_eval, 1));
+ MalVal *_argv = _listX(0);
+ for (i=2; i < argc; i++) {
+ MalVal *arg = malval_new_string(argv[i]);
+ g_array_append_val(_argv->val.array, arg);
+ }
+ env_set(repl_env, "*ARGV*", _argv);
+
// core.mal: defined using the language itself
RE(repl_env, "", "(def! not (fn* (a) (if a false true)))");
RE(repl_env, "",
@@ -286,7 +293,7 @@ int main(int argc, char *argv[])
// Set the initial prompt and environment
snprintf(prompt, sizeof(prompt), "user> ");
- init_repl_env();
+ init_repl_env(argc, argv);
if (argc > 1) {
char *cmd = g_strdup_printf("(load-file \"%s\")", argv[1]);
@@ -294,7 +301,7 @@ int main(int argc, char *argv[])
return 0;
}
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/step9_interop.c b/c/step9_interop.c
index 743fb22..f248c55 100644
--- a/c/step9_interop.c
+++ b/c/step9_interop.c
@@ -263,12 +263,12 @@ MalVal *RE(Env *env, char *prompt, char *str) {
// Setup the initial REPL environment
Env *repl_env;
-void init_repl_env() {
+void init_repl_env(int argc, char *argv[]) {
repl_env = new_env(NULL, NULL, NULL);
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -276,6 +276,13 @@ void init_repl_env() {
env_set(repl_env, "eval",
malval_new_function((void*(*)(void *))do_eval, 1));
+ MalVal *_argv = _listX(0);
+ for (i=2; i < argc; i++) {
+ MalVal *arg = malval_new_string(argv[i]);
+ g_array_append_val(_argv->val.array, arg);
+ }
+ env_set(repl_env, "*ARGV*", _argv);
+
// core.mal: defined using the language itself
RE(repl_env, "", "(def! not (fn* (a) (if a false true)))");
RE(repl_env, "",
@@ -292,7 +299,7 @@ int main(int argc, char *argv[])
// Set the initial prompt and environment
snprintf(prompt, sizeof(prompt), "user> ");
- init_repl_env();
+ init_repl_env(argc, argv);
if (argc > 1) {
char *cmd = g_strdup_printf("(load-file \"%s\")", argv[1]);
@@ -300,7 +307,7 @@ int main(int argc, char *argv[])
return 0;
}
- // REPL loop
+ // repl loop
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {
diff --git a/c/stepA_more.c b/c/stepA_more.c
index 8547607..de49568 100644
--- a/c/stepA_more.c
+++ b/c/stepA_more.c
@@ -284,12 +284,12 @@ MalVal *RE(Env *env, char *prompt, char *str) {
// Setup the initial REPL environment
Env *repl_env;
-void init_repl_env() {
+void init_repl_env(int argc, char *argv[]) {
repl_env = new_env(NULL, NULL, NULL);
// core.c: defined using C
int i;
- for(i=0; i< (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
+ for(i=0; i < (sizeof(core_ns) / sizeof(core_ns[0])); i++) {
env_set(repl_env, core_ns[i].name,
malval_new_function(core_ns[i].func, core_ns[i].arg_cnt));
}
@@ -297,6 +297,13 @@ void init_repl_env() {
env_set(repl_env, "eval",
malval_new_function((void*(*)(void *))do_eval, 1));
+ MalVal *_argv = _listX(0);
+ for (i=2; i < argc; i++) {
+ MalVal *arg = malval_new_string(argv[i]);
+ g_array_append_val(_argv->val.array, arg);
+ }
+ env_set(repl_env, "*ARGV*", _argv);
+
// core.mal: defined using the language itself
RE(repl_env, "", "(def! *host-language* \"c\")");
RE(repl_env, "", "(def! not (fn* (a) (if a false true)))");
@@ -314,7 +321,7 @@ int main(int argc, char *argv[])
// Set the initial prompt and environment
snprintf(prompt, sizeof(prompt), "user> ");
- init_repl_env();
+ init_repl_env(argc, argv);
if (argc > 1) {
char *cmd = g_strdup_printf("(load-file \"%s\")", argv[1]);
@@ -322,7 +329,8 @@ int main(int argc, char *argv[])
return 0;
}
- // REPL loop
+ // repl loop
+ RE(repl_env, "", "(println (str \"Mal [\" *host-language* \"]\"))");
for(;;) {
exp = RE(repl_env, prompt, NULL);
if (mal_error && strcmp("EOF", mal_error->val.string) == 0) {