{"id":15048021,"url":"https://github.com/treefrogframework/cpi","last_synced_at":"2025-04-07T13:07:55.321Z","repository":{"id":5851816,"uuid":"7068470","full_name":"treefrogframework/cpi","owner":"treefrogframework","description":"Tiny c++ interpreter","archived":false,"fork":false,"pushed_at":"2024-04-15T05:33:26.000Z","size":104,"stargazers_count":190,"open_issues_count":1,"forks_count":34,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-05-02T01:05:35.382Z","etag":null,"topics":["c-plus-plus","cpp","cpp14","cpp17","cpp20","interpreter"],"latest_commit_sha":null,"homepage":"https://treefrogframework.github.io/cpi/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/treefrogframework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"treefrogframework"}},"created_at":"2012-12-08T14:45:36.000Z","updated_at":"2024-04-15T05:19:33.000Z","dependencies_parsed_at":"2024-04-14T01:43:49.961Z","dependency_job_id":"acfafe3e-5698-4c67-a755-34b1fbebecbb","html_url":"https://github.com/treefrogframework/cpi","commit_stats":{"total_commits":80,"total_committers":3,"mean_commits":"26.666666666666668","dds":0.1875,"last_synced_commit":"360f67e2c26528637438f8305469493a0e494b78"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treefrogframework%2Fcpi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treefrogframework%2Fcpi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treefrogframework%2Fcpi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treefrogframework%2Fcpi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treefrogframework","download_url":"https://codeload.github.com/treefrogframework/cpi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","cpp","cpp14","cpp17","cpp20","interpreter"],"created_at":"2024-09-24T21:07:00.073Z","updated_at":"2025-04-07T13:07:55.302Z","avatar_url":"https://github.com/treefrogframework.png","language":"C++","readme":"# Tiny C++ Interpreter\n\n[![ActionsCI](https://github.com/treefrogframework/cpi/actions/workflows/actions.yml/badge.svg)](https://github.com/treefrogframework/cpi/actions/workflows/actions.yml)\n[![License](https://img.shields.io/badge/license-MIT-blue)](https://opensource.org/licenses/MIT)\n[![Release](https://img.shields.io/github/v/release/treefrogframework/cpi.svg)](https://github.com/treefrogframework/cpi/releases)\n\nCpi is a tiny interpreter for C++17 or C++20.\n\n## Requirements\nThe following softwares are needed to build and execute cpi.\nThe compiler is used as interpreter of cpi internally.\n  * Qt tookit version 6\n  * Compiler - GNU C++ compiler, LLVM C++ compiler or MSVC C++ compiler\n\n## Install\n\nLinux:\n```sh\n$ qmake\n$ make\n$ sudo make install\n$ cpi -v\ncpi 2.2.0\n```\n\nWindows (Command prompt for VS2022):\n```bat\n**********************************************************************\n** Visual Studio 2022 Developer Command Prompt v17.9.6\n** Copyright (c) 2022 Microsoft Corporation\n**********************************************************************\n[vcvarsall.bat] Environment initialized for: 'x64'\n\n\u003e C:\\Qt\\6.7.0\\msvc2019_64\\bin\\qtenv2.bat\nSetting up environment for Qt usage...\n\u003e cd (cpi root directory)\n\u003e qmake\n\u003e nmake\n\u003e cpi.bat -h        (Run cpi command)\nUsage: cpi.exe [options] [file] [-]\nTiny C++ Interpreter.\nRuns in interactive mode by default.\n\nOptions:\n  -?, -h, --help  Displays help on commandline options.\n  --help-all      Displays help, including generic Qt options.\n  -v, --version   Displays version information.\n\nArguments:\n  file            File to compile.\n  -               Reads from stdin.\n```\n\n## Interactive Mode\n\n```\n  $ cpi           (Run cpi.bat in windows)\n  cpi 2.2.0\n  Type \".help\" for more information.\n  Loaded INI file: /home/foo/.config/cpi/cpi.conf\n\n  cpi\u003e 3 \u003c\u003c 23;        (Bitwise operation)\n  25165824\n\n  cpi\u003e int a = 3;\n  cpi\u003e ~a;              (Complement)\n  -4\n  cpi\u003e a ^ 2;           (XOR)\n  1\n\n  cpi\u003e auto func = [](int n) { return n*n; };     (Lambda function)\n  cpi\u003e func(3);\n  9\n\n  cpi\u003e .quit         ( or press ctrl+c )\n```\n\nCode can be pasted.\n```cpp\n  $ cpi              (Run cpi.bat in windows)\n  cpi\u003e #include \u003cmap\u003e         (Paste code here)\n  #include \u003ciostream\u003e\n\n  int main()\n  {\n    std::map\u003cint, std::string\u003e m = { {1, \"one\"}, {2, \"two\"} };\n    if (auto it = m.find(2); it != m.end()) {\n      std::cout \u003c\u003c it-\u003esecond \u003c\u003c std::endl;\n    }\n  }              (Press enter)\n  two            (The result of the executed output)\n```\n\n## Executive mode\nSave C++ source code as *hello.cpp*.\n\n```cpp\n#include \u003ciostream\u003e\n\nint main()\n{\n    std::cout \u003c\u003c \"Hello world\\n\";\n    return 0;\n}\n```\n\nRun cpi in command line.\n\n```sh\n  $ cpi hello.cpp\n  Hello world\n```\n\nImmediately compiled and executed! Almost a script language, but the source file is also C++ program which a compiler can compile successfully.\n\nNext code outputs a square root of input argument.\nSpecify options for compiler or linker with \"CompileOptions: \" word. In this example, linking math library specified by \"-lm\" option.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003ccmath\u003e\n#include \u003ccstdlib\u003e\n\nint main(int argc, char *argv[])\n{\n    if (argc != 2) return 0;\n\n    std::cout \u003c\u003c sqrt(atoi(argv[1])) \u003c\u003c std::endl;\n    return 0;\n}\n// CompileOptions: -lm\n```\n\n```sh\n  $ cpi sqrt.cpp 2\n  1.41421\n\n  $ cpi sqrt.cpp 3\n  1.7320\n```\n\nFurthermore, pkg-config command can be used for *CompileOptions*.\n\n```cpp\n#include \u003ccblas.h\u003e\n#include \u003ciostream\u003e\n\nint main()\n{\n    // 2x2 Matrix\n    int M = 2, N = 2, K = 2;\n    double A[4] = {1.0, 2.0, 3.0, 4.0};\n    double B[4] = {5.0, 6.0, 7.0, 8.0};\n    double C[4];\n\n    // General Matrix-Matrix multiplication\n    cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,\n        M, N, K,\n        1.0, A, K, B, N,\n        0.0, C, N);\n\n    // Print results\n    std::cout \u003c\u003c \"Result of A * B = C:\" \u003c\u003c std::endl;\n    for (int i = 0; i \u003c 2; ++i) {\n        for (int j = 0; j \u003c 2; ++j) {\n            std::cout \u003c\u003c C[i * 2 + j] \u003c\u003c \" \";\n        }\n        std::cout \u003c\u003c std::endl;\n    }\n    return 0;\n}\n\n// CompileOptions: `pkg-config --cflags --libs openblas`\n```\n\n```sh\n $ cpi dgemm.cpp\n Result of A * B = C:\n 19 22\n 43 50\n```\n\nQt application can also be run.\n\n```cpp\n#include \u003cQApplication\u003e\n#include \u003cQLabel\u003e\n\nint main(int argc, char *argv[])\n{\n    QApplication app(argc, argv);\n    QLabel label(\"Hello, world!\");\n    label.setAlignment(Qt::AlignCenter);\n    label.setWindowTitle(\"Hello\");\n    label.resize(200, 100);\n    label.show();\n    return app.exec();\n}\n\n// CompileOptions: `pkg-config --cflags --libs Qt6Widgets`\n```\n\n```sh\n $ cpi helloworld_qt.cpp\n```\n\n#### Running like a scripting language\nAdding a shebang, save as *hello.cpps*. No longer compiled in a C++ compiler successfully.\n\n```cpp\n#!/usr/bin/env cpi\n#include \u003ciostream\u003e\n\nint main()\n{\n    std::cout \u003c\u003c \"Hello world\\n\";\n    return 0;\n}\n```\n\n```sh\n  $ chmod +x hello.cpps\n  $ ./hello.cpps\n  Hello world\n```\n\nYes, a shell script. I named it CppScript.\n\n## Help\n\n```\n  cpi\u003e .help\n   .conf        Display the current values for various settings.\n   .help        Display this help.\n   .rm LINENO   Remove the code of the specified line number.\n   .show        Show the current source code.\n   .quit        Exit this program.\n```\n\n## Download\n [Download Page](https://github.com/treefrogframework/cpi/releases)\n\n\n## Web Site\n http://treefrogframework.github.io/cpi/\n","funding_links":["https://github.com/sponsors/treefrogframework"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreefrogframework%2Fcpi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreefrogframework%2Fcpi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreefrogframework%2Fcpi/lists"}