Skip to content

Commit

Permalink
Lots of interesting debug statements, rock is such a fiddle beast.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Wenger committed Jun 6, 2012
1 parent ea8deb6 commit 8e55059
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
10 changes: 9 additions & 1 deletion source/rock/backend/cnaughty/CGenerator.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,15 @@ CGenerator: class extends Skeleton {
if(vDecl isStatic()) {
current app("static ")
}
vDecl getType() write(current, vDecl getFullName())

if (vDecl debugCondition()) "vDecl %p (%s) has type %s" printfln(vDecl, vDecl toString(), vDecl getType() ? vDecl getType() toString() : "nil")

if (vDecl getType()) {
vDecl getType() write(current, vDecl getFullName())
} else {
// FIXME: just testing
current app(" wtf_unknown_type "). app(vDecl getFullName())
}
if(vDecl expr && !vDecl isArg)
current app(" = "). app(vDecl expr)
}
Expand Down
17 changes: 16 additions & 1 deletion source/rock/middle/Argument.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ DotArg: class extends Argument {

resolve: func (trail: Trail, res: Resolver) -> Response {

if(debugCondition()) "Resolving %s" printfln(toString())

idx := trail find(TypeDecl)
if(idx == -1) res throwError(InternalError new(token, "Use of a %s outside a type declaration! That's nonsensical." format(class name)))


tDecl := trail get(idx, TypeDecl)
ref = tDecl getVariable(name)

if(debugCondition()) "tDecl = %s" printfln(tDecl toString())

if(debugCondition()) "ref = %s" printfln(ref ? ref toString() : "nil")

if(ref == null) {
if(res fatal) res throwError(UnresolvedArgumentAccess new(token,
"%s refers to non-existing member variable '%s' in type '%s'" format(class name, name, tDecl getName())))
Expand All @@ -89,6 +97,7 @@ DotArg: class extends Argument {

if(type == null) {
type = ref getType()
if(debugCondition()) "type = %s" printfln(type ? type toString() : "nil")

if(type == null) {
if(res fatal) {
Expand All @@ -97,17 +106,23 @@ DotArg: class extends Argument {
res wholeAgain(this, "Hasn't resolved type yet :x")
return Response OK
} else if(type isGeneric()) {
if(debugCondition()) "type %s is generic, cloning and resolving" printfln(type ? type toString() : "nil")

type = type clone()
// force re-resolving in the child's context
// useful in case of generic specialization, e.g.
// A: class <T> {}
// B: class extends A<Int> {}
type setRef(null)
type resolve(trail, res)

if(debugCondition()) "now type = %s and ref is %s" printfln(type toString(), type getRef() ? type getRef() toString() : "nil")
}

if(debugCondition()) "now type for %p = %s" printfln(this, type ? type toString() : "nil")
}

return super(trail, res)
return super(trail, res)

}

Expand Down
25 changes: 19 additions & 6 deletions source/rock/middle/ClassDecl.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ClassDecl: class extends TypeDecl {
copy module = module

typeArgs each(|ta| copy addTypeArg(ta clone()))
variables each(|k, v| copy getMeta() addVariable(v clone()))
variables each(|k, v| copy addVariable(v clone()))
getMeta() functions each(|fuuuuu| copy getMeta() addFunction(fuuuuu clone()))

copy
Expand Down Expand Up @@ -99,10 +99,6 @@ ClassDecl: class extends TypeDecl {

resolve: func (trail: Trail, res: Resolver) -> Response {

specializations each(|k, specialized|
specialized resolve(trail, res)
)

if(shouldCheckNoArgConstructor) {
finalScore := 0
if(defaultInit == null || hasOtherInit()) {
Expand Down Expand Up @@ -148,7 +144,16 @@ ClassDecl: class extends TypeDecl {
if (!response ok()) return response
}

return Response OK
finalResponse := Response OK
specializations each(|k, specialized|
response := specialized resolve(trail, res)
if (!response ok()) finalResponse = response

response = specialized getMeta() resolve(trail, res)
if (!response ok()) finalResponse = response
)

return finalResponse
}

writeSize: func (w: TabbedWriter, instance: Bool) {
Expand Down Expand Up @@ -350,6 +355,14 @@ ClassDecl: class extends TypeDecl {

addFunction(constructor)
}

toString: func -> String {
if (isSpecialized()) {
super() + " (specialized)"
} else {
super()
}
}
}

NoDefaultConstructorError: class extends Error {
Expand Down
4 changes: 2 additions & 2 deletions source/rock/middle/TypeDecl.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ TypeDecl: abstract class extends Declaration {
}

resolveType: func (type: BaseType, res: Resolver, trail: Trail) -> Int {

if(type getName() == "This") {
if(type suggest(getNonMeta() ? getNonMeta() : this)) return 0
}
Expand All @@ -646,7 +646,7 @@ TypeDecl: abstract class extends Declaration {
resolveAccess: func (access: VariableAccess, res: Resolver, trail: Trail) -> Int {

if(access debugCondition()) {
"Resolving access %s. isMeta = %s\n" format(access toString(), isMeta toString()) println()
"resolveAccess(%s) in %s\n" format(access toString(), toString()) println()
}

// don't allow to resolve any access before finishing ghosting
Expand Down
3 changes: 2 additions & 1 deletion source/rock/middle/VariableAccess.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ VariableAccess: class extends Expression {
hasSideEffects : func -> Bool { false }

debugCondition: func -> Bool {
false
name == "X"
}

suggest: func (node: Node) -> Bool {
Expand Down Expand Up @@ -202,6 +202,7 @@ VariableAccess: class extends Expression {
suggest(node as TypeDecl thisDecl)
}
}

node resolveAccess(this, res, trail)

if(ref) {
Expand Down
1 change: 1 addition & 0 deletions source/rock/middle/VariableDecl.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ VariableDecl: class extends Declaration {
copy isGlobal = isGlobal
copy isConst = isConst
copy isProto = isProto
copy isStatic = isStatic
copy externName = externName
copy unmangledName = unmangledName
copy fDecl = fDecl
Expand Down

0 comments on commit 8e55059

Please sign in to comment.