Skip to content

Instantly share code, notes, and snippets.

@CinchBlue
Created April 6, 2015 16:47
Show Gist options
  • Save CinchBlue/b4c2afd4f66a8c37ee54 to your computer and use it in GitHub Desktop.
Save CinchBlue/b4c2afd4f66a8c37ee54 to your computer and use it in GitHub Desktop.

#Hyper Programming Language

Hyper is a new programming language that aims to:

  1. Maintain the power of C++ and C.
  2. Streamline the syntax of C-like languages for readability.
  3. Make embedding into programs easy
  4. Make inter-portability between C and C++ easy at compile-time and run-time.

##Types

There are several basic types in Hyper:

  • bool - 1 byte
  • byte - 1 byte (hex, dec, or bin literals)
  • int - 4 bytes (positive or negative)
  • float - 8 bytes (positive or negative)
  • string - X bytes (UTF-8, still ASCII-compatible)
  • ref - X bytes (size of pointer on system)
  • func - X bytes (size of function pointer on system)
  • obj - X bytes (defined by class or obj)

##Declaration of Types

All variable initialization occurs with the following syntax:

//new TYPE NAME;
new int b;

All types in Hyper, if not specified, are initialized to a single value: NULL;

All variable assignment takes on this form:

//variable = other;
new int c = -239;
b = c;

All function definitions take on this form:

//new func NAME(TYPE arg_name1, TYPE arg_name2): CODE ;
def func add(float a, float b):
	return a + b;
;

Functions can only return one single object or data type, but this data type doesn't have to be predefined. The compiler should always be able to deduce the correct type that the function must return.

Additionally, lambda functions are implemented in the form of new func:

//new func NAME: CODE ;
new func hello_world:
	print("Hello World!");
;

Functions can be passed around, but still have static type. In reality, each function is still a class object that only has its op() defined.

All class definitions take on this form:

new class NAME:
	INIIiALIZE VARIABLES & MEMBER OBJECTS
	INITIALIZE FUNCTIONS
;

It is also important to note that classes require their internal members variables to be created before they are used. Constructors and destructors are defined similarly to C++, but both copy and move constructors are defined using op_copy() and op_move(). Similarly, op_=copy() and op_=move() are the copy and move assignment operators. op_new() and op_delete() functions follow the same naming conventions of C++.

Inheritance is iffy; I'm not sure if I want to have it or deal with it, especially with vtables and the sort. Okay it's out. I don't want to have it and composition is better anyways.

Virtual functions are available in Hyper. A virtual function that is defined but not implemented is defined as abstract.

new class NAME:
	def virtual func(int a, int b):
		CODE
	;

Composition within Hyper depends on the host class on instantiating the member object. Use of the keyword new is required.

def class Foo:
	int a;

	def func op_new(int i):
		a = i;
	;
;

def class Bar:
	new Foo foo;
	new int b;
	
	def func op_new(int i):
		foo = new Foo(i);
		b = i;
	;
;

Classes' privacy can also be amended with public, private, and protected qualifiers, using public: private: protected: By default, all variables and functions are left private.

##Code inclusion features

Hyper has integration with both other Hyper code, C code, and C++ code. Hyper itself can integrate with the full C++ and C library as long as it binds to actual C++ or C functions and/or objects.

To include other Hyper code in your source file, do this:

include "file.hyp";

Each file must define all of its functions and classes in the same scope. Hyper code is to be compiled to an intermediate file format called HYPO for inclusion with other source files in the style of C++ headers to avoid parsing an entire class over and over again.

To insure that Hyper classes and functions can be linked later, do the following:

Hyper also includes a namespace functionality.

namespace NAME:
	CODE
;

##Passing C++ classes and C structures to Hyper

It is possible to define classes and structures at runtime from a C++ or C program to be compatible with Hyper. Once a class is exposed to Hyper, Hyper may then treat it as any other object it has defined.

In this manner, it is possible to manually expose C++ libraries or C libraries to Hyper. In fact, given enough time, a compiler could make it possible to bind C++ and C code itself to Hyper or even make it usable in Hyper.

For now, most of the binding must occur before the Hyper state is initialized. Once the Hyper state begins, Hyper need only call the associated functions, variables, or classes. Hyper can also use check to determine whether a certain alias is registered, and if so, by whom outside the Hyper runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment