IOT>> Ark>> 返回
项目作者: ArkScript-lang

项目描述 :
ArkScript is a small, fast, functional and scripting language for C++ projects
高级语言: C++
项目地址: git://github.com/ArkScript-lang/Ark.git
创建时间: 2019-06-03T09:52:14Z
项目社区:https://github.com/ArkScript-lang/Ark

开源协议:Mozilla Public License 2.0

下载


" class="reference-link">ArkScript Latest version

Code size
Downloads
GitHub Workflow Status
Coverage
CodSpeed Badge

ArkScript log by Mazz

Nota bene: the project is referred as “Ark” and as “ArkScript”. The official public name is “ArkScript” since “Ark” is already being used by another language

Key features

ArkScript is

  • small: the core fit under 8000 lines of code ; also small in terms of keywords (only 9)
  • a scripting language: very easy to embed it in your projects. Registering your own functions in the language is made easy
  • portable: a unique bytecode which can be run everywhere the virtual machine is
  • a functional language: every parameter is passed by value, everything is immutable unless specified
  • powerful: provides closures and explicit capture
  • promoting functionalities before performances: expressiveness often brings more productivity, though performances aren’t left behind
  • a Lisp inspired language, with fewer parentheses: [...] is expanded to (list ...) and {} to (begin ...)
  • extensible: supports C++ module to use it in the language, adding functionalities

Also, it has:

  • macros: if/else, values, and functions
  • tail call optimization
  • a REPL with autocompletion and coloration
  • a growing standard library, composed of ArkScript code (under lib/std/) and C++ (under lib/modules/)
  • a lot of unit tests (but never enough), which are ran before every release to ensure everything works as expected
  • docker images:
    • stable, built after each release
    • nightly, built after each commit

Examples

Fibonacci suite

  1. (let fibo (fun (n)
  2. (if (< n 2)
  3. n
  4. (+ (fibo (- n 1)) (fibo (- n 2))))))
  5. (print (fibo 28)) # display 317811

More or less game

  1. (let number (random 0 10000))
  2. (let game (fun () {
  3. (let impl (fun (tries) {
  4. (let guess (toNumber (input "Input a numeric value: ")))
  5. (if (< guess number)
  6. {
  7. (print "It's more than " guess)
  8. (impl (+ tries 1)) }
  9. (if (= guess number)
  10. {
  11. (print "You found it!")
  12. tries }
  13. {
  14. (print "It's less than " guess)
  15. (impl (+ tries 1)) }))}))
  16. (let tries (impl 0))
  17. (print "You won in " tries " tries.") }))
  18. (game)

More examples are available inside examples/.

Installation

You can either use docker:

  1. docker pull arkscript/stable:latest
  2. # or use the most updated repo
  3. docker pull arkscript/nightly:latest

or build the project with CMake and install it with CMake:

  1. cmake --install build

Contributing

  • First, fork the repository
  • Then, clone your fork: git clone git@github.com:username/Ark.git
  • Install the pre-commit hooks: pre-commit install (you may need to install pre-commit first)
  • Create a branch for your feature: git switch -c feat-my-awesome-idea
  • When you’re done, push it to your fork and submit a pull request

Make sure you follow the contribution guidelines before submitting your pull request!

Don’t know what to work on? No worries, we have a list of things to do :wink:

We have other projects tightly related to ArkScript, which aren’t necessarily C++ oriented:

  • the standard library, written in ArkScript itself
  • the standard library modules, extending the capacities of the language, written in C++
  • ArkDoc, a documentation generator à la doxygen for ArkScript, written in Python 3
  • our website written in HTML, CSS and JavaScript

Our beloved contributors

Full list here.

Coding guidelines for contributing

See C++ Coding guidelines if you want to contribute to ArkScript compiler / runtime.

Also, see ArkScript Coding guidelines for other files, written in ArkScript.

For performance reasons, some functions might be written in C++, in include/Ark/Builtins/Builtins.hpp and src/Builtins/.

Building

Dependencies

  • C++20
  • CMake >= 3.15
  • Visual Studio >= 11 (on Windows)
  • On macOS versions prior to 10.15, libc++ lacks filesystem in the standard library.
    • Install a newer compiler using Homebrew: brew install gcc && brew link gcc
    • Pass compiler path to cmake in the build step: -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-14 -DCMAKE_C_COMPILER=/usr/local/bin/gcc-14

⚠️ When passing a specific C++ compiler to CMake, add the corresponding C compiler as ArkScript relies on C code as well ; otherwise you’ll cryptic get compilation/linking errors (using CMAKE_CXX_COMPILER and CMAKE_C_COMPILER).

Through CMake

Different CMake switches are available to customize the build:

  • -DARK_BUILD_EXE to generate an executable, defaults to Off, building a shared library only
  • -DARK_ENABLE_SYSTEM to enable sys:exec (execute shell commands without restrictions), defaults to On
  • -DARK_NO_STDLIB to avoid the installation of the ArkScript standard library
  • -DARK_BUILD_MODULES to trigger the modules build
  • -DARK_SANITIZERS to enable ASAN and UBSAN
  • -DARK_TESTS to build the unit tests (separate target named unittests)
    • -DARK_COVERAGE to enable coverage analysis ; only works in conjunction with -DARK_TESTS, enables the coverage target: cmake --build build --target coverage
  1. # first, clone it
  2. git clone --depth=50 --branch=dev https://github.com/ArkScript-lang/Ark.git
  3. cd Ark
  4. git submodule update --init --recursive
  5. # building Ark
  6. cmake . -Bbuild -DCMAKE_BUILD_TYPE=Release -DARK_BUILD_EXE=On
  7. cmake --build build --config Release
  8. # installing Ark (might need administrative privileges)
  9. cmake --install build --config Release

Desired output of arkscript --help:

  1. DESCRIPTION
  2. ArkScript programming language
  3. SYNOPSIS
  4. arkscript -h
  5. arkscript -v
  6. arkscript --dev-info
  7. arkscript -e <expression>
  8. arkscript -c <file> [-d] [-f(importsolver|no-importsolver)]
  9. [-f(macroprocessor|no-macroprocessor)] [-f(optimizer|no-optimizer)]
  10. [-f(iroptimizer|no-iroptimizer)] [-fdump-ir]
  11. arkscript <file> [-d] [-L <lib_dir>] [-f(importsolver|no-importsolver)]
  12. [-f(macroprocessor|no-macroprocessor)] [-f(optimizer|no-optimizer)]
  13. [-f(iroptimizer|no-iroptimizer)] [-fdump-ir]
  14. arkscript -f <file> [--(dry-run|check)]
  15. arkscript --ast <file> [-d] [-L <lib_dir>]
  16. arkscript -bcr <file> -on
  17. arkscript -bcr <file> -a [-s <start> <end>]
  18. arkscript -bcr <file> -st [-s <start> <end>]
  19. arkscript -bcr <file> -vt [-s <start> <end>]
  20. arkscript -bcr <file> [-cs] [-p <page>] [-s <start> <end>]
  21. OPTIONS
  22. -h, --help Display this message
  23. -v, --version Display ArkScript version and exit
  24. --dev-info Display development information and exit
  25. -e, --eval Evaluate ArkScript expression
  26. -c, --compile Compile the given program to bytecode, but do not run
  27. -d, --debug... Increase debug level (default: 0)
  28. -f(importsolver|no-importsolver)
  29. Toggle on and off the import solver pass
  30. -f(macroprocessor|no-macroprocessor)
  31. Toggle on and off the macro processor pass
  32. -f(optimizer|no-optimizer) Toggle on and off the optimizer pass
  33. -f(iroptimizer|no-iroptimizer)
  34. Toggle on and off the IR optimizer pass
  35. -fdump-ir Dump IR to file.ark.ir
  36. -d, --debug... Increase debug level (default: 0)
  37. -L, --lib Set the location of the ArkScript standard library. Paths can be
  38. delimited by ';'
  39. -f(importsolver|no-importsolver)
  40. Toggle on and off the import solver pass
  41. -f(macroprocessor|no-macroprocessor)
  42. Toggle on and off the macro processor pass
  43. -f(optimizer|no-optimizer) Toggle on and off the optimizer pass
  44. -f(iroptimizer|no-iroptimizer)
  45. Toggle on and off the IR optimizer pass
  46. -fdump-ir Dump IR to file.ark.ir
  47. -f, --format Format the given source file in place
  48. --dry-run Do not modify the file, only print out the changes
  49. --check Check if a file formating is correctly, without modifying it.
  50. Return 1 if formating is needed, 0 otherwise
  51. --ast Compile the given program and output its AST as JSON to stdout
  52. -d, --debug... Increase debug level (default: 0)
  53. -L, --lib Set the location of the ArkScript standard library. Paths can be
  54. delimited by ';'
  55. -bcr, --bytecode-reader Launch the bytecode reader
  56. <file> .arkc bytecode file or .ark source file that will be compiled
  57. first
  58. -on, --only-names Display only the bytecode segments names and sizes
  59. -a, --all Display all the bytecode segments (default)
  60. -st, --symbols Display only the symbols table
  61. -vt, --values Display only the values table
  62. -cs, --code Display only the code segments
  63. -p, --page Set the bytecode reader code segment to display
  64. -s, --slice Select a slice of instructions in the bytecode
  65. VERSION
  66. 4.0.0-c24c8f22
  67. LICENSE
  68. Mozilla Public License 2.0

In your own project

Please refer to the embedding ArkScript tutorial.

Performances

See https://github.com/ArkScript-lang/benchmarks

Games

You can find a snake created in ArkScript in the folder examples/games/snake (run it from there, otherwise it won’t find the font and the sprites ; you won’t need to install the SFML).

ArkSnake

Controls are the arrows (left, right, up and down), the game closes itself when you successfully collect the 3 apples.

The donors

Huge thanks to those people for their donations to support the project:

Cool graphs

Star History Chart

Credits

This project was inspired by game programing patterns and ofan lisp.cpp

Copyright (c) 2019-2024 Alexandre Plateau. All rights reserved.

This ArkScript distribution contains no GNU GPL code, which means it can be used in proprietary projects.