Skip to content

Commit

Permalink
Merge 593ce31 into 1cc9c7d
Browse files Browse the repository at this point in the history
  • Loading branch information
peq committed Feb 10, 2019
2 parents 1cc9c7d + 593ce31 commit f0c71d5
Show file tree
Hide file tree
Showing 93 changed files with 4,039 additions and 574 deletions.
2 changes: 1 addition & 1 deletion de.peeeq.wurstscript/build.gradle
Expand Up @@ -70,7 +70,7 @@ dependencies {
antlr "org.antlr:antlr4:4.7"

// tool for generating AST-classes
compileOnly 'com.github.peterzeller:abstractsyntaxgen:0.3.1'
compileOnly 'com.github.peterzeller:abstractsyntaxgen:0bbad156084643268d3341cba5f21106e8c9e0d6'

// JUnit for testing
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
Expand Down
71 changes: 35 additions & 36 deletions de.peeeq.wurstscript/deploy.gradle
Expand Up @@ -41,51 +41,50 @@ create_zip_wurstpack_compiler.dependsOn(make_for_wurstpack)

task create_zips {
doLast {
mkdir("../downloads/")
copy {
from 'build/distributions/'
into '../downloads/'
}
copy {
from 'build/install/wurstscript/lib/wurstscript.jar'
into '../downloads/'
}
copy {
from '../Wurstpack'
into '../downloads/Wurstpack/'
}
copy {
from '../WurstSetup/build/libs/WurstSetup.jar'
into '../downloads/'
}
// create checksums
mkdir("../Checksums/bin")
mkdir("../downloads/")
copy {
from 'build/distributions/'
into '../downloads/'
}
copy {
from 'build/install/wurstscript/lib/wurstscript.jar'
into '../downloads/'
}
copy {
from '../Wurstpack'
into '../downloads/Wurstpack/'
}
copy {
from '../WurstSetup/build/libs/WurstSetup.jar'
into '../downloads/'
}
// create checksums
mkdir("../Checksums/bin")

javaexec {
classpath = sourceSets.main.runtimeClasspath
main = "de.peeeq.wurstio.Checksums"
args = ["../downloads/Wurstpack/",
"../downloads/wurstpack.md5"]
}
javaexec {
classpath = sourceSets.main.runtimeClasspath
main = "de.peeeq.wurstio.Checksums"
args = ["../downloads/Wurstpack/",
"../downloads/wurstpack.md5"]
}
}

}
create_zips.dependsOn(installDist)
create_zips.dependsOn(create_zip_wurstpack_complete)
create_zips.dependsOn(create_zip_wurstpack_compiler)

task generate_hotdoc {
doLast {
copy {
from("/src/main/resources/")
into("/build/classes/main/")
}
javaexec {
classpath = sourceSets.main.runtimeClasspath
main = "de.peeeq.wurstio.Main"
args = ["--hotdoc",
"./build/deps/",
"../downloads/hotdoc"]
copy {
from("/src/main/resources/")
into("/build/classes/main/")
}
javaexec {
classpath = sourceSets.main.runtimeClasspath
main = "de.peeeq.wurstio.Main"
args = ["--hotdoc",
"./build/deps/",
"../downloads/hotdoc"]
}
}
}
Expand Down
83 changes: 59 additions & 24 deletions de.peeeq.wurstscript/parserspec/jass_im.parseq
Expand Up @@ -6,13 +6,16 @@ abstract syntax:
ImProg(
@ignoreForEquality de.peeeq.wurstscript.ast.Element trace,
ImVars globals,
ImFunctions functions,
ImClasses classes,
ImFunctions functions,
ImMethods methods,
ImClasses classes,
ImTypeClassFuncs typeClassFunctions,
java.util.Map<ImVar, java.util.List<ImExpr>> globalInits)

ImVars * ImVar
ImFunctions * ImFunction
ImClasses * ImClass
ImTypeClassFuncs * ImTypeClassFunc

ImVar(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImType type, String name, boolean isBJ)

Expand All @@ -22,25 +25,42 @@ ImType =
| ImArrayTypeMulti(ref ImType entryType, java.util.List<Integer> arraySize)
| ImTupleType(java.util.List<ImType> types, java.util.List<String> names)
| ImVoid()

| ImClassType(ref ImClass classDef, ImTypeArguments typeArguments)
| ImTypeVarRef(ref ImTypeVar typeVariable)

ImTypeVars * ImTypeVar

ImTypeVar(String name)

ImFunction(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace,
String name,
String name,
ImTypeVars typeVariables,
ImVars parameters,
ref ImType returnType,
ImVars locals,
ImStmts body,
java.util.List<de.peeeq.wurstscript.translation.imtranslation.FunctionFlag> flags)

ImTypeClassFunc(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace,
String name,
ImTypeVars typeVariables,
ImVars parameters,
ref ImType returnType)


ImClass(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace,
String name,
String name,
ImTypeVars typeVariables,
ImVars fields,
ImMethods methods,
java.util.List<ImClass> superClasses)
ImMethods methods,
ImFunctions functions,
java.util.List<ImClassType> superClasses)

ImMethods * ImMethod

ImMethod(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace,
String name,
ImMethod(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace,
ref ImClassType methodClass,
String name,
ref ImFunction implementation,
java.util.List<ImMethod> subMethods,
boolean isAbstract)
Expand Down Expand Up @@ -75,6 +95,9 @@ ImExpr =
| ImGetStackTrace()
| ImCompiletimeExpr(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ImExpr expr, int executionOrderIndex)
| ImLExpr
| ImTypeVarDispatch(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImTypeClassFunc typeClassFunc, ImExprs arguments
, ref ImTypeVar typeVariable)
| ImCast(ImExpr expr, ref ImType toType)

// an expression which can be used on the left hand side of an assignment
ImLExpr =
Expand All @@ -87,18 +110,26 @@ ImLExpr =



ImClassRelatedExpr =
ImMethodCall(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImMethod method, ImExpr receiver, ImExprs arguments, boolean tuplesEliminated)
| ImAlloc(ref ImClass clazz)
| ImDealloc(ref ImClass clazz, ImExpr obj)
| ImMemberAccess(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ImExpr receiver, ref ImVar var)
| ImInstanceof(ImExpr obj, ref ImClass clazz)
| ImTypeIdOfObj(ImExpr obj, ref ImClass clazz)
| ImTypeIdOfClass(ref ImClass clazz)
ImClassRelatedExpr =
ImMemberOrMethodAccess
| ImClassRelatedExprWithClass

ImMemberOrMethodAccess =
ImMethodCall(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImMethod method, ImTypeArguments typeArguments, ImExpr receiver, ImExprs arguments, boolean tuplesEliminated)
| ImMemberAccess(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ImExpr receiver, ImTypeArguments typeArguments, ref ImVar var, ImExprs indexes)

ImClassRelatedExprWithClass =
ImAlloc(ref ImClassType clazz)
| ImDealloc(ref ImClassType clazz, ImExpr obj)
| ImInstanceof(ImExpr obj, ref ImClassType clazz)
| ImTypeIdOfObj(ImExpr obj, ref ImClassType clazz)
| ImTypeIdOfClass(ref ImClassType clazz)




ImCall =
ImFunctionCall(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImFunction func, ImExprs arguments
ImFunctionCall(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImFunction func, ImTypeArguments typeArguments, ImExprs arguments
, boolean tuplesEliminated, de.peeeq.wurstscript.translation.imtranslation.CallType callType)
| ImOperatorCall(de.peeeq.wurstscript.WurstOperator op, ImExprs arguments)

Expand All @@ -107,9 +138,13 @@ ImConst =
| ImRealVal(String valR)
| ImStringVal(String valS)
| ImBoolVal(boolean valB)
| ImFuncRef(ref ImFunction func)
| ImFuncRef(@ignoreForEquality de.peeeq.wurstscript.ast.Element trace, ref ImFunction func)
| ImNull(ref ImType type)

ImTypeArguments * ImTypeArgument

ImTypeArgument(ref ImType type, java.util.Map<ImTypeClassFunc, fj.data.Either<ImMethod, ImFunction>> typeClassBinding)

// helper types:


Expand All @@ -118,14 +153,14 @@ JassImElementWithName = ImVar | ImFunction | ImClass | ImMethod
ElementWithTrace = ImVar | ImFunction | ImClass | ImMethod | ImIf | ImLoop | ImExitwhen | ImReturn
| ImSet | ImSetTuple | ImSetArray | ImSetArrayMulti | ImSetArrayTuple
| ImMethodCall | ImFunctionCall | ImCompiletimeExpr | ImVarArrayAccess | ImMemberAccess
| ImProg
| ImProg | ImFuncRef

ElementWithTypes = ImTupleType | ImTupleArrayType

ElementWithVar = ImVarAccess | ImVarArrayAccess | ImVarArrayMultiAccess | ImMemberAccess


ImPrintable = ImStmt | ImFunction | ImProg | ImVar | ImType | ImStmts | ImExprOpt
ImPrintable = ImStmt | ImFunction | ImProg | ImVar | ImType | ImStmts | ImExprOpt | ImType | ImTypeVar | ImClass

ImVarWrite = ImSet | ImSetArray | ImSetArrayMulti | ImSetArrayTuple | ImSetTuple
ImVarRead = ImVarAccess | ImVarArrayAccess | ImVarArrayMultiAccess
Expand All @@ -140,7 +175,7 @@ ImPrintable.print(java.lang.Appendable sb, int indent)
returns void
implemented by de.peeeq.wurstscript.translation.imtranslation.ImPrinter.print

ImPrintable.toString()
Element.toString()
returns String
implemented by de.peeeq.wurstscript.translation.imtranslation.ImPrinter.asString

Expand Down Expand Up @@ -315,7 +350,7 @@ ImMethod.attrClass()
returns ImClass
implemented by de.peeeq.wurstscript.translation.imtojass.ImAttributes.attrClass

ImClass.attrTypeId
ImClass.attrTypeId()
returns int
implemented by de.peeeq.wurstscript.translation.imtranslation.TypeId.get

Expand All @@ -338,4 +373,4 @@ ImProg.attrSubclasses
ImLExpr.isUsedAsLValue()
returns boolean
implemented by de.peeeq.wurstscript.translation.imtranslation.LValues.isUsedAsLValue


12 changes: 10 additions & 2 deletions de.peeeq.wurstscript/parserspec/wurstscript.parseq
Expand Up @@ -115,7 +115,9 @@ ArraySizes * Expr

TypeParamDefs * TypeParamDef

TypeParamDef(de.peeeq.wurstscript.parser.WPos source, Modifiers modifiers, Identifier nameId)
TypeParamDef(de.peeeq.wurstscript.parser.WPos source, Modifiers modifiers, Identifier nameId, TypeParamConstraints typeParamConstraints)

TypeParamConstraints = NoTypeParamConstraints() | TypeExprList


WParameters * WParameter
Expand Down Expand Up @@ -343,7 +345,9 @@ AstElementWithIndexes = ExprMemberArrayVar | ExprVarArrayAccess

ClassOrModule = ClassDef | ModuleDef

StructureDef = ClassOrModuleOrModuleInstanciation | InterfaceDef
StructureDef = ClassOrModuleOrModuleInstanciation | ClassOrInterface

ClassOrInterface = ClassDef | InterfaceDef

ClassOrModuleInstanciation = ClassDef | ModuleInstanciation
ClassOrModuleOrModuleInstanciation = ClassOrModule | ClassOrModuleInstanciation
Expand Down Expand Up @@ -518,6 +522,10 @@ Element.attrNearestClassDef()
returns @Nullable ClassDef
implemented by de.peeeq.wurstscript.attributes.AttrNearest.nearestClassDef

Element.attrNearestClassOrInterface()
returns @Nullable ClassOrInterface
implemented by de.peeeq.wurstscript.attributes.AttrNearest.nearestClassOrInterface

Element.attrNearestClassOrModule()
returns @Nullable ClassOrModule
implemented by de.peeeq.wurstscript.attributes.AttrNearest.nearestClassOrModule
Expand Down
Expand Up @@ -132,6 +132,15 @@ classDef:
ENDBLOCK)?
;

typeclassDef:
modifiersWithDoc 'typeclass' name=ID typeParams
('extends' implemented+=typeExpr (',' implemented+=typeExpr)*)?
NL (STARTBLOCK
classSlots
ENDBLOCK)?
;


enumDef: modifiersWithDoc 'enum' name=ID NL (STARTBLOCK
(enumMembers+=ID NL)*
ENDBLOCK)?;
Expand Down Expand Up @@ -406,7 +415,10 @@ shortFormalParameter: typeExpr? name=ID;

typeParams: ('<' (params+=typeParam (',' params+=typeParam)*)? '>')?;

typeParam: name=ID;
typeParam: name=ID typeParamConstraints?;

typeParamConstraints: ':' (constraints+=typeExpr ('and' constraints+=typeExpr)*)?;


stmtForLoop:
forRangeLoop
Expand Down
Expand Up @@ -156,7 +156,7 @@ protected void print(String message) {
runTests.runTests(compiler.getImProg(), null, null);

for (RunTests.TestFailure e : runTests.getFailTests()) {
gui.sendError(new CompileError(e.getFunction().attrTrace().attrErrorPos(), e.getMessage()));
gui.sendError(new CompileError(e.getFunction(), e.getMessage()));
if (runArgs.isGui()) {
// when using graphical user interface, send stack trace to GUI
for (ILStackFrame sf : Utils.iterateReverse(e.getStackTrace().getStackFrames())) {
Expand Down
Expand Up @@ -267,7 +267,7 @@ private ImExpr constantToExprHashtable(ImCompiletimeExpr cte, Element trace, Arr
WPos errorPos = trace.attrErrorPos();
ImFunction initHashtable = findNative("InitHashtable", errorPos);
ImStmts stmts = JassIm.ImStmts(
JassIm.ImSet(trace, JassIm.ImVarAccess(htVar), JassIm.ImFunctionCall(trace, initHashtable, JassIm.ImExprs(), false, CallType.NORMAL))
JassIm.ImSet(trace, JassIm.ImVarAccess(htVar), JassIm.ImFunctionCall(trace, initHashtable, JassIm.ImTypeArguments(), JassIm.ImExprs(), false, CallType.NORMAL))
);

// we have to collect all values after all compiletime functions have run, so use delayedActions
Expand All @@ -278,7 +278,7 @@ private ImExpr constantToExprHashtable(ImCompiletimeExpr cte, Element trace, Arr
if (v instanceof ILconstInt) {
ILconstInt iv = (ILconstInt) v;
ImFunction SaveInteger = findNative("SaveInteger", errorPos);
stmts.add(JassIm.ImFunctionCall(trace, SaveInteger, JassIm.ImExprs(
stmts.add(JassIm.ImFunctionCall(trace, SaveInteger, JassIm.ImTypeArguments(), JassIm.ImExprs(
JassIm.ImVarAccess(htVar),
JassIm.ImIntVal(key.getParentkey()),
JassIm.ImIntVal(key.getChildkey()),
Expand Down
Expand Up @@ -394,6 +394,11 @@ public JassProg transformProgToJass() {
imTranslator2.assertProperties();
checkNoCompiletimeExpr(imProg2);
int stage = 2;
// eliminate
beginPhase(2, "Eliminate generics");
new EliminateGenerics(imTranslator2, imProg2).transform();
printDebugImProg("./test-output/im " + stage++ + "_genericsEliminated.im");

// eliminate classes
beginPhase(2, "translate classes");

Expand Down
Expand Up @@ -571,6 +571,11 @@ public List<Either<String, MarkedString>> case_NativeType(NativeType nativeType)
return description(nativeType);
}

@Override
public List<Either<String, MarkedString>> case_NoTypeParamConstraints(NoTypeParamConstraints noTypeParamConstraints) {
return string("No type parameter constraints given.");
}

@Override
public List<Either<String, MarkedString>> case_StmtForRangeUp(StmtForRangeUp stmtForRangeUp) {
return string("Execute the body several times, counting up");
Expand Down
Expand Up @@ -109,7 +109,7 @@ public static ModuleInstanciations expandModules(ModuleInstanciation mi) {
return mi.getP_moduleInstanciations();
}

private static <T extends Element> T smartCopy(T e, List<Pair<WurstType, WurstType>> typeReplacements) {
public static <T extends Element> T smartCopy(T e, List<Pair<WurstType, WurstType>> typeReplacements) {
List<Pair<ImmutableList<Integer>, TypeExpr>> replacementsByPath = Lists.newArrayList();
calcReplacementsByPath(typeReplacements, replacementsByPath, e, ImmutableList.<Integer>emptyList());

Expand All @@ -118,7 +118,7 @@ private static <T extends Element> T smartCopy(T e, List<Pair<WurstType, WurstTy

// Do the type replacements
for (Pair<ImmutableList<Integer>, TypeExpr> rep : replacementsByPath) {
doReplacement(copy, rep.getA(), (TypeExpr) rep.getB().copy());
doReplacement(copy, rep.getA(), rep.getB().copy());
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit f0c71d5

Please sign in to comment.