tagged release 0.6.4
[parrot.git] / languages / tcl / runtime / builtin / source.pir
blob36c84f6165e1fc52189ccc77988ae4cd67f9ea60
1 ###
2 # [source]
4 .HLL 'Tcl', 'tcl_group'
5 .namespace []
7 .sub '&source'
8   .param pmc argv :slurpy
10   .local int argc
11   argc = elements argv
12   if argc != 1 goto bad_args
14   .local string filename
15   filename = shift argv
17   .local string file_contents
18   $P99 = open filename, '<'
19   push_eh badfile
20     file_contents = $P99.'slurp'('')
21   pop_eh
23   .local pmc ns, interp
24   interp = getinterp
25   ns = interp['namespace';1]
27   .local pmc __script, code
28   __script = get_root_global ['_tcl'], '__script'
29   code = __script ( file_contents, 'ns' => ns, 'bsnl' => 1)
31   .return code()
33 badfile:
34   $S0 = "couldn't read file \""
35   $S0 .= filename
36   $S0 .= '": no such file or directory'
37   tcl_error $S0
39 bad_args:
40   tcl_error 'wrong # args: should be "source fileName"'
41 .end
43 # Local Variables:
44 #   mode: pir
45 #   fill-column: 100
46 # End:
47 # vim: expandtab shiftwidth=4 ft=pir: