Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove debug code. Make AstBuilder less newline-y for the.. what, 5th…

… time now? Yay merges. Also, prevent BinaryOp from returning right's type before we're sure there's no possible overload for us. Closes #124
  • Loading branch information...
commit d75486d58f80da88e37f2d4ea7fa81019e5d1e09 1 parent 97eb998
nddrylliog authored
View
4 sdk/io/File.ooc
@@ -57,9 +57,7 @@ File: abstract class {
assert(parent != null)
assert(parent path != null)
assert(!parent path empty?())
- s := parent path + This separator + path
- s println()
- return new(s)
+ new(parent path + This separator + path)
}
/**
View
59 sdk/lang/Buffer.ooc
@@ -2,9 +2,8 @@ import io/[Writer, Reader]
import structs/ArrayList
import text/EscapeSequence
- include stdio
-
- cprintf: extern(printf) func(Char*, ...) -> Int
+include stdio
+cprintf: extern(printf) func(Char*, ...) -> Int
WHITE_SPACE := EscapeSequence unescape(" \r\n\t") toCString()
@@ -605,7 +604,7 @@ Buffer: class {
/** return (a copy of) *this* with all characters contained by *s* stripped
from the right side. */
trimRight: func ~pointer (s: Char*, sLength: SizeT) {
- c :Char= s@
+ //c :Char= s@
//if (sLength == 1) cprintf("trimRight: %02X\n", c)
//else cprintf("trimRight: %p:%s\n", sLength, s)
if(sLength > 1 && (s + sLength)@ != '\0') raise("something wrong here!")
@@ -613,7 +612,7 @@ Buffer: class {
end := size
while( end > 0 && (data + (end - 1))@ containedIn?(s, sLength)) {
- cprintf("%c contained in %s!\n", (data + (end - 1))@, s)
+ //cprintf("%c contained in %s!\n", (data + (end - 1))@, s)
end -= 1
}
setLength(end);
@@ -1068,9 +1067,9 @@ Buffer_unittest: class {
TEST_FILE_OUT : const String = "/tmp/buftest"
b := Buffer new(0)
- if (!b fromFile(TEST_FILE_IN) || b size == 0) printf("read failed: b size=%d\n" format (b size))
- if (!(b toFile(TEST_FILE_OUT))) ("write failed") println
- if (! ((c := Buffer new(0) fromFile(TEST_FILE_IN) ) == b ) ) ( "comparison failed") println
+ if (!b fromFile(TEST_FILE_IN) || b size == 0) "read failed: b size=%d" format(b size) println()
+ if (!(b toFile(TEST_FILE_OUT))) ("write failed") println()
+ if (! ((c := Buffer new(0) fromFile(TEST_FILE_IN) ) == b ) ) ("comparison failed") println()
}
testFind: static func {
@@ -1081,41 +1080,41 @@ Buffer_unittest: class {
p = b find(what, p+1)
l := b findAll( String new ("1"))
- if ( l size() != ( 3 as SizeT)) ( "find failed 1") println
+ if ( l size() != ( 3 as SizeT)) ( "find failed 1") println()
else {
- if ( l get(0) != 0) ( "find failed 2") println
- if ( l get(1) != 5) ( "find failed 3") println
- if ( l get(2) != 10) ( "find failed 4") println
+ if ( l get(0) != 0) ( "find failed 2") println()
+ if ( l get(1) != 5) ( "find failed 3") println()
+ if ( l get(2) != 10) ( "find failed 4") println()
}
}
testOperators: static func {
- if (String new ("1") == String new(0) ) ("op equals failed 3") println
- if (String new ("123") == String new("1234") ) ("op equals failed 4") println
- if (String new ("1234") != String new("1234") ) ("op equals failed 5") println
- if (String new ("1234") == String new("4444") ) ("op equals failed 6") println
+ if (String new ("1") == String new(0) ) ("op equals failed 3") println()
+ if (String new ("123") == String new("1234") ) ("op equals failed 4") println()
+ if (String new ("1234") != String new("1234") ) ("op equals failed 5") println()
+ if (String new ("1234") == String new("4444") ) ("op equals failed 6") println()
}
testReplace: static func {
- if ( String new ("1234512345") replaceAll( "1", "2") != String new ("2234522345") ) ("replace failed 1," + String new ("1234512345") replaceAll( "1", "2")) println
- if ( String new ("1234512345") replaceAll( "12333333333333333333", "2") != String new ("1234512345") ) ("replace failed 2") println
- if ( String new ("1234512345") replaceAll( "23", "11") != String new ("1114511145") ) ("replace failed 3") println
- if ( String new ("112") replaceAll( "1", "XXX") != String new ("XXXXXX2") ) ("replace failed 4, " + String new ("112") replaceAll( "1", "XXX") )println
- if ( String new ("112") replaceAll( "1", "") != String new ("2") ) ("replace failed 5") println
- if ( String new ("111") replaceAll( "1", "") != String new ("") ) ("replace failed 6") println
- if ( String new ("") replaceAll( "1", "") != String new ("") ) ("replace failed 7") println
- if ( String new ("") replaceAll( "", "1") != String new ("") ) ("replace failed 8") println
- if ( String new ("111") replaceAll( "", "") != String new ("111") ) ("replace failed 9") println
+ if ( String new ("1234512345") replaceAll( "1", "2") != String new ("2234522345") ) ("replace failed 1," + String new ("1234512345") replaceAll( "1", "2")) println()
+ if ( String new ("1234512345") replaceAll( "12333333333333333333", "2") != String new ("1234512345") ) ("replace failed 2") println()
+ if ( String new ("1234512345") replaceAll( "23", "11") != String new ("1114511145") ) ("replace failed 3") println()
+ if ( String new ("112") replaceAll( "1", "XXX") != String new ("XXXXXX2") ) ("replace failed 4, " + String new ("112") replaceAll( "1", "XXX")) println()
+ if ( String new ("112") replaceAll( "1", "") != String new ("2") ) ("replace failed 5") println()
+ if ( String new ("111") replaceAll( "1", "") != String new ("") ) ("replace failed 6") println()
+ if ( String new ("") replaceAll( "1", "") != String new ("") ) ("replace failed 7") println()
+ if ( String new ("") replaceAll( "", "1") != String new ("") ) ("replace failed 8") println()
+ if ( String new ("111") replaceAll( "", "") != String new ("111") ) ("replace failed 9") println()
}
testSplit: static func {
if (("X XXX X") split (" ") size() != 3) Exception new ("split failed 1") throw()
- if (("X XXX X") split (" ") get(0) != String new("X")) ("split failed 2") println
- if (("X XXX X") split (" ") get(1) != String new ("XXX")) ("split failed 3") println
- if (("X XXX X") split (" ") get(2) != String new ("X")) ("split failed 4") println
+ if (("X XXX X") split (" ") get(0) != String new("X")) ("split failed 2") println()
+ if (("X XXX X") split (" ") get(1) != String new ("XXX")) ("split failed 3") println()
+ if (("X XXX X") split (" ") get(2) != String new ("X")) ("split failed 4") println()
/* actually that's hows it supposed to be, java has an additional argument to solve this: split(";" -1) or so
- if (Buffer new ("X XXX X") split ("X") size() != 2) println ("split failed 5")
+ if (Buffer new ("X XXX X") split ("X") size() != 2) println("split failed 5")
b := Buffer new ("X XXX X") split ("X")
for (item in b) {
if (item) (item toString() + "_") println()
@@ -1130,7 +1129,7 @@ Buffer_unittest: class {
b size = 0
memcpy (b data as Char*, "1111", 4)
b append(Buffer new("222"))
- if (b data[3] != '\0') ("trZero failed 1") println
+ if (b data[3] != '\0') ("trZero failed 1") println()
}
unittest: static func {
View
1  sdk/math.use
@@ -2,4 +2,3 @@
Name: math
Description: math lib
Libs: -lm
-
View
10 source/rock/frontend/AstBuilder.ooc
@@ -53,10 +53,12 @@ AstBuilder: class {
init: func (=modulePath, =module, =params) {
first := static true
+ clearline := " \r"
if(params verbose) {
- if(!first) "%s\r" format((" " times(76) toCString())) println()
- "Parsing %s" format (modulePath toCString()) println()
+ if(!first) clearline print()
+ "Parsing " print()
+ modulePath print()
}
cache put(File new(modulePath) getAbsolutePath(), module)
@@ -100,14 +102,12 @@ AstBuilder: class {
* Turn import paths like "../frontend/AstBuilder" into "/opt/ooc/rock/source/rock/frontend/AstBuilder"
*/
getRealImportPath: static func (imp: Import, module: Module, params: BuildParams, path: String@, impPath, impElement: File@) -> File {
- if(params veryVerbose) ("getRealImportPath " + imp path) println()
path = FileUtils resolveRedundancies(imp path + ".ooc")
impElement = params sourcePath getElement(path)
impPath = params sourcePath getFile(path)
if(impPath == null) {
parent := File new(module getPath()) parent()
if(parent != null) {
- if(params veryVerbose) ("getRealImportPath parent = " + parent path) println()
path = FileUtils resolveRedundancies(parent path + File separator + imp path + ".ooc")
impElement = params sourcePath getElement(path)
impPath = params sourcePath getFile(path)
@@ -154,7 +154,6 @@ AstBuilder: class {
}
onImport: unmangled(nq_onImport) func (path, name: CString) {
- if(params veryVerbose) printf("nq_import %s %s\n", path, name)
namestr := name toString()
output : String = ((path == null) || (path@ == '\0')) ? namestr : path toString() + namestr
module addImport(Import new( output , token()))
@@ -451,7 +450,6 @@ AstBuilder: class {
// same hash? compare length and then full-string comparison
word := reservedWords[idx]
if(word length() == vd getName() length() && word == vd getName()) {
- "(%zd, %zd)\n" printf(vd token start, vd token length)
params errorHandler onError(ReservedKeywordError new(vd token, "%s is a reserved C99 keyword, you can't use it in a variable declaration" format(vd getName() toCString())))
}
}
View
3  source/rock/frontend/BuildParams.ooc
@@ -28,9 +28,7 @@ BuildParams: class {
init: func (execName: String) {
findDist(execName)
- ("dist loc:" + distLocation path) println()
findSdk()
- ("sdk loc:" + sdkLocation path) println()
sdkLocation = sdkLocation getAbsoluteFile()
findLibsPath()
@@ -51,7 +49,6 @@ BuildParams: class {
}
if (env && !env empty?()) {
- ("env: " + env) println()
distLocation = File new(env trimRight(File separator))
return
}
View
1  source/rock/frontend/compilers/BaseCompiler.ooc
@@ -11,7 +11,6 @@ BaseCompiler: abstract class extends AbstractCompiler {
}
setExecutable: func (=executableName) {
- ("exe:" + executableName) println()
execFile := File new(executableName)
if (!execFile exists?()) {
View
1  source/rock/frontend/drivers/SequenceDriver.ooc
@@ -201,7 +201,6 @@ SequenceDriver: class extends Driver {
}
return dirtyModules
}
- if(params verbose) printf("\nFirst compilation with lib-caching, we have to generate + compile everything\n")
}
oPaths := ArrayList<String> new()
View
2  source/rock/middle/ArrayAccess.ooc
@@ -297,7 +297,7 @@ ArrayAccess: class extends Expression {
}
getType: func -> Type {
- return type
+ type
}
toString: func -> String {
View
25 source/rock/middle/BinaryOp.ooc
@@ -64,6 +64,9 @@ BinaryOp: class extends Expression {
left, right: Expression
type: OpType
+ inferredType: Type
+ replaced := false
+
init: func ~binaryOp (=left, =right, =type, .token) {
super(token)
}
@@ -83,8 +86,8 @@ BinaryOp: class extends Expression {
// It's just an access, it has no side-effects whatsoever
hasSideEffects : func -> Bool { !isAssign() }
- // that's probably not right (haha)
- getType: func -> Type { left getType() }
+ getType: func -> Type { inferredType }
+
getLeft: func -> Expression { left }
getRight: func -> Expression { right }
@@ -127,7 +130,12 @@ BinaryOp: class extends Expression {
{
response := resolveOverload(trail, res)
- if(!response ok()) return response
+ if(!response ok()) return Response OK // needs another resolve later
+ }
+
+ if(!replaced && inferredType == null) {
+ // that's probably not right - for example, for integer/float types promotion, etc.
+ inferredType = left getType()
}
if(type == OpType ass) {
@@ -354,7 +362,7 @@ BinaryOp: class extends Expression {
true
}
- resolveOverload: func (trail: Trail, res: Resolver) -> Response {
+ resolveOverload: func (trail: Trail, res: Resolver) -> (Response, Bool) {
// so here's the plan: we give each operator overload a score
// depending on how well it fits our requirements (types)
@@ -367,7 +375,7 @@ BinaryOp: class extends Expression {
for(opDecl in trail module() getOperators()) {
score := getScore(opDecl, reqType)
//if(score > 0) ("Considering " + opDecl toString() + " for " + toString() + ", score = %d\n") format(score) println()
- if(score == -1) { res wholeAgain(this, "score of op == -1 !!"); return Response OK }
+ if(score == -1) { res wholeAgain(this, "score of op == -1 !!"); return Response LOOP }
if(score > bestScore) {
bestScore = score
candidate = opDecl
@@ -379,7 +387,7 @@ BinaryOp: class extends Expression {
for(opDecl in module getOperators()) {
score := getScore(opDecl, reqType)
//if(score > 0) ("Considering " + opDecl toString() + " for " + toString() + ", score = %d\n") format(score) println()
- if(score == -1) { res wholeAgain(this, "score of op == -1 !!"); return Response OK }
+ if(score == -1) { res wholeAgain(this, "score of op == -1 !!"); return Response LOOP }
if(score > bestScore) {
bestScore = score
candidate = opDecl
@@ -394,7 +402,7 @@ BinaryOp: class extends Expression {
trail push(this)
right resolve(trail, res)
trail pop(this)
- return Response OK
+ return Response LOOP
}
fDecl := candidate getFunctionDecl()
@@ -405,8 +413,9 @@ BinaryOp: class extends Expression {
if(!trail peek() replace(this, fCall)) {
if(res fatal) res throwError(CouldntReplace new(token, this, fCall, trail))
res wholeAgain(this, "failed to replace oneself, gotta try again =)")
- return Response OK
+ return Response LOOP
}
+ replaced = true
res wholeAgain(this, "Just replaced with an operator overload")
}
View
4 source/rock/middle/UseDef.ooc
@@ -112,7 +112,7 @@ UseDef: class {
}
reader rewind(1)
- id := reader readUntil(':') trim() trim(8 as Char /* backspace */)
+ id := reader readUntil(':') trim() trim(8 as Char /* backspace */) trim(0 as Char /* null-character */)
value := reader readLine() trim()
if(id startsWith?("_")) {
@@ -167,6 +167,8 @@ UseDef: class {
version = value
} else if(id == "Origin" || id == "Variant") {
// known, but ignored ids
+ } else if(id startsWith?("_")) {
+ // unknown and ignored ids
} else if(!id empty?()) {
"%s: Unknown id %s (length %d, first = %d) in usefile" format(file getPath() toCString(), id toCString(), id length(), id[0]) println()
}
Please sign in to comment.
Something went wrong with that request. Please try again.