1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
############################################################################
#
# File: loadfile.icn
#
# Subject: Procedure to produce and load program on the fly
#
# Author: Ralph E. Griswold
#
# Date: November 21, 1996
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# loadfile(exp, link, ...) produces and loads a program that generates
# the results of exp. The trailing arguments name link
# files needed for the expression. loadfile() returns a procedure
# that generates the results.
#
############################################################################
#
# Requires: MT-Icon, system(), pipes, /tmp
#
############################################################################
#
# Links: io
#
############################################################################
link io
procedure loadfile(exp, links[]) #: produce and load program
local output, prog
static name
output := tempfile("load", ".icn", "/tmp")
image(output) ? {
="file("
name := tab(find(".icn"))
}
write(output, "invocable all")
every write(output, "link ", image(!links))
write(output, "procedure main(args)")
write(output, " suspend ", exp)
write(output, "end")
close(output)
if system("mticont -o " || name || " -s " || name ||
" >/dev/null 2>/dev/null") ~= 0 then fail
remove(name || ".icn") # remove source code file
# Load the program
prog := load(name) | stop("*** load failure in loadfile")
return variable("main", prog)
end
|