Giter Site home page Giter Site logo

crest's Introduction

crest

demo

#include "print.cr" // `#includes` are currently textual but I think I'd prefer a semantic include in the future

proc main() {
	procedures();
	variables();
	constants();
	loops();
	structs();
	arrays();
}

proc procedures() {
	proc sqr(var value: float) float {
		return value * value;
	}
	print_float(sqr(3) * sqr(5));
}

proc variables() {
	var some_ptr: ^int;
	var some_int = 4;
	some_ptr = &some_int;
}

proc constants() {
	const HENLO = "Henlo ";
	const WORLD = "World!";
	const HENLO_WORLD = HENLO + WORLD;
	#assert HENLO_WORLD == "Henlo World!"
}

proc loops() {
	var i = 10;
	while i > 0 {
		i -= 1;
	}
	// todo: c-style for loop and foreach
}

proc structs() {
	type Vector2 {
		var x: float;
		var y: float;
	}

	var vec: Vector2;
	vec.x = 1.0;
	vec.y = 4.0;

	const MyInt = int; // type alias
	#assert MyInt == int
	var a: int = 5;
	var b: ^MyInt = &a;
	print_int(^b);

	type Other_Vector2 Vector2; // distinct type
	#assert Other_Vector2 != Vector2
	var x: Vector2;
	var y: Other_Vector2;
	// y = x; <- type mismatch
}

proc arrays() {
	const N = 16;
	var arr: [N]float;
	arr[0] = 76;
	arr[2] = 123;
	print_float(arr[0]);
	print_float(arr[2]);
}

crest's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

crest's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.