This commit is contained in:
Dmitry Boulytchev 2020-01-26 07:58:11 +03:00
parent c09a3b36b6
commit 33ec55e76e
6 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Number of commands-line arguments: 1
arg [0 ] = "./test009"

View file

@ -0,0 +1,7 @@
local i;
printf ("Number of commands-line arguments: %d\n", sysargs.length);
for i := 0, i < sysargs.length, i := i + 1 do
printf (" arg [%-2d] = %s\n", i, sysargs[i].string)
od

View file

@ -0,0 +1 @@
0

View file

@ -1,3 +1,4 @@
V,sysargs;
F,makeArray;
F,clone;
F,hash;

View file

@ -102,6 +102,35 @@ typedef struct {
extern void* alloc (size_t);
extern void* Bsexp (int n, ...);
void *global_sysargs;
void set_args (int argc, char *argv[]) {
data *a;
int n = argc;
int i;
__pre_gc ();
a = (data*) alloc (sizeof(int) * (n+1));
a->tag = ARRAY_TAG | (n << 3);
for (i=0; i<n; i++) {
data *s;
int k = strlen (argv[i]);
s = (data*) alloc (k + 1 + sizeof (int));
s->tag = STRING_TAG | (k << 3);
strncpy (s->contents, argv[i], k + 1);
((int*)a->contents)[i] = s->contents;
}
__post_gc ();
global_sysargs = a->contents;
}
// Functional synonym for built-in operator ":";
void* Ls__Infix_58 (void *p, void *q) {
void *res;

View file

@ -377,7 +377,7 @@ let compile cmd env imports code =
Repmovsl
] @
(if f = "main"
then [Call "L__gc_init"]
then [Call "L__gc_init"; Push (I (12, ebp)); Push (I (8, ebp)); Call "set_args"; Binop ("+", L 8, esp)]
else []
) @
(if f = cmd#topname