hoshi-lang dev
Yet another programming language
|
This is one of my practice during Senior High School period.
hoshi
means both $\mathop{desire}\limits^{欲しい}$ and $\mathop{stars}\limits^{星}$ in Japanese, which also represents my silly wishes: I hope some day I would become the stars I once live up to.
Hoshi-lang is a statically-typed, general-purpose programming language with a focus on performance, safety, and modern language features. It is designed to be a simple yet powerful tool for building a wide range of applications.
This project is currently under active development and is a personal exploration into language design and implementation.
interface
, struct
, and impl
.template
s for both functions and structs.+
, -
, *
, /
, etc.typeid
and interfaceof
.struct
type using dyn_cast
.use
statement.In Hoshi-lang, all data types are heap-allocated objects. This includes primitives like int
, bool
, etc., which are "boxed" into object wrappers. The compiler and runtime manage these objects through pointers.
All objects share a common header:
Offset | Field | Type | Description |
---|---|---|---|
0-7 | gc_refcount | unsigned long long | The object's current reference count. |
8-15 | type_id | unsigned long long | A unique ID for the object's runtime type. |
Specific object types then have their own layouts following this header.
Interface objects are special "shell" objects that enable polymorphism. When a struct
instance is cast to an interface
, a new interfaceObject
is created with the following layout:
Offset | Field | Description |
---|---|---|
0-15 | (Standard Header) | gc_refcount and type_id for the interface object itself. |
16-23 | this Pointer | A pointer to the concrete struct instance that implements the interface. |
24-31 | gc_refcount_increase V-Ptr | A virtual function pointer to the increase GC function for the concrete struct . |
32-39 | gc_refcount_decrease V-Ptr | A virtual function pointer to the decrease GC function for the concrete struct . |
40+ | Virtual Method Pointers | A sequence of function pointers to the concrete implementations of the interface's methods (the v-table). |
This structure is created by the compiler via the construct_interface_impl
IR instruction.
Memory is managed via Automatic Reference Counting (ARC).
gc_refcount
is incremented.gc_refcount
is decremented.The compiler is responsible for generating calls to the appropriate _gc_refcount_increase
and _gc_refcount_decrease
functions for each type at the right places.
Hoshi-lang now supports callable objects and lambda expressions, allowing for more flexible and functional programming styles.
Hoshi-lang now has basic support for multi-threading.
You can now de-structure arrays and structs into individual variables.
The alias
keyword can be used to create a new name for an existing type.
Hoshi-lang's standard library is growing and currently includes:
console
: For console input and output.file
: An interface for file-like objects.fs
: For file system operations.hashMap
: A hash map implementation.io
: For I/O operations.json
: For parsing JSON.math
: For mathematical functions.runtime
: For runtime-specific functions.str
: A string library.threading
: For multi-threaded programming.vec
: A dynamic array implementation.macOS / Linux:
Windows:
Options:
-o <output_file>
: Specify the output file name.-D <key> <value>
: Define a macro.