mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
Revert "Implement SRFI 193: Command lines"
This commit is contained in:
parent
751675c6b2
commit
9f0ed1a869
3 changed files with 8 additions and 60 deletions
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
(define-library (srfi 193)
|
|
||||||
(export command-line command-name command-args script-file script-directory)
|
|
||||||
(import (scheme base) (chibi filesystem) (chibi pathname)
|
|
||||||
(only (meta) command-line raw-script-file))
|
|
||||||
(begin
|
|
||||||
|
|
||||||
(define (command-name)
|
|
||||||
(let ((filename (car (command-line))))
|
|
||||||
(and (not (= 0 (string-length filename)))
|
|
||||||
(path-strip-extension (path-strip-directory filename)))))
|
|
||||||
|
|
||||||
(define (command-args)
|
|
||||||
(cdr (command-line)))
|
|
||||||
|
|
||||||
(define (script-file)
|
|
||||||
(and raw-script-file
|
|
||||||
(path-normalize
|
|
||||||
(path-resolve raw-script-file (current-directory)))))
|
|
||||||
|
|
||||||
(define (script-directory)
|
|
||||||
(let ((filename (script-file)))
|
|
||||||
(and filename (string-append (path-directory filename) "/"))))))
|
|
32
main.c
32
main.c
|
@ -9,8 +9,7 @@
|
||||||
#include "chibi/eval.h"
|
#include "chibi/eval.h"
|
||||||
#include "chibi/gc_heap.h"
|
#include "chibi/gc_heap.h"
|
||||||
|
|
||||||
#define sexp_command_line_symbol "command-line"
|
#define sexp_argv_symbol "command-line"
|
||||||
#define sexp_raw_script_file_symbol "raw-script-file"
|
|
||||||
|
|
||||||
#define sexp_import_prefix "(import ("
|
#define sexp_import_prefix "(import ("
|
||||||
#define sexp_import_suffix "))"
|
#define sexp_import_suffix "))"
|
||||||
|
@ -283,14 +282,6 @@ static void do_init_context (sexp* ctx, sexp* env, sexp_uint_t heap_size,
|
||||||
#define init_context() if (! ctx) do { \
|
#define init_context() if (! ctx) do { \
|
||||||
do_init_context(&ctx, &env, heap_size, heap_max_size, fold_case); \
|
do_init_context(&ctx, &env, heap_size, heap_max_size, fold_case); \
|
||||||
sexp_gc_preserve4(ctx, tmp, sym, args, env); \
|
sexp_gc_preserve4(ctx, tmp, sym, args, env); \
|
||||||
sexp_set_parameter( \
|
|
||||||
ctx, sexp_meta_env(ctx), \
|
|
||||||
sym=sexp_intern(ctx, sexp_command_line_symbol, -1), \
|
|
||||||
args=sexp_cons(ctx, sexp_c_string(ctx,"",-1), SEXP_NULL)); \
|
|
||||||
sexp_env_define( \
|
|
||||||
ctx, sexp_meta_env(ctx), \
|
|
||||||
sym=sexp_intern(ctx, sexp_raw_script_file_symbol, -1), \
|
|
||||||
SEXP_FALSE); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define load_init(bootp) if (! init_loaded++) do { \
|
#define load_init(bootp) if (! init_loaded++) do { \
|
||||||
|
@ -315,7 +306,7 @@ sexp run_main (int argc, char **argv) {
|
||||||
sexp_uint_t heap_size=0, heap_max_size=SEXP_MAXIMUM_HEAP_SIZE;
|
sexp_uint_t heap_size=0, heap_max_size=SEXP_MAXIMUM_HEAP_SIZE;
|
||||||
sexp out=SEXP_FALSE, ctx=NULL, ls;
|
sexp out=SEXP_FALSE, ctx=NULL, ls;
|
||||||
sexp_gc_var4(tmp, sym, args, env);
|
sexp_gc_var4(tmp, sym, args, env);
|
||||||
args = NULL;
|
args = SEXP_NULL;
|
||||||
env = NULL;
|
env = NULL;
|
||||||
|
|
||||||
/* SRFI 22: invoke `main` procedure by default if the interpreter is */
|
/* SRFI 22: invoke `main` procedure by default if the interpreter is */
|
||||||
|
@ -554,22 +545,15 @@ sexp run_main (int argc, char **argv) {
|
||||||
done_options:
|
done_options:
|
||||||
if (!quit || main_symbol != NULL) {
|
if (!quit || main_symbol != NULL) {
|
||||||
init_context();
|
init_context();
|
||||||
load_init(i < argc || main_symbol != NULL);
|
|
||||||
/* build argument list */
|
/* build argument list */
|
||||||
if (i < argc) {
|
if (i < argc)
|
||||||
args = SEXP_NULL;
|
|
||||||
for (j=argc-1; j>=i; j--)
|
for (j=argc-1; j>=i; j--)
|
||||||
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[j],-1), args);
|
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[j],-1), args);
|
||||||
sexp_set_parameter(
|
/* if no script name, use interpreter name */
|
||||||
ctx, sexp_meta_env(ctx),
|
if (i >= argc || main_module != NULL)
|
||||||
sym=sexp_intern(ctx, sexp_command_line_symbol, -1),
|
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[0],-1), args);
|
||||||
args);
|
load_init(i < argc || main_symbol != NULL);
|
||||||
sexp_env_define(
|
sexp_set_parameter(ctx, sexp_meta_env(ctx), sym=sexp_intern(ctx, sexp_argv_symbol, -1), args);
|
||||||
ctx, sexp_meta_env(ctx),
|
|
||||||
sym=sexp_intern(ctx, sexp_raw_script_file_symbol, -1),
|
|
||||||
sexp_c_string(ctx,argv[i],-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i >= argc && main_symbol == NULL) {
|
if (i >= argc && main_symbol == NULL) {
|
||||||
/* no script or main, run interactively */
|
/* no script or main, run interactively */
|
||||||
repl(ctx, env);
|
repl(ctx, env);
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#! /usr/bin/env chibi-scheme
|
|
||||||
|
|
||||||
(import (scheme base) (scheme write) (srfi 193))
|
|
||||||
|
|
||||||
(define-syntax pp
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ expr) (begin (write 'expr) (display " => ") (write expr) (newline)))))
|
|
||||||
|
|
||||||
(pp (command-line))
|
|
||||||
(pp (command-name))
|
|
||||||
(pp (command-args))
|
|
||||||
(pp (script-file))
|
|
||||||
(pp (script-directory))
|
|
Loading…
Add table
Reference in a new issue