示例#1
0
 /// <summary>
 ///     <para>Load a value from the specified local variable.</para>
 /// </summary>
 /// <param name = "sym">The variable to load.</param>
 public void EmitLoadPValue(CilSymbol sym)
 {
     if (sym.Kind == SymbolKind.Local)
     {
         EmitLoadLocal(sym.Local);
     }
     else if (sym.Kind == SymbolKind.LocalRef)
     {
         EmitLoadLocal(sym.Local);
         Il.EmitCall(OpCodes.Call, Compiler.GetValueMethod, null);
     }
     else
     {
         throw new PrexoniteException("Cannot emit code for CilSymbol");
     }
 }
示例#2
0
文件: Compiler.cs 项目: SealedSun/prx
        private static void _buildSymbolTable(CompilerState state)
        {
            //Create local ref variables for shared names
            //  and populate them with the contents of the sharedVariables parameter
            if (state.Source.Meta.ContainsKey(PFunction.SharedNamesKey))
            {
                var sharedNames = state.Source.Meta[PFunction.SharedNamesKey].List;
                for (var i = 0; i < sharedNames.Length; i++)
                {
                    if (state.Source.Variables.Contains(sharedNames[i]))
                        continue; //Arguments are redeclarations.
                    var sym = new CilSymbol(SymbolKind.LocalRef)
                        {
                            Local = state.Il.DeclareLocal(typeof (PVariable))
                        };
                    var id = sharedNames[i].Text;

                    state.EmitLoadArg(CompilerState.ParamSharedVariablesIndex);
                    state.Il.Emit(OpCodes.Ldc_I4, i);
                    state.Il.Emit(OpCodes.Ldelem_Ref);
                    state.EmitStoreLocal(sym.Local.LocalIndex);

                    state.Symbols.Add(id, sym);
                }
            }

            //Create index -> id map
            foreach (var mapping in state.Source.LocalVariableMapping)
                state.IndexMap.Add(mapping.Value, mapping.Key);

            //Add entries for paramters
            foreach (var parameter in state.Source.Parameters)
                if (!state.Symbols.ContainsKey(parameter))
                    state.Symbols.Add(parameter, new CilSymbol(SymbolKind.Local));

            //Add entries for enumerator variables
            foreach (var hint in state._ForeachHints)
            {
                if (state.Symbols.ContainsKey(hint.EnumVar))
                    throw new PrexoniteException(
                        "Invalid foreach hint. Enumerator variable is shared.");
                state.Symbols.Add(hint.EnumVar, new CilSymbol(SymbolKind.LocalEnum));
            }

            //Add entries for non-shared local variables
            foreach (var variable in state.Source.Variables)
                if (!state.Symbols.ContainsKey(variable))
                    state.Symbols.Add(variable, new CilSymbol(SymbolKind.Local));
        }