コード例 #1
0
ファイル: Parser.cs プロジェクト: treert/SimpleScript
        AsyncCall ParseAsyncStatement()
        {
            NextToken();
            var statement = new AsyncCall(_current.m_line);

            if (LookAhead().m_type == (int)TokenType.DO)
            {
                var func = new FunctionBody(_current.m_line);
                NextToken();
                func.block = ParseBlock();
                if (NextToken().m_type != (int)TokenType.END)
                {
                    throw NewParserException("expect 'end' after async function-body", _current);
                }
                statement.caller = func;
            }
            else
            {
                var tmp_token = LookAhead();
                // must be funccall
                SyntaxTree tmp = ParseOtherStatement();
                if (tmp is FuncCall)
                {
                    var t = tmp as FuncCall;
                    statement.caller = t.caller;
                    statement.args   = t.args;
                }
                else
                {
                    throw NewParserException("expect 'func call' after async", tmp_token);
                }
            }
            return(statement);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: treert/SimpleScript
        FunctionBody ParseFunctionBody()
        {
            if (NextToken().m_type != (int)'(')
            {
                throw NewParserException("expect '(' to start function-body", _current);
            }
            var statement = new FunctionBody(_current.m_line);

            statement.param_list = ParseParamList();
            if (NextToken().m_type != (int)')')
            {
                throw NewParserException("expect ')' after param-list", _current);
            }
            statement.block = ParseBlock();
            if (NextToken().m_type != (int)TokenType.END)
            {
                throw NewParserException("expect 'end' after function-body", _current);
            }

            return(statement);
        }
コード例 #3
0
ファイル: CodeGenerate.cs プロジェクト: treert/SimpleScript
        void HandleFunctionBody(FunctionBody tree, string define_name)
        {
            EnterFunction(tree.line, define_name);
            var func_index = GetFunctionIndex();

            {
                EnterBlock();
                if (tree.param_list != null)
                {
                    HandleParamList(tree.param_list);
                }
                HandleBlock(tree.block);
                LeaveBlock();
            }
            LeaveFunction();

            var f        = GetCurrentFunction();
            int register = GenerateRegisterId();
            var code     = Instruction.ABx(OpType.OpType_Closure, register, func_index);

            f.AddInstruction(code, tree.line);
            ResetRegisterId(register);
        }