Skip to content
This repository
Browse code

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
@@ -6,6 +6,7 @@ import unistd
6 6 open: extern func(CString, Int) -> Int
7 7
8 8
  9 +PIPE_BUF: extern Int
9 10 STDIN_FILENO : extern FileDescriptor
10 11 STDOUT_FILENO: extern FileDescriptor
11 12 STDERR_FILENO: extern FileDescriptor
2  sdk/os/Terminal.ooc
... ... @@ -1,3 +1,5 @@
  1 +import FileDescriptor
  2 +
1 3 /**
2 4 * Set text colors and attributes for VT100 compatible terminals
3 5 * @author eagle2com
4 sdk/os/unistd.ooc
... ... @@ -1,9 +1,5 @@
1 1 include unistd | (__USE_GNU)
2 2
3   -PIPE_BUF: extern Int
4   -STDOUT_FILENO: extern Int
5   -STDERR_FILENO: extern Int
6   -
7 3 /* Functions */
8 4 chdir: extern func(CString) -> Int
9 5 dup2: extern func(Int, Int) -> Int
1  source/rock/backend/cnaughty/ModuleWriter.ooc
@@ -309,6 +309,7 @@ ModuleWriter: abstract class extends Skeleton {
309 309 cw nl(). app("GC_INIT();")
310 310 }
311 311 cw nl(). app(module getLoadFuncName()). app("();")
  312 + cw nl(). app("return 0;")
312 313 cw closeBlock(). nl()
313 314 }
314 315
2  source/rock/frontend/AstBuilder.ooc
@@ -809,7 +809,7 @@ AstBuilder: class {
809 809 }
810 810 case node instanceOf?(ClassDecl) =>
811 811 cDecl := node as ClassDecl
812   - fDecl := cDecl lookupFunction(ClassDecl DEFAULTS_FUNC_NAME, "")
  812 + fDecl := (cDecl isMeta) ? cDecl lookupFunction(ClassDecl DEFAULTS_FUNC_NAME, null) : cDecl meta lookupFunction(ClassDecl DEFAULTS_FUNC_NAME, null)
813 813 if(fDecl == null) {
814 814 fDecl = FunctionDecl new(ClassDecl DEFAULTS_FUNC_NAME, cDecl token)
815 815 cDecl addFunction(fDecl)
2  source/rock/frontend/compilers/Gcc.ooc
@@ -11,7 +11,7 @@ Gcc: class extends BaseCompiler {
11 11 super("gcc")
12 12 }
13 13
14   - init: func~withExecutableName (executableName: String) {
  14 + init: func ~withExecutableName (executableName: String) {
15 15 super(executableName)
16 16 }
17 17
17 source/rock/middle/BinaryOp.ooc
@@ -3,7 +3,7 @@ import ../frontend/Token
3 3 import Expression, Visitor, Type, Node, FunctionCall, OperatorDecl,
4 4 Import, Module, FunctionCall, ClassDecl, CoverDecl, AddressOf,
5 5 ArrayAccess, VariableAccess, Cast, NullLiteral, PropertyDecl,
6   - Tuple, VariableDecl
  6 + Tuple, VariableDecl, FuncType
7 7 import tinker/[Trail, Resolver, Response, Errors]
8 8
9 9 OpType: enum {
@@ -381,6 +381,21 @@ BinaryOp: class extends Expression {
381 381 if(type == OpType exp || type == OpType expAss || type == OpType doubleArr) return false
382 382 }
383 383
  384 + if (lRef instanceOf?(FuncType) || rRef instanceOf?(FuncType)) {
  385 + // By default, only assignment should be allowed when a Func-type is involved.
  386 + // Exception, of course, is an overloaded operator.
  387 + if (!isAssign()) {
  388 + return false
  389 + }
  390 +
  391 + // If the left side is an immutable function, fail immediately.
  392 + l := lRef as FuncType
  393 + if (!(l isClosure)) {
  394 + token module params errorHandler onError(InvalidBinaryOverload new(token,
  395 + "%s is an immutable function. You must not reassign it. (Perhaps you want to use a first-class function instead?)" format(left toString())))
  396 + }
  397 + }
  398 +
384 399 if(isAssign()) {
385 400 score := lType getScore(rType)
386 401 if(score == -1) {
34 source/rock/middle/ClassDecl.ooc
@@ -125,16 +125,27 @@ ClassDecl: class extends TypeDecl {
125 125 return fDecl
126 126 }
127 127
128   - getBaseClass: func ~noInterfaces (fDecl: FunctionDecl) -> ClassDecl {
129   - getBaseClass(fDecl, false)
  128 +
  129 + getBaseClass: func ~afterResolve(fDecl: FunctionDecl) -> ClassDecl {
  130 + b: Bool
  131 + getBaseClass(fDecl, false, b&)
130 132 }
131 133
132   - getBaseClass: func (fDecl: FunctionDecl, withInterfaces: Bool) -> ClassDecl {
133   - sRef := getSuperRef() as ClassDecl
  134 + getBaseClass: func ~noInterfaces (fDecl: FunctionDecl, comeBack: Bool*) -> ClassDecl {
  135 + getBaseClass(fDecl, false, comeBack)
  136 + }
134 137
  138 + getBaseClass: func (fDecl: FunctionDecl, withInterfaces: Bool, comeBack: Bool*) -> ClassDecl {
  139 + sRef := getSuperRef() as ClassDecl
  140 + // An interface might not yet be resolved.
  141 + comeBack = false
135 142 // first look in the supertype, if any
136 143 if(sRef != null) {
137   - base := sRef getBaseClass(fDecl)
  144 +
  145 + base := sRef getBaseClass(fDecl, comeBack)
  146 + if (comeBack) { // ugly_
  147 + return null
  148 + }
138 149 if(base != null) {
139 150 return base
140 151 }
@@ -142,10 +153,19 @@ ClassDecl: class extends TypeDecl {
142 153
143 154 // look in interface types, if any
144 155 if(withInterfaces && getNonMeta()) for(interfaceType in getNonMeta() interfaceTypes) {
145   - iRef := interfaceType getRef() as ClassDecl
  156 + iRef := interfaceType getRef() as ClassDecl // missing interface
  157 + if (!iRef) { // ugly_
  158 + comeBack=true
  159 + return null
  160 + }
  161 +
146 162 if(!iRef isMeta) iRef = iRef getMeta()
147 163 if(iRef != null) {
148   - base := iRef getBaseClass(fDecl)
  164 + base := iRef getBaseClass(fDecl, comeBack)
  165 + if (comeBack) { // ugly_
  166 + comeBack=true
  167 + return null
  168 + }
149 169 if(base != null) {
150 170 return base
151 171 }
7 source/rock/middle/FunctionDecl.ooc
@@ -463,7 +463,12 @@ FunctionDecl: class extends Declaration {
463 463 // handle the case where we specialize a generic function
464 464 if(owner) {
465 465 meat := owner isMeta ? owner as ClassDecl : owner getMeta()
466   - base := meat getBaseClass(this, true)
  466 + comeBack: Bool
  467 + base := meat getBaseClass(this, true, comeBack&)
  468 + if (comeBack) { // ugly_
  469 + res wholeAgain(this, "Resolving a missing interface declaration.")
  470 + return Response OK
  471 + }
467 472
468 473 if(base != null) {
469 474 finalScore := 0
2  source/rock/middle/NamespaceDecl.ooc
@@ -11,7 +11,7 @@ NamespaceDecl: class extends Declaration {
11 11 name: String
12 12 imports := ArrayList<Import> new()
13 13
14   - init: func~namespace(=name) {
  14 + init: func ~namespace(=name) {
15 15 super(nullToken)
16 16 }
17 17
20 source/rock/middle/VariableAccess.ooc
@@ -245,6 +245,7 @@ VariableAccess: class extends Expression {
245 245 parent := trail peek()
246 246
247 247 if (!fType isClosure) {
  248 +
248 249 closureElements := [
249 250 this
250 251 NullLiteral new(token)
@@ -252,6 +253,7 @@ VariableAccess: class extends Expression {
252 253
253 254 closureType: FuncType = null
254 255
  256 +
255 257 if (parent instanceOf?(FunctionCall)) {
256 258 /*
257 259 * The case we're looking for is this one:
@@ -292,6 +294,24 @@ VariableAccess: class extends Expression {
292 294 if (fIndex != -1) {
293 295 closureType = trail get(fIndex, FunctionDecl) returnType clone()
294 296 }
  297 + } elseif (parent instanceOf?(VariableDecl)) {
  298 + /*
  299 + Handle the assignment of a first-class function.
  300 + Example:
  301 +
  302 + f: func() {}
  303 + g := f
  304 +
  305 + The right side needs to be a Closure having f and null as context.
  306 + */
  307 + p := parent as VariableDecl
  308 + if (p expr == this) {
  309 + closureType = ref getType()
  310 + if (!closureType) {
  311 + res wholeAgain(this, "need type of FDecl")
  312 + return Response OK
  313 + }
  314 + }
295 315 }
296 316
297 317 if (closureType && closureType instanceOf?(FuncType)) {

0 comments on commit 4b1edf3

Please sign in to comment.
Something went wrong with that request. Please try again.