All Projects → assyrianic → Go2SourcePawn

assyrianic / Go2SourcePawn

Licence: MIT License
Go2SourcePawn is a transpiler that transforms a subset of Golang-like code to equivalent SourcePawn.

Programming Languages

go
31211 projects - #10 most used programming language
SourcePawn
201 projects
shell
77523 projects

Projects that are alternatives of or similar to Go2SourcePawn

coffee-to-ts
[NOT ACTIVELY MAINTAINED] Convert CoffeeScript to TypeScript
Stars: ✭ 34 (+161.54%)
Mutual labels:  transpiler
sugartex
SugarTeX is a more readable LaTeX language extension and transcompiler to LaTeX. Fast Unicode autocomplete in Atom editor via https://github.com/kiwi0fruit/atom-sugartex-completions
Stars: ✭ 74 (+469.23%)
Mutual labels:  transpiler
sqlglot
Python SQL Parser and Transpiler
Stars: ✭ 310 (+2284.62%)
Mutual labels:  transpiler
habrlang
Step by Step guide how to make your own programming language
Stars: ✭ 20 (+53.85%)
Mutual labels:  transpiler
go-mlog
Go to Mindustry (MLOG) compiler, runtime and decompiler (WIP)
Stars: ✭ 19 (+46.15%)
Mutual labels:  transpiler
Headache
Programming Language that compiles to 8 Bit Brainfuck
Stars: ✭ 59 (+353.85%)
Mutual labels:  transpiler
py2v
A Python to V transpiler.
Stars: ✭ 47 (+261.54%)
Mutual labels:  transpiler
BashClass
BashClass is an Object Oriented Programming language that compiles to BASH 4.4
Stars: ✭ 40 (+207.69%)
Mutual labels:  transpiler
ShenScript
Shen for JavaScript
Stars: ✭ 40 (+207.69%)
Mutual labels:  transpiler
qaffeine
Decaffeinate your JS-powered CSS stylesheets
Stars: ✭ 22 (+69.23%)
Mutual labels:  transpiler
War3Net
A .NET implementation of Warcraft III related libraries.
Stars: ✭ 76 (+484.62%)
Mutual labels:  transpiler
json-sql-builder2
Level Up Your SQL-Queries
Stars: ✭ 59 (+353.85%)
Mutual labels:  transpiler
js-slang
Implementations of the Source languages, which are small sublanguages of JavaScript designed for SICP JS
Stars: ✭ 41 (+215.38%)
Mutual labels:  transpiler
preact-codemod
🍧 Shave some bytes by using Preact.
Stars: ✭ 39 (+200%)
Mutual labels:  transpiler
grizzly
A Python-to-SQL transpiler as replacement for Python Pandas
Stars: ✭ 27 (+107.69%)
Mutual labels:  transpiler
atom-ts-transpiler
A transpiler for Atom packages that processes code with TypeScript
Stars: ✭ 14 (+7.69%)
Mutual labels:  transpiler
escapin
Escapin is a JS/TS transpiler for escaping from complicated usage of cloud services and APIs
Stars: ✭ 20 (+53.85%)
Mutual labels:  transpiler
go2hx
Go -> Haxe -> JS Java C# C++ C Python Lua
Stars: ✭ 49 (+276.92%)
Mutual labels:  transpiler
rewrite-imports
Rewrite `import` statements as `require()`s; via RegExp
Stars: ✭ 31 (+138.46%)
Mutual labels:  transpiler
bck2brwsr
Bck2Brwsr VM to transpile Java bytecode to JavaScript
Stars: ✭ 93 (+615.38%)
Mutual labels:  transpiler

Go2SourcePawn

v1.4 beta

Introduction

Go2SourcePawn is a transpiler that transforms a subset of Golang code to equivalent SourcePawn. The rationale behind Go2SourcePawn is to automate as much of the boilerplate possible when creating SourcePawn plugins.

Purpose

To increase SourcePawn plugin development time by using Golang's streamline engineered syntax.

Features

  • Abstracted common types into their own type classes such as float[3] aliasing as Vec3, etc. Here is the current types list and what params it abstracts to:
int     => int
float   => float
bool    => bool
*[]char => char[]
string  => const char[]
*string => char[]
Vec3    => const float[3]
*Vec3   => float[3]
  • Pattern matching

Array/slice types will be automatically const unless passed by reference like: *[]type. So having parameters such as []int will be generated as const int[] while *[]int will be generated as int[].

  • relative file imports are handled by using a dot . as the first letter
import ".file"

Becomes:

#include "file"
  • Multiple return values are supported by mutating them into variable references.

  • Range loops for arrays:

var players [MAXPLAYERS+1]Entity
for index, player := range players {
	/// code;
}
  • Switch statements with and without an expression.
switch x {
	case 1, 2:
	default:
}

switch {
	case x < 10, x+y < 10.0:
		
	default:
}

Expression-less switchs are useful for a more compact if-else-if series.

  • Function pointer calls are broken down into manual Function API calling:
func main() {
	CB := OnClientPutInServer
	for i := 1; i<=MaxClients; i++ {
		CB(i)
	}
}

func OnClientPutInServer(client Entity) {}

Becomes:

public void OnPluginStart() {
	Function CB = OnClientPutInServer;
	for (int i = 1; i <= MaxClients; i++) {
		Call_StartFunction(null, CB);
		Call_PushCell(i);
		Call_Finish();
	}
}

public void OnClientPutInServer(int client) {}
  • Anonymous Functions (aka Function Literals) are supported:
my_timer := CreateTimer(2.0, func(timer Timer, data any) Action {
	return Plugin_Continue
}, 0, TIMER_REPEAT)
  • Inline SourcePawn code using the builtin function __sp__ - for those parts of SourcePawn that just can't be generated (like using new or making a methodmap from scratch).

__sp__ only takes a single string of raw SourcePawn code. Optionally, you can also use a named string constant (it will be generated into the resulting code file, so keep that in mind.)

/// using raw string quotes here so that single & double quotes don't have to be escaped.
var kv KeyValues
__sp__(`kv = new KeyValues("key_value", "key", "val");`)

...
__sp__(`delete kv;`)
  • make for making dynamically sized, local arrays:
my_str := make([]char, size)

becomes:

char[] my_str = new char[size];

Planned Features

  • Generate Natives and Forwards with an include file for them.
  • Abstract, type-based syntax translation for higher data types like StringMap and ArrayList.
  • Handle-based Data Structures are abstracted into supportive syntax such where it's value = Map["key"] instead of map.GetValue("key", value);

Goal

Generate SourcePawn source code that is compileable by spcomp without having to modify/assist the generate source code.

Contributing

To submit a patch, file an issue and/or hit up a pull request.

Help

Command line options:

  • --debug, -dbg - prints the file's modified AST and pretty-printed version to a file for later checking.

  • --force, -f - forcefully generates a SourcePawn source code file, even if errors/issues occurred during transpilation.

  • --help, -h - Prints help list.

  • --version - Prints the version of SourceGo.

  • --no-spcomp, -n - Generates a SourcePawn source-code file without trying to invoke the SourcePawn compiler.

  • --verbose, -v - prints additional warnings.

If you need help or have any question, simply file an issue with [HELP] in the title.

Installation

Requirements

Latest Golang version.

Credits

  • Nergal - main dev.

License

This project is licensed under MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].