diff --git a/.gitignore b/.gitignore index eda7641..4dbe06d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,15 @@ *.out *.app -build/ -.idea/ +# CMake +CMakeCache.txt +CMakeFiles/ +CTestTestfile.cmake +Makefile +Testing/ +cmake_install.cmake +compile_commands.json +install_manifest.txt + +# Beaker +config.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cbf743..87d4c16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,18 @@ # Copyright (c) 2015 Andrew Sutton # All rights reserved -# Project configuration cmake_minimum_required(VERSION 3.1) + +# Project configuration project(beaker VERSION 0.0 LANGUAGES C CXX) enable_testing() -foreach(component MAJOR MINOR PATCH TWEAK) - if(PROJECT_VERSION_${component} STREQUAL "") - set(PROJECT_VERSION_${component} 0) - endif() -endforeach() - -set(BEAKER_PACKAGE_NAME ${PROJECT_NAME}) -set(BEAKER_PACKAGE_TARNAME ${BEAKER_PACKAGE_NAME}) -set(BEAKER_PACKAGE_VERSION ${PROJECT_VERSION}) -set(BEAKER_PACKAGE_STRING "${BEAKER_PACKAGE_NAME} ${BEAKER_PACKAGE_VERSION}") -set(BEAKER_PACKAGE_BUGREPORT "https://github.com/asutton/beaker/issues") -set(BEAKER_PACKAGE_URL "https://github.com/asutton/beaker") - -set(BEAKER_VERSION ${PROJECT_VERSION}) -set(BEAKER_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) -set(BEAKER_VERSION_MINOR ${PROJECT_VERSION_MINOR}) -set(BEAKER_VERSION_PATCH ${PROJECT_VERSION_PATCH}) -set(BEAKER_VERSION_TWEAK ${PROJECT_VERSION_TWEAK}) +set(PACKAGE_NAME ${PROJECT_NAME}) +set(PACKAGE_TARNAME ${PACKAGE_NAME}) +set(PACKAGE_VERSION ${PROJECT_VERSION}) +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +set(PACKAGE_BUGREPORT "https://github.com/asutton/beaker/issues") +set(PACKAGE_URL "https://github.com/asutton/beaker") # Boost dependencies find_package(Boost 1.55.0 REQUIRED COMPONENTS system filesystem program_options) @@ -49,14 +38,14 @@ find_program(LLVM_IR_COMPILER llc HINTS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH # # TODO: Actually use the low-level tools and link # only against the minimal Beaker runtime. -set(BEAKER_NATIVE_COMPILER ${CMAKE_C_COMPILER}) -set(BEAKER_NATIVE_ARCHIVER ${CMAKE_AR}) +set(NATIVE_COMPILER ${CMAKE_C_COMPILER}) +set(NATIVE_ARCHIVER ${CMAKE_AR}) # Compiler configuration set(CMAKE_CXX_FLAGS "-Wall -std=c++1y") -# TODO: Remove when 'lingo' submodule is updated. -include_directories(lingo) +# Generate the configuration header. +configure_file(config.hpp.in config.hpp) if(NOT TARGET check) add_custom_target(check COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test) diff --git a/beaker/CMakeLists.txt b/beaker/CMakeLists.txt index 7c972a4..6f0976b 100644 --- a/beaker/CMakeLists.txt +++ b/beaker/CMakeLists.txt @@ -1,9 +1,6 @@ # Copyright (c) 2015 Andrew Sutton # All rights reserved -# Generate the configuration header. -configure_file(config.hpp.in config.hpp) - # Add the core Beaker library. add_library(beaker file.cpp diff --git a/beaker/compiler.cpp b/beaker/compiler.cpp index d1c315e..b27d10d 100644 --- a/beaker/compiler.cpp +++ b/beaker/compiler.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/options.hpp" #include "beaker/job.hpp" #include "beaker/lexer.hpp" @@ -104,7 +106,7 @@ compiler_main(int argc, char* argv[]) .run(), vm); po::notify(vm); - } catch(std::exception& err) { + } catch (std::exception& err) { std::cerr << "error: " << err.what() << "\n\n"; usage(std::cerr, all_opts); return -1; @@ -116,7 +118,7 @@ compiler_main(int argc, char* argv[]) return 0; } if (vm["version"].as()) { - std::cout << BEAKER_PACKAGE_STRING << '\n'; + std::cout << PACKAGE_STRING << '\n'; return 0; } diff --git a/beaker/config.hpp.in b/beaker/config.hpp.in deleted file mode 100644 index e6997c2..0000000 --- a/beaker/config.hpp.in +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) 2015 Andrew Sutton -// All rights reserved - -/* config.hpp. Generated from config.hpp.in by cmake. */ - -#ifndef BEAKER_CONFIG_HPP -#define BEAKER_CONFIG_HPP - -/* Name of package. */ -#define BEAKER_PACKAGE "@BEAKER_PACKAGE_NAME@" - -/* Define to the full name of this package. */ -#define BEAKER_PACKAGE_NAME "@BEAKER_PACKAGE_NAME@" - -/* Define to the one symbol short name of this package. */ -#define BEAKER_PACKAGE_TARNAME "@BEAKER_PACKAGE_TARNAME@" - -/* Define to the version of this package. */ -#define BEAKER_PACKAGE_VERSION "@BEAKER_PACKAGE_VERSION@" - -/* Define to the full name and version of this package. */ -#define BEAKER_PACKAGE_STRING "@BEAKER_PACKAGE_STRING@" - -/* Define to the address where bug reports for this package should be sent. */ -#define BEAKER_PACKAGE_BUGREPORT "@BEAKER_PACKAGE_BUGREPORT@" - -/* Define to the home page for this package. */ -#define BEAKER_PACKAGE_URL "@BEAKER_PACKAGE_URL@" - -/* The version number of the Beaker library. */ -#define BEAKER_VERSION "@BEAKER_VERSION@" - -/* The major version of the Beaker library. */ -#define BEAKER_VERSION_MAJOR @BEAKER_VERSION_MAJOR@ - -/* The minor version of the Beaker library. */ -#define BEAKER_VERSION_MINOR @BEAKER_VERSION_MINOR@ - -/* The patch version of the Beaker library. */ -#define BEAKER_VERSION_PATCH @BEAKER_VERSION_PATCH@ - -/* The tweak version of the Beaker library. */ -#define BEAKER_VERSION_TWEAK @BEAKER_VERSION_TWEAK@ - - -// Tools -#define BEAKER_LLVM_IR_COMPILER "@LLVM_IR_COMPILER@" -#define BEAKER_NATIVE_C_COMPILER "@CMAKE_C_COMPILER@" -#define BEAKER_NATIVE_AS "@CMAKE_C_COMPILER@" -#define BEAKER_NATIVE_LD "@CMAKE_C_COMPILER@" -#define BEAKER_NATIVE_AR "@CMAKE_AR@" - -// File properties -#define BEAKER_OBJECT_EXT "@CMAKE_C_OUTPUT_EXTENSION@" -#define BEAKER_EXECUTABLE_EXT "@CMAKE_EXECUTABLE_SUFFIX@" -#define BEAKER_LIBRARY_PRE "@CMAKE_SHARED_LIBRARY_PREFIX@" -#define BEAKER_LIBRARY_EXT "@CMAKE_SHARED_LIBRARY_SUFFIX@" -#define BEAKER_ARCHIVE_PRE "@CMAKE_STATIC_LIBRARY_PREFIX@" -#define BEAKER_ARCHIVE_EXT "@CMAKE_STATIC_LIBRARY_SUFFIX@" - - -inline char const* -llvm_compiler() -{ - return BEAKER_LLVM_IR_COMPILER; -} - - -inline char const* -native_c_compiler() -{ - return BEAKER_NATIVE_C_COMPILER; -} - - -inline char const* -native_assembler() -{ - return BEAKER_NATIVE_AS; -} - - -inline char const* -native_archiver() -{ - return BEAKER_NATIVE_AR; -} - - -inline char const* -native_linker() -{ - return BEAKER_NATIVE_LD; -} - - -inline char const* -object_extension() -{ - return BEAKER_OBJECT_EXT; -} - - -inline char const* -executable_extension() -{ - return BEAKER_EXECUTABLE_EXT; -} - - -inline char const* -library_extension() -{ - return BEAKER_LIBRARY_EXT; -} - - -inline char const* -archive_extension() -{ - return BEAKER_ARCHIVE_EXT; -} - - -#endif diff --git a/beaker/convert.cpp b/beaker/convert.cpp index 5af2a9b..2d861f7 100644 --- a/beaker/convert.cpp +++ b/beaker/convert.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/convert.hpp" #include "beaker/type.hpp" #include "beaker/expr.hpp" @@ -8,62 +10,67 @@ #include + // This finds the target that both operands should // be converted to. Default int32. Type const* get_promotion_target(Expr* first, Expr* second) { - // get type of both expressions - Type const* first_t = first->type(); - Type const* second_t = second->type(); - - // if both are not scalar, default is int32 - // if one is not scalar, choose the other type - if (!is_scalar(first_t) && !is_scalar(second_t)) - return get_integer_type(); - else if (!is_scalar(first_t)) - return second_t; - else if (!is_scalar(second_t)) - return first_t; - - // if the same type use that as the target - if (first_t == second_t) - return first_t; - - // make highest rank the target - if (get_scalar_rank(first_t) > get_scalar_rank(second_t)) - return first_t; - else - return second_t; + // get type of both expressions + Type const* first_t = first->type(); + Type const* second_t = second->type(); + + // if both are not scalar, default is int32 + // if one is not scalar, choose the other type + if (!is_scalar(first_t) && !is_scalar(second_t)) + return get_integer_type(); + else if (!is_scalar(first_t)) + return second_t; + else if (!is_scalar(second_t)) + return first_t; + + // if the same type use that as the target + if (first_t == second_t) + return first_t; + + // make highest rank the target + if (get_scalar_rank(first_t) > get_scalar_rank(second_t)) + return first_t; + else + return second_t; } + // This finds the target that the operand should // be converted to. Default int32. Type const* get_promotion_target(Expr* first) { - // get type of expression - Type const* first_t = first->type(); + // get type of expression + Type const* first_t = first->type(); - // if not scalar, default is int32 - if (!is_scalar(first_t)) - return get_integer_type(); + // if not scalar, default is int32 + if (!is_scalar(first_t)) + return get_integer_type(); - // if it is scalar then type remains - return first_t; + // if it is scalar then type remains + return first_t; } + // if promotion is not allowed then the origninal // expr is returned. This allows for operations // with same types to occur. Expr* -promote(Expr* e, Type const* t){ - if (get_scalar_rank(t) > get_scalar_rank(e->type())) - return new Promote_conv(t,e); - else - return e; +promote(Expr* e, Type const* t) +{ + if (get_scalar_rank(t) > get_scalar_rank(e->type())) + return new Promote_conv(t, e); + else + return e; } + // If e has reference type T&, return a conversion // to the value type T. Otherwise, no conversions // are required and e is returned. @@ -93,10 +100,9 @@ convert_to_block(Expr* e) Expr* convert_to_base(Expr* e) { - if (Record_type const* r = as(e->type()->nonref())) { + if (Record_type const* r = as(e->type()->nonref())) return new Base_conv(get_record_type(r->declaration()), e); - } - else + else return e; } @@ -109,14 +115,11 @@ convert(Expr* e, Type const* t) { // If e has type t, no conversions are needed. if (e->type() == t) - { return e; - } - Expr* c = e; - + Expr* c = e; - // Ojbect/value transformations + // Object/value transformations // If t is a non-reference type, try an // object-to-value conversion: @@ -126,7 +129,7 @@ convert(Expr* e, Type const* t) c = convert_to_value(e); if (c->type() == t) return c; - }//bit cast + } // bit cast // Type conversions @@ -147,17 +150,17 @@ convert(Expr* e, Type const* t) // // FIXME: Implement me. if (is(t)) { - // Need another convert class - // 0 -> false - // everything else -> true - throw std::runtime_error("not implemented"); + // Need another convert class + // 0 -> false + // everything else -> true + throw std::runtime_error("not implemented"); } // Try to apply a type promotion if (is_scalar(t) && !is(e->type())) { - c = promote(e,t); + c = promote(e, t); if (c->type() == t) - return c; + return c; } // FIXME: Clean this up. @@ -179,7 +182,7 @@ convert(Expr* e, Type const* t) return ret; } } - + // FIXME: We never actually get here. if (c->type() == t) return c; diff --git a/beaker/decl.cpp b/beaker/decl.cpp index bf38eb6..8312412 100644 --- a/beaker/decl.cpp +++ b/beaker/decl.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/decl.hpp" @@ -62,7 +64,7 @@ Record_decl::is_empty() const if (Record_decl const* b = base_declaration()) if (b->is_empty()) return false; - + // An empty base class has no fields. return fields_.empty(); } diff --git a/beaker/driver.cpp b/beaker/driver.cpp index 00c1042..4148708 100644 --- a/beaker/driver.cpp +++ b/beaker/driver.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/file.hpp" #include "beaker/error.hpp" diff --git a/beaker/elaborator.cpp b/beaker/elaborator.cpp index ef2016c..60e5d12 100644 --- a/beaker/elaborator.cpp +++ b/beaker/elaborator.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/elaborator.hpp" #include "beaker/type.hpp" #include "beaker/expr.hpp" @@ -114,7 +116,6 @@ Elaborator::qualified_lookup(Scope* s, Symbol const* sym) } - Overload* Elaborator::member_lookup(Record_decl* d, Symbol const* sym) { @@ -170,7 +171,6 @@ Elaborator::elaborate_def(Type const* t) } - Type const* Elaborator::elaborate(Type const* t) { @@ -240,35 +240,39 @@ Elaborator::elaborate(Character_type const* t) return t; } + Type const* Elaborator::elaborate(Integer_type const* t) { return t; } + Type const* Elaborator::elaborate(Float_type const* t) { return t; } + Type const* Elaborator::elaborate(Double_type const* t) { return t; } + // Elaborate each type in the function type. Type const* Elaborator::elaborate(Function_type const* t) { Type_seq ts; ts.reserve(t->parameter_types().size()); - for (Type const* t1 : t->parameter_types()){ + for (Type const* t1 : t->parameter_types()) { // HERE! we are checking function paramters for // function type and elaborating them as references to function types instead - if(is(t1)){ + if (is(t1)) { Type const * tempType = elaborate(t1); ts.push_back(elaborate(tempType->ref())); } @@ -293,6 +297,7 @@ Elaborator::elaborate(Array_type const* t) return get_array_type(t1, n); } + Type const* Elaborator::elaborate(Block_type const* t) { @@ -566,7 +571,6 @@ Elaborator::elaborate(Rem_expr* e) } -// Expr* Elaborator::elaborate(Neg_expr* e) { @@ -625,7 +629,6 @@ Elaborator::elaborate(Ne_expr* e) } - namespace { @@ -691,7 +694,6 @@ Elaborator::elaborate(Ge_expr* e) namespace { - // TODO: Document me! Expr* check_binary_logical_expr(Elaborator& elab, Binary_expr* e) @@ -886,7 +888,6 @@ Elaborator::resolve(Overload_expr* ovl, Expr_seq const& args) } - // Resolve a function call. The target of a function // may be one of the following: // @@ -973,10 +974,10 @@ Elaborator::elaborate(Call_expr* e) // Check for value conversion nodes // This is the case for lambda initialized variables and parameters - if(is(f)){ + if (is(f)) { f = cast(f)->first; auto decl = cast(f)->declaration(); - if(auto var = as(decl)) { + if (auto var = as(decl)) { auto f_decl = cast(var->init())->first; f = f_decl; } @@ -1045,7 +1046,7 @@ get_path(Record_decl* r, Field_decl* f) } //Method_path -//get_path(Record_decl* r, Method_decl* m){ +//get_path(Record_decl* r, Method_decl* m) { // Method_path p; // get_path(r, m, p); // lingo_assert(!p.empty()); @@ -1351,7 +1352,7 @@ Elaborator::elaborate(Variable_decl* d) { d->type_ = elaborate_type(d->type_); - if(is(d->type_)) + if (is(d->type_)) { d->type_ = d->type_->ref(); cast(d->init_)->type_ = d->type_; @@ -1390,7 +1391,7 @@ Elaborator::elaborate(Parameter_decl* d) { d->type_ = elaborate_type(d->type_); // Check for function type and set to reference to function type - if(is(d->type_)) + if (is(d->type_)) d->type_ = d->type_->ref(); declare(d); @@ -1461,7 +1462,7 @@ Elaborator::elaborate(Module_decl* m) for (Decl*& d : m->decls_) d = elaborate_def(d); - for(auto && a : lambda_decls_) + for (auto && a : lambda_decls_) m->decls_.insert(m->decls_.begin(), a.second); return m; @@ -1501,7 +1502,7 @@ Elaborator::elaborate_decl(Decl* d) Decl* Elaborator::elaborate_decl(Variable_decl* d) { - if(is(d->type_)) + if (is(d->type_)) { d->type_ = d->type()->ref(); } @@ -1616,7 +1617,6 @@ find_override(Record_decl const* d, Method_decl const* m) return -1; } - } // namespace @@ -1728,7 +1728,6 @@ struct Elab_def_fn Decl* operator()(Module_decl* d) const { return elab.elaborate_def(d); } }; - } // namespace diff --git a/beaker/environment.cpp b/beaker/environment.cpp index 72797f3..fb45e45 100644 --- a/beaker/environment.cpp +++ b/beaker/environment.cpp @@ -1,4 +1,6 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/environment.hpp" diff --git a/beaker/equal.cpp b/beaker/equal.cpp index 0f612c5..b58f145 100644 --- a/beaker/equal.cpp +++ b/beaker/equal.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/equal.hpp" #include "beaker/type.hpp" diff --git a/beaker/error.cpp b/beaker/error.cpp index 0f640f8..de70da8 100644 --- a/beaker/error.cpp +++ b/beaker/error.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/error.hpp" #include diff --git a/beaker/evaluator.cpp b/beaker/evaluator.cpp index 97c89f2..12ad592 100644 --- a/beaker/evaluator.cpp +++ b/beaker/evaluator.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/evaluator.hpp" #include "beaker/type.hpp" #include "beaker/expr.hpp" @@ -47,7 +49,7 @@ Evaluator::eval(Expr const* e) Value operator()(Block_conv const* e) { return ev.eval(e); } Value operator()(Base_conv const* e) { return ev.eval(e); } Value operator()(Promote_conv const* e) { return ev.eval(e); } - + // Initializers are not evaluated like normal expressions. Value operator()(Init const* e) { lingo_unreachable(); } }; @@ -78,7 +80,7 @@ struct Eval_init_fn void -Evaluator::eval_init(Expr const* e, Value& v) +Evaluator::eval_init(Expr const* e, Value& v) { apply(e, Eval_init_fn {*this, v}); } @@ -396,18 +398,18 @@ Evaluator::eval(Promote_conv const* e) const Type * t = e->target(); Value v = eval(e->source()); - if(is(t)) { - if(v.is_integer()) + if (is(t)) { + if (v.is_integer()) { return new Value((float)(v.get_integer())); } } - else if(is(t)) { - if(v.is_integer()) + else if (is(t)) { + if (v.is_integer()) { return new Value((double)(v.get_integer())); } - if(v.is_float()) + if (v.is_float()) { return new Value((double)(v.get_float())); } diff --git a/beaker/expr.cpp b/beaker/expr.cpp index cfe33a5..f36d225 100644 --- a/beaker/expr.cpp +++ b/beaker/expr.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/expr.hpp" #include "beaker/type.hpp" #include "beaker/decl.hpp" @@ -19,12 +21,14 @@ Decl_expr::name() const return decl->name(); } + Function_type const* Lambda_expr::type() const { return cast(type_); } + Type const* Lambda_expr::return_type() const { @@ -32,6 +36,7 @@ Lambda_expr::return_type() const return type()->return_type(); } + Record_decl* Field_expr::record() const { diff --git a/beaker/file.cpp b/beaker/file.cpp index 4e403f4..e905fa2 100644 --- a/beaker/file.cpp +++ b/beaker/file.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/file.hpp" @@ -34,5 +36,5 @@ get_file_kind(Path const& p) if (ext == ".out") return program_file; else - return unspecified_file; + return unspecified_file; } diff --git a/beaker/generator.cpp b/beaker/generator.cpp index f478f15..dba0fd0 100644 --- a/beaker/generator.cpp +++ b/beaker/generator.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/generator.hpp" #include "beaker/type.hpp" #include "beaker/expr.hpp" @@ -97,23 +99,24 @@ Generator::get_type(Character_type const*) return build.getInt8Ty(); } + // Return the standard integer type. llvm::Type* Generator::get_type(Integer_type const* t) { - switch (t->precision()) - { - case 32: - return build.getInt32Ty(); - case 16: - return build.getInt16Ty(); - case 64: - return build.getInt64Ty(); - default: - throw std::runtime_error("No integer with precision " + std::to_string(t->precision())); + switch (t->precision()) { + case 32: + return build.getInt32Ty(); + case 16: + return build.getInt16Ty(); + case 64: + return build.getInt64Ty(); + default: + throw std::runtime_error("No integer with precision " + std::to_string(t->precision())); } } + // Return the float type. llvm::Type* Generator::get_type(Float_type const*) @@ -121,6 +124,7 @@ Generator::get_type(Float_type const*) return build.getFloatTy(); } + // Return the double type. llvm::Type* Generator::get_type(Double_type const*) @@ -128,6 +132,7 @@ Generator::get_type(Double_type const*) return build.getDoubleTy(); } + // Return a function type. llvm::Type* Generator::get_type(Function_type const* t) @@ -242,6 +247,7 @@ Generator::gen(Expr const* e) namespace { + struct Gen_init_fn { Generator& g; @@ -249,14 +255,13 @@ struct Gen_init_fn template void operator()(T const*) { lingo_unreachable(); } - + void operator()(Default_init const* e) { g.gen_init(ptr, e); } void operator()(Trivial_init const* e) { g.gen_init(ptr, e); } void operator()(Copy_init const* e) { g.gen_init(ptr, e); } void operator()(Reference_init const* e) { g.gen_init(ptr, e); } }; - } // namespace @@ -382,9 +387,8 @@ Generator::gen(Rem_expr const* e) llvm::Value* Generator::gen(Neg_expr const* e) { - llvm::Value* zero = build.getInt32(0); - llvm::Value* val = gen(e->operand()); - return build.CreateSub(zero, val); + llvm::Value* operand = gen(e->operand()); + return build.CreateNeg(operand); } @@ -497,15 +501,11 @@ Generator::gen(Or_expr const* e) } -// Logical not is a simple XOR with the value true -// 1 xor 1 = 0 -// 0 xor 1 = 1 llvm::Value* Generator::gen(Not_expr const* e) { - llvm::Value* one = build.getTrue(); llvm::Value* operand = gen(e->operand()); - return build.CreateXor(one, operand); + return build.CreateNot(operand); } @@ -524,7 +524,6 @@ calls_virtual_method(Call_expr const* e) return nullptr; } - } // namespace @@ -631,13 +630,14 @@ Generator::gen(Value_conv const* e) return build.CreateLoad(v); } + llvm::Value* Generator::gen(Promote_conv const* e) { llvm::Value* v = gen(e->source()); const Type * t = e->target(); - if(is(t)) { + if (is(t)) { const Integer_type * t2 = dynamic_cast(t); return build.CreateIntCast(v, get_type(t2), t2->is_signed()); } @@ -645,9 +645,7 @@ Generator::gen(Promote_conv const* e) return build.CreateFPCast(v, get_type(t)); } - else - return v; - + return v; } @@ -678,6 +676,7 @@ Generator::gen(Base_conv const* e) return build.CreateGEP(a, args); } + // TODO: Return the value or store it? void Generator::gen_init(llvm::Value* ptr, Default_init const* e) @@ -706,12 +705,14 @@ Generator::gen_init(llvm::Value* ptr, Default_init const* e) throw std::runtime_error("unhahndled default initializer"); } + void Generator::gen_init(llvm::Value* ptr, Trivial_init const* e) { - return; + // Do nothing. } + // TODO: Return the value or store it? void Generator::gen_init(llvm::Value* ptr, Copy_init const* e) diff --git a/beaker/hash.cpp b/beaker/hash.cpp index 61172d6..ecb0e90 100644 --- a/beaker/hash.cpp +++ b/beaker/hash.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/hash.hpp" #include "beaker/type.hpp" diff --git a/beaker/interpreter.cpp b/beaker/interpreter.cpp index c0d8700..225348a 100644 --- a/beaker/interpreter.cpp +++ b/beaker/interpreter.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/lexer.hpp" #include "beaker/parser.hpp" #include "beaker/decl.hpp" diff --git a/beaker/job.cpp b/beaker/job.cpp index b28eab8..6138c9e 100644 --- a/beaker/job.cpp +++ b/beaker/job.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/job.hpp" #include diff --git a/beaker/less.cpp b/beaker/less.cpp index 9d3387f..06ad7ce 100644 --- a/beaker/less.cpp +++ b/beaker/less.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/less.hpp" #include "beaker/type.hpp" #include "beaker/expr.hpp" @@ -124,28 +126,28 @@ is_less(Type const* a, Type const* b) bool is_less(Error_value const& a, Error_value const& b) -{ - return false; +{ + return false; } bool is_less(Integer_value const& a, Integer_value const& b) -{ +{ return a < b; } bool is_less(Float_value const& a, Float_value const& b) -{ - return a < b; +{ + return a < b; } bool is_less(Function_value const& a, Function_value const& b) -{ +{ std::less cmp; return cmp(a, b); } @@ -153,14 +155,14 @@ is_less(Function_value const& a, Function_value const& b) bool is_less(Reference_value const& a, Reference_value const& b) -{ +{ std::less cmp; - return cmp(a, b); + return cmp(a, b); } bool is_less(Array_value const& a, Array_value const& b) -{ +{ auto cmp = [](Value const& x, Value const& y) { return is_less(x, y); }; return std::lexicographical_compare(a.data, a.data + a.len, b.data, b.data + b.len, cmp); @@ -168,7 +170,7 @@ is_less(Array_value const& a, Array_value const& b) bool is_less(Tuple_value const& a, Tuple_value const& b) -{ +{ auto cmp = [](Value const& x, Value const& y) { return is_less(x, y); }; return std::lexicographical_compare(a.data, a.data + a.len, b.data, b.data + b.len, cmp); diff --git a/beaker/lexer.cpp b/beaker/lexer.cpp index 8de8642..6f71291 100644 --- a/beaker/lexer.cpp +++ b/beaker/lexer.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/lexer.hpp" #include @@ -20,8 +22,6 @@ Input_buffer::Input_buffer(File const& f) } - - // Returns the current character and advances the // stream. char @@ -84,7 +84,7 @@ Lexer::scan() return slash(); } - case '\\': return f_slash(); + case '\\': return bslash(); case '%': return percent(); case '=': return equal(); case '!': return bang(); @@ -188,13 +188,14 @@ Lexer::on_word() Token -Lexer::on_f_slash(){ +Lexer::on_bslash() +{ //Look for lambda identifier in Symbol_table //if it's found mutate the identifier String str = "lambda"; long int count = 0; Symbol const* sym = syms_.get(str); - while(sym) + while (sym) { str = "lambda"; str += "_"; @@ -206,6 +207,7 @@ Lexer::on_f_slash(){ return Token(loc_, sym->token(), sym); } + // Return a new integer token. inline Token Lexer::on_integer() @@ -216,6 +218,7 @@ Lexer::on_integer() return Token(loc_, integer_tok, sym); } + // Return a new floating point number token. inline Token Lexer::on_real() diff --git a/beaker/lexer.hpp b/beaker/lexer.hpp index cd86018..7d11bf3 100644 --- a/beaker/lexer.hpp +++ b/beaker/lexer.hpp @@ -175,7 +175,7 @@ class Lexer Token rangle(); Token ampersand(); Token bar(); - Token f_slash(); + Token bslash(); Token number(); Token word(); Token character(); @@ -188,7 +188,7 @@ class Lexer // Semantic actions Token on_token(); Token on_word(); - Token on_f_slash(); + Token on_bslash(); Token on_integer(); Token on_real(); Token on_character(); @@ -264,9 +264,8 @@ Lexer::scan(Token_stream& ts) ts.put(tok); //FIXME is this ok or is it too hacky? //HACK for lambda function identifier injection - if(tok.kind() == f_slash_tok){ - ts.put(on_f_slash()); - } + if (tok.kind() == bslash_tok) + ts.put(on_bslash()); return true; } return false; @@ -389,8 +388,10 @@ Lexer::star() return symbol1(); } + inline Token -Lexer::tilde(){ +Lexer::tilde() +{ return symbol1(); } @@ -484,7 +485,7 @@ Lexer::bar() } inline Token -Lexer::f_slash() +Lexer::bslash() { return symbol1(); } diff --git a/beaker/line.cpp b/beaker/line.cpp index 9d04193..9758a86 100644 --- a/beaker/line.cpp +++ b/beaker/line.cpp @@ -1,4 +1,6 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/line.hpp" diff --git a/beaker/location.cpp b/beaker/location.cpp index 250a952..8728190 100644 --- a/beaker/location.cpp +++ b/beaker/location.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/location.hpp" #include "beaker/file.hpp" diff --git a/beaker/mangle.cpp b/beaker/mangle.cpp index a81dc73..9023898 100644 --- a/beaker/mangle.cpp +++ b/beaker/mangle.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/mangle.hpp" #include "beaker/type.hpp" #include "beaker/decl.hpp" @@ -50,18 +52,21 @@ mangle(std::ostream& os, Integer_type const* t) os << (t->is_signed()?"":"u") << 'i' << std::to_string(t->precision()); } + void mangle(std::ostream& os, Float_type const* t) { os << 'f'; } + void mangle(std::ostream& os, Double_type const* t) { os << 'd'; } + // 'F' p* r // // Note that p* expands to the sequence @@ -219,7 +224,6 @@ mangle(std::ostream& os, Module_decl const* d) void mangle(std::ostream& os, Decl const* d) { - struct Fn { std::ostream& os; diff --git a/beaker/options.cpp b/beaker/options.cpp index 2835bd5..c2914c7 100644 --- a/beaker/options.cpp +++ b/beaker/options.cpp @@ -1,4 +1,6 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/options.hpp" diff --git a/beaker/overload.cpp b/beaker/overload.cpp index 9f349c2..4967a58 100644 --- a/beaker/overload.cpp +++ b/beaker/overload.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/overload.hpp" #include "beaker/type.hpp" #include "beaker/decl.hpp" @@ -28,7 +30,6 @@ same_parameters(Function_decl const* f1, Function_decl const* f2) return t1->parameter_types() == t2->parameter_types(); } - } // namespace diff --git a/beaker/parser.cpp b/beaker/parser.cpp index c5b4f83..06df0cc 100644 --- a/beaker/parser.cpp +++ b/beaker/parser.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/parser.hpp" #include "beaker/symbol.hpp" #include "beaker/type.hpp" @@ -35,7 +37,7 @@ Parser::primary_expr() // integer-literal if (Token tok = match_if(integer_tok)) return on_int(tok); - + // floating-point-literal if (Token tok = match_if(floating_tok)) return on_float(tok); @@ -50,7 +52,7 @@ Parser::primary_expr() // NOTE NOTE NOTE // Lambda additions - if (lookahead() == f_slash_tok) + if (lookahead() == bslash_tok) return lambda_expr(); // paren-expr @@ -66,8 +68,6 @@ Parser::primary_expr() } - - // Parse a postfix expression. // // postfix-expression -> postfix-expression '(' argument-list ')' @@ -115,6 +115,7 @@ Parser::postfix_expr() return e1; } + // Parse a unary expression. // // unary-expr -> '+' unary-expr @@ -167,7 +168,6 @@ Parser::multiplicative_expr() } - // Parse an additive expression. // // additive-expr -> additive-expr '*' multiplicative-expr @@ -296,7 +296,7 @@ Parser::logical_or_expr() Expr* Parser::lambda_expr() { - require(f_slash_tok); + require(bslash_tok); //Match the identifier inserted earlier Token n = match(identifier_tok); @@ -329,7 +329,6 @@ Parser::lambda_expr() } - Expr* Parser::expr() { @@ -370,55 +369,55 @@ Parser::primary_type() // int else if (match_if(int_kw)) return get_integer_type(); - + // uint else if (match_if(uint_kw)) return get_integer_type(false); - + // short else if (match_if(short_kw)) return get_integer_type(16); - + // ushort else if (match_if(ushort_kw)) - return get_integer_type(false,16); - + return get_integer_type(false, 16); + // long else if (match_if(long_kw)) return get_integer_type(64); - + // ulong else if (match_if(ulong_kw)) - return get_integer_type(false,64); - + return get_integer_type(false, 64); + // int16 else if (match_if(int16_kw)) return get_integer_type(16); - + // uint16 else if (match_if(uint16_kw)) - return get_integer_type(false,16); - + return get_integer_type(false, 16); + // int32 else if (match_if(int32_kw)) return get_integer_type(); - + // uint32 else if (match_if(uint32_kw)) return get_integer_type(false); - + // int64 else if (match_if(int64_kw)) return get_integer_type(64); - + // uint64 else if (match_if(uint64_kw)) - return get_integer_type(false,64); - + return get_integer_type(false, 64); + // float else if (match_if(float_kw)) return get_float_type(); - + // double else if (match_if(double_kw)) return get_double_type(); @@ -499,7 +498,6 @@ Parser::type() } - // -------------------------------------------------------------------------- // // Declaration parsing @@ -760,7 +758,7 @@ Parser::decl() return variable_decl(spec); case def_kw: return function_decl(spec); - case f_slash_tok: + case bslash_tok: // case struct_kw: return record_decl(spec); @@ -957,7 +955,7 @@ Parser::stmt() case var_kw: case def_kw: case foreign_kw: - case f_slash_tok: + case bslash_tok: return declaration_stmt(); default: @@ -1154,6 +1152,7 @@ Parser::on_int(Token tok) return init(tok.location(), t, v); } + Expr* Parser::on_float(Token tok) { @@ -1162,6 +1161,7 @@ Parser::on_float(Token tok) return init(tok.location(), t, v); } + Expr* Parser::on_char(Token tok) { @@ -1328,6 +1328,7 @@ Parser::on_dot(Expr* e1, Expr* e2) return new Dot_expr(e1, e2); } + // NOTE NOTE NOTE // ADDITIONS FOR LAMBDAS //Lambda_expr(Symbol * s, Decl_seq const& d, Type const * t, Stmt* const& b) @@ -1338,6 +1339,7 @@ Parser::on_lambda(Token tok, Decl_seq const& p, Type const* t, Stmt* b) return init(tok.location(), tok.symbol(), p, f, b); } + // TODO: Check declaration specifiers. Not every specifier // makes sense in every combination or for every declaration. // A foreign parameter is not particularly useful. diff --git a/beaker/prelude.cpp b/beaker/prelude.cpp index 65162af..6e6d885 100644 --- a/beaker/prelude.cpp +++ b/beaker/prelude.cpp @@ -1,4 +1,6 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/prelude.hpp" diff --git a/beaker/prelude.hpp b/beaker/prelude.hpp index ce90785..61e8b9a 100644 --- a/beaker/prelude.hpp +++ b/beaker/prelude.hpp @@ -4,8 +4,6 @@ #ifndef BEAKER_PRELUDE_HPP #define BEAKER_PRELUDE_HPP -#include - #include #include #include diff --git a/beaker/print.cpp b/beaker/print.cpp index 4396295..d57f1cb 100644 --- a/beaker/print.cpp +++ b/beaker/print.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/print.hpp" #include "beaker/expr.hpp" #include "beaker/decl.hpp" diff --git a/beaker/scope.cpp b/beaker/scope.cpp index 52282d3..b0aef2f 100644 --- a/beaker/scope.cpp +++ b/beaker/scope.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/scope.hpp" #include "beaker/decl.hpp" diff --git a/beaker/specifier.cpp b/beaker/specifier.cpp index d60aa5e..b0ce9cb 100644 --- a/beaker/specifier.cpp +++ b/beaker/specifier.cpp @@ -1,4 +1,6 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/specifier.hpp" diff --git a/beaker/stmt.cpp b/beaker/stmt.cpp index 7022770..650f6aa 100644 --- a/beaker/stmt.cpp +++ b/beaker/stmt.cpp @@ -1,4 +1,6 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/stmt.hpp" diff --git a/beaker/symbol.cpp b/beaker/symbol.cpp index c6ca721..ea47a32 100644 --- a/beaker/symbol.cpp +++ b/beaker/symbol.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/symbol.hpp" diff --git a/beaker/token.cpp b/beaker/token.cpp index 5b7376b..09ab816 100644 --- a/beaker/token.cpp +++ b/beaker/token.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/token.hpp" @@ -40,39 +42,37 @@ spelling(Token_kind k) case amp_tok: return "&"; case arrow_tok: return "->"; case tilde_tok: return "~"; - case f_slash_tok: return "\\"; + case bslash_tok: return "\\"; case abstract_kw: return "abstract"; case bool_kw: return "bool"; case break_kw: return "break"; case char_kw: return "char"; case continue_kw: return "continue"; case def_kw: return "def"; + case double_kw: return "double"; case else_kw: return "else"; + case float_kw: return "float"; case foreign_kw: return "else"; case if_kw: return "if"; + case int16_kw: return "int16"; + case int32_kw: return "int32"; + case int64_kw: return "int64"; + case int_kw: return "int"; + case long_kw: return "long"; case return_kw: return "return"; + case short_kw: return "short"; case struct_kw: return "struct"; case this_kw: return "this"; case trivial_kw: return "trivial"; - case var_kw: return "var"; - case virtual_kw: return "virtual"; - case while_kw: return "while"; - case int_kw: return "int"; - case uint_kw: return "uint"; - case short_kw: return "short"; - case ushort_kw: return "ushort"; - case long_kw: return "long"; - case ulong_kw: return "ulong"; - case int16_kw: return "int16"; case uint16_kw: return "uint16"; - case int32_kw: return "int32"; case uint32_kw: return "uint32"; - case int64_kw: return "int64"; case uint64_kw: return "uint64"; - case float_kw: return "float"; - case double_kw: return "double"; - - + case uint_kw: return "uint"; + case ulong_kw: return "ulong"; + case ushort_kw: return "ushort"; + case var_kw: return "var"; + case virtual_kw: return "virtual"; + case while_kw: return "while"; default: return ""; } } @@ -113,10 +113,7 @@ init_symbols(Symbol_table& syms) syms.put("&", amp_tok); syms.put("->", arrow_tok); syms.put("~", tilde_tok); - - //NOTE NOTE NOTE NOTE NOTE NOTE - //ADDITIONS - syms.put("\\", f_slash_tok); + syms.put("\\", bslash_tok); // Keywords syms.put("abstract", abstract_kw); @@ -125,32 +122,32 @@ init_symbols(Symbol_table& syms) syms.put("char", char_kw); syms.put("continue", continue_kw); syms.put("def", def_kw); + syms.put("double", double_kw); syms.put("else", else_kw); + syms.put("float", float_kw); syms.put("foreign", foreign_kw); syms.put("if", if_kw); + syms.put("int", int_kw); + syms.put("int16", int16_kw); + syms.put("int32", int32_kw); + syms.put("int64", int64_kw); + syms.put("long", long_kw); syms.put("return", return_kw); + syms.put("short", short_kw); syms.put("struct", struct_kw); syms.put("this", this_kw); syms.put("trivial", trivial_kw); - syms.put("var", var_kw); - syms.put("int", int_kw); syms.put("uint", uint_kw); - syms.put("short", short_kw); - syms.put("ushort", ushort_kw); - syms.put("long", long_kw); - syms.put("ulong", ulong_kw); - syms.put("int16", int16_kw); syms.put("uint16", uint16_kw); - syms.put("int32", int32_kw); syms.put("uint32", uint32_kw); - syms.put("int64", int64_kw); syms.put("uint64", uint64_kw); - syms.put("float", float_kw); - syms.put("double", double_kw); + syms.put("ulong", ulong_kw); + syms.put("ushort", ushort_kw); + syms.put("var", var_kw); syms.put("virtual", virtual_kw); syms.put("while", while_kw); - // Reserved names. + // Reserved names syms.put("true", boolean_tok, true); syms.put("false", boolean_tok, false); diff --git a/beaker/token.hpp b/beaker/token.hpp index 4970d97..40c9f53 100644 --- a/beaker/token.hpp +++ b/beaker/token.hpp @@ -52,10 +52,7 @@ enum Token_kind amp_tok, arrow_tok, tilde_tok, - - //NOTE NOTE NOTE NOTE NOTE - //ADDITIONS - f_slash_tok, + bslash_tok, // Keywords abstract_kw, @@ -64,30 +61,30 @@ enum Token_kind char_kw, continue_kw, def_kw, + double_kw, else_kw, + float_kw, foreign_kw, if_kw, + int16_kw, + int32_kw, + int64_kw, + int_kw, + long_kw, return_kw, + short_kw, struct_kw, this_kw, trivial_kw, - var_kw, - virtual_kw, - while_kw, - int_kw, - uint_kw, - short_kw, - ushort_kw, - long_kw, - ulong_kw, - int16_kw, uint16_kw, - int32_kw, uint32_kw, - int64_kw, uint64_kw, - float_kw, - double_kw, + uint_kw, + ulong_kw, + ushort_kw, + var_kw, + virtual_kw, + while_kw, // Multi-valued tokens boolean_tok, // true | false diff --git a/beaker/translator.cpp b/beaker/translator.cpp index 9c07986..1e6c367 100644 --- a/beaker/translator.cpp +++ b/beaker/translator.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/options.hpp" #include "beaker/job.hpp" #include "beaker/lexer.hpp" @@ -73,7 +75,7 @@ translator_main(int argc, char* argv[]) .run(), vm); po::notify(vm); - } catch(std::exception& err) { + } catch (std::exception& err) { std::cerr << "error: " << err.what() << "\n\n"; usage(std::cerr, all); return -1; diff --git a/beaker/type.cpp b/beaker/type.cpp index 91fc11d..4684f1c 100644 --- a/beaker/type.cpp +++ b/beaker/type.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/type.hpp" #include "beaker/decl.hpp" #include "beaker/less.hpp" @@ -54,7 +56,6 @@ Record_type::scope() const } - // Returns the size of the array as an // integer value. int @@ -112,36 +113,36 @@ Type const* get_integer_type(bool is_signed, int precision) { static Integer_type st16(16); - static Integer_type ut16(false,16); + static Integer_type ut16(false, 16); static Integer_type st32(32); static Integer_type ut32(false); static Integer_type st64(64); - static Integer_type ut64(false,64); - - if (is_signed) - switch (precision) - { - case 32: - return &st32; - case 16: - return &st16; - case 64: - return &st64; - default: - throw std::runtime_error("No integer with precision " + std::to_string(precision)); + static Integer_type ut64(false, 64); + + if (is_signed) { + switch (precision) { + case 32: + return &st32; + case 16: + return &st16; + case 64: + return &st64; + default: + throw std::runtime_error("No integer with precision " + std::to_string(precision)); } - else - switch (precision) - { - case 32: - return &ut32; - case 16: - return &ut16; - case 64: - return &ut64; - default: - throw std::runtime_error("No integer with precision " + std::to_string(precision)); + } + else { + switch (precision) { + case 32: + return &ut32; + case 16: + return &ut16; + case 64: + return &ut64; + default: + throw std::runtime_error("No integer with precision " + std::to_string(precision)); } + } } @@ -217,50 +218,53 @@ get_record_type(Record_decl* r) return &*ins.first; } + // Gets the rank of a type int get_scalar_rank(Type const* t) { - // static types - static Type const* b = get_boolean_type(); - static Type const* c = get_character_type(); - static Type const* ui16 = get_integer_type(false,16); - static Type const* i16 = get_integer_type(16); - static Type const* ui32 = get_integer_type(false); - static Type const* i32 = get_integer_type(); - static Type const* ui64 = get_integer_type(false,64); - static Type const* i64 = get_integer_type(64); - static Type const* f = get_float_type(); - static Type const* d = get_double_type(); - - // return rank - if (t == b) - return bool_rnk; - if (t == c) - return char_rnk; - if (t == ui16) - return uint16_rnk; - if (t == i16) - return int16_rnk; - if (t == ui32) - return uint32_rnk; - if (t == i32) - return int32_rnk; - if (t == ui64) - return uint64_rnk; - if (t == i64) - return int64_rnk; - if (t == f) - return float_rnk; - if (t == d) - return double_rnk; - - // default case - return default_rnk; + // static types + static Type const* b = get_boolean_type(); + static Type const* c = get_character_type(); + static Type const* ui16 = get_integer_type(false, 16); + static Type const* i16 = get_integer_type(16); + static Type const* ui32 = get_integer_type(false); + static Type const* i32 = get_integer_type(); + static Type const* ui64 = get_integer_type(false, 64); + static Type const* i64 = get_integer_type(64); + static Type const* f = get_float_type(); + static Type const* d = get_double_type(); + + // return rank + if (t == b) + return bool_rnk; + if (t == c) + return char_rnk; + if (t == ui16) + return uint16_rnk; + if (t == i16) + return int16_rnk; + if (t == ui32) + return uint32_rnk; + if (t == i32) + return int32_rnk; + if (t == ui64) + return uint64_rnk; + if (t == i64) + return int64_rnk; + if (t == f) + return float_rnk; + if (t == d) + return double_rnk; + + // default case + return default_rnk; } + bool -is_derived(Type const* derived, Type const* base){ +is_derived(Type const* derived, Type const* base) +{ if (Record_type const* d = as(derived)) { if (Record_type const* b = as(base)) { // If D and B are the same return true diff --git a/beaker/value.cpp b/beaker/value.cpp index e55d323..85f3bee 100644 --- a/beaker/value.cpp +++ b/beaker/value.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2015 Andrew Sutton // All rights reserved +#include "config.hpp" + #include "beaker/value.hpp" #include "beaker/decl.hpp" @@ -91,6 +93,7 @@ zero_init(Integer_value& v) v = 0; } + // Set to 0. inline void zero_init(Float_value& v) @@ -131,6 +134,7 @@ zero_init(Aggregate_value& v) zero_init(v.data[i]); } + // Zero initialzie the value. void zero_init(Value& v) diff --git a/config.hpp.in b/config.hpp.in new file mode 100644 index 0000000..f420010 --- /dev/null +++ b/config.hpp.in @@ -0,0 +1,113 @@ +// Copyright (c) 2015 Andrew Sutton +// All rights reserved + +/* config.hpp. Generated from config.hpp.in by cmake. */ + +#ifndef BEAKER_CONFIG_HPP +#define BEAKER_CONFIG_HPP + +/* Name of package. */ +#define PACKAGE "@PACKAGE_NAME@" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "@PACKAGE_TARNAME@" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "@PACKAGE_URL@" + +/* Version number of package. */ +#define VERSION "@PACKAGE_VERSION@" + + +// Tools +#define LLVM_IR_COMPILER "@LLVM_IR_COMPILER@" +#define NATIVE_C_COMPILER "@CMAKE_C_COMPILER@" +#define NATIVE_AS "@CMAKE_C_COMPILER@" +#define NATIVE_LD "@CMAKE_C_COMPILER@" +#define NATIVE_AR "@CMAKE_AR@" + +// File properties +#define OBJECT_SUFFIX "@CMAKE_C_OUTPUT_EXTENSION@" +#define EXECUTABLE_SUFFIX "@CMAKE_EXECUTABLE_SUFFIX@" +#define LIBRARY_PREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@" +#define LIBRARY_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@" +#define ARCHIVE_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@" +#define ARCHIVE_SUFFIX "@CMAKE_STATIC_LIBRARY_SUFFIX@" + + +inline char const* +llvm_compiler() +{ + return LLVM_IR_COMPILER; +} + + +inline char const* +native_c_compiler() +{ + return NATIVE_C_COMPILER; +} + + +inline char const* +native_assembler() +{ + return NATIVE_AS; +} + + +inline char const* +native_archiver() +{ + return NATIVE_AR; +} + + +inline char const* +native_linker() +{ + return NATIVE_LD; +} + + +inline char const* +object_extension() +{ + return OBJECT_SUFFIX; +} + + +inline char const* +executable_extension() +{ + return EXECUTABLE_SUFFIX; +} + + +inline char const* +library_extension() +{ + return LIBRARY_SUFFIX; +} + + +inline char const* +archive_extension() +{ + return ARCHIVE_SUFFIX; +} + + +#endif diff --git a/lingo b/lingo index d337f06..26865ba 160000 --- a/lingo +++ b/lingo @@ -1 +1 @@ -Subproject commit d337f061935a05978dba95b99ebda2828525a2f9 +Subproject commit 26865ba57507ad94b83d2f850a4af75543f0ac20