Update of /var/lib/cvs/src/d2c/compiler/main
In directory cantor:/tmp/cvs-serv17977/d2c/compiler/main
Modified Files:
Tag: GD_2_5
lid-mode-state.dylan main-unit-state.dylan
single-file-mode-state.dylan
Log Message:
Some more refactorings to make the code smaller and more modular.
Index: lid-mode-state.dylan
===================================================================
RCS file: /var/lib/cvs/src/d2c/compiler/main/lid-mode-state.dylan,v
retrieving revision 1.20.2.9
retrieving revision 1.20.2.10
diff -u -d -r1.20.2.9 -r1.20.2.10
--- lid-mode-state.dylan 4 Feb 2004 12:52:49 -0000 1.20.2.9
+++ lid-mode-state.dylan 5 Feb 2004 01:12:57 -0000 1.20.2.10
@@ -373,63 +373,30 @@
block ()
let tlfs = state.unit-tlfs;
- format(*debug-output*, "Converting top level forms.\n");
- state.progress-indicator := make(<n-of-k-progress-indicator>,
- total: tlfs.size,
- stream: *debug-output*);
- for (tlf in tlfs)
- block ()
- compile-1-tlf(tlf, state);
- cleanup
- end-of-context();
- exception (<fatal-error-recovery-restart>)
- #f;
- end block;
- end for;
-
- format(*debug-output*, "Optimizing top level forms.\n");
- state.progress-indicator := make(<n-of-k-progress-indicator>,
- total: tlfs.size,
- stream: *debug-output*);
- for (tlf in tlfs)
- block ()
- let name = format-to-string("%s", tlf);
- increment-and-report-progress(state.progress-indicator);
- note-context(name);
- optimize-component(*current-optimizer*, tlf.tlf-component);
- cleanup
- end-of-context();
- exception (<fatal-error-recovery-restart>)
- #f;
- end block;
- end for;
-
- format(*debug-output*, "Emitting C code.\n");
- state.progress-indicator := make(<n-of-k-progress-indicator>,
- total: tlfs.size,
- stream: *debug-output*);
-
+ run-stage("Converting top level forms.",
+ method(tlf)
+ compile-1-tlf(tlf, state);
+ end method, tlfs);
+
+ run-stage("Optimizing top level forms.",
+ method(tlf)
+ optimize-component(*current-optimizer*, tlf.tlf-component);
+ end method, tlfs);
+
let base-name = concatenate(state.unit-mprefix, "-guts");
let c-name = concatenate(base-name, ".c");
let temp-c-name = concatenate(c-name, "-temp");
let body-stream
= make(<file-stream>, locator: temp-c-name, direction: #"output");
+ let file = make(<file-state>, unit: state.unit-cback-unit,
+ body-stream: body-stream);
block ()
- let file = make(<file-state>, unit: state.unit-cback-unit,
- body-stream: body-stream);
emit-prologue(file, state.unit-other-cback-units);
- for (tlf in tlfs)
- block ()
- let name = format-to-string("%s", tlf);
- increment-and-report-progress(state.progress-indicator);
- note-context(name);
- emit-1-tlf(tlf, file, state);
- cleanup
- end-of-context();
- exception (<fatal-error-recovery-restart>)
- #f;
- end block;
- end for;
+
+ run-stage("Emitting C code.",
+ method(tlf)
+ emit-1-tlf(tlf, file, state);
+ end method, tlfs);
cleanup
close(body-stream);
// fresh-line(*debug-output*);
@@ -478,12 +445,7 @@
begin
let c-name = concatenate(state.unit-mprefix, "-init.c");
- #if (macos)
- let temp-c-name = concatenate(state.unit-lid-file.filename-prefix,
- c-name);
- #else
let temp-c-name = concatenate(c-name, "-temp");
- #endif
let body-stream = make(<file-stream>,
locator: temp-c-name, direction: #"output");
let file = make(<file-state>, unit: state.unit-cback-unit,
@@ -517,11 +479,7 @@
define method build-local-heap-file (state :: <lid-mode-state>) => ();
format(*debug-output*, "Emitting Library Heap.\n");
let c-name = concatenate(state.unit-mprefix, "-heap.c");
- #if (macos)
- let temp-c-name = concatenate(state.unit-lid-file.filename-prefix, c-name);
- #else
let temp-c-name = concatenate(c-name, "-temp");
- #endif
let heap-stream = make(<file-stream>,
locator: temp-c-name, direction: #"output");
let prefix = state.unit-cback-unit.unit-prefix;
@@ -682,13 +640,7 @@
format(stream, "}\n");
if(~state.unit-embedded?)
format(stream, "\nextern void real_main(int argc, char *argv[]);\n\n");
-#if (macos)
- format(stream, "#include<console.h>\n");
-#endif
format(stream, "int main(int argc, char *argv[]) {\n");
-#if (macos)
- format(stream, " argc = ccommand( &argv );\n");
-#endif
format(stream, " real_main(argc, argv);\n");
format(stream, " exit(0);\n");
format(stream, "}\n");
Index: main-unit-state.dylan
===================================================================
RCS file: /var/lib/cvs/src/d2c/compiler/main/main-unit-state.dylan,v
retrieving revision 1.5.2.8
retrieving revision 1.5.2.9
diff -u -d -r1.5.2.8 -r1.5.2.9
--- main-unit-state.dylan 4 Feb 2004 12:52:49 -0000 1.5.2.8
+++ main-unit-state.dylan 5 Feb 2004 01:12:57 -0000 1.5.2.9
@@ -145,9 +145,6 @@
define method compile-1-tlf
(tlf :: <top-level-form>, state :: <main-unit-state>)
=> ();
- let name = format-to-string("%s", tlf);
- increment-and-report-progress(state.progress-indicator);
- note-context(name);
let component = make(<fer-component>);
tlf.tlf-component := component;
let builder = make-builder(component);
@@ -308,6 +305,26 @@
end;
layout-instance-slots();
end method finalize-library;
+
+define method run-stage(message :: <string>, func :: <function>,
+ tlfs :: <collection>) => ()
+ format(*debug-output*, "%s\n", message);
+ let progress-indicator = make(<n-of-k-progress-indicator>,
+ total: tlfs.size,
+ stream: *debug-output*);
+ for (tlf in tlfs)
+ block ()
+ let name = format-to-string("%s", tlf);
+ increment-and-report-progress(progress-indicator);
+ note-context(name);
+ func(tlf);
+ cleanup
+ end-of-context();
+ exception (<fatal-error-recovery-restart>)
+ #f;
+ end block;
+ end for;
+end method run-stage;
define variable *Current-Library* :: false-or(<library>) = #f;
Index: single-file-mode-state.dylan
===================================================================
RCS file: /var/lib/cvs/src/d2c/compiler/main/single-file-mode-state.dylan,v
retrieving revision 1.14.2.5
retrieving revision 1.14.2.6
diff -u -d -r1.14.2.5 -r1.14.2.6
--- single-file-mode-state.dylan 4 Feb 2004 12:52:49 -0000 1.14.2.5
+++ single-file-mode-state.dylan 5 Feb 2004 01:12:57 -0000 1.14.2.6
@@ -159,7 +159,18 @@
end method parse-and-finalize-library;
define method compile-file (state :: <single-file-mode-state>) => ();
- format(*debug-output*, "Processing %s\n", state.unit-source-file);
+ let tlfs = state.unit-tlfs;
+
+ run-stage("Converting top level forms.",
+ method(tlf)
+ compile-1-tlf(tlf, state);
+ end method, tlfs);
+
+ run-stage("Optimizing top level forms.",
+ method(tlf)
+ optimize-component(*current-optimizer*, tlf.tlf-component);
+ end method, tlfs);
+
let c-name = concatenate(state.unit-name, ".c");
let body-stream
= make(<file-stream>, locator: c-name, direction: #"output");
@@ -169,18 +180,10 @@
state.unit-stream := body-stream;
emit-prologue(file, state.unit-other-cback-units);
- for (tlf in state.unit-tlfs)
- block ()
- compile-1-tlf(tlf, state);
- optimize-component(*current-optimizer*, tlf.tlf-component);
- emit-1-tlf(tlf, file, state);
- cleanup
- end-of-context();
- exception (<fatal-error-recovery-restart>)
- #f;
- end block;
- end for;
- format(*debug-output*, "\n");
+ run-stage("Emitting C code.",
+ method(tlf)
+ emit-1-tlf(tlf, file, state);
+ end method, tlfs);
end method compile-file;
@@ -194,7 +197,6 @@
define method build-local-heap-file (state :: <single-file-mode-state>) => ();
format(*debug-output*, "Emitting Library Heap.\n");
- let heap-stream = state.unit-stream;
let prefix = state.unit-cback-unit.unit-prefix;
let (undumped, extra-labels) = build-local-heap(state.unit-cback-unit,
state.unit-c-file);
@@ -208,7 +210,6 @@
define method build-da-global-heap (state :: <single-file-mode-state>) => ();
format(*debug-output*, "Emitting Global Heap.\n");
- let heap-stream = state.unit-stream;
build-global-heap(apply(concatenate, map(undumped-objects, *units*)),
state.unit-c-file);
end method;
@@ -224,13 +225,7 @@
end;
format(stream, "}\n");
format(stream, "\nextern void real_main(int argc, char *argv[]);\n\n");
-#if (macos)
- format(stream, "#include<console.h>\n");
-#endif
format(stream, "int main(int argc, char *argv[]) {\n");
-#if (macos)
- format(stream, " argc = ccommand( &argv );\n");
-#endif
format(stream, " real_main(argc, argv);\n");
format(stream, " exit(0);\n");
format(stream, "}\n");
_______________________________________________
Gd-chatter mailing list
Gd-chatter@xxxxxxxxxxxxxxxx
http://www.gwydiondylan.org/mailman/listinfo/gd-chatter
|