Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into bson

  • Loading branch information...
commit 4413e9ed14bdc2e1c05c6a8feddad8d538f82b83 2 parents 24dec4d + 28f9330
@fredreichbier fredreichbier authored
View
2  sdk/lang/String.ooc
@@ -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
}
View
3  sdk/os/native/PipeUnix.ooc
@@ -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
View
4 sdk/structs/Stack.ooc
@@ -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)
View
13 source/rock/middle/BaseType.ooc
@@ -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)
@@ -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
}
}
@@ -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
View
58 source/rock/middle/FunctionCall.ooc
@@ -21,6 +21,7 @@ import tinker/[Response, Resolver, Trail, Errors]
*
* @author Amos Wenger (nddrylliog)
*/
+
FunctionCall: class extends Expression {
/**
@@ -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>()'
@@ -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
@@ -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
@@ -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()
@@ -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"
@@ -437,8 +443,12 @@ 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
@@ -446,7 +456,7 @@ FunctionCall: class extends Expression {
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
@@ -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()
@@ -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
+ }
+ )
+ }
}
}
@@ -1168,7 +1180,9 @@ 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)
}
@@ -1176,4 +1190,8 @@ UnresolvedCall: class extends Error {
super(call expr ? call expr token enclosing(call token) : call token, message)
}
+ format: func -> String {
+ token formatMessage(message, "ERROR") + precisions
+ }
+
}
View
1  source/rock/middle/OperatorDecl.ooc
@@ -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
View
11 source/rock/middle/Type.ooc
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.