]> git.leonardobizzoni.com Git - LBPL/commitdiff
Merged `/lib` and `/src`
authorLeonardoBizzoni <leo2002714@gmail.com>
Mon, 2 Sep 2024 15:16:27 +0000 (17:16 +0200)
committerLeonardoBizzoni <leo2002714@gmail.com>
Mon, 2 Sep 2024 15:16:27 +0000 (17:16 +0200)
38 files changed:
CMakeLists.txt
lib/runtime_error.h [deleted file]
main.lbpl [new file with mode: 0644]
shell.nix [new file with mode: 0644]
src/LBPLCallable.hpp [moved from lib/LBPLCallable.h with 89% similarity]
src/LBPLClass.cpp
src/LBPLClass.hpp [moved from lib/LBPLClass.h with 92% similarity]
src/LBPLFunction.cpp
src/LBPLFunction.hpp [moved from lib/LBPLFunction.h with 90% similarity]
src/LBPLInstance.cpp
src/LBPLInstance.hpp [moved from lib/LBPLInstance.h with 86% similarity]
src/LBPLTypes.hpp [moved from lib/LBPLTypes.h with 100% similarity]
src/ast_printer.cpp
src/ast_printer.hpp [moved from lib/ast_printer.h with 96% similarity]
src/builtin_methods.hpp [moved from lib/builtin_methods.h with 96% similarity]
src/common.hpp [moved from lib/common.h with 63% similarity]
src/environment.cpp
src/environment.hpp [moved from lib/environment.h with 92% similarity]
src/expressions.hpp [moved from lib/expressions.h with 96% similarity]
src/interpreter.cpp
src/interpreter.hpp [moved from lib/interpreter.h with 95% similarity]
src/lexer.cpp
src/lexer.hpp [moved from lib/lexer.h with 88% similarity]
src/main.cpp
src/main.hpp [moved from lib/main.h with 100% similarity]
src/parser.cpp
src/parser.hpp [moved from lib/parser.h with 95% similarity]
src/resolver.cpp
src/resolver.hpp [moved from lib/resolver.h with 94% similarity]
src/runtime_error.cpp
src/runtime_error.hpp [new file with mode: 0644]
src/statements.hpp [moved from lib/statements.h with 82% similarity]
src/syntax_error.cpp
src/syntax_error.hpp [moved from lib/syntax_error.h with 56% similarity]
src/token.hpp [moved from lib/token.h with 93% similarity]
src/token_type.hpp [moved from lib/token_type.h with 100% similarity]
src/tree_nodes.hpp [moved from lib/tree_nodes.h with 100% similarity]
src/visitor.hpp [moved from lib/visitor.h with 95% similarity]

index b93afa33c9269109fa6e47d4a06c3b661f1f7099..d53e11553a02107cc92cb6c87af1116fef0bfbf1 100755 (executable)
@@ -1,14 +1,38 @@
-cmake_minimum_required (VERSION 3.26.4)
-
-add_compile_options(-O2)
+cmake_minimum_required(VERSION 3.29)
+project(lbpl CXX)
 
+# Set C++ standard
 set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_EXTENSIONS OFF)
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-project (lbpl VERSION 0.1.0)
 
-include_directories(lib)
+if(NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE "Debug")
+endif()
+
+# Set output directories
+set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
+
+file(GLOB_RECURSE SRC "src/*.cpp" "src/*.hpp")
+add_executable(${PROJECT_NAME} ${SRC})
+
+set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
+target_compile_definitions(${PROJECT_NAME} PRIVATE ROOTDIR="${CMAKE_SOURCE_DIR}")
+
+# Set output directories
+set_target_properties(${PROJECT_NAME} PROPERTIES
+                      RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}"
+                      ARCHITE_OUTPUT_DIRECTORY "${OUTPUT_DIR}"
+                      LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}")
+
+# Configuration-specific settings
+target_compile_definitions(${PROJECT_NAME} PRIVATE
+    $<$<CONFIG:Debug>:DEBUG>
+    $<$<CONFIG:OptimizedDebug>:OPTDEBUG>
+    $<$<CONFIG:Release>:RELEASE>)
 
-file(GLOB SRCFILES src/*.cpp)
-add_executable(${PROJECT_NAME} ${SRCFILES})
+# Configuration-specific optimizations
+target_compile_options(${PROJECT_NAME} PRIVATE
+    $<$<CONFIG:Debug>:-g>
+    $<$<CONFIG:OptimizedDebug>:-O3>
+    $<$<CONFIG:Release>:-O3>)
diff --git a/lib/runtime_error.h b/lib/runtime_error.h
deleted file mode 100644 (file)
index 1d791de..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef RUNTIME_ERROR_H
-#define RUNTIME_ERROR_H
-
-#include "token.h"
-#include "expressions.h"
-#include "statements.h"
-
-#include <string>
-#include <optional>
-#include <iomanip>
-#include <sstream>
-
-struct RuntimeError {
-public:
-  int line;
-  int column;
-  std::string filename;
-  std::string msg;
-
-public:
-  RuntimeError(const Token *errToken, const std::string &msg)
-      : line(errToken->line), column(errToken->column), filename(errToken->filename), msg(msg) {}
-
-  RuntimeError(Expr *errToken, const std::string &msg)
-      : line(errToken->line), column(errToken->column), filename(errToken->file), msg(msg) {}
-
-  RuntimeError(Stmt *errToken, const std::string &msg)
-      : line(errToken->line), column(errToken->column), filename(errToken->filename), msg(msg) {}
-
-  std::string what();
-};
-
-#endif
diff --git a/main.lbpl b/main.lbpl
new file mode 100644 (file)
index 0000000..d182846
--- /dev/null
+++ b/main.lbpl
@@ -0,0 +1,37 @@
+fn fib(n) {
+   return fibIter(n, 0, 1);
+}
+
+fn fibIter(n, curr, next) {
+   if (n == 0) {
+      return curr;
+   } else if (n == 1) {
+     return next;
+   } else {
+     return fibIter(n - 1, next, curr + next);
+   }
+}
+
+class Prova {
+    init(n) {
+        this.n = n;
+        this.start = clock();
+        this.fib_n = fib(n);
+        this.end = clock();
+    }
+
+    runtime() {
+        println("fib("+ this.n +") = " +
+               this.fib_n +
+                " runtime: " +
+                (this.end - this.start));
+    }
+}
+
+let a = Prova(25);
+a.var1 = 10;
+println(a.var1);
+a.var1 = 210;
+println(a.var1);
+
+a.runtime();
\ No newline at end of file
diff --git a/shell.nix b/shell.nix
new file mode 100644 (file)
index 0000000..fe2e96d
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,20 @@
+{ pkgs ? import <nixpkgs> { } }:
+
+pkgs.mkShell {
+  nativeBuildInputs = with pkgs; [
+    man-pages
+    man-pages-posix
+
+    gnumake
+    cmake
+    seer
+    clang-tools
+    cmake-language-server
+    tree-sitter-grammars.tree-sitter-cpp
+    tree-sitter-grammars.tree-sitter-c
+  ];
+
+  shellHook = ''
+    ${pkgs.onefetch}/bin/onefetch
+  '';
+}
similarity index 89%
rename from lib/LBPLCallable.h
rename to src/LBPLCallable.hpp
index eb2b0560e0fc6cca38572cec559b4fd7f21c9eca..c18dd0d43590e158182370b44439edb7f0a0d780 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef LBPL_CALLABLE_H
 #define LBPL_CALLABLE_H
 
-#include "LBPLTypes.h"
+#include "LBPLTypes.hpp"
 #include <vector>
 
 class Interpreter;
index f4a2bd6069380c6720af7a3c5f66af48803d2e67..3870718791f1422d287014965d10db9d4ef255ab 100644 (file)
@@ -1,6 +1,6 @@
-#include "LBPLClass.h"
-#include "LBPLInstance.h"
-#include "interpreter.h"
+#include "LBPLClass.hpp"
+#include "LBPLInstance.hpp"
+#include "interpreter.hpp"
 
 Value LBPLClass::call(Interpreter *interpreter, std::vector<Value> &args) {
     auto instance = std::make_shared<LBPLInstance>(this);
similarity index 92%
rename from lib/LBPLClass.h
rename to src/LBPLClass.hpp
index 752e7ebb7f8411325381a37d5a0a57c81793268b..846db0b313c44c8f5f3a8b282d1bd9f5bd3186f9 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef LBPL_CLASS_H
 #define LBPL_CLASS_H
 
-#include "LBPLCallable.h"
-#include "LBPLFunction.h"
+#include "LBPLCallable.hpp"
+#include "LBPLFunction.hpp"
 
 #include <map>
 #include <memory>
index c2a7a5e5c0f69e82b075b7af7235b06d468ca75d..ac9c602ef9feadd31851c8b8a07a604d586b1582 100644 (file)
@@ -1,5 +1,5 @@
-#include "LBPLFunction.h"
-#include "interpreter.h"
+#include "LBPLFunction.hpp"
+#include "interpreter.hpp"
 
 void LBPLFunc::bind(std::shared_ptr<LBPLInstance> &&instance) {
   closureEnv = std::make_shared<Environment>();
similarity index 90%
rename from lib/LBPLFunction.h
rename to src/LBPLFunction.hpp
index c33d905b43def6e639d40d49bf8d403d162371e3..f4df5de3693f0650963323a194d0eb4dcc4336cd 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef LBPL_FUNCTION_H
 #define LBPL_FUNCTION_H
 
-#include "LBPLCallable.h"
-#include "environment.h"
-#include "statements.h"
+#include "LBPLCallable.hpp"
+#include "environment.hpp"
+#include "statements.hpp"
+
 #include <memory>
 
 class LBPLFunc : public LBPLCallable {
index 73e0d3e1291ed418c6a6e4e81c9ffdfdd9f325ed..72951b9e22c804185037cd9ad0c68aa9c8b37958 100644 (file)
@@ -1,4 +1,5 @@
-#include "LBPLInstance.h"
+#include "LBPLInstance.hpp"
+#include "runtime_error.hpp"
 
 Value LBPLInstance::get(const Token *name) {
   if (fields.contains(name->lexeme)) {
similarity index 86%
rename from lib/LBPLInstance.h
rename to src/LBPLInstance.hpp
index d895701ba96242824fa8737e0157b73de07f19b2..9c1635660676d0c8a1441cfaacbaf7b5a41faef4 100644 (file)
@@ -1,11 +1,9 @@
 #ifndef LBPL_INSTANCE_H
 #define LBPL_INSTANCE_H
 
-#include "LBPLClass.h"
-#include "runtime_error.h"
+#include "LBPLClass.hpp"
 
 #include <map>
-#include <memory>
 
 class LBPLInstance {
 private:
similarity index 100%
rename from lib/LBPLTypes.h
rename to src/LBPLTypes.hpp
index 04c89a8b62bb8ed167823589cb88bbabd7e7169a..18dff9f29df6839b8a963b1a99707a5db0b05b57 100755 (executable)
@@ -1,5 +1,5 @@
-#include "ast_printer.h"
-#include "statements.h"
+#include "ast_printer.hpp"
+#include "statements.hpp"
 
 #include <iostream>
 
similarity index 96%
rename from lib/ast_printer.h
rename to src/ast_printer.hpp
index 3b8a4b5a3671c672e20297c4bdc62624d1665056..0bf1bb79cd86d65b850ee64466ceadd2502a8834 100755 (executable)
@@ -1,8 +1,8 @@
 #ifndef AST_PRINTER_H
 #define AST_PRINTER_H
 
-#include "tree_nodes.h"
-#include "visitor.h"
+#include "tree_nodes.hpp"
+#include "visitor.hpp"
 
 class AST_Printer : public Statement::Visitor, public Expression::Visitor {
   void printLocation(Stmt *);
similarity index 96%
rename from lib/builtin_methods.h
rename to src/builtin_methods.hpp
index 24f0613e099c536f4fb4b3b894d9432834cf6da5..be2a64c71bd5da2be7387879b7ac4c29aca0ead6 100644 (file)
@@ -1,8 +1,7 @@
 #ifndef BUILTIN_METHODS_H
 #define BUILTIN_METHODS_H
 
-#include "LBPLCallable.h"
-#include "statements.h"
+#include "LBPLCallable.hpp"
 
 #include <chrono>
 #include <iostream>
similarity index 63%
rename from lib/common.h
rename to src/common.hpp
index fbdc444e7f5d2ed5b5939b21c5d7f92b9b201571..cea8e3e24dfffc3bf4bf3049177625c2eb728abb 100755 (executable)
@@ -1,8 +1,8 @@
 #ifndef COMMON_H
 #define COMMON_H
 
-#include "token.h"
-#include "token_type.h"
+#include "token.hpp"
+#include "token_type.hpp"
 
 #include <string>
 #include <iostream>
index f33df8bc83d30db19761abba869ec1c0fe8e87e0..4ef6a96648338fb647c87436d8cb1e613c49298c 100755 (executable)
@@ -1,10 +1,12 @@
-#include "environment.h"
-#include "LBPLTypes.h"
-#include "runtime_error.h"
+#include "environment.hpp"
+#include "LBPLTypes.hpp"
+#include "runtime_error.hpp"
+
 #include <memory>
 #include <string>
 #include <utility>
 #include <variant>
+#include <iostream>
 
 void Environment::define(const std::string &name, Value &value) {
   env.insert(std::make_pair(name, value));
@@ -13,7 +15,6 @@ void Environment::define(const std::string &name, Value &&value) {
   env.insert(std::make_pair(name, value));
 }
 
-
 Value Environment::get(std::shared_ptr<const Token> &name) {
   auto it = env.find(name->lexeme);
 
@@ -24,7 +25,7 @@ Value Environment::get(std::shared_ptr<const Token> &name) {
     return enclosing->get(name);
   }
 
-  throw RuntimeError(name.get(), "Undefined name '"+name->lexeme+"'.");
+  throw RuntimeError(name.get(), "Undefined name '" + name->lexeme + "'.");
 }
 
 Value Environment::getAt(int depth, std::shared_ptr<const Token> &name) {
@@ -33,7 +34,7 @@ Value Environment::getAt(int depth, std::shared_ptr<const Token> &name) {
 
 Value Environment::getAt(int depth, const std::string &name) {
   if (depth > 0) {
-    return enclosing->getAt(depth-1, name);
+    return enclosing->getAt(depth - 1, name);
   }
 
   auto it = env.find(name);
@@ -46,7 +47,8 @@ void Environment::assign(std::shared_ptr<const Token> &name, Value &value) {
   } else if (enclosing) {
     enclosing->assign(name, value);
   } else {
-    throw RuntimeError(name.get(), "Undefined variable '"+name->lexeme+"'.");
+    throw RuntimeError(name.get(),
+                       "Undefined variable '" + name->lexeme + "'.");
   }
 }
 
@@ -54,17 +56,18 @@ void Environment::assign(std::shared_ptr<const Token> &name, Value &&value) {
   assign(name, value);
 }
 
-void Environment::assignAt(int depth, std::shared_ptr<const Token> &name, Value &value) {
+void Environment::assignAt(int depth, std::shared_ptr<const Token> &name,
+                           Value &value) {
   if (depth > 0) {
-    enclosing->assignAt(depth-1, name, value);
+    enclosing->assignAt(depth - 1, name, value);
   }
 
   env.insert_or_assign(name->lexeme, value);
 }
 
 void Environment::printEnv(const std::string &&msg) {
-  std::cout << "========"<< msg <<"=========" << std::endl;
-  for (const auto[key, value] : env) {
+  std::cout << "========" << msg << "=========" << std::endl;
+  for (const auto &[key, value] : env) {
     std::cout << "\t" << key << ": ";
 
     if (std::holds_alternative<int>(value)) {
similarity index 92%
rename from lib/environment.h
rename to src/environment.hpp
index 989fbc1d7bc10a52f2ec266a1750a2233089c07a..f8f9415c30c4c09dd10397e68f1aa0341c6ebaaf 100755 (executable)
@@ -1,14 +1,12 @@
 #ifndef ENVIRONMENT_H
 #define ENVIRONMENT_H
 
-#include "LBPLTypes.h"
-#include "token.h"
-#include "tree_nodes.h"
+#include "LBPLTypes.hpp"
+#include "token.hpp"
 
 #include <map>
 #include <memory>
 #include <string>
-#include <variant>
 
 class Environment {
 public:
similarity index 96%
rename from lib/expressions.h
rename to src/expressions.hpp
index 86d1bebe20153884c7168f06bcbf84f394589127..a774eb1cb6d2e830a77293e6800680c07983b19b 100755 (executable)
@@ -1,11 +1,12 @@
 #ifndef EXPRESSIONS_H
 #define EXPRESSIONS_H
 
-#include "common.h"
-#include "token.h"
-#include "visitor.h"
+#include "token.hpp"
+
+#include "token.hpp"
+#include "visitor.hpp"
+#include <string>
 
-#include <cstdint>
 #include <memory>
 #include <vector>
 
@@ -16,7 +17,7 @@ struct Expr {
   Expr(int line, int column, const std::string &filename)
       : line(line), column(column), file(filename) {}
 
-  virtual ~Expr(){};
+  virtual ~Expr() {};
   virtual Value accept(Expression::Visitor *) { return nullptr; }
 };
 
@@ -99,7 +100,8 @@ struct ThisExpr : public Expr {
 public:
   std::shared_ptr<const Token> keyword;
 
-  ThisExpr(int line, int column, const std::string &file, std::shared_ptr<const Token>& keyword)
+  ThisExpr(int line, int column, const std::string &file,
+           std::shared_ptr<const Token> &keyword)
       : keyword(keyword), Expr(line, column, file) {}
 
   Value accept(Expression::Visitor *visitor) {
index 4ba86d89051164a4df1511100bf5c23114f1f245..a2f9f6a965d570d3df3b375d1ec9f19aeee9abef 100644 (file)
@@ -1,9 +1,9 @@
-#include "interpreter.h"
-#include "LBPLClass.h"
-#include "LBPLFunction.h"
-#include "LBPLInstance.h"
-#include "LBPLTypes.h"
-#include "runtime_error.h"
+#include "interpreter.hpp"
+#include "LBPLClass.hpp"
+#include "LBPLFunction.hpp"
+#include "LBPLInstance.hpp"
+#include "LBPLTypes.hpp"
+#include "runtime_error.hpp"
 
 #include <cstddef>
 #include <map>
similarity index 95%
rename from lib/interpreter.h
rename to src/interpreter.hpp
index 4c4ccb4336e8d00faa6399d656f5703708abbb86..1f3535b5c7a38a193d54685787d4c1ad1bdb489b 100644 (file)
@@ -1,11 +1,10 @@
 #ifndef INTERPRETER_H
 #define INTERPRETER_H
 
-#include "LBPLTypes.h"
-#include "builtin_methods.h"
-#include "environment.h"
-#include "runtime_error.h"
-#include "visitor.h"
+#include "LBPLTypes.hpp"
+#include "builtin_methods.hpp"
+#include "environment.hpp"
+#include "visitor.hpp"
 
 #include <map>
 #include <memory>
index adde981f23926e1419f5bd9cb67b975172f7eeb4..4fc6691942de7f3c1666ea295f36ab216def55c9 100755 (executable)
@@ -1,4 +1,4 @@
-#include "lexer.h"
+#include "lexer.hpp"
 
 Lexer::Lexer(const char *stream, const std::string &filename)
     : line(1), hadError(false), filename(filename), current(stream), start(stream) {}
similarity index 88%
rename from lib/lexer.h
rename to src/lexer.hpp
index c116a22510b77d11a99fe2567afcdcd2c72106f8..d18b7fb1b36624cc4863a780fc57f68f1505a80f 100755 (executable)
@@ -1,12 +1,11 @@
 #ifndef LEXER_H
 #define LEXER_H
 
-#include "common.h"
+#include "token.hpp"
+#include "token_type.hpp"
 
-#include <fstream>
-#include <iomanip>
+#include <string>
 #include <memory>
-#include <vector>
 
 class Lexer {
 private:
@@ -41,7 +40,7 @@ private:
   bool match(char ch);
 
 public:
-  Lexer(const char*, const std::string &);
+  Lexer(const char *, const std::string &);
 
   int getLine();
   int getColumn();
index 6a90ea6bebc0992dbbcd85c6b77d5d81971e10e4..77608cf7f781f7b8fb7a2fde85002ed962be5cbf 100755 (executable)
@@ -1,10 +1,13 @@
-#include "main.h"
 #include <fcntl.h>
 #include <iostream>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "parser.hpp"
+#include "interpreter.hpp"
+#include "resolver.hpp"
+
 int main(const int argc, const char **argv) {
   if (argc < 2) {
     std::cerr << "\033[1;31mNot enough arguemnts.\tUsage: lbpl [script]"
similarity index 100%
rename from lib/main.h
rename to src/main.hpp
index 83a80de977047b2afa140916b809802e108ba038..88caeb8533d341757481bca5e7e5ece31bc3e150 100755 (executable)
@@ -1,5 +1,8 @@
-#include "parser.h"
+#include "parser.hpp"
+#include "syntax_error.hpp"
+
 #include <fcntl.h>
+#include <iostream>
 #include <sys/mman.h>
 #include <sys/stat.h>
 
@@ -455,7 +458,8 @@ std::unique_ptr<Expr> Parser::primary() {
 
     return std::make_unique<SuperExpr>(line, col, lexer->getFilename(), field);
   } else if (match(TokenType::This)) {
-    return std::make_unique<ThisExpr>(line, col, lexer->getFilename(), previous);
+    return std::make_unique<ThisExpr>(line, col, lexer->getFilename(),
+                                      previous);
   } else if (match(TokenType::Identifier)) {
     return std::make_unique<VariableExpr>(line, col, lexer->getFilename(),
                                           previous);
@@ -493,6 +497,8 @@ void Parser::synchronize() {
     case TokenType::If:
     case TokenType::Return:
       return;
+    default:
+      break;
     }
 
     advance();
similarity index 95%
rename from lib/parser.h
rename to src/parser.hpp
index 943849bef4746553e751917d84b9fb003edadf9a..94f5867996a0444253707643610541a4520f04b8 100755 (executable)
@@ -1,12 +1,10 @@
 #ifndef PARSER_H
 #define PARSER_H
 
-#include "expressions.h"
-#include "lexer.h"
-#include "statements.h"
-#include "syntax_error.h"
+#include "expressions.hpp"
+#include "lexer.hpp"
+#include "statements.hpp"
 
-#include <fstream>
 #include <memory>
 #include <unordered_set>
 #include <vector>
index 29214ceaf59ee0cd69c41e9a916820ad5c84695b..05c9541b16008b7e41461f115dacf86d558d95e6 100644 (file)
@@ -1,4 +1,5 @@
-#include "resolver.h"
+#include "resolver.hpp"
+#include "syntax_error.hpp"
 
 void Resolver::resolve(std::vector<std::unique_ptr<Stmt>> &stmts) {
   for (auto &&stmt : stmts) {
similarity index 94%
rename from lib/resolver.h
rename to src/resolver.hpp
index d4e0f930c5395de0ef66212de4d74f6c2c028bcd..a8b9e19cf77f006ba3d197095bd8bb3c7017bdc7 100644 (file)
@@ -1,11 +1,9 @@
 #ifndef RESOLVER_H
 #define RESOLVER_H
 
-#include "environment.h"
-#include "interpreter.h"
-#include "statements.h"
-#include "syntax_error.h"
-#include "visitor.h"
+#include "interpreter.hpp"
+#include "statements.hpp"
+#include "visitor.hpp"
 
 #include <map>
 #include <memory>
index da079da2829940ccffb1b63726885cb03de43083..fb445e1aeb784ee017153ff05f10c4efc1401050 100644 (file)
@@ -1,4 +1,5 @@
-#include "runtime_error.h"
+#include "runtime_error.hpp"
+#include <sstream>
 
 std::string RuntimeError::what() {
   std::stringstream ss(msg);
diff --git a/src/runtime_error.hpp b/src/runtime_error.hpp
new file mode 100644 (file)
index 0000000..5c06189
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef RUNTIME_ERROR_H
+#define RUNTIME_ERROR_H
+
+#include "expressions.hpp"
+#include "statements.hpp"
+#include "token.hpp"
+
+#include <string>
+
+struct RuntimeError {
+public:
+  int line;
+  int column;
+  std::string filename;
+  std::string msg;
+
+public:
+  RuntimeError(const Token *errToken, const std::string &msg)
+      : line(errToken->line), column(errToken->column),
+        filename(errToken->filename), msg(msg) {}
+
+  RuntimeError(Expr *errToken, const std::string &msg)
+      : line(errToken->line), column(errToken->column),
+        filename(errToken->file), msg(msg) {}
+
+  RuntimeError(Stmt *errToken, const std::string &msg)
+      : line(errToken->line), column(errToken->column),
+        filename(errToken->filename), msg(msg) {}
+
+  std::string what();
+};
+
+#endif
similarity index 82%
rename from lib/statements.h
rename to src/statements.hpp
index 992f489756755f747a7468bfc260695537f72aae..92331136a2ce862af98663e1cce7d9feca3cb974 100755 (executable)
@@ -1,11 +1,8 @@
 #ifndef STATEMENTS_H
 #define STATEMENTS_H
 
-#include "expressions.h"
-
+#include "expressions.hpp"
 #include <memory>
-#include <optional>
-#include <utility>
 
 struct Stmt {
   std::string filename;
@@ -20,12 +17,15 @@ struct Stmt {
 
 struct FnStmt : public Stmt {
   std::shared_ptr<const Token> name;
-  std::vector<std::shared_ptr<const Token> > args;
+  std::vector<std::shared_ptr<const Token>> args;
   std::vector<std::unique_ptr<Stmt>> body;
 
-  FnStmt(int line, int column, const std::string &file, std::shared_ptr<const Token> &name,
-         std::vector<std::shared_ptr<const Token>> &args, std::vector<std::unique_ptr<Stmt>> &&body)
-      : name(name), args(args), body(std::move(body)), Stmt(line, column, file) {}
+  FnStmt(int line, int column, const std::string &file,
+         std::shared_ptr<const Token> &name,
+         std::vector<std::shared_ptr<const Token>> &args,
+         std::vector<std::unique_ptr<Stmt>> &&body)
+      : name(name), args(args), body(std::move(body)),
+        Stmt(line, column, file) {}
 
   void accept(Statement::Visitor *visitor) { visitor->visitFnStmt(this); }
 };
@@ -34,10 +34,9 @@ struct VarStmt : public Stmt {
   std::shared_ptr<const Token> name;
   std::unique_ptr<Expr> value;
 
-  VarStmt(int line, int column, const std::string &file, std::shared_ptr<const Token> &name,
-          std::unique_ptr<Expr> &value)
-      : name(name), value(std::move(value)),
-        Stmt(line, column, file) {}
+  VarStmt(int line, int column, const std::string &file,
+          std::shared_ptr<const Token> &name, std::unique_ptr<Expr> &value)
+      : name(name), value(std::move(value)), Stmt(line, column, file) {}
 
   void accept(Statement::Visitor *visitor) { visitor->visitVarStmt(this); }
 };
@@ -47,7 +46,8 @@ struct ClassStmt : public Stmt {
   std::unique_ptr<VariableExpr> superclass;
   std::vector<std::unique_ptr<Stmt>> body;
 
-  ClassStmt(int line, int column, const std::string &file, std::shared_ptr<const Token> &name,
+  ClassStmt(int line, int column, const std::string &file,
+            std::shared_ptr<const Token> &name,
             std::unique_ptr<VariableExpr> &superclass,
             std::vector<std::unique_ptr<Stmt>> &&body)
       : name(name), superclass(std::move(superclass)), body(std::move(body)),
@@ -62,8 +62,8 @@ struct IfStmt : public Stmt {
   std::unique_ptr<Stmt> falseBranch;
 
   IfStmt(int line, int column, const std::string &file,
-         std::unique_ptr<Expr> &condition,
-         std::unique_ptr<Stmt> &trueBranch, std::unique_ptr<Stmt> &falseBranch)
+         std::unique_ptr<Expr> &condition, std::unique_ptr<Stmt> &trueBranch,
+         std::unique_ptr<Stmt> &falseBranch)
       : condition(std::move(condition)), trueBranch(std::move(trueBranch)),
         falseBranch(std::move(falseBranch)), Stmt(line, column, file) {}
 
index fa7ef687d3daa69a0a7e3518ed28c6e249bea783..cbb77298f03ee500e53ee6bb5b2cfd5dd598f5b5 100755 (executable)
@@ -1,4 +1,5 @@
-#include "syntax_error.h"
+#include "syntax_error.hpp"
+#include <sstream>
 
 std::string SyntaxError::what() {
   std::stringstream ss(msg);
similarity index 56%
rename from lib/syntax_error.h
rename to src/syntax_error.hpp
index 48c17c8935d21afc67da097e4004d0dbe5bc739b..c464fba2ed4d97cdcc4e9ce1c76e0a42a9be0f6f 100755 (executable)
@@ -1,14 +1,11 @@
 #ifndef SYNTAX_ERROR_H
 #define SYNTAX_ERROR_H
 
-#include "token.h"
-#include "expressions.h"
-#include "statements.h"
+#include "expressions.hpp"
+#include "statements.hpp"
+#include "token.hpp"
 
 #include <string>
-#include <optional>
-#include <iomanip>
-#include <sstream>
 
 struct SyntaxError {
 public:
@@ -19,13 +16,16 @@ public:
 
 public:
   SyntaxError(const Token *errToken, const std::string &msg)
-      : line(errToken->line), column(errToken->column), filename(errToken->filename), msg(msg) {}
+      : line(errToken->line), column(errToken->column),
+        filename(errToken->filename), msg(msg) {}
 
   SyntaxError(Expr *errExpr, const std::string &msg)
-      : line(errExpr->line), column(errExpr->column), filename(errExpr->file), msg(msg) {}
+      : line(errExpr->line), column(errExpr->column), filename(errExpr->file),
+        msg(msg) {}
 
   SyntaxError(Stmt *errStmt, const std::string &msg)
-      : line(errStmt->line), column(errStmt->column), filename(errStmt->filename), msg(msg) {}
+      : line(errStmt->line), column(errStmt->column),
+        filename(errStmt->filename), msg(msg) {}
 
   std::string what();
 };
similarity index 93%
rename from lib/token.h
rename to src/token.hpp
index 47c4be1682c9ffec7a158390b8c40843fcdced92..8c2ff6bb59cc2ced17b9a647dcf872fe3893b02a 100755 (executable)
@@ -1,7 +1,7 @@
 #ifndef TOKEN_H
 #define TOKEN_H
 
-#include "token_type.h"
+#include "token_type.hpp"
 
 #include <string>
 
similarity index 100%
rename from lib/token_type.h
rename to src/token_type.hpp
similarity index 100%
rename from lib/tree_nodes.h
rename to src/tree_nodes.hpp
similarity index 95%
rename from lib/visitor.h
rename to src/visitor.hpp
index 255105ed94a74378440d9945db03c025bbbaddef..b2afa7340a7b2963a89d613bb8675694b1d626c9 100755 (executable)
@@ -1,10 +1,8 @@
 #ifndef VISITOR_H
 #define VISITOR_H
 
-#include "LBPLTypes.h"
-#include "tree_nodes.h"
-
-#include <iostream>
+#include "LBPLTypes.hpp"
+#include "tree_nodes.hpp"
 
 namespace Statement {
 struct Visitor {