Skip to content

Commit

Permalink
Merge branch 'master' of g:nddrylliog/rock into bsd-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Markwell committed May 14, 2012
2 parents 7760ee6 + 366e5e0 commit 4b1edf3
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 16 deletions.
1 change: 1 addition & 0 deletions sdk/os/FileDescriptor.ooc
Expand Up @@ -6,6 +6,7 @@ import unistd
open: extern func(CString, Int) -> Int open: extern func(CString, Int) -> Int




PIPE_BUF: extern Int
STDIN_FILENO : extern FileDescriptor STDIN_FILENO : extern FileDescriptor
STDOUT_FILENO: extern FileDescriptor STDOUT_FILENO: extern FileDescriptor
STDERR_FILENO: extern FileDescriptor STDERR_FILENO: extern FileDescriptor
Expand Down
2 changes: 2 additions & 0 deletions sdk/os/Terminal.ooc
@@ -1,3 +1,5 @@
import FileDescriptor

/** /**
* Set text colors and attributes for VT100 compatible terminals * Set text colors and attributes for VT100 compatible terminals
* @author eagle2com * @author eagle2com
Expand Down
4 changes: 0 additions & 4 deletions sdk/os/unistd.ooc
@@ -1,9 +1,5 @@
include unistd | (__USE_GNU) include unistd | (__USE_GNU)


PIPE_BUF: extern Int
STDOUT_FILENO: extern Int
STDERR_FILENO: extern Int

/* Functions */ /* Functions */
chdir: extern func(CString) -> Int chdir: extern func(CString) -> Int
dup2: extern func(Int, Int) -> Int dup2: extern func(Int, Int) -> Int
Expand Down
1 change: 1 addition & 0 deletions source/rock/backend/cnaughty/ModuleWriter.ooc
Expand Up @@ -309,6 +309,7 @@ ModuleWriter: abstract class extends Skeleton {
cw nl(). app("GC_INIT();") cw nl(). app("GC_INIT();")
} }
cw nl(). app(module getLoadFuncName()). app("();") cw nl(). app(module getLoadFuncName()). app("();")
cw nl(). app("return 0;")
cw closeBlock(). nl() cw closeBlock(). nl()
} }


Expand Down
2 changes: 1 addition & 1 deletion source/rock/frontend/AstBuilder.ooc
Expand Up @@ -809,7 +809,7 @@ AstBuilder: class {
} }
case node instanceOf?(ClassDecl) => case node instanceOf?(ClassDecl) =>
cDecl := node as ClassDecl cDecl := node as ClassDecl
fDecl := cDecl lookupFunction(ClassDecl DEFAULTS_FUNC_NAME, "") fDecl := (cDecl isMeta) ? cDecl lookupFunction(ClassDecl DEFAULTS_FUNC_NAME, null) : cDecl meta lookupFunction(ClassDecl DEFAULTS_FUNC_NAME, null)
if(fDecl == null) { if(fDecl == null) {
fDecl = FunctionDecl new(ClassDecl DEFAULTS_FUNC_NAME, cDecl token) fDecl = FunctionDecl new(ClassDecl DEFAULTS_FUNC_NAME, cDecl token)
cDecl addFunction(fDecl) cDecl addFunction(fDecl)
Expand Down
2 changes: 1 addition & 1 deletion source/rock/frontend/compilers/Gcc.ooc
Expand Up @@ -11,7 +11,7 @@ Gcc: class extends BaseCompiler {
super("gcc") super("gcc")
} }


init: func~withExecutableName (executableName: String) { init: func ~withExecutableName (executableName: String) {
super(executableName) super(executableName)
} }


Expand Down
17 changes: 16 additions & 1 deletion source/rock/middle/BinaryOp.ooc
Expand Up @@ -3,7 +3,7 @@ import ../frontend/Token
import Expression, Visitor, Type, Node, FunctionCall, OperatorDecl, import Expression, Visitor, Type, Node, FunctionCall, OperatorDecl,
Import, Module, FunctionCall, ClassDecl, CoverDecl, AddressOf, Import, Module, FunctionCall, ClassDecl, CoverDecl, AddressOf,
ArrayAccess, VariableAccess, Cast, NullLiteral, PropertyDecl, ArrayAccess, VariableAccess, Cast, NullLiteral, PropertyDecl,
Tuple, VariableDecl Tuple, VariableDecl, FuncType
import tinker/[Trail, Resolver, Response, Errors] import tinker/[Trail, Resolver, Response, Errors]


OpType: enum { OpType: enum {
Expand Down Expand Up @@ -381,6 +381,21 @@ BinaryOp: class extends Expression {
if(type == OpType exp || type == OpType expAss || type == OpType doubleArr) return false if(type == OpType exp || type == OpType expAss || type == OpType doubleArr) return false
} }


if (lRef instanceOf?(FuncType) || rRef instanceOf?(FuncType)) {
// By default, only assignment should be allowed when a Func-type is involved.
// Exception, of course, is an overloaded operator.
if (!isAssign()) {
return false
}

// If the left side is an immutable function, fail immediately.
l := lRef as FuncType
if (!(l isClosure)) {
token module params errorHandler onError(InvalidBinaryOverload new(token,
"%s is an immutable function. You must not reassign it. (Perhaps you want to use a first-class function instead?)" format(left toString())))
}
}

if(isAssign()) { if(isAssign()) {
score := lType getScore(rType) score := lType getScore(rType)
if(score == -1) { if(score == -1) {
Expand Down
34 changes: 27 additions & 7 deletions source/rock/middle/ClassDecl.ooc
Expand Up @@ -125,27 +125,47 @@ ClassDecl: class extends TypeDecl {
return fDecl return fDecl
} }


getBaseClass: func ~noInterfaces (fDecl: FunctionDecl) -> ClassDecl {
getBaseClass(fDecl, false) getBaseClass: func ~afterResolve(fDecl: FunctionDecl) -> ClassDecl {
b: Bool
getBaseClass(fDecl, false, b&)
} }


getBaseClass: func (fDecl: FunctionDecl, withInterfaces: Bool) -> ClassDecl { getBaseClass: func ~noInterfaces (fDecl: FunctionDecl, comeBack: Bool*) -> ClassDecl {
sRef := getSuperRef() as ClassDecl getBaseClass(fDecl, false, comeBack)
}


getBaseClass: func (fDecl: FunctionDecl, withInterfaces: Bool, comeBack: Bool*) -> ClassDecl {
sRef := getSuperRef() as ClassDecl
// An interface might not yet be resolved.
comeBack = false
// first look in the supertype, if any // first look in the supertype, if any
if(sRef != null) { if(sRef != null) {
base := sRef getBaseClass(fDecl)
base := sRef getBaseClass(fDecl, comeBack)
if (comeBack) { // ugly_
return null
}
if(base != null) { if(base != null) {
return base return base
} }
} }


// look in interface types, if any // look in interface types, if any
if(withInterfaces && getNonMeta()) for(interfaceType in getNonMeta() interfaceTypes) { if(withInterfaces && getNonMeta()) for(interfaceType in getNonMeta() interfaceTypes) {
iRef := interfaceType getRef() as ClassDecl iRef := interfaceType getRef() as ClassDecl // missing interface
if (!iRef) { // ugly_
comeBack=true
return null
}

if(!iRef isMeta) iRef = iRef getMeta() if(!iRef isMeta) iRef = iRef getMeta()
if(iRef != null) { if(iRef != null) {
base := iRef getBaseClass(fDecl) base := iRef getBaseClass(fDecl, comeBack)
if (comeBack) { // ugly_
comeBack=true
return null
}
if(base != null) { if(base != null) {
return base return base
} }
Expand Down
7 changes: 6 additions & 1 deletion source/rock/middle/FunctionDecl.ooc
Expand Up @@ -463,7 +463,12 @@ FunctionDecl: class extends Declaration {
// handle the case where we specialize a generic function // handle the case where we specialize a generic function
if(owner) { if(owner) {
meat := owner isMeta ? owner as ClassDecl : owner getMeta() meat := owner isMeta ? owner as ClassDecl : owner getMeta()
base := meat getBaseClass(this, true) comeBack: Bool
base := meat getBaseClass(this, true, comeBack&)
if (comeBack) { // ugly_
res wholeAgain(this, "Resolving a missing interface declaration.")
return Response OK
}


if(base != null) { if(base != null) {
finalScore := 0 finalScore := 0
Expand Down
2 changes: 1 addition & 1 deletion source/rock/middle/NamespaceDecl.ooc
Expand Up @@ -11,7 +11,7 @@ NamespaceDecl: class extends Declaration {
name: String name: String
imports := ArrayList<Import> new() imports := ArrayList<Import> new()


init: func~namespace(=name) { init: func ~namespace(=name) {
super(nullToken) super(nullToken)
} }


Expand Down
20 changes: 20 additions & 0 deletions source/rock/middle/VariableAccess.ooc
Expand Up @@ -245,13 +245,15 @@ VariableAccess: class extends Expression {
parent := trail peek() parent := trail peek()


if (!fType isClosure) { if (!fType isClosure) {

closureElements := [ closureElements := [
this this
NullLiteral new(token) NullLiteral new(token)
] as ArrayList<VariableAccess> ] as ArrayList<VariableAccess>


closureType: FuncType = null closureType: FuncType = null



if (parent instanceOf?(FunctionCall)) { if (parent instanceOf?(FunctionCall)) {
/* /*
* The case we're looking for is this one: * The case we're looking for is this one:
Expand Down Expand Up @@ -292,6 +294,24 @@ VariableAccess: class extends Expression {
if (fIndex != -1) { if (fIndex != -1) {
closureType = trail get(fIndex, FunctionDecl) returnType clone() closureType = trail get(fIndex, FunctionDecl) returnType clone()
} }
} elseif (parent instanceOf?(VariableDecl)) {
/*
Handle the assignment of a first-class function.
Example:
f: func() {}
g := f
The right side needs to be a Closure having f and null as context.
*/
p := parent as VariableDecl
if (p expr == this) {
closureType = ref getType()
if (!closureType) {
res wholeAgain(this, "need type of FDecl")
return Response OK
}
}
} }


if (closureType && closureType instanceOf?(FuncType)) { if (closureType && closureType instanceOf?(FuncType)) {
Expand Down

0 comments on commit 4b1edf3

Please sign in to comment.