]> git.localhorst.tv Git - l2e.git/blobdiff - src/main.cpp
new language, new compiler
[l2e.git] / src / main.cpp
index f0811de23ede1282543681de19c6996aff6223f2..8fa276ce73f07566b182b465b2457aea7af4580c 100644 (file)
@@ -19,8 +19,6 @@
 #include "common/Script.h"
 #include "common/Spell.h"
 #include "common/Stats.h"
-#include "math/Fixed.h"
-#include "math/Vector.h"
 #include "graphics/CharSelect.h"
 #include "graphics/ComplexAnimation.h"
 #include "graphics/Font.h"
@@ -31,7 +29,9 @@
 #include "graphics/Sprite.h"
 #include "graphics/Texture.h"
 #include "loader/Caster.h"
+#include "loader/Compiler.h"
 #include "loader/Interpreter.h"
+#include "loader/Loader.h"
 #include "loader/ParsedSource.h"
 #include "loader/Parser.h"
 #include "loader/TypeDescription.h"
@@ -41,6 +41,8 @@
 #include "map/MapState.h"
 #include "map/Tile.h"
 #include "map/Trigger.h"
+#include "math/Fixed.h"
+#include "math/Vector.h"
 #include "menu/Resources.h"
 #include "sdl/InitImage.h"
 #include "sdl/InitScreen.h"
@@ -66,16 +68,18 @@ using common::GameConfig;
 using common::GameState;
 using common::Hero;
 using common::Spell;
-using math::Fixed;
-using math::Vector;
 using graphics::Texture;
 using loader::Caster;
+using loader::Compiler;
 using loader::Interpreter;
+using loader::Loader;
 using loader::ParsedSource;
 using loader::Parser;
 using loader::TypeDescription;
 using map::Entity;
 using map::MapState;
+using math::Fixed;
+using math::Vector;
 using sdl::InitImage;
 using sdl::InitScreen;
 using sdl::InitSDL;
@@ -91,7 +95,7 @@ int main(int argc, char **argv) {
        const int width = 512;
        const int height = 448;
 
-       const Fixed<8> walkSpeed = Fixed<8>(1, 8);
+       const int walkSpeed = 8;
 
        bool battle(false);
 
@@ -140,10 +144,25 @@ int main(int argc, char **argv) {
 
                ParsedSource source;
 
+               Loader ld;
+
                for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
-                       Parser(*i, source).Parse();
+                       string filePath(*i);
+                       switch (filePath[filePath.size() - 1]) {
+                               case 'o':
+                                       ld.Load(filePath);
+                                       break;
+                               case 's':
+                                       Parser(filePath, source).Parse();
+                                       break;
+                               default:
+                                       throw std::runtime_error("don't know what to do with " + filePath);
+                       }
                }
 
+               Interpreter intp(source);
+               intp.ReadSource();
+
                switch (args.GetRunLevel()) {
                        case Arguments::WRITE:
                        {
@@ -154,6 +173,15 @@ int main(int argc, char **argv) {
                                                source.WriteHeader(outstream);
                                                break;
                                        }
+                                       case 'o': {
+                                               std::fstream outstream(args.OutfilePath(), std::ios_base::out|std::ios_base::trunc);
+                                               outstream.flush();
+                                               outstream.close();
+                                               outstream.open(args.OutfilePath());
+                                               outstream.exceptions(std::ios_base::badbit|std::ios_base::failbit);
+                                               Compiler(intp).Write(outstream);
+                                               break;
+                                       }
                                        default: {
                                                throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
                                        }
@@ -161,7 +189,7 @@ int main(int argc, char **argv) {
                                return 0;
                        }
                        case Arguments::DUMP: {
-                               std::cout << source << std::endl;
+                               std::cout << source << ld << std::endl;
                                return 0;
                        }
                        case Arguments::SOURCE_WIKI: {
@@ -176,9 +204,6 @@ int main(int argc, char **argv) {
                                break;
                }
 
-               Interpreter intp(source);
-               intp.ReadSource();
-
                if (intp.PostponedDefinitions().size() > 0) {
                        for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
                                std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;
@@ -186,7 +211,7 @@ int main(int argc, char **argv) {
                        return 3;
                }
 
-               Caster caster(intp);
+               Caster caster(ld, intp);
 
                GameState gameState;