annotate dang/compiler.d @ 194:08f68d684047

Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with". Also added support for alias.
author Anders Johnsen <skabet@gmail.com>
date Tue, 29 Jul 2008 13:54:44 +0200
parents dc9bf56b7ace
children 4e1a7265d620
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1 module dang.compiler;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
2
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
3 import tango.io.Stdout,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
4 tango.core.Signal,
91
1a24e61eb104 Fixed the SourceLocation/SourceManager for files stretching by more then one CheckPoints
johnsen@johnsen-laptop
parents: 90
diff changeset
5 tango.core.Memory,
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
6 tango.sys.Process,
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
7 tango.time.StopWatch,
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
8 tango.text.Util,
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
9 tango.io.FileConduit,
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
10 tango.io.FilePath;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
11
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
12 import lexer.Lexer,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
13 parser.Parser;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
14
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
15 import basic.SourceManager;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
16
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
17 import basic.Message;
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
18
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
19 import ast.Module;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
20
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
21 import tools.AstPrinter,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
22 tools.DotPrinter;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
23
51
c96cdcbdb9d6 Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents: 50
diff changeset
24 import gen.CodeGen;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
25
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
26 import sema.Visitor,
51
c96cdcbdb9d6 Rearranged some stuff, and renamed LLVMGen -> CodeGen
Anders Halager <halager@gmail.com>
parents: 50
diff changeset
27 sema.AstAction,
194
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
28 sema.BuildScopes,
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
29 sema.BuildSymbols,
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
30 sema.CheckScopes,
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
31 sema.CheckTypes,
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 101
diff changeset
32 sema.LiteralInterpreter,
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
33 sema.VC,
194
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
34 sema.ObjectOriented;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
35
97
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
36 import tango.stdc.posix.unistd;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
37 import tango.stdc.stdlib;
97
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
38
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
39 import Opt = dang.OptParse;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
40
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
41 class NullAction : Action
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
42 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
43 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
44
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
45 void checkFiles(char[][] *files)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
46 {
176
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
47 // GC.disable();
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
48 bool non_existant_files = false;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
49 bool duplicate_files = false;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
50
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
51 char[][] validFiles;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
52
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
53 foreach (file; *files)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
54 {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
55 scope path = new FilePath(file);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
56
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
57 if (!path.exists)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
58 {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
59 Stderr.formatln("'{}' does not exist", file).newline;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
60 non_existant_files = true;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
61
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
62 continue;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
63 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
64
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
65 bool fileInStack = false;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
66 foreach (vFile; validFiles)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
67 if (vFile == file)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
68 {
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
69 fileInStack = true;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
70 duplicate_files = true;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
71 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
72
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
73 if (fileInStack)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
74 continue;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
75
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
76 validFiles ~= path.toString();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
77 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
78
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
79 *files = validFiles;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
80
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
81 if (non_existant_files)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
82 throw new Exception("All files given must exist");
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
83 if (duplicate_files)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
84 Stderr("warning: duplicate files ignored").newline;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
85 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
86
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
87 void main(char[][] args)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
88 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
89 char[][] filesToHandle;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
90
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
91 Signal!(char[][]*) preStart;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
92
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
93 Signal!(char[]) preLex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
94 Signal!(Lexer) postLex;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
95
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
96 Signal!(Lexer) preParse;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
97 Signal!(Module[], SourceManager) postParse;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
98 Signal!(Module[], SourceManager) postSema;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
99
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
100 preStart.attach(&checkFiles);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
101
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
102 auto argParse = new Opt.OptionParser(`Dang "D" compiler v0.0`);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
103
40
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
104 bool optimize = false;
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
105 bool inline = false;
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
106
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
107
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
108 SourceManager src_mgr = new SourceManager;
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
109 MessageHandler messages = new MessageHandler(src_mgr);
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
110
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
111 argParse.addOption(["-h", "--help"], Opt.Action.Help)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
112 .help("Show this help message");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
113
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
114 argParse.addOption(["--ast-dump-dot"],
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
115 "what-to-do", Opt.Action.StoreConst, "dot")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
116 .help("Output the AST in the dot format");
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
117 argParse.addOption(["--ast-dump-code"],
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
118 "what-to-do", Opt.Action.StoreConst, "code")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
119 .help("Output the AST as code");
176
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
120 argParse.addOption(["--semantic-only"],
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
121 "what-to-do", Opt.Action.StoreConst, "exit")
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
122 .help("Exit after semantics and before codegen");
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
123 argParse.addOption(["--gen-llvm"],
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
124 "what-to-do", Opt.Action.StoreConst, "gen-llvm")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
125 .help("Compile to LLVM code (default)");
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
126 argParse.addOption(["-c"],
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
127 "what-to-do", Opt.Action.StoreConst, "compile")
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
128 .help("Compile to .o or executeable");
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
129 argParse.addOption(["--syntax-only"],
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
130 "what-to-do", Opt.Action.StoreConst, "parse")
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
131 .help("Only parse the file(s) and output parseing errors.");
40
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
132
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
133 argParse.addOption(
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
134 ["-O","--optimize"], {
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
135 optimize = true;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
136 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
137 ).help("Tell LLVM to do its standard optimizations");
40
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
138
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
139 argParse.addOption(
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
140 ["--inline"], {
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
141 inline = true;
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
142 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
143 ).help("Tell LLVM that its allowed to inline functions");
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
144
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
145 argParse
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
146 .addOption(["--time"], Opt.Action.SetTrue, "time")
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
147 .help("Time the various operations performed.");
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
148
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
149 auto options = argParse.parse(args);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
150
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
151 filesToHandle ~= options.args;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
152
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
153 // Will throw exception if some files don't exist
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
154 preStart(&filesToHandle);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
155
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
156 struct Measurement { char[] label; double time; }
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
157 Measurement[] timings;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
158
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
159 auto what = options["what-to-do"];
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
160 if (what == "" || what == "gen-llvm")
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
161 postSema.attach(
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
162 (Module[] modules, SourceManager sm) {
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
163 foreach(m ; modules)
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
164 {
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
165 if (!m.outputModule)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
166 continue;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
167 StopWatch w; w.start;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
168 auto llvmGen = new CodeGen();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
169 auto file = new FileConduit(m.moduleName~".bc", FileConduit.WriteCreate);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
170 llvmGen.gen(m, file.fileHandle, optimize, inline);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
171 timings ~= Measurement("Generating LLVM bytecode", w.stop);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
172 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
173 });
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
174 else if (what == "compile")
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
175 postSema.attach(
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
176 (Module[] modules, SourceManager sm) {
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
177 foreach(m ; modules)
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
178 {
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
179 if (!m.outputModule)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
180 continue;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
181 StopWatch w; w.start;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
182 auto llvmGen = new CodeGen();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
183 auto llc = new Process("llc","-o=-");
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
184 auto gcc = new Process("gcc","-c","-o",m.moduleName~".o","-x","assembler","-");
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
185 llc.execute();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
186 int i = dup(llc.stdin.fileHandle);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
187 llc.stdin.detach;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
188 llvmGen.gen(m, i, optimize, inline);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
189 llc.wait();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
190 gcc.execute();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
191 gcc.stdin.copy(llc.stdout);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
192 gcc.stdin.detach;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
193 gcc.wait();
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
194 timings ~= Measurement("Generating ASM", w.stop);
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
195 }
97
198ad05f3ace "-c" as argument now generates out.o (only works on linux now)
Anders Johnsen <skabet@gmail.com>
parents: 94
diff changeset
196
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
197 });
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
198 else if (what == "parse")
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
199 preParse.attach(
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
200 (Lexer lexer) {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
201 auto parser = new Parser(messages);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
202 auto action = new NullAction();
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
203 parser.parse(src_mgr, lexer, action);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
204 messages.checkErrors(ExitLevel.Parser);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
205 exit(0);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
206 });
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
207 else if (what == "dot")
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
208 postSema.attach(
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
209 (Module[] m, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
210 StopWatch w; w.start;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
211 // auto print = new DotPrinter();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
212 // print.print(m);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
213 timings ~= Measurement("Generating dot output", w.stop);
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
214 });
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
215 else if (what == "code")
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
216 postSema.attach(
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
217 (Module[] modules, SourceManager sm) {
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
218 StopWatch w; w.start;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
219 auto print = new AstPrinter(sm);
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
220 foreach ( m ; modules )
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
221 if (m.outputModule)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
222 print.print(m);
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
223 timings ~= Measurement("Converting AST to text", w.stop);
40
9fb190ad81a4 Added -O and --inline args to Dang.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
224 });
176
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
225 else if (what == "exit")
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
226 postSema.attach(
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
227 (Module[] modules, SourceManager sm) {
dc9bf56b7ace Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents: 168
diff changeset
228 });
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
229 StopWatch total;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
230 total.start;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
231
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
232 Module[] modules;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
233
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
234 StopWatch watch;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
235 watch.start;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
236 foreach (file; filesToHandle)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
237 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
238 preLex(file);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
239
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
240 auto start = src_mgr.addFile(file);
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
241 auto lexer = new Lexer(start, src_mgr, messages);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
242 postLex(lexer);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
243
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
244 preParse(lexer);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
245
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
246 auto parser = new Parser(messages);
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
247 auto action = new AstAction(src_mgr);
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
248 modules ~= cast(Module)parser.parse(src_mgr, lexer, action);
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
249 timings ~= Measurement("Lex + Parse of '"~file~"'", watch.stop);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
250 messages.checkErrors(ExitLevel.Parser);
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
251 /*
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
252 StopWatch watch2;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
253 watch.start;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
254 watch2.start;
100
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 97
diff changeset
255 Module[] mods = (new LoadModule).visit(m, src_mgr, messages);
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
256 (new ScopeBuilder).visit(m);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
257 auto scope_builder = watch2.stop;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
258 watch2.start;
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
259 (new ScopeCheck).visit(m);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
260 auto scope_check = watch2.stop;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
261 watch2.start;
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
262 (new TypeCheck).visit(m);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
263 auto type_check = watch2.stop;
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
264 watch2.start;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents: 1
diff changeset
265
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
266 foreach (decl; m.decls)
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
267 decl.simplify();
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
268 auto simplify = watch2.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
269 auto extra_stuff = watch.stop;
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
270 timings ~= Measurement("Extra stuff", watch.stop);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
271 timings ~= Measurement(" - Building scopes", scope_builder);
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
272 timings ~= Measurement(" - Checking scopes", scope_check);
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 91
diff changeset
273 timings ~= Measurement(" - Checking types", type_check);
56
4ae365eff712 Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
274
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
275 postParse(m, src_mgr);*/
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
276 }
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
277
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 101
diff changeset
278 (new LiteralInterpreter(messages)).visit(modules);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
279 messages.checkErrors;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
280 postParse(modules, src_mgr);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
281
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
282 class ModuleLoader : Visitor!(void)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
283 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
284 Module[] visit(Module[] modules, MessageHandler messages, SourceManager src_mgr)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
285 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
286 this.modules = modules;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
287 this.messages = messages;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
288 this.src_mgr = src_mgr;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
289 super.visit(modules);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
290 return this.modules;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
291 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
292
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
293 override void visitImportDecl(ImportDecl decl)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
294 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
295 char[] path = replace!(char)(decl.get,'.','/')~".d";
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
296
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
297 auto start = src_mgr.addFile(path);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
298 auto lexer = new Lexer(start, src_mgr, messages);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
299
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
300 auto parser = new Parser(messages);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
301 auto action = new AstAction(src_mgr);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
302
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
303 Module m = cast(Module)parser.parse(src_mgr, lexer, action);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
304 modules ~= m;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
305 m.outputModule = false;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
306 // decl.env.mHandle.add(m);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
307 messages.checkErrors(ExitLevel.Parser);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
308 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
309
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
310 Module[] modules;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
311 SourceManager src_mgr;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
312 MessageHandler messages;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
313 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
314
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
315 modules = (new ModuleLoader()).visit(modules, messages, src_mgr);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
316 messages.checkErrors;
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 101
diff changeset
317
194
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
318 (new BuildScopes).visit(modules);
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
319 (new BuildSymbols).visit(modules);
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
320 StopWatch watch2;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
321 watch.start;
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
322 watch2.start;
194
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
323 (new CheckScopes(messages)).visit(modules);
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
324 messages.checkErrors;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
325 auto scope_check = watch2.stop;
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
326
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
327 watch2.start;
194
08f68d684047 Rename some files. Hopefully we can get a more iterative sema pass, that's a lot easier to "get startet with".
Anders Johnsen <skabet@gmail.com>
parents: 176
diff changeset
328 (new CheckTypes(messages)).visit(modules);
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
329 messages.checkErrors;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
330 auto type_check = watch2.stop;
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
331
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
332 watch2.start;
168
7982eb63c0eb Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
333 (new ObjectOriented(messages)).visit(modules);
7982eb63c0eb Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
334 messages.checkErrors;
7982eb63c0eb Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
335 auto object_check = watch2.stop;
7982eb63c0eb Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
336
7982eb63c0eb Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
337 watch2.start;
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
338 auto vc = new VC;
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
339 vc.msg = messages;
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
340 foreach (m; modules)
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
341 m.verify(vc);
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 106
diff changeset
342 messages.checkErrors;
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 136
diff changeset
343 auto ast_verify = watch2.stop;
101
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
344
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
345 foreach (m; modules)
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
346 foreach (decl; m.decls)
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
347 decl.simplify();
fea8d61a2451 First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
348
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
349 timings ~= Measurement("Total", total.stop);
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 114
diff changeset
350 postSema(modules, src_mgr);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
351
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
352 if (options.flag("time"))
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
353 foreach (m; timings)
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
354 Stderr.formatln("{,-45} {}ms", m.label, m.time*1e3);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
355 }
87
9a35a973175a Some improvements to the compiler program
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
356