Skip to content

Commit

Permalink
FIXES
Browse files Browse the repository at this point in the history
  • Loading branch information
nddrylliog committed Jul 20, 2010
1 parent 6af2966 commit a5fba7c
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.anjuta*
old-sdk*
build
*~
*.swp
Expand Down
5 changes: 3 additions & 2 deletions sdk/structs/ArrayList.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ ArrayList: class <T> extends List<T> {
return copy
}

emptyClone: func -> This<T> {
This<T> new()
emptyClone: func <K> -> This<K> {
"Empty-cloning to %s<%s>" printfln(class name, K name)
This<K> new()
}

/** */
Expand Down
4 changes: 2 additions & 2 deletions sdk/structs/LinkedList.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ LinkedList: class <T> extends List<T> {
return list
}

emptyClone: func -> This<T> {
This<T> new()
emptyClone: func <K> -> This<K> {
This<K> new()
}

print: func {
Expand Down
15 changes: 13 additions & 2 deletions sdk/structs/List.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ List: abstract class <T> extends BackIterable<T> {
clone: abstract func -> List<T>

/**
@return a list of the same type, empty.
@return a list of the same concrete type, empty.
useful when writing algorithms that need to create
new lists, but not of a specific type.
*/
emptyClone: abstract func -> List <T>
emptyClone: abstract func <K> (K: Class) -> List <K>

emptyClone: func ~defaults -> List <T> { emptyClone(T) }

/**
Return two sublists. The first one contains all the elements
Expand Down Expand Up @@ -231,11 +233,20 @@ List: abstract class <T> extends BackIterable<T> {
return arr& as Pointer
}

map: func <K> (f: Func (T) -> K) -> This<K> {
"Mapping from %s<%s> to %s<%s>" printfln(class name, T name, class name, K name)
copy := emptyClone(K)
each(|x| copy add(f(x)))
copy
}

/*
map: func (f: Func (T) -> T) -> This<T> {
copy := emptyClone()
each(|x| copy add(f(x)))
copy
}
*/

filter: func (f: Func (T) -> Bool) -> This<T> {
copy := emptyClone()
Expand Down
8 changes: 6 additions & 2 deletions source/rock/middle/BinaryOp.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ BinaryOp: class extends Expression {
return Responses OK
}

//if(fDecl getReturnType() isGeneric()) {
if(!fDecl getReturnArgs() isEmpty()) {
fCall setReturnArg(fDecl getReturnType() isGeneric() ? left getGenericOperand() : left)
trail peek() replace(this, fCall)
Expand All @@ -188,7 +187,12 @@ BinaryOp: class extends Expression {
}

if(isGeneric()) {
sizeAcc := VariableAccess new(VariableAccess new(left getType() getName(), token), "size", token)
sizeAcc: VariableAccess
if(left getType() isGeneric() && !right getType() isGeneric()) {
sizeAcc = VariableAccess new(VariableAccess new(right getType(), token), "size", token)
} else {
sizeAcc = VariableAccess new(VariableAccess new(left getType(), token), "size", token)
}

fCall := FunctionCall new("memcpy", token)

Expand Down
3 changes: 1 addition & 2 deletions source/rock/middle/FuncType.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ FuncType: class extends Type {
varArg := false
returnType : Type = null
cached := ArrayList<Module> new()

isClosure := false
init: func ~funcType (.token) {
super(token)
CoverDecl new("", token)
}

write: func (w: AwesomeWriter, name: String) {
//w app (toMangledString())
w app("lang_types__Closure")
if(name) w app(' '). app(name)
}
Expand Down
34 changes: 33 additions & 1 deletion source/rock/middle/FunctionCall.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FunctionCall: class extends Expression {

debugCondition: inline func -> Bool {
//false
name == "map"
name == "f"
}

suggest: func (candidate: FunctionDecl) -> Bool {
Expand Down Expand Up @@ -655,6 +655,23 @@ FunctionCall: class extends Expression {
}
}

/* myFunction: func <T> (myArg: Func -> T) */
if(argType instanceOf(FuncType)) {
fType := argType as FuncType

if(fType returnType getName() == typeArgName) {
if(debugCondition()) " >> Hey, we have an interesting FuncType %s" printfln(fType toString())
implArg := args get(j)
if(implArg instanceOf(FunctionDecl)) {
fDecl := implArg as FunctionDecl
if(fDecl inferredReturnType) {
"Got inferredReturnType = %s!" printfln(fDecl inferredReturnType toString())
return fDecl inferredReturnType
}
}
}
}

/* myFunction: func <T> (T: Class) */
if(arg getName() == typeArgName) {
implArg := args get(j)
Expand Down Expand Up @@ -714,6 +731,21 @@ FunctionCall: class extends Expression {
}
}
}

idx = trail find(FunctionDecl)
while(idx != -1) {
fDecl := trail get(idx, FunctionDecl)
if(debugCondition()) "\n===\nFound fDecl %s, with %d typeArgs" format(fDecl toString(), fDecl getTypeArgs() size()) println()
for(typeArg in fDecl getTypeArgs()) {
"%s vs %s" printfln(typeArg getName(), typeArgName)
if(typeArg getName() == typeArgName) {
result := BaseType new(typeArgName, token)
result setRef(typeArg)
return result
}
}
idx = trail find(FunctionDecl, idx - 1)
}
}

if(expr != null) {
Expand Down
1 change: 1 addition & 0 deletions source/rock/middle/FunctionDecl.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ FunctionDecl: class extends Declaration {
name = "", suffix = null, fullName = null, doc = "" : String

returnType := voidType
inferredReturnType : Type = null

/** Attributes */
isAbstract := false
Expand Down
3 changes: 3 additions & 0 deletions source/rock/middle/Return.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Return: class extends Statement {
retType: Type = null
if(idx != -1) {
fDecl = trail get(idx) as FunctionDecl

if(expr) fDecl inferredReturnType = expr getType()

retType = fDecl getReturnType()
if (!retType isResolved()) {
return Responses LOOP
Expand Down
14 changes: 13 additions & 1 deletion source/rock/middle/VariableAccess.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ VariableAccess: class extends Expression {
init: func ~typeAccess (type: Type, .token) {
super(token)
name = type getName()
ref = type getRef()
if(type getRef() instanceOf(VariableDecl)) {
varDecl := type getRef() as VariableDecl
if(varDecl getOwner() != null) {
if(varDecl isStatic) {
expr = VariableAccess new(varDecl getOwner() getInstanceType(), token)
} else {
expr = VariableAccess new("this", token)
}
}
} else {
// else, it's safe to carry the ref
ref = type getRef()
}
}

accept: func (visitor: Visitor) {
Expand Down
11 changes: 9 additions & 2 deletions source/rock/middle/tinker/Trail.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ Trail: class extends Stack<Node> {
* Finds the nearest (from top to bottom) object of class T (or subclasses)
* and return its index, or -1 if not found
*/
find: func (T: Class) -> Int {
find: func ~default (T: Class) -> Int {
find(T, size() - 1)
}

i := size() - 1
/**
* Finds the nearest (from top to bottom) object of class T (or subclasses)
* and return its index, or -1 if not found
* Starting from index i
*/
find: func (T: Class, i: Int) -> Int {
while(i >= 0) {
node := data get(i) as Node
if(node class inheritsFrom(T)) {
Expand Down

0 comments on commit a5fba7c

Please sign in to comment.