private JavaTypeDescriptor arrayOfType(Class type) { if (type.isArray()) { return new ArrayDescriptorImpl( buildName("[" + type.getName()), type.getModifiers(), arrayOfType(type.getComponentType())); } if (type.isPrimitive()) { return Primitives.primitiveArrayDescriptor(type); } else { return new ArrayDescriptorImpl( buildName("[" + type.getName()), type.getModifiers(), getType(buildName(type.getName()))); } }
public Car() { /** * The car's "body" is this instance itself. That may seem a bit strange at first glance, but * it's quite convenient in this case. */ super(Primitives.getBox(8, 0.25f)); rightFront = Primitives.getSphere(5, 4); leftFront = Primitives.getSphere(5, 4); rightRear = Primitives.getSphere(5, 4); leftRear = Primitives.getSphere(5, 4); /** The wheels are parts, i.e. children of the car */ addChild(rightFront); addChild(leftFront); addChild(rightRear); addChild(leftRear); /** Initialize the car and the wheels */ setTexture("car"); rightFront.setTexture("car"); leftFront.setTexture("car"); rightRear.setTexture("car"); leftRear.setTexture("car"); setEnvmapped(Object3D.ENVMAP_ENABLED); rightFront.setEnvmapped(Object3D.ENVMAP_ENABLED); leftFront.setEnvmapped(Object3D.ENVMAP_ENABLED); rightRear.setEnvmapped(Object3D.ENVMAP_ENABLED); leftRear.setEnvmapped(Object3D.ENVMAP_ENABLED); /** We need to offset the wheels a little... */ rightFront.translate(new SimpleVector(-8, 4, 8)); rightRear.translate(new SimpleVector(-8, 4, -8)); leftFront.translate(new SimpleVector(8, 4, 8)); leftRear.translate(new SimpleVector(8, 4, -8)); rightFront.translateMesh(); rightRear.translateMesh(); leftFront.translateMesh(); leftRear.translateMesh(); rightFront.setTranslationMatrix(new Matrix()); rightRear.setTranslationMatrix(new Matrix()); leftFront.setTranslationMatrix(new Matrix()); leftRear.setTranslationMatrix(new Matrix()); /** ...the wheels are now in place. We can now build the car. */ build(); rightRear.build(); rightFront.build(); leftRear.build(); leftFront.build(); }
@Override public long hashInt(int input) { input = NATIVE_CITY.toLittleEndian(input); long unsignedInt = Primitives.unsignedInt(input); long hash = hash4To7Bytes(4L, unsignedInt, unsignedInt); return finalizeHash(hash); }
static { // static initializer that creates a mesh blueprint and loads the // textures. try { SimpleStream ss = new SimpleStream("data/weapon.jpg"); TextureManager.getInstance().addTexture("weapon", new Texture(ss.getStream())); ss.close(); ss = new SimpleStream("data/snork.md2"); bluePrint = new ClientObject(Loader.loadMD2(ss.getStream(), 0.22f)); // 0.32f bluePrint.translate(0, 4.5f, 0); bluePrint.translateMesh(); bluePrint.getTranslationMatrix().setIdentity(); bluePrint.translate(100000, 100000, 100000); sphereBluePrint = Primitives.getSphere(9, 6); sphereBluePrint.build(); sphereBluePrint.setTexture("shield"); sphereBluePrint.calcTextureWrapSpherical(); ss.close(); } catch (Exception e) { e.printStackTrace(); } }
private <T> long hashLen0To16(ReadAccess<T> access, T in, long off, long len) { if (len >= 8L) { long a = fetch64(access, in, off); long b = fetch64(access, in, off + len - 8L); return hash8To16Bytes(len, a, b); } else if (len >= 4L) { long a = Primitives.unsignedInt(fetch32(access, in, off)); long b = Primitives.unsignedInt(fetch32(access, in, off + len - 4L)); return hash4To7Bytes(len, a, b); } else if (len > 0L) { int a = access.readUnsignedByte(in, off); int b = access.readUnsignedByte(in, off + (len >> 1)); int c = access.readUnsignedByte(in, off + len - 1L); return hash1To3Bytes((int) len, a, b, c); } return K2; }
private void set(Map<LWord, LAtom> bindings, LWord name, LAtom value) { if (bindings.containsKey(name) && bindings.get(name) instanceof LList) { if (Primitives.prim((LList) bindings.get(name))) { throw new RuntimeError(this, RuntimeError.Type.MutatePrimitive, name.value); } } bindings.put(name, value); }
/** Collect a callstack trace. */ public List<LAtom> trace() { List<LAtom> ret = new ArrayList<LAtom>(); for (int z = scopes.size() - 1; z >= 0; z--) { if (scopes.get(z).procedure && !Primitives.prim(scopes.get(z).code)) { ret.add(getName(scopes.get(z).code)); } } return ret; }
void call(LWord name) { for (int z = scopes.size() - 1; z >= 0; z--) { if (scopes.get(z).bindings.containsKey(name)) { LList code = Primitives.list(this, scopes.get(z).bindings.get(name)); scopes.peek().trace.push(new Func(this, code)); return; } } throw new RuntimeError(this, RuntimeError.Type.UndefinedProcedure, name.value); }
@Override public JavaTypeDescriptor getType(Name typeName) { if (typeName == null) { return null; } final String typeNameString = typeName.fullName(); if ("void".equals(typeNameString)) { return VoidDescriptor.INSTANCE; } JavaTypeDescriptor descriptor = typeDescriptorMap.get(typeName); if (descriptor == null) { descriptor = Primitives.resolveByName(typeName); } if (descriptor == null) { descriptor = makeTypeDescriptor(typeName); typeDescriptorMap.put(typeName, descriptor); } return descriptor; }
private boolean isPrimitiveOrString(Object objectToVisit) { Class<?> realClazz = objectToVisit.getClass(); return realClazz == Object.class || realClazz == String.class || Primitives.unwrap(realClazz).isPrimitive(); }
@Override public long hashByte(byte input) { int unsignedByte = Primitives.unsignedByte(input); long hash = hash1To3Bytes(1, unsignedByte, unsignedByte, unsignedByte); return finalizeHash(hash); }
@Override public Object execute(Frame frame) { RAny lhsVal = (RAny) lhs.execute(frame); Object rowFromVal = rowFromExpr.execute(frame); Object rowToVal = rowToExpr.execute(frame); Object colFromVal = colFromExpr.execute(frame); Object colToVal = colToExpr.execute(frame); boolean dropVal = dropExpr.executeLogical(frame) != RLogical.FALSE; // FIXME: what is the correct execution order of these args? int exactVal = exactExpr.executeLogical(frame); if (!(lhsVal instanceof RArray)) { throw RError.getObjectNotSubsettable(ast, lhsVal.typeOf()); } RArray array = (RArray) lhsVal; try { int rowFrom = extractLimit(rowFromVal); // zero-based int rowTo = extractLimit(rowToVal); int colFrom = extractLimit(colFromVal); int colTo = extractLimit(colToVal); int[] dim = array.dimensions(); if (dim == null || dim.length != 2) { throw RError.getIncorrectDimensions(getAST()); } int m = dim[0]; int n = dim[1]; int rowStep; int rowSize; if (rowFrom <= rowTo) { rowStep = 1; if (rowTo > m) { throw new UnexpectedResultException(null); } rowSize = rowTo - rowFrom + 1; } else { rowStep = -1; if (rowFrom > m) { throw new UnexpectedResultException(null); } rowSize = rowFrom - rowTo + 1; } int colStep; int colSize; if (colFrom <= colTo) { colStep = 1; if (colTo > n) { throw new UnexpectedResultException(null); } colSize = colTo - colFrom + 1; } else { colStep = -1; if (colFrom > n) { throw new UnexpectedResultException(null); } colSize = colFrom - colTo + 1; } int[] ndim; if (!dropVal || (rowSize > 1 && colSize > 1)) { ndim = new int[] {rowSize, colSize}; } else { ndim = null; } int size = rowSize * colSize; RArray res = Utils.createArray(array, size, ndim, null, null); // drop attributes if (colStep == 1 && rowStep == 1) { int j = colFrom * m + rowFrom; // j - index to source matrix int jmax = j + rowSize; int jadvance = m - rowSize; for (int i = 0; i < size; i++) { res.set(i, array.getRef(j++)); // i - index to target matrix if (j == jmax) { j += jadvance; jmax += m; } } } else { int i = 0; // NOTE: here we know that colFrom != colTo and rowFrom != rowTo for (int col = colFrom; col != colTo + colStep; col += colStep) { for (int row = rowFrom; row != rowTo + rowStep; row += rowStep) { res.set(i++, array.getRef(col * m + row)); } } } return res; } catch (UnexpectedResultException e) { // FIXME: clean this up; does Colon need to be package-private? ASTNode rowAST = rowFromExpr.getAST().getParent(); Builtin rowColon = (Builtin) Primitives.getCallFactory(RSymbol.getSymbol(":"), null) .create(rowAST, rowFromExpr, rowToExpr); SelectorNode selIExpr = Selector.createSelectorNode(rowAST, true, rowColon); ASTNode colAST = colFromExpr.getAST().getParent(); Builtin colColon = (Builtin) Primitives.getCallFactory(RSymbol.getSymbol(":"), null) .create(colAST, colFromExpr, colToExpr); SelectorNode selJExpr = Selector.createSelectorNode(ast, true, colColon); MatrixRead nn = new MatrixRead(ast, true, lhs, selIExpr, selJExpr, dropExpr, exactExpr); replace(nn, "install MatrixRead from MatrixSequenceSubset"); Selector selI = selIExpr.executeSelector( rowColon.doBuiltIn(frame, new RAny[] {(RAny) rowFromVal, (RAny) rowToVal})); Selector selJ = selJExpr.executeSelector( colColon.doBuiltIn(frame, new RAny[] {(RAny) colFromVal, (RAny) colToVal})); return nn.executeLoop(array, selI, selJ, dropVal, exactVal); } }
@Test public void primitives() { Primitives primitives = context.lookup(Primitives.class); primitives.f(false, (byte) 0, '\0', (short) 0, 0, 0L, 0f, 0d); }
private static boolean isAssignableByBoxing(@NotNull Class<?> target, @NotNull Class<?> source) { return Primitives.wrap(target).isAssignableFrom(Primitives.wrap(source)); }