<commit_before>/**********************************************************************/
/* Copyright 2014 RCF                                                 */
/*                                                                    */
/* Licensed under the Apache License, Version 2.0 (the "License");    */
/* you may not use this file except in compliance with the License.   */
/* You may obtain a copy of the License at                            */
/*                                                                    */
/*     http://www.apache.org/licenses/LICENSE-2.0                     */
/*                                                                    */
/* Unless required by applicable law or agreed to in writing,         */
/* software distributed under the License is distributed on an        */
/* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,       */
/* either express or implied.                                         */
/* See the License for the specific language governing permissions    */
/* and limitations under the License.                                 */
/**********************************************************************/

#ifndef HPP_POSITRON_COMPILER_DEFINED
#define HPP_POSITRON_COMPILER_DEFINED

// Default libraries
#include <memory>

// Libraries
#include "Command.hpp"
#include "Desugar.hpp"
#include "Syntax_C.hpp"
#include "Syntax_S.hpp"
#include "Syntax2Asm.hpp"

namespace positron
{
    class Compiler
    {
        public:
            vm::Prog compile(const ExprC *root) const
            {
                Syntax2Asm visitor {};
                root->accept(visitor);
                vm::Prog prog { std::move(visitor.get()) };
                prog.push_back(vm::Command { vm::Command::Opcode::PRN });
                prog.push_back(vm::Command { vm::Command::Opcode::END });
                return prog;
            }
            
            vm::Prog compile(const ExprC& root) const
            {
                return compile(&root);
            }
            
            vm::Prog compile(const ExprS& root) const
            {
                return compile(&root);
            }
            
            vm::Prog compile(const ExprS *root) const
            {
                std::shared_ptr<ExprC> core { Desugar{}.desugar(root) };
                vm::Prog prog { compile(core.get()) };
                return prog;
            }
    };
}

#endif<commit_msg>Adding option to automatically compile from file<commit_after>/**********************************************************************/
/* Copyright 2014 RCF                                                 */
/*                                                                    */
/* Licensed under the Apache License, Version 2.0 (the "License");    */
/* you may not use this file except in compliance with the License.   */
/* You may obtain a copy of the License at                            */
/*                                                                    */
/*     http://www.apache.org/licenses/LICENSE-2.0                     */
/*                                                                    */
/* Unless required by applicable law or agreed to in writing,         */
/* software distributed under the License is distributed on an        */
/* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,       */
/* either express or implied.                                         */
/* See the License for the specific language governing permissions    */
/* and limitations under the License.                                 */
/**********************************************************************/

#ifndef HPP_POSITRON_COMPILER_DEFINED
#define HPP_POSITRON_COMPILER_DEFINED

// Default libraries
#include <memory>
#include <string>
#include <fstream>

// Libraries
#include "Parser.ih"
#include "Command.hpp"
#include "Desugar.hpp"
#include "Syntax_C.hpp"
#include "Syntax_S.hpp"
#include "Syntax2Asm.hpp"

namespace positron
{
    class Compiler
    {
        public:
            vm::Prog compile(std::string filename) const
            {
                std::ifstream file { filename };
                
                // TODO: Throw exception
                if(!file) return vm::Prog{};
                
                // Scan and parse file
                Parser parser { file };
                parser.parse();
                
                return compile(parser.get_tree());
            }
            
            vm::Prog compile(const ExprS *root) const
            {
                std::shared_ptr<ExprC> core { Desugar{}.desugar(root) };
                vm::Prog prog { compile(core.get()) };
                return prog;
            }
            
            vm::Prog compile(const ExprS& root) const
            {
                return compile(&root);
            }
            
            vm::Prog compile(const ExprC *root) const
            {
                Syntax2Asm visitor {};
                root->accept(visitor);
                vm::Prog prog { std::move(visitor.get()) };
                prog.push_back(vm::Command { vm::Command::Opcode::PRN });
                prog.push_back(vm::Command { vm::Command::Opcode::END });
                return prog;
            }
            
            vm::Prog compile(const ExprC& root) const
            {
                return compile(&root);
            }
    };
}

#endif
{'fraction_non_alphanumeric': 0.14586022496773005, 'fraction_numerical': 0.0036879955744053105, 'mean_word_length': 1.2992793556591775, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4599752', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1193, 'n_words': 336}