Lobster Programming Language
repository·master·Indexed 25 days ago
https://github.com/aardappel/lobsterLobster is a statically typed programming language with a Python-like syntax, focusing on an expressive type system and compile-time memory management. The repository also includes the lobster-lsp-server (v0.1.0) and various external library integrations such as imgui_markdown, HIDAPI, and yuv2rgb.
What's inside Lobster
- Lobster is a statically typed programming language featuring a Python-esque syntax. It is designed to combine an expressive type system with compile-time memory management, using a lightweight and terse syntax that automates much of the heavy lifting for the developer.
Overview of stb_vorbis
masterstb_vorbis is a single-file library used to decode Ogg Vorbis files. It supports decoding from both files and memory into either floating-point or 16-bit signed integer output formats.Integrate imgui_markdown into Dear ImGui
masterimgui_markdown is a single-header markdown library for Dear ImGui. It requires C++11 or above. It provides support for wrapped text, headers (H1-H3), emphasis, indented text, unordered lists, links, images, and horizontal rules.Understand Lobster multi-threading model
masterLobster uses an isolated multi-threading model where each thread runs an independent Lobster VM on a hardware core.
Key Characteristics:
- No Shared Memory: Threads do not share memory or VM state. This eliminates race conditions and the need for a Global Interpreter Lock (GIL).
- Communication via Tuple Spaces: Threads communicate by passing messages through a "tuple space" (a bag of Lobster objects). Messages are copied rather than shared.
- Concurrency Style: This model is optimized for "worker" style concurrency, where tasks are placed in a tuple space and available VMs grab and complete them, providing automatic load balancing.
For a practical implementation example, refer to
samples/threads.lobsterin the repository.Identify what Lobster is not suitable for
masterBefore using Lobster, be aware of its design constraints:
- Not for beginners: Requires familiarity with concepts like higher-order functions and the rendering pipeline.
- Not for large-scale/team programming: The type system favors expressive power over building rigid interfaces for large teams.
- No built-in IDE or Editor: Everything is handled via code; there is no visual game editor.
- Not a mainstream/C-based language: It uses a terse syntax and functional semantics that differ significantly from C-style languages.
Lexical definition and syntax rules
masterLobster's syntax is a mix of Python and C conventions. Key lexical rules include:
- Whitespace: Uses spaces, tabs, carriage returns, and comments.
- Comments:
- Single-line:
// - Nested/Multi-line:
/* ... */
- Single-line:
- Strings:
- Standard: Delimited by
"(e.g.,"hello"). - Character constants: Delimited by
'(e.g.,'A'). - Triple-quotes:
"""allows verbatim content including newlines and quotes. - Escape codes:
\n,\t,\r,\",\',\, and\xfollowed by 2 hex digits (e.g.,\xFF).
- Standard: Delimited by
- Numbers:
- Integers:
123 - Hexadecimal:
0xABADCAFE - Floating point:
.1,1., or1.1
- Integers:
- Identifiers: Alphanumeric characters and
_(cannot start with a digit). - Indentation: Uses
indentanddedenttokens. Adjacent lines must start with the same sequence of spaces/tabs to ensure visual consistency.
Understand Lobster's design philosophy and target use cases
masterLobster is a general-purpose programming language strongly biased toward game programming and related fields. It is designed for small to medium-sized projects and prioritizes refactoring and compositionality.
Key Characteristics:
- Functional Influence: While imperative, it encourages a functional style using terse higher-order functions and optional immutable objects.
- Refactoring-Oriented: Uses free variables to allow code to be moved and reorganized with minimal changes to function arguments.
- Type System: A powerful static type system that uses specialization, type inference, and flow-sensitive typing to provide efficiency while maintaining a developer experience similar to dynamic typing.
- Memory Management: Highly efficient via compile-time reference counting (lifetime analysis), inline structs, and a fast allocator.
- Hybrid Workflow: Designed to work alongside C++. Lobster is intended to be the main program (glue/high-level logic), while C++ is used for performance-critical libraries.
- Engine Model: Uses an immediate mode rendering pipeline, providing low-level control rather than a retained-mode object system (like Flash).
Understand Lobster's Ownership Analysis
masterLobster uses a hybrid memory management strategy combining runtime reference counting with a compile-time ownership analysis algorithm. This is often referred to as "compile-time reference counting."
How it works:
- The algorithm automatically picks a single owner for each new heap allocation (usually the first variable or field it is assigned to).
- Subsequent uses of that value are treated as borrows.
- Ownership and borrows do not require runtime reference counting.
- Runtime reference counting is only inserted when a new owner is required (e.g., when a value is assigned to a new variable that needs to own it).
- This approach typically removes approximately 95% of runtime reference count operations.
Note: While the system is mostly automatic, the compiler may occasionally require minor code adjustments to satisfy ownership requirements.
Configure Syntax Highlighting for Lobster
masterTo enable syntax highlighting for
.lobsterfiles in Notepad++:- Set your theme to a dark background (e.g., Zenburn) via Settings -> Style Configurator -> Select Theme.
- Go to Language -> Define your language....
- Click Import... and select the
docs/notepad++/notepadpp_udl_lobster.xmlfile from the repository. - Use Save As... to name the language
lobster.
Once configured,
.lobsterfiles will automatically use the correct highlighting, or you can select it manually from the Language menu.Set up SublimeText as a Lobster IDE
masterTo use SublimeText as an IDE for Lobster, follow these steps:
- Copy the files from the
docs/sublimedirectory in the Lobster repository to your SublimeTextPackages/Userfolder.- Windows path example:
\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages\User
- Windows path example:
- Open
lobster.sublime-buildand verify that the path to yourlobsterexecutable is correct. - Note that the build system uses a custom version of the execution script called
lobster_exec.py. This version suppresses window pop-ups, which means any graphical output from Lobster will be disabled. - Open a
.lobsterfile and pressCtrl+Bto run the program.
- Copy the files from the
Call functions using different syntaxes
masterLobster provides several ways to invoke functions:
- Standard:
name(1, 2) - Dot Notation:
1.name(2). If the function has only one argument, parentheses can be omitted:v.length. - No Parentheses:
print "hi!". This is allowed for known functions with one expression argument used as a statement.
Note: When using dot notation, the first argument is placed ahead of the call.
name(1, 2) 1.name(2) v.length print "hi!"- Standard:
Integrate HIDAPI into a CMake project
masterTo use HIDAPI in your own CMake-based project, use
find_package(hidapi REQUIRED).Basic Usage
project(my_application) add_executable(my_application main.c) find_package(hidapi REQUIRED) target_link_libraries(my_application PRIVATE hidapi::hidapi)Locating HIDAPI
If
find_packagefails to locate HIDAPI, specify the installation path using thehidapi_ROOTvariable (requires CMake 3.12+):cmake <your_project_source> -Dhidapi_ROOT=<path_to_hidapi_prefix>For older CMake versions, use
CMAKE_PREFIX_PATHinstead.project(my_application) add_executable(my_application main.c) find_package(hidapi REQUIRED) target_link_libraries(my_application PRIVATE hidapi::hidapi)