コード例 #1
0
        public override void Generate(ILProcessor il, SemanticEnvironment environment)
        {
            var list = new ExpList();

            if (ExpList is ExpList expList)
            {
                list = expList;
            }

            foreach (var node in list.Nodes)
            {
                node.Generate(il, environment);
            }

            PostfixNode.Generate(il, environment);

            if (PostfixNode is Id id) // Push null to stack if function return void.
            {
                var type = (environment.GetSymbol(id.IdName) as FuncSymbol).Type as FuncType;
                if (type.ReturnType.SymbolTypeKind == SymbolTypeKind.VOID)
                {
                    il.Emit(OpCodes.Ldnull);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #2
0
        public override void Generate(ILProcessor il, SemanticEnvironment environment)
        {
            var symbol = environment.GetSymbol(IdName);

            switch (symbol)
            {
            case VarSymbol varSymbol:
                switch (varSymbol.VariableType)
                {
                case VarSymbol.VarType.VARIABLE:
                    il.Emit(OpCodes.Ldloc, varSymbol.VariableDefinition);
                    break;

                case VarSymbol.VarType.PARAMETER:
                    il.Emit(OpCodes.Ldarg, varSymbol.ParameterDefinition);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case FuncSymbol funcSymbol:
                il.Emit(OpCodes.Call, funcSymbol.Definition);
                break;
            }
        }