Giter Club home page Giter Club logo

compile-time-dynamic-language's Introduction

Compile Time Dynamic Language

Aim of project:

Implement a dynamically typed language in C++ that is evaluated 100% at compile time.

Example Usage

main.cpp contains the following working example:

// pseudo code example
/*
x = 6
y = 2 + x
z = (y * 10) + 7
text = "Hello "
text2 = text + "World!"
bool = !true
ifmodified = false
if 1:
   temp = 10
   ifmodified = true
*/


// equivalent code in C++ here | entirely evaluated at compile time
using code = Execute<TypeStackEmptyNode,
                     Assign<"x", Val<6>>,
                     Assign<"y", Apply<std::plus<>, Val<2>, Var<"x">>>,
                     Assign<"z", Apply<std::plus<>, Apply<std::multiplies<>, Var<"y">, Val<10>>, Val<7>>>,
                     Assign<"text", ValStr<"Hello ">>,
                     Assign<"text2", Apply<std::plus<>, Var<"text">, ValStr<"World!">>>,
                     Assign<"bool", Apply<std::logical_not<>, Val<true>>>,
                     Assign<"ifmodified", Val<false>>,
                     If<Val<1>, 
                        Assign<"temp", Val<10>>,
                        Assign<"ifmodified", Val<true>>>>;


// tests
static_assert(SymbolTableGetValue<NONE, code::values, "x">::value == 6); // basic non modified variable init
static_assert(SymbolTableGetValue<NONE, code::values, "y">::value == 8); // basic evaluation of expression using Apply and ID lookup using Var
static_assert(SymbolTableGetValue<NONE, code::values, "z">::value == 87); // chained expression test
constexpr string_literal teststring = "Hello World!";
static_assert(SymbolTableGetValue<NONE, code::values, "text2">::value == teststring); // string concat test
static_assert(!SymbolTableGetValue<NONE, code::values, "bool">::value); // bool test
static_assert(SymbolTableGetValue<NONE, code::values, "temp">::value == NONE); // GOOD we lose values on the temp if scope
static_assert(SymbolTableGetValue<NONE, code::values, "ifmodified">::value); // GOOD we successfully modified variable in outer scope

Approach

The language will be implemented as a tree-walk interpreter which makes use of nodes that perform operations.

Compiler

GCC-11 /std:c++20

Milestones:

  1. Implement basic chainable expressions such as binary ops for float/number types ✔️
  2. Implement variables using lookup table. ✔️
  3. Implement boolean and string types. ✔️
  4. Implement basic error messages for type related errors to expressions.
  5. Implement basic control flow through if statements. ✔️
  6. Implement for loops.
  7. Implement methods.
  8. Have language parsed through string literal instead of type declarations.

compile-time-dynamic-language's People

Contributors

tmshaer avatar

Stargazers

 avatar

Watchers

 avatar

compile-time-dynamic-language's Issues

Cross-Compability

This fails to work even for GCC 9.2. It's a really cool concept but has a lot of bugs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.