Arturo Programming Language

repository·master·Indexed 21 days ago

https://github.com/arturo-lang/arturo

A simple, expressive, and portable programming language designed for efficient scripting. Arturo features a unique syntax where code is treated as a list of words and symbols without reserved keywords, influenced by concepts from Logo, Rebol, Forth, Ruby, Haskell, D, Smalltalk, Tcl, and Lisp.

Tokens
3.3K
Snippets
10
Records
18
Agent score
75%

What's inside Arturo

  1. What is Arturo?

    master

    Arturo is a simple, expressive, and portable programming language designed for efficient scripting. It is an independently-developed modern language influenced by concepts from Logo, Rebol, Forth, Ruby, Haskell, D, Smalltalk, Tcl, and Lisp.

    Key design principles:

    • Code consists of a list of words, symbols, and literal values.
    • Words and symbols within a block are interpreted according to their context.
    • There are no reserved words or keywords.
    factorial: function [n][
    	switch n > 0 -> n * factorial n-1
    	             -> 1
    ]
    
    loop 1..19 [x]->
    	print ["Factorial of" x "=" factorial x]
  2. Understand the Arturo project structure

    master

    Arturo is primarily written in Nim, with C/C++ used for external libraries and wrappers. The project is organized into several key directories:

    • src/: The main source code.
    • src/vm/: The Virtual Machine core, including:
      • parse.nim: Lexer/parser (input to parse tree).
      • eval.nim: Evaluator (parse tree to bytecode).
      • exec.nim: Execution engine (bytecode loop).
      • stack.nim: Stack manipulation.
      • value.nim: The core Value object and arithmetic/printing logic.
      • bytecode.nim: Bytecode definitions.
      • env.nim: VM environment handling.
    • src/library/: The Arturo standard library.
    • src/system/: Components written in Arturo (REPL, packager, etc.).
    • src/helpers/: Shared utility methods.
    • src/extras/: 3rd party open-source code.
    • examples/: Working Arturo code examples.
    • tests/: Unit tests.
    • bin/: Destination for the compiled binary.
  3. How the Arturo library reference is generated

    master

    Arturo's library reference and the info function are automatically generated from the source code of the built-in modules located in src/library. Each built-in function is defined using a builtin macro that includes metadata such as description, args, returns, and example. When you add or modify a builtin definition in a library module, the documentation is updated automatically.

        builtin "darken",
            alias       = unaliased, 
            rule        = PrefixPrecedence,
            description = "darken color by given percentage (0.0-1.0)",
            args        = {
                "color"     : {ValueKind.Color},
                "percent"   : {Floating}
            },
            attrs       = NoAttrs,
            returns     = {ValueKind.Color},
            example     = """
                darken #red 0.2         ; => #CC0000
                darken #red 0.5         ; => #7F0000
                darken #9944CC 0.3      ; => #6B308F
            """:
                ##########################################################
                if x.kind == Literal:
                    SetInPlace(newColor(alterColorValue(InPlace.l, y.f * (-1))))
                else:
                    push newColor(alterColorValue(x.l, y.f * (-1)))
  4. Run Arturo using Docker

    master

    You can use the official Docker image to run Arturo. This is useful for testing or if you do not want to install the compiler locally.

    To start an interactive session:

    docker run -it arturolang/arturo

    To run a specific local script file:

    docker run -it -v $(pwd):/home arturolang/arturo <yourscript.art>
  5. Trace mimalloc events using Event Tracing for Windows (ETW)

    master

    You can profile mimalloc allocation and free events on Windows using Event Tracing for Windows (ETW). The event manifest is defined in etw.man, which generates etw.h. The specific event IDs used are:

    • 100: Allocation
    • 101: Free

    To capture these events, use the Windows Performance Recorder (WPR) with the provided profile etw-mimalloc.wprp.

    ```bash
    # 1. Start the trace using the mimalloc WPR profile in an admin prompt
    wpr -start src\prim\windows\etw-mimalloc.wprp -filemode
    
    # 2. Run your mimalloc-based program
    <my mimalloc program>
    
    # 3. Stop the trace and save to a .etl file
    wpr -stop test.etl

    After capturing the trace, you can open the resulting test.etl file in the Windows Performance Analyzer (WPA) to inspect the allocation and free events.

  6. Editing miscellaneous documentation pages

    master
    Non-library documentation pages (such as language guides) are generated from templates using Webize. To edit these pages, modify the corresponding template files located in the docs/website directory. These templates are typically written using a combination of Markdown and Arturo syntax.
  7. Install Arturo via curl

    master

    For Unix/Mac users, you can automatically install the most recent stable version of Arturo by running the following command in your terminal:

    curl -sSL https://get.arturo-lang.io | sh

    To install the most recent nightly build instead of the stable version, use:

    curl -sSL https://get.arturo-lang.io/latest | sh
  8. Set up a development environment on macOS

    master

    To compile Arturo on macOS, install the latest clang via Xcode tools and then install nim using Homebrew or choosenim (recommended).

    xcode-select --install
    brew install nim

    Or via choosenim:

    curl https://nim-lang.org/choosenim/init.sh -sSf | sh
    choosenim 2.2.6
  9. Access Arturo Documentation and Examples

    master
  10. Migrate webview source files from the parent repository

    master

    If you need to pull the latest source files from the webview/webview parent repository into Arturo, follow these manual steps to ensure compatibility across Windows and Unix platforms without converting the Nim project to C++.

    Note: This process involves splitting the parent files into specific Arturo files (webview-windows.h, webview.h, and webview-unix.cc) and updating the Nim bindings.

    1. Update Header and Implementation Files

    Let P denote the parent files (webview/webview) and A denote Arturo's files.

    • For Windows (A:webview-windows.h):

      • Copy the entire contents of P:webview.h into A:webview-windows.h.
    • For the Common Header (A:webview.h):

      • Locate the section in P:webview.h starting immediately after #define WEBVIEW_H (but before #ifndef WEBVIEW_API) and ending just before #ifndef WEBVIEW_HEADER.
      • Copy this section into A:webview.h.
      • Important: Do not include the #ifndef WEBVIEW_HEADER line. Note that a trailing #endif will be missing; you must ensure the header is valid.
    • For Unix (A:webview-unix.cc):

      • Locate the section in P:webview.h starting from #ifndef WEBVIEW_API (including preceding comments) until the final #endif /* __cplusplus */.
      • Copy this into A:webview-unix.cc.
      • Important: Remove the #ifndef WEBVIEW_HEADER statement and its corresponding #endif from this section.

    2. Update Nim Bindings

    After updating the C/C++ files, you must ensure the Nim interface matches the new source:

    • Verify that the main function signatures have not changed.
    • If signatures have changed or new functions have been added to the parent repository, add the corresponding definitions to extras/webview.nim.