Skip to content

Commit

Permalink
Get rid of: InlineContext, Yajit. Fix cloning problems.
Browse files Browse the repository at this point in the history
InlineContext was removed in conspiracy a while ago but that
never floated up to master. Yajit isn't even in the SDK anymore,
but it was still referred to here when dealing with flat closures..
which we officially don't support anymore.

This still doesn't make my test3 pass (having cover templates with
different templateArgs in the same file) but at least I feel like
I'm getting somewhere.

Also, see? Long commit messages with a nice short one on top.

Maybe I am getting better with age.
  • Loading branch information
nddrylliog committed Feb 15, 2013
1 parent e477c06 commit f139e2b
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 626 deletions.
6 changes: 1 addition & 5 deletions source/rock/backend/cnaughty/CGenerator.ooc
Expand Up @@ -14,7 +14,7 @@ import ../../middle/[Module, FunctionDecl, FunctionCall, Expression, Type,
Cast, Comparison, Ternary, BoolLiteral, Argument, Statement,
AddressOf, Dereference, CommaSequence, UnaryOp, ArrayAccess, Match,
FlowControl, InterfaceDecl, Version, Block, EnumDecl, ArrayLiteral,
ArrayCreation, StructLiteral, InlineContext, FuncType]
ArrayCreation, StructLiteral, FuncType]

import Skeleton, FunctionDeclWriter, ControlStatementWriter,
ClassDeclWriter, ModuleWriter, CoverDeclWriter, FunctionCallWriter,
Expand Down Expand Up @@ -349,10 +349,6 @@ CGenerator: class extends Skeleton {
writeLine(stmt)
}
current untab(). nl(). app('}')
// ifs are evil. fix that.
if(b instanceOf?(InlineContext)) {
current nl(). app(b as InlineContext label). app(":;")
}
}

/** Write a range literal */
Expand Down
12 changes: 8 additions & 4 deletions source/rock/frontend/CommandLine.ooc
Expand Up @@ -112,20 +112,24 @@ CommandLine: class {
params entryPoint = arg substring(arg indexOf('=') + 1)

} else if (option == "newsdk") {

hardDeprecation("newsdk", params)

} else if (option == "newstr") {

hardDeprecation("newstr", params)

} else if(option == "cstrings") {

hardDeprecation("cstrings", params)

} else if (option == "inline") {

if(!longOption) warnUseLong("inline")
params inlining = true
hardDeprecation("inline", params)

} else if (option == "no-inline") {

if(!longOption) warnUseLong("no-inline")
params inlining = false
hardDeprecation("inline", params)

} else if (option == "c") {

Expand Down
20 changes: 20 additions & 0 deletions source/rock/middle/Argument.ooc
Expand Up @@ -35,6 +35,11 @@ Argument: abstract class extends VariableDecl {

}

clone: func -> This {
copy := new(type ? type clone() : null, name, token)
cloneInto(copy) as This
}

}

VarArg: class extends Argument {
Expand Down Expand Up @@ -63,6 +68,11 @@ VarArg: class extends Argument {

toString: func -> String { "..." }

clone: func -> This {
copy := new(token, name)
cloneInto(copy) as This
}

}

DotArg: class extends Argument {
Expand Down Expand Up @@ -113,6 +123,11 @@ DotArg: class extends Argument {

toString: func -> String { "." + name }

clone: func -> This {
copy := new(name, token)
cloneInto(copy) as This
}

}

AssArg: class extends DotArg {
Expand Down Expand Up @@ -150,6 +165,11 @@ AssArg: class extends DotArg {

toString: func -> String { "=" + name }

clone: func -> This {
copy := new(name, token)
cloneInto(copy) as This
}

}

UnresolvedArgumentAccess: class extends Error {
Expand Down
13 changes: 12 additions & 1 deletion source/rock/middle/BaseType.ooc
Expand Up @@ -375,11 +375,22 @@ BaseType: class extends Type {
null
}

breakPoint: func {
// ohyeah
}

clone: func -> This {
copy := new(name, token)
if(getTypeArgs()) for(typeArg in getTypeArgs()) {
copy addTypeArg(typeArg)
copy addTypeArg(typeArg clone())
}

if (name == "HashMap") {
"Cloning type HashMap!" println()
breakPoint()
}

// Why does HashMap need this?
copy setRef(getRef())
copy
}
Expand Down
2 changes: 1 addition & 1 deletion source/rock/middle/Block.ooc
Expand Up @@ -11,7 +11,7 @@ Block: class extends ControlStatement {

clone: func -> This {
copy := new(token)
body list each(|e| copy body add(e clone()))
body list each(|stat| copy body add(stat clone()))
copy
}

Expand Down
10 changes: 7 additions & 3 deletions source/rock/middle/ClassDecl.ooc
Expand Up @@ -257,12 +257,16 @@ ClassDecl: class extends TypeDecl {
return
}

newType := isMeta ? getNonMeta() getInstanceType() as BaseType : getInstanceType() as BaseType
newType := (isMeta ? getNonMeta() getInstanceType() : getInstanceType()) as BaseType

constructor := FunctionDecl new("new", fDecl token)
constructor setStatic(true)
constructor setSuffix(fDecl getSuffix())
retType := newType clone() as BaseType
retType := newType clone()

// FIXME: Why is that needed?
retType setRef(newType getRef())

if(retType getTypeArgs()) retType getTypeArgs() clear()

constructor getArguments() addAll(fDecl getArguments())
Expand All @@ -279,7 +283,7 @@ ClassDecl: class extends TypeDecl {
expr := Cast new(allocCall, newType, fDecl token)
vdfe = VariableDecl new(null, "this", expr, fDecl token)
} else {
vdfe = VariableDecl new(newType clone(), "this", fDecl token)
vdfe = VariableDecl new(retType, "this", fDecl token)
}
constructor getBody() add(vdfe)

Expand Down
2 changes: 1 addition & 1 deletion source/rock/middle/CommaSequence.ooc
Expand Up @@ -13,7 +13,7 @@ CommaSequence: class extends Expression {

clone: func -> This {
copy := new(token)
body each(|e| copy body add(e clone()))
body each(|stat| copy body add(stat clone()))
copy
}

Expand Down
2 changes: 1 addition & 1 deletion source/rock/middle/Foreach.ooc
Expand Up @@ -17,7 +17,7 @@ Foreach: class extends ControlStatement {

clone: func -> This {
copy := new(variable clone(), collection clone(), token)
body list each(|e| copy body add(e clone()))
body list each(|stat| copy body add(stat clone()))
copy
}

Expand Down
30 changes: 23 additions & 7 deletions source/rock/middle/FuncType.ooc
Expand Up @@ -53,20 +53,36 @@ FuncType: class extends Type {

realTypize: func (call: FunctionCall) -> Type {
copy := This new(token)
if(typeArgs) typeArgs each(|typeArg| copy addTypeArg(typeArg))
for(argType in argTypes) {
copy argTypes add(argType realTypize(call))
if(typeArgs) {
typeArgs each(|typeArg|
copy addTypeArg(typeArg)
)
}
copy returnType = returnType realTypize

argTypes each(|argType|
copy argTypes add(argType realTypize(call))
)

copy returnType = returnType ? returnType realTypize(call) : null
copy varArg = varArg
copy isClosure = isClosure
copy
}

clone: func -> This {
copy := This new(token)
if(typeArgs) typeArgs each(|typeArg| copy addTypeArg(typeArg))
copy argTypes addAll(argTypes)
copy returnType = returnType

if(typeArgs) {
typeArgs each(|typeArg|
copy addTypeArg(typeArg clone())
)
}

argTypes each(|argType|
copy argTypes add(argType clone())
)

copy returnType = returnType ? returnType clone() : null
copy varArg = varArg
copy isClosure = isClosure
copy
Expand Down
52 changes: 2 additions & 50 deletions source/rock/middle/FunctionCall.ooc
Expand Up @@ -3,7 +3,7 @@ import ../frontend/[Token, BuildParams, CommandLine]
import Visitor, Expression, FunctionDecl, Argument, Type,
TypeDecl, Node, VariableDecl, VariableAccess, AddressOf, CommaSequence, BinaryOp,
InterfaceDecl, Cast, NamespaceDecl, BaseType, FuncType, Return,
TypeList, Scope, Block, InlineContext, StructLiteral, NullLiteral,
TypeList, Scope, Block, StructLiteral, NullLiteral,
IntLiteral, Ternary, ClassDecl, CoverDecl, ArrayLiteral
import tinker/[Response, Resolver, Trail, Errors]

Expand Down Expand Up @@ -154,8 +154,7 @@ FunctionCall: class extends Expression {
* a return expression, when it's being used.
*/
debugCondition: inline func -> Bool {
//false
name == "new"
false
}

/**
Expand Down Expand Up @@ -384,53 +383,6 @@ FunctionCall: class extends Expression {
return Response OK
}

// resolved. if we're inlining, do it now!
// FIXME: this is oh-so-primitive.
if(res params inlining && ref doInline) {
if(expr && (expr getType() == null || !expr getType() isResolved())) {
res wholeAgain(this, "need expr type!")
return Response OK
}

"Inlining %s! type = %s" format(toString(), getType() ? getType() toString() : "<unknown>") println()

retDecl := VariableDecl new(getType(), generateTempName("retval"), token)
retAcc := VariableAccess new(retDecl, token)
trail addBeforeInScope(this, retDecl)

block := InlineContext new(this, token)
block returnArgs add(retDecl) // Note: this isn't sufficient. What with TypeList return types?

reservedNames := ref args map(|arg| arg name)

for(i in 0..args getSize()) {
callArg := args get(i)

name := ref args get(i) getName()

if(callArg instanceOf?(VariableAccess)) {
vAcc := callArg as VariableAccess
if(reservedNames contains?(vAcc getName())) {
tempDecl := VariableDecl new(null, generateTempName(name), callArg, callArg token)
block body add(0, tempDecl)
callArg = VariableAccess new(tempDecl, tempDecl token)
}
}

block body add(VariableDecl new(null, name, callArg, callArg token))
}

ref inlineCopy getBody() list each(|x|
block body add(x clone())
)

trail addBeforeInScope(this, block)
trail peek() replace(this, retAcc)

res wholeAgain(this, "finished inlining")
return Response OK
}

if(!handleGenerics(trail, res) ok()) {
res wholeAgain(this, "looping because of generics!")
return Response OK
Expand Down

0 comments on commit f139e2b

Please sign in to comment.