-
Notifications
You must be signed in to change notification settings - Fork 0
/
compileutil.def
187 lines (156 loc) · 4.97 KB
/
compileutil.def
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
include: macros_util/debug.def
include: macros_compile/preproc.def
include: macros_compile/callsub.def
include: macros_compile/parse.def
include: macros_compile/macro.def
include: macros_compile/ogdl.def
include: macros_compile/list.def
include: macros_compile/util.def
page: compileutil
type: pm
output_dir: lib/MyDef
package: MyDef::compileutil
1;
fncode: output($plines)
my $page=$MyDef::page
my $pagename=$page->{_pagename}
my $pageext=$page->{_pageext}
my $outdir=$page->{_outdir}
my $outname=$outdir."/".$pagename;
$if $pageext
$outname.=".$pageext";
$if !${MyDef::var}->{silent}
print " --> [$outname]\n";
my $n=@$plines
$if $n==0
$print "Strange, no output!"
$else
&call open_w, $outname
$foreach $l in @$plines
print Out $l;
$page->{outname}=$outname
fncode: compile
my $page=$MyDef::page
my $pagename=$page->{_pagename}
$call output_outdir
$call do_compile
$call @end_compile_report
# -----------------
subcode: output_outdir
my $outdir=".";
$if $MyDef::var->{output_dir}
$outdir=$MyDef::var->{output_dir};
$if $page->{output_dir}
$if $page->{output_dir}=~/^[\/\.]/
$outdir=$page->{output_dir};
$else
$outdir=$outdir."/".$page->{output_dir};
$outdir=~s/^\s+//;
# create output dir
$if ! -d "$outdir/"
my @tdir_list=split /\//, $outdir;
my $tdir;
my $slash=0;
$foreach my $t in @tdir_list
$if !$slash
$tdir=$t;
$slash=1;
$else
$tdir=$tdir.'/'.$t;
if(!$tdir){next;}
$if ! -d $tdir
mkdir $tdir or die "Can't create output directory: $tdir\n";
#---------------------
$page->{_outdir}=$outdir
# -----------------
subcode: do_compile
$deflist=[$MyDef::def, $MyDef::def->{macros}, $page];
# for debug purpose
$deflist->[0]->{_name_}="def_root"
$deflist->[1]->{_name_}="macros"
$deflist->[2]->{_name_}="page $page->{_pagename}"
$call @merge_page_macros
my $mode=$f_init->($page);
$if $mode
modepush($mode)
init_output();
$if !${MyDef::var}->{silent}
print "PAGE: $pagename\n";
#---- save var
my %varsave;
$while my ($k, $v)=each %$page
$varsave{$k}=$MyDef::var->{$k};
$MyDef::var->{$k}=$v;
#---- autoload
$global $in_autoload
$in_autoload=1
# note: potentially a_autoload, b_autoload ...
my $codelist=$MyDef::def->{codes};
$foreach $codename in sort keys %$codelist
$if $codename=~/_autoload$/
call_sub($codename)
$in_autoload=0
#---- main
# ref: callsub.def - fncode call_sub
$main_called = 0
$if !$page->{_frame} and $codelist->{basic_frame}
$page->{_frame} = "basic_frame"
$if $page->{_frame} and $page->{_frame} ne "-"
call_sub($page->{_frame})
# if frame didn't call main --
$if !$main_called
call_sub("main")
$f_parse->("NOOP POST_MAIN")
#---- restore var
$while my ($k, $v)=each %varsave
$MyDef::var->{$k}=$v;
#---- Dump
$if !$page->{subpage}
my @buffer;
$f_dumpout->(\@buffer, fetch_output(0))
return \@buffer
subcode: merge_page_macros
$if $page->{macros}
$foreach %{$page->{macros}}
$if !defined $page->{$k}
$page->{$k} = $v
#################################################
subcode: _autoload
$global $deflist, %misc_vars
$global $debug=0
fncode: set_output($output)
my $old=$out
$out=$output
$f_setout->($out)
return $old
macros:
# ref output.def
interface: $f_init, $f_parse, $f_setout, $f_modeswitch, $f_dumpout
subcode: _autoload
$global $(interface)
fncode: set_interface
($(interface))=@_;
fncode: set_interface_partial
my $t
($f_init, $f_parse, $f_setout, $t, $f_dumpout)=@_;
#-----------------------------------------------
#- push/pop _interface is also used by output_www.def
subcode: _autoload
$global @interface_stack
fncode: push_interface($module)
push @interface_stack, [$(interface)]
$(for:$(module_list))
$case $module eq "$1"
$(set:M=MyDef::output_$1)
require $(M)
set_interface_partial($(M)::get_interface())
$else
$call warn, " push_interface: module $module not found\n"
return undef
$f_setout->($out)
fncode: pop_interface
$if @interface_stack
my $interface = pop @interface_stack
set_interface_partial(@$interface)
$else
$call warn, " pop_interface: stack empty\n"