Re-add LIFO stack optimizations.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
22 #include "../include/keima.h"
26 class MessageReporter : public IMessageReporter
29 void onOutOfMemory() {
30 fprintf(stderr, "Out of memory!\n");
32 void onUncaughtException(const char *message) {
33 fprintf(stderr, "Uncaught exception: %s\n", message);
35 IStackFrameIterator *iter = Keima::NewStackFrameIterator();
37 while (!iter->done() && index < 10) {
38 fprintf(stderr, "[%d] %s (%s line %d)\n",
47 virtual void beginCompilationErrors(const char *file) {
48 fprintf(stderr, "\nDisplaying compilation errors for \"%s\"\n", file);
50 virtual void reportCompilationError(const char *message, unsigned line, unsigned col) {
51 fprintf(stderr, " line %d, col %d: %s\n", line, col, message);
53 virtual void endCompilationErrors() {
57 class MainCollector : public Ke::IPublicFunctionListener
63 void registerPublic(Handle<Function> fun) {
64 Local<String> str = fun->name();
65 if (str && strcmp(str->chars(), "main") == 0)
69 void unregisterPublic(Handle<Function> fun) {
71 fun_ = Handle<Function>();
74 Handle<Function> fun() const {
82 intptr_t PrintFloat(void *blah, intptr_t *params)
84 fprintf(stdout, "%f", *reinterpret_cast<float *>(¶ms[1]));
88 intptr_t PrintNum(void *blah, intptr_t *params)
90 fprintf(stdout, "%i", *reinterpret_cast<int *>(¶ms[1]));
94 intptr_t PrintString(void *blah, intptr_t *params)
96 fprintf(stdout, "%s", *reinterpret_cast<const char **>(¶ms[1]));
100 int main(int argc, char **argv)
103 fprintf(stderr, "Usage: <file>\n");
107 if (!Keima::Initialize())
112 Keima::InstallMessageReporter(&s_Reporter);
115 Keima::SetPublicFunctionListener(&entry);
120 Keima::CollectGarbage();
122 Keima::BindNative("PrintFloat", (void *)PrintFloat);
123 Keima::BindNative("PrintNum", (void *)PrintNum);
124 Keima::BindNative("PrintString", (void *)PrintString);
126 Handle<Function> fun = entry.fun();
129 fprintf(stdout, "Not running; no public 'main'.\n");
131 if (!Keima::Invoke(fun, NULL, 0, true, &rval))
141 /* Overload a few things to prevent libstdc++ linking */
142 #if defined __linux__ || defined __APPLE__
143 extern "C" void __cxa_pure_virtual(void)
147 void *operator new(size_t size)
152 void *operator new[](size_t size)
157 void operator delete(void *ptr)
162 void operator delete[](void * ptr)