while (al) {
struct var *v = cast(var, al->left);
struct value *vl = v->var->val;
+ struct value arg;
if (argv[0] == NULL) {
printf("Not enough args\n");
exit(1);
}
- al = cast(binode, al->right);
- if (vl)
- free_value(v->var->type, vl);
+ if (v->var->type != Tstr) {
+ printf("Arg not string!!\n"); // NOTEST
+ exit(2); // NOTEST
+ }
if (!vl) {
vl = val_alloc(c, v->var->type, NULL);
v->var->val = vl;
}
- free_value(v->var->type, vl);
- vl->str.len = strlen(argv[0]);
- vl->str.txt = malloc(vl->str.len);
- memcpy(vl->str.txt, argv[0], vl->str.len);
+
+ arg.str.txt = argv[0];
+ arg.str.len = strlen(argv[0]);
+ free_value(Tstr, vl);
+ dup_value(Tstr, &arg, vl);
+
+ al = cast(binode, al->right);
argv++;
}
v = interp_exec(c, p->right, &vtype);