Skip to content

Commit

Permalink
Merge branch 'master' into bson
Browse files Browse the repository at this point in the history
  • Loading branch information
fredreichbier committed Aug 9, 2010
2 parents 24dec4d + 28f9330 commit 4413e9e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 40 deletions.
2 changes: 1 addition & 1 deletion sdk/lang/String.ooc
Expand Up @@ -99,7 +99,7 @@ Char: cover from char {
/** convert to an integer. This only works for digits, otherwise -1 is returned */
toInt: func -> Int {
if (digit?()) {
return (this - '0')
return (this - '0') as Int
}
return -1
}
Expand Down
3 changes: 1 addition & 2 deletions sdk/os/native/PipeUnix.ooc
Expand Up @@ -52,8 +52,7 @@ PipeUnix: class extends Pipe {

/** read 'len' bytes at most from the pipe */
read: func(len: Int) -> Pointer {
//return readFD read(len)
buf := gc_malloc(len + 1)
buf := gc_malloc(len + 1) as Char*
howmuch := readFD read(buf, len)
buf[howmuch] = '\0'
return buf
Expand Down
4 changes: 2 additions & 2 deletions sdk/structs/Stack.ooc
Expand Up @@ -28,9 +28,9 @@ Stack: class <T> extends BackIterable<T> {
peek: func ~index (index: Int) -> T {
size := data size()
if (index < 1)
Exception new(This, "Trying to peek(%d)! index must be >= 1 < size" format(index)) throw()
Exception new(This, "Trying to peek(%d)! index must be >= 1 <= size" format(index)) throw()

if (index >= size)
if (index > size)
Exception new(This, "Trying to peek(%d) a stack of size %d" format(index, size)) throw()

return data get(size - index)
Expand Down
13 changes: 5 additions & 8 deletions source/rock/middle/BaseType.ooc
Expand Up @@ -245,11 +245,6 @@ BaseType: class extends Type {
}
}

if(getName() == other getName()) {
// *sigh* I wish we didn't have to do that
return scoreSeed / 2
}

if(getRef() instanceOf?(TypeDecl) && other getRef() instanceOf?(TypeDecl)) {
inheritsScore := getRef() as TypeDecl inheritsScore(other getRef() as TypeDecl, scoreSeed)

Expand All @@ -264,12 +259,14 @@ BaseType: class extends Type {
}

// cool, a match =)
if(inheritsScore > 0) return inheritsScore
if(inheritsScore > 0) {
return inheritsScore
}
}

if(isNumericType() && other isNumericType()) {
// Only half a match - it's not too good to mix integer types. Maybe we need more safety here?
return scoreSeed / 2
return scoreSeed / 4
}
}

Expand Down Expand Up @@ -391,7 +388,7 @@ BaseType: class extends Type {
result = BaseType new(ref as VariableDecl getName(), token)
result setRef(ref) // FIXME: that is experimental. is that a good idea?
} else if(ref instanceOf?(FuncType)) {
printf("ref of %s is a %s!\n", candidate toString(), ref class name)
//printf("ref of %s is a %s!\n", candidate toString(), ref class name)
result = ref as FuncType
}
return result
Expand Down
58 changes: 38 additions & 20 deletions source/rock/middle/FunctionCall.ooc
Expand Up @@ -21,6 +21,7 @@ import tinker/[Response, Resolver, Trail, Errors]
*
* @author Amos Wenger (nddrylliog)
*/

FunctionCall: class extends Expression {

/**
Expand Down Expand Up @@ -87,6 +88,7 @@ FunctionCall: class extends Expression {
* keeps track of what has been modified, to be able to restore it.
*/
argsBeforeConversion: HashMap<Int, Expression>
candidateUsesAs := false

/**
* Create a new function call to the function '<name>()'
Expand Down Expand Up @@ -166,6 +168,7 @@ FunctionCall: class extends Expression {
args set(i, argsBeforeConversion[i])
}
}
candidateUsesAs = false

for(i in 0..args size()) {
if(i >= candidate args size()) break
Expand All @@ -176,24 +179,25 @@ FunctionCall: class extends Expression {
if (declArgType isGeneric()) {
declArgType = declArgType realTypize(this)
}

if(callArg getType() getScore(declArgType) == Type NOLUCK_SCORE) {
ref := callArg getType() getRef()
if(ref instanceOf?(TypeDecl)) {
ref as TypeDecl implicitConversions each(|opdecl|
if(opdecl fDecl getReturnType() equals?(declArgType)) {
args set(i, Cast new(callArg, declArgType, callArg token))
if(!argsBeforeConversion) {
// lazy instantiation of argsBeforeConversion
argsBeforeConversion = HashMap<Int, Expression> new()
candidateUsesAs = true
if(candidate isExtern()) {
args set(i, Cast new(callArg, declArgType, callArg token))
if(!argsBeforeConversion) {
// lazy instantiation of argsBeforeConversion
argsBeforeConversion = HashMap<Int, Expression> new()
}
argsBeforeConversion put(i, callArg)
}
argsBeforeConversion put(i, callArg)
}
)
}
}
}

return score > 0
}
return false
Expand Down Expand Up @@ -315,7 +319,7 @@ FunctionCall: class extends Expression {
if(expr getType() isGeneric()) {
message += " (you can't call methods on generic types! you have to cast them first)"
}
res throwError(UnresolvedCall new(this, message))
res throwError(UnresolvedCall new(this, message, ""))
}
tDecl := expr getType() getRef() as TypeDecl
meta := tDecl getMeta()
Expand Down Expand Up @@ -421,6 +425,8 @@ FunctionCall: class extends Expression {

if(refScore <= 0) {

precisions := ""

// Still no match, and in the fatal round? Throw an error.
if(res fatal) {
message := "No such function"
Expand All @@ -437,16 +443,20 @@ FunctionCall: class extends Expression {

if(ref) {
// If we have a near-match, show it here.
message += showNearestMatch(res params)
precisions += showNearestMatch(res params)
// TODO: add levenshtein distance

if (ref && candidateUsesAs) {
precisions += "\n\n(Hint: 'implicit as' isn't allowed on non-extern functions)"
}
} else {
if(res params helpful) {
// Try to find such a function in other modules in the sourcepath
similar := findSimilar(res)
if(similar) message += similar
}
}
res throwError(UnresolvedCall new(this, message))
res throwError(UnresolvedCall new(this, message, precisions))
} else {
res wholeAgain(this, "not resolved")
return Responses OK
Expand Down Expand Up @@ -490,7 +500,7 @@ FunctionCall: class extends Expression {
showNearestMatch: func (params: BuildParams) -> String {
b := Buffer new()

b append("\tNearest match is:\n\n\t\t%s\n" format(ref toString(this)))
b append("\n\n\tNearest match is:\n\n\t\t%s\n" format(ref toString(this)))

callIter := args iterator()
declIter := ref args iterator()
Expand Down Expand Up @@ -1042,14 +1052,16 @@ FunctionCall: class extends Expression {
}
return -1
}
if(typeScore == Type NOLUCK_SCORE) {
ref := callArg getType() getRef()
if(ref instanceOf?(TypeDecl)) {
ref as TypeDecl implicitConversions each(|opdecl|
if(opdecl fDecl getReturnType() equals?(declArgType)) {
typeScore = Type SCORE_SEED / 4
}
)
if (decl isExtern()) {
if(typeScore == Type NOLUCK_SCORE) {
ref := callArg getType() getRef()
if(ref instanceOf?(TypeDecl)) {
ref as TypeDecl implicitConversions each(|opdecl|
if(opdecl fDecl getReturnType() equals?(declArgType)) {
typeScore = Type SCORE_SEED / 4
}
)
}
}
}

Expand Down Expand Up @@ -1168,12 +1180,18 @@ FunctionCall: class extends Expression {
UnresolvedCall: class extends Error {

call: FunctionCall
init: func (.call, .message) {
precisions: String

init: func (.call, .message, =precisions) {
init(call token, call, message)
}

init: func ~withToken(.token, =call, .message) {
super(call expr ? call expr token enclosing(call token) : call token, message)
}

format: func -> String {
token formatMessage(message, "ERROR") + precisions
}

}
1 change: 0 additions & 1 deletion source/rock/middle/OperatorDecl.ooc
Expand Up @@ -75,7 +75,6 @@ OperatorDecl: class extends Expression {
return Responses OK
}

"Got implicit as from %s to %s" printfln(fromType toString(), toType toString())
ref := fromType getRef()
if(ref instanceOf?(TypeDecl)) {
_doneImplicit = true
Expand Down
11 changes: 5 additions & 6 deletions source/rock/middle/Type.ooc
Expand Up @@ -125,12 +125,11 @@ Type: abstract class extends Expression {
if ((
name == "Int" || name == "UInt" || name == "Short" ||
name == "UShort"|| name == "Long" || name == "ULong" ||
name == "LLong" || name == "ULLong"|| name == "Char" ||
name == "UChar" || name == "Int8" || name == "Int16" ||
name == "Int32" || name == "Int64" || name == "UInt8" ||
name == "UInt16"|| name == "UInt32"|| name == "UInt64"||
name == "SizeT" || name == "Float" || name == "Double"||
name == "SSizeT"))
name == "LLong" || name == "ULLong"|| name == "Int8" ||
name == "Int16" || name == "Int32" || name == "Int64" ||
name == "UInt8" || name == "UInt16"|| name == "UInt32"||
name == "UInt64"|| name == "SizeT" || name == "Float" ||
name == "Double"|| name == "SSizeT"))
return true

down := dig()
Expand Down

0 comments on commit 4413e9e

Please sign in to comment.