mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
update generated type code and fix most link errors
This commit is contained in:
parent
d595a2fd61
commit
6756ade3bd
20
makefile
20
makefile
@ -31,13 +31,13 @@ stdcpp-sources = $(src)/stdc++.cpp
|
||||
stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src))
|
||||
stdcpp-cflags = $(fast) $(cflags)
|
||||
|
||||
type-headers = \
|
||||
$(bld)/type-header.h \
|
||||
$(bld)/type-declarations.h \
|
||||
$(bld)/type-constructors.h \
|
||||
$(bld)/type-primary-inits.h
|
||||
interpreter-headers = \
|
||||
$(type-headers) \
|
||||
generated-code = \
|
||||
$(bld)/type-declarations.cpp \
|
||||
$(bld)/type-members.cpp \
|
||||
$(bld)/type-constructors.cpp \
|
||||
$(bld)/type-initializations.cpp
|
||||
interpreter-depends = \
|
||||
$(generated-code) \
|
||||
$(src)/heap.h \
|
||||
$(src)/system.h
|
||||
interpreter-sources = \
|
||||
@ -114,8 +114,8 @@ clean:
|
||||
@echo "removing $(bld)"
|
||||
rm -r $(bld)
|
||||
|
||||
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.h:\1:')
|
||||
$(type-headers): %.h: $(src)/types.def $(generator-executable)
|
||||
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:')
|
||||
$(generated-code): %.cpp: $(src)/types.def $(generator-executable)
|
||||
@echo "generating $(@)"
|
||||
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
|
||||
|
||||
@ -123,7 +123,7 @@ $(bld)/vm.o \
|
||||
$(bld)/test-vm.o \
|
||||
$(bld)/stress-vm.o \
|
||||
$(bld)/fast-vm.o: \
|
||||
$(interpreter-headers)
|
||||
$(interpreter-depends)
|
||||
|
||||
$(bld)/type-generator.o: \
|
||||
$(generator-headers)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
namespace vm {
|
||||
|
||||
enum OpCode {
|
||||
aaload,
|
||||
aastore,
|
||||
@ -175,7 +177,7 @@ enum OpCode {
|
||||
new_,
|
||||
newarray,
|
||||
nop,
|
||||
pop_,
|
||||
pop,
|
||||
pop2,
|
||||
putfield,
|
||||
putstatic,
|
||||
@ -225,4 +227,6 @@ const unsigned ACC_TRANSIENT = 1 << 7;
|
||||
const unsigned ACC_INTERFACE = 1 << 9;
|
||||
const unsigned ACC_ABSTRACT = 1 << 10;
|
||||
|
||||
} // namespace vm
|
||||
|
||||
#endif//CONSTANTS_H
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef HEAP_H
|
||||
#define HEAP_H
|
||||
|
||||
namespace vm {
|
||||
|
||||
class Heap {
|
||||
public:
|
||||
enum CollectionType {
|
||||
@ -26,4 +28,6 @@ class Heap {
|
||||
virtual void mark(void** p);
|
||||
};
|
||||
|
||||
} // namespace vm
|
||||
|
||||
#endif//HEAP_H
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace vm {
|
||||
|
||||
class Stream {
|
||||
public:
|
||||
class Client {
|
||||
@ -75,4 +77,6 @@ class Stream {
|
||||
unsigned position;
|
||||
};
|
||||
|
||||
} // namespace vm
|
||||
|
||||
#endif//STREAM_H
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace vm {
|
||||
|
||||
class System {
|
||||
public:
|
||||
typedef int Status;
|
||||
@ -60,4 +62,6 @@ class System {
|
||||
virtual void abort() = 0;
|
||||
};
|
||||
|
||||
} // namespace vm
|
||||
|
||||
#endif//SYSTEM_H
|
||||
|
@ -1209,7 +1209,7 @@ writeConstructorInitializations(Output* out, Object* t)
|
||||
case Object::Scalar: {
|
||||
out->write(" ");
|
||||
writeAccessorName(out, m, true);
|
||||
out->write("(o) = ");
|
||||
out->write("(t, o) = ");
|
||||
out->write(obfuscate(memberName(m)));
|
||||
out->write(";\n");
|
||||
} break;
|
||||
@ -1250,39 +1250,6 @@ writeConstructorDeclarations(Output* out, Object* declarations)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
typeProtectedMemberCount(Object* o)
|
||||
{
|
||||
unsigned count = 0;
|
||||
for (MemberIterator it(o); it.hasMore();) {
|
||||
Object* m = it.next();
|
||||
if (m->type == Object::Scalar
|
||||
and equal(memberTypeName(m), "object"))
|
||||
{
|
||||
++ count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
writeProtected(Output* out, Object* o)
|
||||
{
|
||||
bool wrote = false;
|
||||
for (MemberIterator it(o); it.hasMore();) {
|
||||
Object* m = it.next();
|
||||
if (m->type == Object::Scalar
|
||||
and equal(memberTypeName(m), "object"))
|
||||
{
|
||||
if (wrote) {
|
||||
out->write(", ");
|
||||
}
|
||||
out->write(obfuscate(memberName(m)));
|
||||
wrote = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
writeConstructors(Output* out, Object* declarations)
|
||||
{
|
||||
@ -1301,20 +1268,22 @@ writeConstructors(Output* out, Object* declarations)
|
||||
|
||||
out->write(")\n{\n");
|
||||
|
||||
unsigned protectedCount = typeProtectedMemberCount(o);
|
||||
if (protectedCount) {
|
||||
out->write(" PROTECT");
|
||||
out->write(protectedCount);
|
||||
out->write("(");
|
||||
writeProtected(out, o);
|
||||
out->write(");\n");
|
||||
for (MemberIterator it(o); it.hasMore();) {
|
||||
Object* m = it.next();
|
||||
if (m->type == Object::Scalar
|
||||
and equal(memberTypeName(m), "object"))
|
||||
{
|
||||
out->write(" PROTECT(t, ");
|
||||
out->write(obfuscate(memberName(m)));
|
||||
out->write(");\n");
|
||||
}
|
||||
}
|
||||
|
||||
out->write(" object o = allocate(t, ");
|
||||
writeOffset(out, typeOffset(o), true);
|
||||
out->write(");\n");
|
||||
|
||||
out->write(" objectClass(o) = system->");
|
||||
out->write(" objectClass(o) = t->vm->");
|
||||
out->write(typeName(o));
|
||||
out->write("Class;\n");
|
||||
|
||||
@ -1329,7 +1298,7 @@ writeConstructors(Output* out, Object* declarations)
|
||||
}
|
||||
|
||||
void
|
||||
writeDeclarations(Output* out, Object* declarations)
|
||||
writeMembers(Output* out, Object* declarations)
|
||||
{
|
||||
for (Object* p = declarations; p; p = cdr(p)) {
|
||||
Object* o = car(p);
|
||||
@ -1446,7 +1415,7 @@ typeObjectMask(Object* type)
|
||||
}
|
||||
|
||||
void
|
||||
writePrimaryInitialization(Output* out, Object* type)
|
||||
writeInitialization(Output* out, Object* type)
|
||||
{
|
||||
unsigned memberCount = ::memberCount(type);
|
||||
if (memberCount == 0) return;
|
||||
@ -1456,34 +1425,32 @@ writePrimaryInitialization(Output* out, Object* type)
|
||||
if (typeObjectMask(type)) {
|
||||
out->write(" object mask = makeIntArray(t, 1);\n");
|
||||
|
||||
out->write(" objectMaskBody(mask)[0] = ");
|
||||
out->write(" intArrayBody(t, mask)[0] = ");
|
||||
out->write(typeObjectMask(type));
|
||||
out->write(";\n");
|
||||
} else {
|
||||
out->write(" object mask = 0;\n");
|
||||
}
|
||||
|
||||
out->write(" object ");
|
||||
out->write(" t->vm->");
|
||||
out->write(typeName(type));
|
||||
out->write("Class = makeClass");
|
||||
out->write("(t, ");
|
||||
out->write(capitalize(typeName(type)));
|
||||
out->write("Type, ");
|
||||
out->write("(t, 0, ");
|
||||
out->write(typeFixedSize(type));
|
||||
out->write(", ");
|
||||
out->write(typeArrayElementSize(type));
|
||||
out->write(", mask, 0, 0, 0, 0, 0);\n");
|
||||
out->write(", mask, 0, 0, 0, 0, 0, 0, 0, 0);\n");
|
||||
|
||||
out->write("}\n\n");
|
||||
}
|
||||
|
||||
void
|
||||
writePrimaryInitializations(Output* out, Object* declarations)
|
||||
writeInitializations(Output* out, Object* declarations)
|
||||
{
|
||||
for (Object* p = declarations; p; p = cdr(p)) {
|
||||
Object* o = car(p);
|
||||
if (o->type == Object::Type) {
|
||||
writePrimaryInitialization(out, o);
|
||||
writeInitialization(out, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1492,7 +1459,7 @@ void
|
||||
usageAndExit(const char* command)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s {header,declarations,constructors,primary-inits}\n",
|
||||
"usage: %s {declarations,members,constructors,initializations}\n",
|
||||
command);
|
||||
exit(-1);
|
||||
}
|
||||
@ -1504,10 +1471,10 @@ main(int ac, char** av)
|
||||
{
|
||||
if ((ac != 1 and ac != 2)
|
||||
or (ac == 2
|
||||
and not equal(av[1], "header")
|
||||
and not equal(av[1], "declarations")
|
||||
and not equal(av[1], "members")
|
||||
and not equal(av[1], "constructors")
|
||||
and not equal(av[1], "primary-inits")))
|
||||
and not equal(av[1], "initializations")))
|
||||
{
|
||||
usageAndExit(av[0]);
|
||||
}
|
||||
@ -1518,22 +1485,22 @@ main(int ac, char** av)
|
||||
|
||||
FileOutput out(0, stdout, false);
|
||||
|
||||
if (ac == 1 or equal(av[1], "header")) {
|
||||
if (ac == 1 or equal(av[1], "declarations")) {
|
||||
writePods(&out, declarations);
|
||||
writeAccessors(&out, declarations);
|
||||
writeConstructorDeclarations(&out, declarations);
|
||||
}
|
||||
|
||||
if (ac == 1 or equal(av[1], "declarations")) {
|
||||
writeDeclarations(&out, declarations);
|
||||
if (ac == 1 or equal(av[1], "members")) {
|
||||
writeMembers(&out, declarations);
|
||||
}
|
||||
|
||||
if (ac == 1 or equal(av[1], "constructors")) {
|
||||
writeConstructors(&out, declarations);
|
||||
}
|
||||
|
||||
if (ac == 1 or equal(av[1], "primary-inits")) {
|
||||
writePrimaryInitializations(&out, declarations);
|
||||
if (ac == 1 or equal(av[1], "initializations")) {
|
||||
writeInitializations(&out, declarations);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
31
src/vm.cpp
31
src/vm.cpp
@ -3,6 +3,7 @@
|
||||
#include "heap.h"
|
||||
#include "class_finder.h"
|
||||
#include "stream.h"
|
||||
#include "constants.h"
|
||||
|
||||
#define PROTECT(thread, name) \
|
||||
Thread::Protector MAKE_NAME(protector_) (thread, &name);
|
||||
@ -10,17 +11,25 @@
|
||||
#define ACQUIRE(t, x) MonitorResource MAKE_NAME(monitorResource_) (t, x)
|
||||
#define ACQUIRE_RAW(t, x) RawMonitorResource MAKE_NAME(monitorResource_) (t, x)
|
||||
|
||||
using namespace vm;
|
||||
|
||||
namespace {
|
||||
|
||||
typedef void* object;
|
||||
typedef unsigned Type;
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
class Thread;
|
||||
|
||||
void assert(Thread*, bool);
|
||||
object resolveClass(Thread*, object);
|
||||
object allocate(Thread* t, unsigned size);
|
||||
|
||||
inline unsigned
|
||||
pad(unsigned n)
|
||||
{
|
||||
unsigned extra = n % sizeof(void*);
|
||||
return (extra ? n + sizeof(void*) - extra : n);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T&
|
||||
@ -49,7 +58,7 @@ class Machine {
|
||||
System::Monitor* classLock;
|
||||
object classMap;
|
||||
|
||||
#include "type-declarations.h"
|
||||
#include "type-members.cpp"
|
||||
};
|
||||
|
||||
class Thread {
|
||||
@ -97,7 +106,8 @@ class Thread {
|
||||
Protector* protector;
|
||||
};
|
||||
|
||||
#include "type-header.h"
|
||||
#include "type-declarations.cpp"
|
||||
#include "type-constructors.cpp"
|
||||
|
||||
void enter(Thread* t, Thread::State state);
|
||||
|
||||
@ -171,10 +181,12 @@ dispose(Machine* m)
|
||||
void
|
||||
init(Thread* t, Machine* m)
|
||||
{
|
||||
memset(m, 0, sizeof(Thread));
|
||||
memset(t, 0, sizeof(Thread));
|
||||
t->vm = m;
|
||||
m->rootThread = t;
|
||||
t->state = Thread::NoState;
|
||||
|
||||
#include "type-initializations.cpp"
|
||||
}
|
||||
|
||||
void
|
||||
@ -993,8 +1005,9 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
|
||||
if (flags & ACC_STATIC) {
|
||||
fieldOffset(t, value) = staticOffset++;
|
||||
} else {
|
||||
if (memberOffset % sizeof(void*) and isReferenceField(t, value)) {
|
||||
while (memberOffset % sizeof(void*)) ++ memberOffset;
|
||||
unsigned excess = memberOffset % sizeof(void*);
|
||||
if (excess and isReferenceField(t, value)) {
|
||||
memberOffset += sizeof(void*) - excess;
|
||||
}
|
||||
|
||||
fieldOffset(t, value) = memberOffset;
|
||||
@ -2452,7 +2465,7 @@ run(Thread* t)
|
||||
push(t, arrayBody(t, codePool(t, code))[(index1 << 8) | index2]);
|
||||
} goto loop;
|
||||
|
||||
case ldiv: {
|
||||
case vm::ldiv: {
|
||||
object b = pop(t);
|
||||
object a = pop(t);
|
||||
|
||||
@ -2609,7 +2622,7 @@ run(Thread* t)
|
||||
|
||||
case nop: goto loop;
|
||||
|
||||
case pop_: {
|
||||
case vm::pop: {
|
||||
-- sp;
|
||||
} goto loop;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user