core: Expose command line.

* mes.c (scm_symbol_argv): New symbol
  (main): Use it to add argv to environment.
* module/mes/base.mes (command-line): New function.
This commit is contained in:
Jan Nieuwenhuizen 2017-01-03 23:41:11 +01:00
parent e1fa4ed8be
commit d0e222dac3
2 changed files with 10 additions and 2 deletions

8
mes.c
View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
@ -102,6 +102,7 @@ scm scm_symbol_primitive_load = {SYMBOL, "primitive-load"};
scm scm_symbol_read_input_file = {SYMBOL, "read-input-file"};
scm scm_symbol_write = {SYMBOL, "write"};
scm scm_symbol_display = {SYMBOL, "display"};
scm scm_symbol_argv = {SYMBOL, "argv"};
scm scm_symbol_mes_version = {SYMBOL, "%version"};
scm scm_symbol_mes_prefix = {SYMBOL, "%prefix"};
@ -1020,6 +1021,11 @@ main (int argc, char *argv[])
SCM program = (argc > 1 && !strcmp (argv[1], "--load"))
? bload_env (r0) : load_env (r0);
if (argc > 1 && !strcmp (argv[1], "--dump")) return dump ();
SCM lst = cell_nil;
for (int i=argc; i; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i-1])), lst);
r0 = acons (cell_symbol_argv, lst, r0);
stderr_ (begin_env (program, r0));
fputs ("", stderr);
gc (g_stack);

View File

@ -1,7 +1,7 @@
;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of Mes.
;;;
@ -42,6 +42,8 @@
(define (identity x) x)
(define (command-line) argv)
(define-macro (or . x)
(if (null? x) #f
(if (null? (cdr x)) (car x)