Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My New Unnamed Programming Language (unfinished)

It's my new, unnamed programming language. It's like C++ but better.

I need names for it! Z is the placeholder

Strict No LLM / No AI Policy

  • No LLMs for issues.
  • No LLMs for patches / pull requests.
  • No LLMs for comments on the bug tracker.
  • No LLMs for development on this repository in any way.

Examples (planned syntax)

Basic example:

fn main() {
	let number: i32 = 21;
	std.print(f"The Number is: {number * 2}"); // prints "The Number is: 42"
}

Structs example:

// There's a build in Vec2 type but this is hear just for the example
struct Point {
	let x: f32 = 0.0;
	let y: f32 = 0.0;

	// Member functions
	fn member() bool {
		std.print("Called the useless member function on Point");
		true
	}
	
	// Rust-like constructors allowed, and inline forces it to be inlined not just suggesting
	inline fn self(x: f32, y: f32) Self {
		Self {x, y}
	}

	// Operator overloading is supported like this, and copy tells it to copy self rather than taking a reference, good for simple types
	copy fn operator_add(other: Self) Self {
		Self(self.x + other.x, self.y + other.y)
	}

	fn operator_add_assign(other: Self) {
		x += other.x;
		y += other.y;
	}

	// used in printing automatically
	fn format() String {
		f"({self.x}, {self.y})"
	}
}

fn main() {
	// When initializing with bracket notation, Uninitialized values are set to their default, unless they don't have one then it throws an error if unset
	let test = Point { y: 0.1 + 0.2 };

	let point: Point; // initalizes with defaults (0, 0)
	point += Point(1.0, 2.0);
	std.print(f"Point: {point}");
	let point2 = point + Point(-0.567465, 45.473678);
	std.print(f"Point2: {point2}");
}

Classes & Inheritance example:

// Classes are just like structs but with inheritance
// Base classes implicitly inherit Object which is a class with nothing but a VTable Pointer
class Node {
	let name: String;
	let parent: &Node = null;
	let children: Vec<&Node> = Vec.new();
	let position: vec2 = vec2(0.0, 0.0);

  // statics are per-type rather then per-instance
	static useless = 3483;

	// constructors are like this
	fn self(name_: String, position_: vec2) {
	  name = name_;
		position = position_;
	}
	
	virtual fn process(dt: f32) {}

	// This would usally be generated by some reflect macro but it's manual here just for the example
	static virtual fn get_name() String {"Node"}
}

class Sprite : Node {
	let texture_path: String;

	fn self(name_: String, position_: vec2, tex_: String) {
	  name = name_;
		position = position_;
		texture_path = tex_;
	}
	
	override fn process(dt: f32) {
		position.x += 10.0 * dt;
		std.print(f"Position of {name}: {position}");
	}
	
	static override fn get_name() String {"Sprite"}
}

fn main() {
  // Only structs are allowed to have a brace initialization but not classes
  // You must use a constructor
  // Adding "new" prefix does heap allocation
  // I will probably add a way to have multiple different constructors later
  
	let world: Vec<&Node> = [
	  new Sprite("Player", vec2(0.0, 0.0), "assets/player.png"),
		new Sprite("Enemy", vec2(0.0, 100.0), "assets/enemy.png"),
	];
	
	while true {
		for node in world {
			node.process();
		}
		std.sleep(16); // in miliseconds
	}
}

Enums example:

pub enum IntegerType {
  // Cases are automatically public
  case Int16, Int32, Int64;
  case Uint16, Uint32, Uint64;
  case Byte;
}

Macros:

#global // this macro makes it exist during compilation rather than runtime
static REGISTERED: Vec<StructAst> = Vec.new();

#derive_macro
fn Reflect(obj: StructAst) { // -Ast paramaters are auto-set when using derive macros
  REGISTERED.push(obj);
}

#macro
fn RegisterAll() Vec<Expr> { // If the () is empty the macro doesn't need () to be called
  // here you would build expressions with each doing `std.print(f"Found Type: {obj.name}");`
}

#Reflect
struct Object {
  #hide pub field: i32,
  #show another_field: i32,
  pub hdjgsdg: f32,
}

fn main() {
  #RegisterAll
}

Data-types: (might not be added)

// Simple things that only store data. Can not have methods or defaults and can only be created with braces {}
datastruct Options {
	running: bool,
	paused: bool,
	score: i32,
}
// Trailing commas are optional
dataenum Type {
	Red, Blue, Bomb, Wall
}

fn main() {
	let thing = Type.Red;
	let other = Options {
		running: true,
		paused: false,
		score: 42,
	};
}

About

My programming language

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages