예제 #1
0
			internal Iterator(ObjToIntMap master)
			{
				// Map implementation via hashtable,
				// follows "The Art of Computer Programming" by Donald E. Knuth
				// ObjToIntMap is a copy cat of ObjToIntMap with API adjusted to object keys
				this.master = master;
			}
예제 #2
0
파일: Block.cs 프로젝트: hazzik/Rhino.Net
			private static Block[] ReduceToArray(ObjToIntMap map)
			{
				Block[] result = null;
				if (!map.IsEmpty())
				{
					result = new Block[map.Size()];
					int i = 0;
					ObjToIntMap.Iterator iter = map.NewIterator();
					for (iter.Start(); !iter.Done(); iter.Next())
					{
						Block.FatBlock fb = (Block.FatBlock)(iter.GetKey());
						result[i++] = fb.realBlock;
					}
				}
				return result;
			}
예제 #3
0
파일: Codegen.cs 프로젝트: hazzik/Rhino.Net
		private void InitScriptNodesData(ScriptNode scriptOrFn)
		{
			ObjArray x = new ObjArray();
			CollectScriptNodes_r(scriptOrFn, x);
			int count = x.Size();
			scriptOrFnNodes = new ScriptNode[count];
			x.ToArray(scriptOrFnNodes);
			scriptOrFnIndexes = new ObjToIntMap(count);
			for (int i = 0; i != count; ++i)
			{
				scriptOrFnIndexes.Put(scriptOrFnNodes[i], i);
			}
		}
예제 #4
0
		// The sole purpose of the method is to avoid accessing private fields
		// from the Iterator inner class to workaround JDK 1.1 compiler bug which
		// generates code triggering VerifierError on recent JVMs
		internal void InitIterator(ObjToIntMap.Iterator i)
		{
			i.Init(keys, values, keyCount);
		}
예제 #5
0
		/// <summary>Compile JavaScript source into one or more Java class files.</summary>
		/// <remarks>
		/// Compile JavaScript source into one or more Java class files.
		/// The first compiled class will have name mainClassName.
		/// If the results of
		/// <see cref="GetTargetExtends()">GetTargetExtends()</see>
		/// or
		/// <see cref="GetTargetImplements()">GetTargetImplements()</see>
		/// are not null, then the first compiled
		/// class will extend the specified super class and implement
		/// specified interfaces.
		/// </remarks>
		/// <returns>
		/// array where elements with even indexes specifies class name
		/// and the following odd index gives class file body as byte[]
		/// array. The initial element of the array always holds
		/// mainClassName and array[1] holds its byte code.
		/// </returns>
		public virtual object[] CompileToClassFiles(string source, string sourceLocation, int lineno, string mainClassName)
		{
			Parser p = new Parser(compilerEnv);
			AstRoot ast = p.Parse(source, sourceLocation, lineno);
			IRFactory irf = new IRFactory(compilerEnv);
			ScriptNode tree = irf.TransformTree(ast);
			// release reference to original parse tree & parser
			irf = null;
			ast = null;
			p = null;
			Type superClass = GetTargetExtends();
			Type[] interfaces = GetTargetImplements();
			string scriptClassName;
			bool isPrimary = (interfaces == null && superClass == null);
			if (isPrimary)
			{
				scriptClassName = mainClassName;
			}
			else
			{
				scriptClassName = MakeAuxiliaryClassName(mainClassName, "1");
			}
			Codegen codegen = new Codegen();
			codegen.SetMainMethodClass(mainMethodClassName);
			byte[] scriptClassBytes = codegen.CompileToClassFile(compilerEnv, scriptClassName, tree, tree.GetEncodedSource(), false);
			if (isPrimary)
			{
				return new object[] { scriptClassName, scriptClassBytes };
			}
			int functionCount = tree.GetFunctionCount();
			ObjToIntMap functionNames = new ObjToIntMap(functionCount);
			for (int i = 0; i != functionCount; ++i)
			{
				FunctionNode ofn = tree.GetFunctionNode(i);
				string name = ofn.GetName();
				if (name != null && name.Length != 0)
				{
					functionNames.Put(name, ofn.GetParamCount());
				}
			}
			if (superClass == null)
			{
				superClass = ScriptRuntime.ObjectClass;
			}
			byte[] mainClassBytes = JavaAdapter.CreateAdapterCode(functionNames, mainClassName, superClass, interfaces, scriptClassName);
			return new object[] { mainClassName, mainClassBytes, scriptClassName, scriptClassBytes };
		}