Giter VIP home page Giter VIP logo

lingdong- / wax Goto Github PK

View Code? Open in Web Editor NEW
731.0 24.0 43.0 1.33 MB

A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly 🚀

Home Page: https://waxc.netlify.app/

License: MIT License

Makefile 0.10% C 84.96% Java 0.12% Python 0.58% JavaScript 2.26% C# 0.06% C++ 0.14% TypeScript 0.01% Swift 0.15% Lua 0.09% WebAssembly 11.47% Shell 0.06%
programming-language transpiler c99 typescript java compiler

wax's Introduction

wax

wax

wax is a tiny language designed to transpile to other languages easily. Currently supported backends: C, C++, Java, TypeScript, Python, C#, Swift, Lua, as well as directly to WebAssembly.

The goal of wax is to be a "common subset" of most major imperative programming languages. By lacking the unique fancy features in each of these languages and being as boring as possible, wax transpiles to all of them seamlessly, producing outputs that are:

  • Readable: The output code looks just like the input code.
  • Editable: A human programmer should be able to work from the output even if the original wax source is unavailable.
  • Integrable: The output code can be imported as libraries to use with the rest of the target language (in addition to just being runnable alone).

These of course, from the programmers' perspective, come at the cost of losing some of the interesting features offered by other languages. Nevertheless, wax retains the crucial bits for a programming language to be productive.

The syntax of wax is inspired by WebAssembly Text Format (wat), hence the name. Though it uses S-expressions reminiscent of the Lisp family, it is actually quite imperative and most resemblant of C in its design. The idea of transpiling to many languages is inspired by Haxe.

wax is currently experimental, so there might be bugs as well as aspects to be improved, in which case PR and Issues are very much appreciated.

Hello World

(func main (result int)
  (print "hello world!")
  (return 0)
)

Newlines and indentations are entirely cosmetic. You can use any type of brackets anywhere (() [] {}). You can mix different types of brackets if you somehow prefer that.

[func main [result int] [print "hello world!"] [return 0]]

{func main {result int} {print "hello world!"} {return 0}}

{func main [result int] 
	(print "hello world!") 
	(return 0)
}

Here's an in-place quicksort to get a quick taste of the language:

;; sort array in-place for index range [lo,hi] inclusive
(func qksort_inplace (param A (arr float)) (param lo int) (param hi int)
	(if (>= lo hi) (then
		(return)
	))
	(let pivot float (get A lo))
	(let left  int lo)
	(let right int hi)
	(while (<= left right) (do
		(while (< (get A left) pivot) (do
			(set left (+ left 1))
		))
		(while (> (get A right) pivot) (do
			(set right (- right 1))
		))
		(if (<= left right) (then
			(let tmp float (get A left))
			(set A left (get A right))
			(set A right tmp)
			(set left  (+ left 1))
			(set right (- right 1))
		))
	))
	(call qksort_inplace A lo right)
	(call qksort_inplace A left hi)
)

(func qksort (param A (arr float))
	(if (! (# A)) (then
		(return)
	))
	(call qksort_inplace A 0 (- (# A) 1))
)

As you might have noticed, writing in wax is pretty much like writing an abstract syntax tree directly!

There're many more examples, check them out here or on the online playground.

Overview

  • wax is strongly statically typed.
  • wax has built-in support for arrays, hashtables and structs.
  • wax supports C-like macros, allowing specifying different behavior/branches for each compile target, as well as embedding target code directly.
  • syntax is simple: an expression is always a list of tokens enclosed in parenthesis (), and the first token is always a keyword/operator. There're 50 keywords in total.
  • wax does not support OOP (meaning that you get structs to pack data together, but you cannot blend methods into structs), nor does it support functional programming.
  • wax does not have a boolean: zero is false, non-zero is true.
  • wax is not garbage-collected. However, it does have constructs to facilitate memory management and make leaky bugs less likely. On compile targets that do support garbage collection (e.g. Java, JS), explicit freeing of resources is not required, and theoretically you can ignore memory management altogether if you intend to compile to these targets only. Check out the Array/Vector/Struct sections in Quickstart for details.

The Compiler

This repo contains a reference implementation of wax called waxc, written from scratch in C99.

  • Compiles from wax to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly.
  • It seems pretty fast. Compiling a 700 lines file takes 0.015 seconds on Macbook Pro 2015. Comparison: the output TypeScript, which is also 700 lines long, took tsc 1.5 seconds to compile.
  • Additionally, it can emit a very detailed and low-level syntax tree in JSON format. (If your favourite language is not a supported wax target yet, it's not too hard to go from this file and write a code generator :)
  • It can print the tokenization and the abstract syntax tree to terminal.
  • Usage:
 _____                                           
|||'  |                                          
|''   |                                          
|_WAX_| Compiler                                 

built Oct 27 2020                               

USAGE: waxc [options] code.wax                   

OPTIONS:                                         
--c     path/out.c     transpile to c            
--java  path/out.java  transpile to java         
--ts    path/out.ts    transpile to typescript   
--py    path/out.py    transpile to python       
--cs    path/out.cs    transpile to c#           
--cpp   path/out.cpp   transpile to c++          
--swift path/out.swift transpile to swift  
--lua   path/out.lua   transpile to lua 
--wat   path/out.wat   transpile to webassembly         
--json  path/out.json  syntax tree to JSON file  
--tokens               print tokenization        
--ast                  print abstract syntax tree
--silent               don't print info          
--help                 print this message 

Example

To compile the fib.wax example included in the example folder to C, and print the abstract syntax tree to terminal:

./waxc examples/fib.wax --c fib.c --ast

Now compile the C output with gcc and run the example:

gcc fib.c
./a.out

Compile to all targets and compile all outputs with target languages' compilers and run all outputs of target languages' compilers:

./waxc examples/fib.wax \
--c fib.c   --java  fib.java  --ts  fib.ts    --py fib.py  --cs  fib.cs  --swift  fib.swift --lua fib.lua;
gcc fib.c;    javac fib.java;   tsc fib.ts;                  csc fib.cs;   swiftc fib.swift;
./a.out;      java  fib;       node fib.js; python fib.py;  mono fib.exe;       ./fib;        lua fib.lua;

Compiling to C++ requires flag -std=c++11:

./waxc examples/fib.wax --cpp fib.cpp;
g++ fib.cpp -std=c++11;
./a.out;

Compiling to WebAssembly

waxc also supports compiling to WebAssembly Text Format (.wat). As the output needs to be further transformed to binary (.wasm) and wrapped with JS for calling, there's a couple more steps:

1. Compile to wat with waxc:

./waxc examples/fib.wax --wat fib.wat

2. Compile wat to wasm, using wat2wasm from wabt:

./wat2wasm fib.wat

3. Optional: Optimize with wasm-opt from binaryen for massive speedups, since (currently) waxc is not an optimizing compiler.

./wasm-opt fib.wasm -o fib.O4.wasm -O4

4. Now that the wasm is ready, you probably need some JS to call it, which basically involves WebAssembly.instantiate(bytes,imports) with console.log (and Math if you used (@include math)) as imports. Luckily you can find a readymade wrapper in tools/waxwasmwrap.js. To use:

Node:

const wrapper = require("tools/waxwasmwrap.js");
wrapper("fib.wasm",function(lib){
  lib.main();
});

Browser:

WAXWASMWRAP("fib.wasm",function(lib){
  lib.main();
});

All user-defined functions are exported under their original names, so you can call

lib.fib(42);

and so on.

Compiling the Compiler

You need:

  • A C compiler that supports C99. e.g. gcc or clang.

To compile:

gcc src/wax.c -o waxc

That's it, no dependencies.

Alternatively you can run the Makefile:

  • make c. Compile it.
  • make co. Compile it with -std=c99 -O3 -std=c99 -pedantic -Wall.
  • make em. Compile it with emscripten as a node.js app. (You might need to edit the rule based on how/when/where you installed emscripten.)
  • make emlib. Compile it as a javascript library with emscripten, without filesystem dependencies. This is what powers the online playground.

Syntax Highlighting + Transpile + Compile + Run + Render

Get Started

Now that the compiler is compiled, head over to QUICKSTART.md for a tour of language features!

wax's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wax's Issues

More languages transpiling support

@LingDong- I ❤️ how wax works and if possible to see more languages wax can transpile to in near future i would be very grateful...

Languages like JavaScript, Ruby, Lisp (Or Scheme), PHP, Kotlin, Objective-C, and more...
Not forcing ya, But if there are any guide about adding transpilers i can work on one if possible!

And thanks for wax!

Typo on `insert` operations

At line 212 it seems that the snippet is not correct.

The doc says:

To insert v into a an array x at index i, use

But the index i is missing in the snippet.

(insert x v)

Should it not be?

(insert x i v)

representing unions/enums

Have you given any thought to how one can represent a tagged union/enum: so, we either have struct1, struct2, etc..?

In C this can be done with a struct with a field holding a tag, and then a field that is the union of all the other possibilities.

It would be very interesting to have this ability in wax.

[file error] cannot read file

Under Windows, waxc works with the files in the examples folder, but not with new files.
Working from a examples file, copy, rename, edit, waxc works again.
There is a slight 3 byte difference between the helloworld.wax and the self-created hello.wax.
Any idea what can cause the different behavior and how to fix it?

How to #include with C backend?

How can I get a valid #include for C?

(asm "#include \"some_file.h\"")
(func main (result int)
    (return 0)
)

gives malformed include

#include "some_file.h"int main() {
    return 0;
}

I tried using an escaped newline and escaping the backslash in the newline but this was included raw into the final output instead of actually escaping a new line

(asm "#include \"some_file.h\"\n")
(func main (result int)
    (return 0)
)

gives

#include "some_file.h"\nint main() {
    return 0;
}

Feature Request - keep comments in generated code

Thanks @LingDong- for your nice little language!
The generated code is really clean and very close to the wax code.

I think it would be really nice if we had the option to keep the comments from wax code in the generated target code.

Not sure if everybody would like this. Maybe an optional compiler flag like --keepComments or a second syntax for comments that should be kept could be introduced?

Convert wax back

Excelent project. Do you have plans to transpile it back to wax ? Like: python to wax, c to wax etc ?

向你致敬!

关注了你的很多项目,原创性和能力都很强,佩服,了不起!

how to prepend string?

(func bothS (param input str) (result str)
	
	(return   (<< input "'") )
)
(func main (result int)
	(print (call bothS "aa"))
	(return 0)	
)
	

I want to ouput 'aa' ,how to do ?

What string operations are supported?

The quickstart only mentions appending to strings and comparing strings. It does not mention accessing the length of strings or indexing characters or substrings. Is that supported?

Wax compiler in wax - working implementation

@LingDong- I've made some surprisingly rapid progress on a self hosted compiler implementation, please see:

https://github.com/jacoblister/wax/blob/compiler/examples/compiler.wax

To use, copy the wax code into the Playground and run - this will output javascript , copy and paste into a browser console window, and get - working example programs!

The following programs are working so far:

  • hello world
  • fibonacci sequence
  • n queens problem
  • hilbert curve
  • turing machine example

just uncomment to example to run in the compiler 'main' function to see the others.

I've only been worked on this for about a week in my spare time/weekends, and already have this much working, so I think the minimal wax language might really be on to something. Looking at what it can do so far, I don't think I'll be too far away from having a self hosted compiler working pretty soon, and all in < 1000 lines of code, with embedded examples!

I have also made a merge request for a Brainfu*k implementation as well - getting that working so easily that got me motivated to try to do a compiler:
28ae5eb

Could you please have a look at that and perhaps merge it into the examples if that's ok?

I'll be having a look at the C language target as well after I get all the basic functionality covered. I would be quite interested in collaborating with you as I make more progress. I can do a longer brain dump about thoughts on approaches if you'd like.

Thanks Kindly,

Jacob

Does wax use short-circuit evaluation for boolean expressions?

Hi, this is a cool project, I'm really enjoying reading through it right now.

Quick question regarding this part of the QUICKSTART.MD documentation:

a && b && c is:

(&& a b c)

which the compiler will read as:

(&& (&& a b) c)

I'm not proficient in all the languages that Wax compiles to, but the ones that I do know would use short-circuit evaluation on this expression - that is, if a is false, then expressions b and c are not evaluated. Does wax also do this to? Or does it always evaluate all expressions? In either case, does it take special care that all compile targets behave as expected? Or does it not make any assumptions about this at all?

https://en.wikipedia.org/wiki/Short-circuit_evaluation

WAT globals interpreted as locals

In the example raycast.wax using WebAssembly output, the variable INFINITY is imported from math:

(global $INFINITY f32 (f32.const 340282346638528859811704183484516925440))

but later is called as local:

(call $set__ray__tmax (local.get $r) (local.get $INFINITY))

which results in a parse error using wabt afterwards to convert to binary.

Segfault while multi transpilation

While trying to generate a multi transpilation we getting segfault see shell script bellow:

#!/bin/sh
#waxfn=examples/traceskeleton
waxfn=examples/vororelax
#valgrind 
./waxc \
    --c $waxfn.c \
    --cpp $waxfn.cpp \
    --cs $waxfn.cs \
    --java $waxfn.java \
    --json $waxfn.json \
    --lua $waxfn.lua \
    --py $waxfn.py \
    --swift $waxfn.swift \
    --ts $waxfn.ts \
    --wat $waxfn.wat \
    $waxfn.wax

Ouptut:

sh test-waxc.sh 
[info] transpiling 'examples/vororelax.wax' to C...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.c
[info] freeing 2332335 bytes (34695 objects).
[info] transpiling 'examples/vororelax.wax' to Java...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.java
[info] freeing 2333528 bytes (34637 objects).
[info] transpiling 'examples/vororelax.wax' to TypeScript...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.ts
[info] freeing 2358929 bytes (34719 objects).
[info] transpiling 'examples/vororelax.wax' to JSON...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.json
[info] freeing 2393164 bytes (36627 objects).
[info] transpiling 'examples/vororelax.wax' to Python...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.py
Segmentation fault (core dumped)

If executing under valgrind we get this output:

sh test-waxc.sh 
==28257== Memcheck, a memory error detector
==28257== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==28257== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==28257== Command: ./waxc --c examples/vororelax.c --cpp examples/vororelax.cpp --cs examples/vororelax.cs --java examples/vororelax.java --json examples/vororelax.json --lua examples/vororelax.lua --py examples/vororelax.py --swift examples/vororelax.swift --ts examples/vororelax.ts --wat examples/vororelax.wat examples/vororelax.wax
==28257== 
[info] transpiling 'examples/vororelax.wax' to C...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.c
[info] freeing 2332335 bytes (34695 objects).
[info] transpiling 'examples/vororelax.wax' to Java...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.java
[info] freeing 2333528 bytes (34637 objects).
[info] transpiling 'examples/vororelax.wax' to TypeScript...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.ts
[info] freeing 2358929 bytes (34719 objects).
[info] transpiling 'examples/vororelax.wax' to JSON...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.json
[info] freeing 2393164 bytes (36627 objects).
[info] transpiling 'examples/vororelax.wax' to Python...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.py
==28257== Conditional jump or move depends on uninitialised value(s)
==28257==    at 0x1174B5: lift_scope (parser.c:3351)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x12DCA2: tree_to_py (to_py.c:648)
==28257==    by 0x14930C: transpile (waxc.c:118)
==28257==    by 0x149B9A: main (waxc.c:234)
==28257== 
==28257== Invalid write of size 1
==28257==    at 0x12DB2D: expr_to_py (to_py.c:628)
==28257==    by 0x12DDCF: tree_to_py (to_py.c:673)
==28257==    by 0x14930C: transpile (waxc.c:118)
==28257==    by 0x149B9A: main (waxc.c:234)
==28257==  Address 0x7ed84ec is 4 bytes before a block of size 32 alloc'd
==28257==    at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28257==    by 0x109E8F: mallocx (common.c:79)
==28257==    by 0x10A029: str_new (common.c:129)
==28257==    by 0x129FD3: expr_to_py (to_py.c:69)
==28257==    by 0x12DDCF: tree_to_py (to_py.c:673)
==28257==    by 0x14930C: transpile (waxc.c:118)
==28257==    by 0x149B9A: main (waxc.c:234)
==28257== 
[info] freeing 2327161 bytes (34685 objects).
[info] transpiling 'examples/vororelax.wax' to C#...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.cs
[info] freeing 2357311 bytes (34733 objects).
[info] transpiling 'examples/vororelax.wax' to C++...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.cpp
[info] freeing 2329169 bytes (34596 objects).
[info] transpiling 'examples/vororelax.wax' to Swift...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.swift
[info] freeing 2358627 bytes (34797 objects).
[info] transpiling 'examples/vororelax.wax' to Lua...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.lua
==28257== Invalid write of size 1
==28257==    at 0x140122: expr_to_lua (to_lua.c:607)
==28257==    by 0x1403B8: tree_to_lua (to_lua.c:655)
==28257==    by 0x149464: transpile (waxc.c:126)
==28257==    by 0x149CB6: main (waxc.c:254)
==28257==  Address 0x75bddfe is 2 bytes before a block of size 32 alloc'd
==28257==    at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28257==    by 0x109E8F: mallocx (common.c:79)
==28257==    by 0x10A029: str_new (common.c:129)
==28257==    by 0x13C280: expr_to_lua (to_lua.c:31)
==28257==    by 0x1403B8: tree_to_lua (to_lua.c:655)
==28257==    by 0x149464: transpile (waxc.c:126)
==28257==    by 0x149CB6: main (waxc.c:254)
==28257== 
[info] freeing 2324454 bytes (34287 objects).
[info] transpiling 'examples/vororelax.wax' to WebAssembly Text...
[info] running preprocessor...
[info] preprocessing 'math' included by 'examples/vororelax.wax'.
[info] constructing syntax tree...
[info] compiling syntax tree...
[info] generating target code: examples/vororelax.wat
==28257== Use of uninitialised value of size 8
==28257==    at 0x1174D5: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x1480EF: tree_to_wat (to_wat.c:1042)
==28257==    by 0x1494BB: transpile (waxc.c:128)
==28257==    by 0x149CFD: main (waxc.c:259)
==28257== 
==28257== Use of uninitialised value of size 8
==28257==    at 0x1174E2: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x1480EF: tree_to_wat (to_wat.c:1042)
==28257==    by 0x1494BB: transpile (waxc.c:128)
==28257==    by 0x149CFD: main (waxc.c:259)
==28257== 
==28257== Invalid read of size 2
==28257==    at 0x1174D5: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==  Address 0x20ba11 is not stack'd, malloc'd or (recently) free'd
==28257== 
==28257== 
==28257== Process terminating with default action of signal 11 (SIGSEGV)
==28257==  Access not within mapped region at address 0x20BA11
==28257==    at 0x1174D5: lift_scope (parser.c:3355)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==    by 0x117689: lift_scope (parser.c:3390)
==28257==  If you believe this happened as a result of a stack
==28257==  overflow in your program's main thread (unlikely but
==28257==  possible), you can try to increase the size of the
==28257==  main thread stack using the --main-stacksize= flag.
==28257==  The main thread stack size used in this run was 8388608.
==28257== 
==28257== HEAP SUMMARY:
==28257==     in use at exit: 6,707,080 bytes in 103,968 blocks
==28257==   total heap usage: 753,269 allocs, 649,301 frees, 42,444,797 bytes allocated
==28257== 
==28257== LEAK SUMMARY:
==28257==    definitely lost: 0 bytes in 0 blocks
==28257==    indirectly lost: 0 bytes in 0 blocks
==28257==      possibly lost: 0 bytes in 0 blocks
==28257==    still reachable: 6,707,080 bytes in 103,968 blocks
==28257==         suppressed: 0 bytes in 0 blocks
==28257== Rerun with --leak-check=full to see details of leaked memory
==28257== 
==28257== For counts of detected and suppressed errors, rerun with: -v
==28257== Use --track-origins=yes to see where uninitialised values come from
==28257== ERROR SUMMARY: 100 errors from 6 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)

Casting structs (or how to handle generic functions)

I have a language ( https://github.com/johnynek/bosatsu ) that I am considering compiling to wax to take advantage of the many backends.

My language supports generics. When I compile to python, this isn't a problem since I leave the code untyped. I had imagined compiling to java by making generic values Object and casting results from calls to generic functions (since the compile can see the resulting type).

For C, I had imagined casting to void* doing a similar approach.

I don't want to have to monomorphize the code (that brings a lot of issues, and it is not clear all recursions result in statically known types inside of recursions, but maybe they do).

Do you have any suggestions of how I would represent generics in my language in wax? There does not seem to be a way to cast pointers or have any equivalent of a void*.

Am I getting that right?

Railroad grammar diagram

Playing around with https://www.bottlecaps.de/rr/ui I've got the beginning of an EBNF wax grammar to produce a railroad diagram, paste the EBNF show bellow in Edit Grammar then switch to tab View Diagram.

program  ::=
	comments
	| expression
	| preprocessor

expression ::=
	atom
	| list

atom ::=
	builtin
	| operator
	| keyword
	| name
	| number
	| string

list     ::= '(' expression+ ')'

keyword  ::=
	'asm'
	| 'call'
	| 'do'
	| 'else'
	| 'extern'
	| 'for'
	| 'func'
	| 'if'
	| 'let'
	| 'local'
	| 'main'
	| 'param'
	| 'result'
	| 'return'
	| 'then'
	| 'while'

types ::=
	'arr'
	| 'float'
	| 'int'
	| 'map'
	| 'str'
	| 'struct'
	| 'vec'

builtin  ::=
	'alloc'
	| 'cast'
	| 'free'
	| 'get'
	| 'insert'
	| 'print'
	| 'remove'
	| 'set'
	| 'slice'

preprocessor
         ::= '@' ( 'define' | 'if' | 'include' | 'pragma' )

operator ::= ( '+' | '-' | '*' | '\' | '#' | '&&' | '||' | '?' | ':' | '=' | '<>' | '<' | '<=' | '>' | '>=' | '<<' | '>>' | '^' | '%' | '&' | '|' | '!' | '~' )?

number   ::= [0-9]+

comments ::= ';;' [^\n]*

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.