summaryrefslogtreecommitdiffstats
path: root/tests/019
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-05-31 20:11:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-05-31 20:11:55 -0700
commiteed8a92921ff3ce55c845d03d5e0bf49a4b395d8 (patch)
treeecccf68bde418cec533c6b480cae00c6441ab631 /tests/019
parent661531cdc4529078c15c222fafe2da025c02591d (diff)
downloadtxr-eed8a92921ff3ce55c845d03d5e0bf49a4b395d8.tar.gz
txr-eed8a92921ff3ce55c845d03d5e0bf49a4b395d8.tar.bz2
txr-eed8a92921ff3ce55c845d03d5e0bf49a4b395d8.zip
load: now passes args via *load-args*
We can give additional arguments to load, which become arguments of the script, which it can retrieve via the *load-args* special variable. * eval.c (load_args_s): New symbol variable. (loadv): New function, taking over the implementation of load. This takes variadic arguments. Loadv binds the *load-args* variable from the list of variadic arguments. (load): Reduced to wrapper around loadv. (rt_load_for): Each clause in load for can now have arguments after the target name. If that file needs to be loaded, then the arguments are passed. (me_load_for): The macro expander for the load-for macro needs to allow for the load-arg expressions and generate code which passes them to sys:rt-load-for. They all get evaluated. (eval-init): Initialize load_args_s and register the *load-args* variable. Update registration of intrinsic function load to use loadv. * tests/019/load-ret.tl, * tests/019/load-ret/module.tl, * tests/019/load-ret/module2.tl: New files. * txr.1: Documented.
Diffstat (limited to 'tests/019')
-rw-r--r--tests/019/load-ret.tl13
-rw-r--r--tests/019/load-ret/module.tl1
-rw-r--r--tests/019/load-ret/module2.tl2
3 files changed, 16 insertions, 0 deletions
diff --git a/tests/019/load-ret.tl b/tests/019/load-ret.tl
new file mode 100644
index 00000000..a79f7da9
--- /dev/null
+++ b/tests/019/load-ret.tl
@@ -0,0 +1,13 @@
+(load "../common")
+
+(mtest
+ (load "load-ret/module") 0
+ (load "load-ret/module" 1) 1
+ (load "load-ret/module" 1 2 3) 6)
+
+(mtest
+ (load-for (var abc "load-ret/module2" 'abc)) 0
+ (load-for (var def "load-ret/module2" 'def 1 2 3)) 6
+ (load-for (var abc "load-ret/module2" 'abc)) nil
+ (load-for (var abc "load-ret/module2" 'abc)
+ (var ghi "load-ret/module2" 'ghi 2 3 4)) 9)
diff --git a/tests/019/load-ret/module.tl b/tests/019/load-ret/module.tl
new file mode 100644
index 00000000..05d69035
--- /dev/null
+++ b/tests/019/load-ret/module.tl
@@ -0,0 +1 @@
+(return-from load [apply + *load-args*])
diff --git a/tests/019/load-ret/module2.tl b/tests/019/load-ret/module2.tl
new file mode 100644
index 00000000..e651c3f5
--- /dev/null
+++ b/tests/019/load-ret/module2.tl
@@ -0,0 +1,2 @@
+(eval ^(defvar ,(pop *load-args*)))
+(return-from load [apply + *load-args*])