treefrogframework / Cpi

Tiny c++ interpreter

Programming Languages

cpp
1120 projects
cpp11
221 projects
cpp14
131 projects

Projects that are alternatives of or similar to Cpi

Aceto
A programming language based on a 2D Hilbert curve grid
Stars: ✭ 83 (-28.45%)
Mutual labels:  interpreter
Root
The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
Stars: ✭ 1,377 (+1087.07%)
Mutual labels:  interpreter
Dummylua Tutorial
这是一个仿制lua解释器的项目,我希望通过逐步实现lua解释器的各个部分,更加深刻地掌握lua的基本结构和运作原理。
Stars: ✭ 108 (-6.9%)
Mutual labels:  interpreter
Hdbf
Hyper-Dimensional Brainfuck
Stars: ✭ 87 (-25%)
Mutual labels:  interpreter
Mages
🎩 MAGES is a very simple, yet powerful, expression parser and interpreter.
Stars: ✭ 92 (-20.69%)
Mutual labels:  interpreter
Endbasic
BASIC environment with a REPL, a web interface, and RPi support written in Rust
Stars: ✭ 106 (-8.62%)
Mutual labels:  interpreter
Xstateful
A wrapper for xstate that stores state, handles transitions, emits events for state changes and actions/activities, and includes an optional reducer framework for updating state and invoking side-effects
Stars: ✭ 81 (-30.17%)
Mutual labels:  interpreter
Brain
An esoteric programming language compiler on top of LLVM based on Brainfuck
Stars: ✭ 112 (-3.45%)
Mutual labels:  interpreter
Sniprun
A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
Stars: ✭ 93 (-19.83%)
Mutual labels:  interpreter
Libforth
libforth: A small Forth interpreter that can be used as a library written in c99
Stars: ✭ 107 (-7.76%)
Mutual labels:  interpreter
Magpie
🐦 Successor of my monkey Interpreter(support for class, linq, sql, net, http, fmt, json and A realtime syntax highlighting REPL).
Stars: ✭ 88 (-24.14%)
Mutual labels:  interpreter
Wasm Forth
A Forth implementation compiling to WebAssembly.
Stars: ✭ 92 (-20.69%)
Mutual labels:  interpreter
Angu
A small DSL/interpreter that can be used to evaluate simple expressions
Stars: ✭ 105 (-9.48%)
Mutual labels:  interpreter
Abrvalg
Python-like programming language interpreter written in Python
Stars: ✭ 83 (-28.45%)
Mutual labels:  interpreter
Quickjs
The official repo is at bellard/quickjs.
Stars: ✭ 1,429 (+1131.9%)
Mutual labels:  interpreter
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-29.31%)
Mutual labels:  interpreter
Lispe
An implementation of a full fledged Lisp interpreter with Data Structure, Pattern Programming and High level Functions with Lazy Evaluation à la Haskell.
Stars: ✭ 105 (-9.48%)
Mutual labels:  interpreter
Pointless
Pointless: a scripting language for learning and fun
Stars: ✭ 116 (+0%)
Mutual labels:  interpreter
Apple Juice Actionscript
Pure .NET 2.0 code Implementation of the ActionScript3 compiler and runtime. Can be used to run scripts in environments where "just-in-time compilation" is not possible
Stars: ✭ 112 (-3.45%)
Mutual labels:  interpreter
Swiftylisp
A minimal LISP implemented in Swift
Stars: ✭ 106 (-8.62%)
Mutual labels:  interpreter

Tiny C++ Interpreter

Cpi is a tiny interpreter for C++11 or C++14.

Requirements

The following softwares are needed to build and execute cpi. The compilers are used as interpreter of cpi internally.

  • Qt tookit
  • Compiler - GNU C++ compiler, LLVM C++ compiler or MSVC C++ compiler

Install

Linux:

  $ qmake
  $ make
  $ sudo make install

Windows:

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.17
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

> C:\Qt\5.13.2\msvc2017_64\bin\qtenv2.bat
Setting up environment for Qt usage...
> cd (cpi root directory)
> qmake
> nmake

Interactive Mode

  $ cpi
  Cpi 2.0.0
  Type ".help" for more information.
  Loaded INI file: /home/foo/.config/cpi/cpi.conf

  cpi> 3 << 23;        (Bitwise operation)
  25165824
  
  cpi> int a = 3;
  cpi> ~a;              (Complement)
  -4
  cpi> a ^ 2;           (XOR)
  1
  
  cpi> auto func = [](int n) { return n*n; };     (Lambda function)
  cpi> func(3);
  9
    
  cpi> .quit         ( or press ctrl+c )

Executive mode

Save C++ source code as hello.cpp.

#include <iostream>

int main()
{
    std::cout << "Hello world\n";
    return 0;
}

Run cpi in command line.

  $ cpi hello.cpp
  Hello world

Immediately compiled and executed! Almost a script language, but the source file is also C++ program which a compiler can compile successfully.

Next code outputs a square root of input argument.
Specify options for compiler or linker with "CompileOptions: " word. In this example, linking math library specified by "-lm" option.

#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
    if (argc != 2) return 0;

    cout << sqrt(atoi(argv[1])) << endl;
    return 0;
}
// CompileOptions: -lm
  $ cpi sqrt.cpp 2
  1.41421

  $ cpi sqrt.cpp 3
  1.7320

Running like a scripting language

Adding a shebang, save as hello.cpps. No longer compiled in a C++ compiler successfully.

#!/usr/bin/env cpi
#include <iostream>

int main()
{
    std::cout << "Hello world\n";
    return 0;
}
  $ chmod +x hello.cpps
  $ ./hello.cpps
  Hello world

Yes, a shell script. I named it CppScript.

Help

  cpi> .help
   .conf        Display the current values for various settings.
   .help        Display this help.
   .rm LINENO   Remove the code of the specified line number.
   .show        Show the current source code.
   .quit        Exit this program.

Download

Download Page

Web Site

http://treefrogframework.github.io/cpi/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].