Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std::io;
- // Any module that imports this module will also import std::core.
- import std::core public;
- import std::random;
- import "stdio.h";
- import Program::Maths;
- // Build steps can be written directly in the program!
- // No cmake or IDE specific build steps, called directly from the hash.exe compiler.
- $project Program1: std::project_generate {
- $func generate(project: std::project*, target: std::build_target) override -> {
- // A unique ID assigned to this project, generated from a website.
- project.set_unique_id(0x371EE67);
- // This version tag is used to generate a comparable version ID.
- project.set_version("0.1.0");
- // Other data can be written into a EXE.
- project.set_copyright("Copyright 2019 Matthew Albrecht");
- project.set_authors("Matthew Albrecht");
- project.set_url("https://github.com/hash/hash.git");
- project.set_icons(null);
- project.set_output_name("Project1");
- project.set_type(std:::project::type::executable);
- project.set_entry_point(Program::Main);
- // Libraries will set build order, these may be system libs, or C libs.
- project.add_library("Library1", 0x2D74EA55, std::project::public);
- // Could set this projects compiler to another system version.
- //project.set_compiler(std::project::get_compilers().first());
- // If a GNU compiler (Clang/GNU) extra build args can be added.
- if (project.compiler & std::compiler::gnu) {
- project.add_build_args("-Wall -Wextra -Wno-unknown-pragmas");
- if (target == std::build_target::debug) {
- project.add_build_args("-O1 -fvisibility-inlines-hidden");
- } else if (target == std::build_target::release) {
- project.add_build_args("-O3 -fno-rtti");
- }
- }
- }
- }
- module Program {
- // Main can be defined as any void global function.
- func Main(): std::entry_point -> {
- Example::Get().val1 = 32.0f;
- std::println($"{Example::Get().val1}, {Example::Get().val2}, {Example::Get().VAL3}");
- add2Int32s := (a: int32, b: int32) -> int32 {
- return a + b;
- };
- add2Values := <T: std::is_arithmetic>(a: T, b: T)[this] -> {
- return a + b;
- };
- addValues := <T...: std::is_arithmetic>(args: T...) -> {
- return (args + ...);
- };
- // Ranged for between 0 and 99.
- foreach (var i; 0..100) {
- }
- // A more typical way to write a for loop.
- for (i: int32; i < 100; i++) {
- }
- // Normal while loop.
- while (std::io::getin()) {
- }
- // Do while loop.
- do {
- } while (std::io::getin());
- pos0 := Vec2(0.5f, -9.75f);
- pos1 := Vec2(2.0f, 3.22f);
- pos2: Vec2<float>;
- pos2 = Vec2(-1, 5);
- if (pos0 * pos1 != 0.0f) {
- std::println($"{pos0} * {pos1} != 0.0f");
- }
- printf("Direct call to C header: %f\n". std::random(-100.0f, 100.0f));
- }
- struct EnumAnimal : std::enum<int32> {
- undefined, // 0
- dog = 1, // 1
- cat, // 2
- frog = 8, // 8
- fish; // 9
- }
- struct EnumBits : std::enum_bits<uint32> {
- bit1, // 1
- bit2, // 2
- bit3, // 4
- bit5 = 16, // 16
- bit6; // 32
- }
- // (EnumBits.bit1 | EnumBits.bit2) | EnumBits.bit1 == true
- // This-module-only statement
- // Protected functions can be used in this namespace anywhere in this assembly.
- func Internal0() protected -> {
- }
- // This-module-only expression
- // Private functions can only be used in this file.
- func Internal0(): std::for_platform<std::platform::windows | std::platform::linux> private -> int32 {
- return -10;
- }
- struct Example: Singleton<Example> {
- val1: mutable float32;
- val2 := Internal0();
- VAL3 static const: float64 = 26.924;
- val4, val5, val6 : int32;
- func init() -> {
- std::println("Created Example Singleton!");
- }
- func deinit() -> {
- std::println("Deleted Example Singleton!");
- }
- func getVal1() const -> val1;
- func setVal1(val1: int32) -> this.val1 = val1;
- // While being compiled methods are turned into functions:
- // func getVal1(this: Example)[] const -> this.val1;
- // func setVal1(this: Example, val1: int32) -> this.val1 = val1;
- }
- struct Singleton<T>: std::non_copyable {
- instance private static: T?;
- func Get() static -> T* {
- if (instance == null) {
- instance = T();
- }
- return instance;
- }
- }
- struct Animal: std::pure_interface {
- GetSound() const virtual -> std::string;
- }
- struct Dog: Animal {
- GetSound() const override -> std::string { return "Bark"; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement