Always add a sign when spewing jump distances.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
22 #include "SemanticAnalysis.h"
24 #include "BytecodeCompiler.h"
26 #include "Interpreter.h"
56 Compile(const char *stream, size_t length)
58 if (!ZONE()->initialize())
61 Parser parser(stream, length);
62 ParseTree *tree = parser.parse();
67 if (!Scope::BindAndAllocate(tree))
70 SemanticAnalysis semantics(tree);
71 if (!semantics.analyze())
74 BytecodeCompiler compiler(tree);
75 Module *module = compiler.compile();
79 printf("\n ------------ \n\n");
81 Disassemble(module->getFunction(0), stdout);
82 //Disassemble(module->getFunction(1), stdout);
84 printf("\n ------------ \n\n");
86 Code *main = module->getFunction(0);
88 Top top = ZONE()->stack().begin();
89 LocalTop localTop(top);
91 Frame *frame = ZONE()->stack().pushFrame(NULL, main);
96 if (!Interpret(frame, &result))
99 printf("Result: %f\n", result.f);
104 int main(int argc, char **argv)
107 fprintf(stderr, "Usage: <file>\n");
111 AutoVec<char> bytes(NULL);
114 File fp = fopen(argv[1], "rb");
116 fprintf(stderr, "Can't open file: \"%s\"\n", argv[1]);
120 if (fseek(fp, 0, SEEK_END)) {
121 fprintf(stderr, "Error seeking file!\n");
124 long size = ftell(fp);
126 fprintf(stderr, "Error getting file length!\n");
130 length = size_t(size);
131 bytes = new char[length + 1];
132 if (fread(bytes, 1, length, fp) != length) {
133 fprintf(stderr, "Error reading file!\n");
138 Compile(bytes, length);