mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Sysargs
This commit is contained in:
parent
c09a3b36b6
commit
33ec55e76e
6 changed files with 41 additions and 1 deletions
2
regression/x86only/orig/test009.log
Normal file
2
regression/x86only/orig/test009.log
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
Number of commands-line arguments: 1
|
||||||
|
arg [0 ] = "./test009"
|
||||||
7
regression/x86only/test009.expr
Normal file
7
regression/x86only/test009.expr
Normal 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
|
||||||
1
regression/x86only/test009.input
Normal file
1
regression/x86only/test009.input
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
0
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
V,sysargs;
|
||||||
F,makeArray;
|
F,makeArray;
|
||||||
F,clone;
|
F,clone;
|
||||||
F,hash;
|
F,hash;
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,35 @@ typedef struct {
|
||||||
extern void* alloc (size_t);
|
extern void* alloc (size_t);
|
||||||
extern void* Bsexp (int n, ...);
|
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 ":";
|
// Functional synonym for built-in operator ":";
|
||||||
void* Ls__Infix_58 (void *p, void *q) {
|
void* Ls__Infix_58 (void *p, void *q) {
|
||||||
void *res;
|
void *res;
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,7 @@ let compile cmd env imports code =
|
||||||
Repmovsl
|
Repmovsl
|
||||||
] @
|
] @
|
||||||
(if f = "main"
|
(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 []
|
else []
|
||||||
) @
|
) @
|
||||||
(if f = cmd#topname
|
(if f = cmd#topname
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue