Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.
/ XieXie-2 Public archive

Compiler and Virtual-Machine for the XièXiè Programming Language (v.2)

License

Notifications You must be signed in to change notification settings

LukasBanana/XieXie-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XièXie Compiler and VirtualMachine (Version 2)

Features

  • High Level Programming Language
  • Compiler written in C++11 (in progress)
  • Virtual Assembler (XASM)
  • Virtual Machine (written in C99, with wrapper written in C++11)

License

3-Clause BSD License

Status

Work in Progress

Programming Guide

Take a look at the XièXie Programming Guide to get started with the XièXie programming language.

Code Examples

This is a small Hello World example:

import Console
class HelloWorld {
	static void main() {
		Console.writeLine("Hello, World!")
	}
}

And this computes the fibonacci series:

import Console
class Fibonacci {
	static void fib(int n) {
		int a, b := 1
		while a < n {
			Console.writeLine(a)
			a, b := b, a + b
		}
	}
	static void main() {
		Fibonacci.fib(1000)
	}
}

Integration Examples

Very high-level interface:

#include <xiexie/xiexie.h>
int main()
{
	XieXie::RunFromString(
		"import MsgBox\n"
		"class MiniExample {\n"
		"    static void main() {\n"
		"        MsgBox.show(\"Info\", \"This is a mini Example!\")\n"
		"    }\n"
		"}\n"
	);
}

Offline compilation:

#include <xiexie/xiexie.h>
int main()
{
	XieXie::CompileConfig config;
	{
		std::string filename = "ExampleFile.xx";
		config.sources.push_back({ filename, std::make_shared<std::ifstream>(filename) });
	}
	XieXie::Compile(config, &(std::cout));
}

Running compiled code:

#include <xiexie/xiexie.h>

void triggerGameEvent(XVM_Env env)
{
	// Read parameter from XVM environment
	int eventID = XVM_ParamInt(env, 1);
	
	/* do something ... */
	
	// Return void and pop 1 argument (eventID)
	XVM_ReturnVoid(env, 1);
}

/* further functions ... */

int main()
{
	XieXie::VirtualMachine::ByteCode bc;
	XieXie::VirtualMachine::Stack st;
	
	// Read XieXie byte code (*.xbc) file
	bc.ReadFromFile("MyGameScript.xbc");
	
	// Bind external invocation "triggerGameEvent"
	bc.BindInvocation("GameInterface.triggerGameEvent", triggerGameEvent);
	
	// Execute byte code in virtual machine
	XieXie::VirtualMachine::ExecuteProgram(bc, st, "GameScript.entryPoint");
}

About

Compiler and Virtual-Machine for the XièXiè Programming Language (v.2)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages