Sha256: c366132ec7186213dde0f70574501470408d60b7789b02b858a2f29b400600d1
Contents?: true
Size: 1.3 KB
Versions: 12
Compression:
Stored size: 1.3 KB
Contents
package org.cx4a.rsense.typing.runtime; import java.util.Map; import java.util.HashMap; import org.cx4a.rsense.ruby.Ruby; import org.cx4a.rsense.ruby.RubyClass; import org.cx4a.rsense.ruby.RubyObject; import org.cx4a.rsense.ruby.IRubyObject; import org.cx4a.rsense.typing.annotation.ClassType; public class ObjectAllocator implements Ruby.ObjectAllocator { private Map<RubyClass, IRubyObject> instances; public ObjectAllocator() { instances = new HashMap<RubyClass, IRubyObject>(); } public IRubyObject allocate(Ruby runtime, RubyClass klass) { ClassType classType = RuntimeHelper.getClassAnnotation(klass); if (classType != null && classType.isPolymorphic()) { return newPolymorphicInstance(runtime, klass, classType); } else { return newMonomorphicInstance(runtime, klass); } } public IRubyObject newPolymorphicInstance(Ruby runtime, RubyClass klass, ClassType type) { return new PolymorphicObject(runtime, klass); } public IRubyObject newMonomorphicInstance(Ruby runtime, RubyClass klass) { IRubyObject instance = instances.get(klass); if (instance == null) { instance = new RubyObject(runtime, klass); instances.put(klass, instance); } return instance; } }
Version data entries
12 entries across 12 versions & 1 rubygems