Skip to content

thewilli/lang-dryad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lang-dryad

Dryad Language Library for the SugarJ Framework (http://sugarj.org)

About

The Dryad Language Library uses code based on the Dryad Compiler (https://strategoxt.org/Stratego/TheDryadCompiler) to enable developing with a mixture of Java and Bytecode. As the compiler is written in Stratego/XT as well not only source- but also compiletime modifications can be realized using Stratego transformations.

Why should I use it?

By being able to hook into the compilation process transformations can use the informations collected by the compiler like the expected and actual type.

This example uses type information to allow the usage of classes that implement a certain Interface to be used instead of int values:

//Interface
public interface IntInterface{
	public int intValue();
}
//Simple implementation
public class IntContainer implements IntInterface{
	private int field;
	public IntContainer(int field){
		this.field = field;
	}
	public int intValue(){
		return field;
	}
}
//How to use it
void test(){
  IntContainer cont1 = new IntContainer(2);
  IntContainer cont2 = new IntContainer(7);
  IntContainer cont3 = new IntContainer(3);
  IntContainer cont4;
  int a,b,c;
  a = cont1; //'cont1' is replaced by 'cont1.intValue()'
  cont4 = cont1; //'cont1' is not modified
  b = 2 + cont2 * cont4 - cont3;
  c = a * (b + cont2 + 5);
  System.out.println(c); //50
}

The IntContainer class extends that Interface, so its instances can be used wherever a regular int could be. If it is placed in an expression where an int is expected, the instance itself is replaced by the result of its intValue() method.

Please see the example project for additional use cases.

About

Dryad Language Library for the SugarJ Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published