Add support for array reference semantics.
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 intptr_t PrintFloat(void *blah, intptr_t *params)
59 fprintf(stdout, "%f", *reinterpret_cast<float *>(¶ms[1]));
63 intptr_t PrintNum(void *blah, intptr_t *params)
65 fprintf(stdout, "%i", *reinterpret_cast<int *>(¶ms[1]));
69 intptr_t PrintString(void *blah, intptr_t *params)
71 fprintf(stdout, "%s", *reinterpret_cast<const char **>(¶ms[1]));
75 int main(int argc, char **argv)
78 fprintf(stderr, "Usage: <file>\n");
82 if (!Keima::Initialize())
87 Keima::InstallMessageReporter(&s_Reporter);
90 Local<Module> module = Compile(argv[1]);
94 Keima::CollectGarbage();
96 // Look for a public named "main".
98 for (unsigned i = 0; i < module->numPublics(); i++) {
99 if (strcmp(module->getPublic(i)->name()->chars(), "main") == 0) {
100 fun = module->getPublic(i);
105 for (unsigned i = 0; i < module->numNatives(); i++) {
106 Local<Native> native = module->getNative(i);
108 if (strcmp(native->name()->chars(), "PrintFloat") == 0)
109 native->bind(reinterpret_cast<void *>(PrintFloat));
110 else if (strcmp(native->name()->chars(), "PrintNum") == 0)
111 native->bind(reinterpret_cast<void *>(PrintNum));
112 else if (strcmp(native->name()->chars(), "PrintString") == 0)
113 native->bind(reinterpret_cast<void *>(PrintString));
118 fprintf(stdout, "Plugin compiles!\nNot running; no public 'main'.\n");
120 if (!Keima::Invoke(fun, NULL, 0, true, &rval))
130 /* Overload a few things to prevent libstdc++ linking */
131 #if defined __linux__ || defined __APPLE__
132 extern "C" void __cxa_pure_virtual(void)
136 void *operator new(size_t size)
141 void *operator new[](size_t size)
146 void operator delete(void *ptr)
151 void operator delete[](void * ptr)