Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of g:nddrylliog/rock into bsd-compat

  • Loading branch information...
commit 4b1edf307d66b8e28c0d94e7d57f8510ce8b8e3f 2 parents 7760ee6 + 366e5e0
Marie Markwell duckinator authored
1  sdk/os/FileDescriptor.ooc
View
@@ -6,6 +6,7 @@ import unistd
open: extern func(CString, Int) -> Int
+PIPE_BUF: extern Int
STDIN_FILENO : extern FileDescriptor
STDOUT_FILENO: extern FileDescriptor
STDERR_FILENO: extern FileDescriptor
2  sdk/os/Terminal.ooc
View
@@ -1,3 +1,5 @@
+import FileDescriptor
+
/**
* Set text colors and attributes for VT100 compatible terminals
* @author eagle2com
4 sdk/os/unistd.ooc
View
@@ -1,9 +1,5 @@
include unistd | (__USE_GNU)
-PIPE_BUF: extern Int
-STDOUT_FILENO: extern Int
-STDERR_FILENO: extern Int
-
/* Functions */
chdir: extern func(CString) -> Int
dup2: extern func(Int, Int) -> Int
1  source/rock/backend/cnaughty/ModuleWriter.ooc
View
@@ -309,6 +309,7 @@ ModuleWriter: abstract class extends Skeleton {
cw nl(). app("GC_INIT();")
}
cw nl(). app(module getLoadFuncName()). app("();")
+ cw nl(). app("return 0;")
cw closeBlock(). nl()
}
2  source/rock/frontend/AstBuilder.ooc
View
@@ -809,7 +809,7 @@ AstBuilder: class {
}
case node instanceOf?(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) {
fDecl = FunctionDecl new(ClassDecl DEFAULTS_FUNC_NAME, cDecl token)
cDecl addFunction(fDecl)
2  source/rock/frontend/compilers/Gcc.ooc
View
@@ -11,7 +11,7 @@ Gcc: class extends BaseCompiler {
super("gcc")
}
- init: func~withExecutableName (executableName: String) {
+ init: func ~withExecutableName (executableName: String) {
super(executableName)
}
17 source/rock/middle/BinaryOp.ooc
View
@@ -3,7 +3,7 @@ import ../frontend/Token
import Expression, Visitor, Type, Node, FunctionCall, OperatorDecl,
Import, Module, FunctionCall, ClassDecl, CoverDecl, AddressOf,
ArrayAccess, VariableAccess, Cast, NullLiteral, PropertyDecl,
- Tuple, VariableDecl
+ Tuple, VariableDecl, FuncType
import tinker/[Trail, Resolver, Response, Errors]
OpType: enum {
@@ -381,6 +381,21 @@ BinaryOp: class extends Expression {
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()) {
score := lType getScore(rType)
if(score == -1) {
34 source/rock/middle/ClassDecl.ooc
View
@@ -125,16 +125,27 @@ ClassDecl: class extends TypeDecl {
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 {
- sRef := getSuperRef() as ClassDecl
+ getBaseClass: func ~noInterfaces (fDecl: FunctionDecl, comeBack: Bool*) -> 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
if(sRef != null) {
- base := sRef getBaseClass(fDecl)
+
+ base := sRef getBaseClass(fDecl, comeBack)
+ if (comeBack) { // ugly_
+ return null
+ }
if(base != null) {
return base
}
@@ -142,10 +153,19 @@ ClassDecl: class extends TypeDecl {
// look in interface types, if any
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 != null) {
- base := iRef getBaseClass(fDecl)
+ base := iRef getBaseClass(fDecl, comeBack)
+ if (comeBack) { // ugly_
+ comeBack=true
+ return null
+ }
if(base != null) {
return base
}
7 source/rock/middle/FunctionDecl.ooc
View
@@ -463,7 +463,12 @@ FunctionDecl: class extends Declaration {
// handle the case where we specialize a generic function
if(owner) {
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) {
finalScore := 0
2  source/rock/middle/NamespaceDecl.ooc
View
@@ -11,7 +11,7 @@ NamespaceDecl: class extends Declaration {
name: String
imports := ArrayList<Import> new()
- init: func~namespace(=name) {
+ init: func ~namespace(=name) {
super(nullToken)
}
20 source/rock/middle/VariableAccess.ooc
View
@@ -245,6 +245,7 @@ VariableAccess: class extends Expression {
parent := trail peek()
if (!fType isClosure) {
+
closureElements := [
this
NullLiteral new(token)
@@ -252,6 +253,7 @@ VariableAccess: class extends Expression {
closureType: FuncType = null
+
if (parent instanceOf?(FunctionCall)) {
/*
* The case we're looking for is this one:
@@ -292,6 +294,24 @@ VariableAccess: class extends Expression {
if (fIndex != -1) {
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)) {
Please sign in to comment.
Something went wrong with that request. Please try again.