ooc-lang / rock Goto Github PK
View Code? Open in Web Editor NEW:ocean: self-hosted ooc compiler that generates c99
Home Page: http://ooc-lang.org/
License: MIT License
:ocean: self-hosted ooc compiler that generates c99
Home Page: http://ooc-lang.org/
License: MIT License
It seems i can't create an array of Func
objects, either raw or by using an ArrayList.
Sample code:
// This works.
test: Float* = gc_malloc(10 * Float size)
// This doesn't work.
test: Func* = gc_malloc(10 * Func size)
Output:
test.ooc: [ERROR] No such variable Func
test: Func* = gc_malloc(10 * Func size)
Sample code (using ArrayList)
import structs/ArrayList
list := ArrayList<Func> new(10)
Output
test.ooc: [ERROR] Missing info for type argument T.
Have you forgotten to qualify ArrayList.new~withCapacity:
static func <T> (=capacity) -> ArrayList<T>, e.g. List<Int>?
That's very annoying.
The parser is unable to understand:
test()()
where the first test() returns a function
that can be called again.
Sample code:
test: func -> Func {
test
}
test()()
Not everyone likes a compiler soft and friendly.
Those who want tough love shouldn't be set apart.
You said on ooc's issue tracker that it won't be implemented there, so I took the liberty of copying the issue here. :D
Currently the documentation states that the type for the raw array literal is derived from the first element in the literal:
http://docs.ooc-lang.org/language/syntax.html#raw-arrays
A better rule will be to use the 'most derived type' - the type to which all the other types can be implicitly converted to. In no such type exists in the literal, it probably should be an error.
For example: [1, 2, 3.0] should be a raw array of Double (assuming that the "1" and "2" literals are 32-bit integers).
Similarly, having classes "Foo" and "Bar extends Foo", [Foo new(), Bar new()] should be a raw array of Foo.
e.g.
(a, b, c) = (1, 2, 3)
Maybe even multi-declassign?
(a, b, c) := (1, 2, 3)
(That makes declarations of a, b and c hard to search for though)
Workaround: use +-I
i wanted to extend String coverage :
String: cover { wtrim: func -> This { if(length() == 0) return this start := 0 while(this[start] isWhitespace()) start += 1; end := length() if(start >= end) return "" while(this[end - 1] isWhitespace()) end -= 1; if(start != 0 || end != length()) return substring(start, end) return this } }
But in some case, it doesn't work :
Rock fails with "[ERROR] No such function String (lang/types [5161, 5167]).wtrim()"
Works :
main: func { id := " aaaaaaaaa \n " id wtrim() println() // doesn't work }
Doesn't work :
main: func { id := String new(100) id = " aaaaaaaaa \n " id wtrim() println() }
but Works :
main: func { id := String new(100) id = " aaaaaaaaa \n " id as String wtrim() println() }
The -r option ("Run the exectuable after a successful compilation.") is ignored in rock 0.9.0.
Especially when you've got a fuckload of libs in your $OOC_LIBS. Trust me.
It currently isn't, but it should. (needed to make oos working)
╰─(☹) ✘ git clone http://github.com/nddrylliog/rock.git
Initialized empty Git repository in /home/xinuc/sandbox/rock/.git/
got d8514be
walk d8514be
got a7df4ad
got eb200e5
Getting alternates list for http://github.com/nddrylliog/rock.git
got 8cc2d1688ccdfb6dda7bede964e8b2826b6c695f
got a0aaf28
Getting pack list for http://github.com/nddrylliog/rock.git
got 284c8f6591f912541501af7cf5084df8ab5db731
Getting index for pack e7604c54e6204e4edf532aa29de279ad1a02f654
Getting index for pack 8dfb1981a63d0bf2cdc69d9999972ce7e028f828
Getting index for pack 2ff0a2805b129546f48621f28e71486b9ae0a866
Getting pack e7604c54e6204e4edf532aa29de279ad1a02f654
which contains 9a40acd
error: Unable to get pack file http://github.com/nddrylliog/rock.git/objects/pack/pack-e7604c54e6204e4edf532aa29de279ad1a02f654.pack
transfer closed with 2434386 bytes remaining to read
error: Unable to find 9a40acd under http://github.com/nddrylliog/rock.git
Cannot obtain needed object 9a40acd
while processing commit d8514be.
fatal: Fetch failed.
can you give me some hint about this thing?
Example code (using 'char' as a function argument name):
http://gist.github.com/355055
I have uncovered the cause of current segfaulting when trying to use the self-hosted rock. It seems the HashMap hashKey function is never set for Module functions. OrderedMultiMap is never calling the HashMap constructor, thus hashKey is never set leading to the segfault.
Should we automatically be calling the super constructor when no init is provided (much like jooc does now) or should the developer be forced to declare an init and call super()?
Dear nddrylliog,
please come into the IRC. We desperately need you.
Yours,
showstopper
rock_tmp/custom-sdk/threading/native/ThreadUnix.c: In function ‘threading_native_ThreadUnix__ThreadUnix_start_impl’: rock_tmp/custom-sdk/threading/native/ThreadUnix.c:39: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type /usr/include/pthread.h:227: note: expected ‘void * (*)(void *)’ but argument is of type ‘void **’
Just replace them with _quest
and _bang
in the function names.
Results vary from rock crashing to the program crashing.
use yajl
import yajl/Yajl // into JSON
main: func {
packet := parse("{\"mode\":\"test\"}", ValueMap)
value := packet["mode", String]
}
Note the packet[key, class] syntax. This is taken from the ooc-yajl README. Rock fails to compile this:
error.ooc:6:3 [ERROR] Expected statement or a closing bracket
value := packet["mode", String]
^
[FAIL]
Here is a second code sample which I tried before I looked at ooc-yajl docs. The ooc-yajl docs do not document what this should do. (j/ooc gives gcc some strange code, which causes a C build error, so it doesn't help me figure out what I should expect)
use yajl
import yajl/Yajl // into JSON
main: func {
packet := parse("{\"mode\":\"test\"}", ValueMap)
value := packet["mode"]
}
Rock crashes with not much helpful info:
danopia@danopia:~/Dev/fbi/ooc$ rock error.ooc
[Exception in ArrayList]: Index too big! 2 >= 2
Floating point exception
danopia@danopia:~/Dev/fbi/ooc$
I had a backtrace, and I can post it if you would like. I consider this crash "bad" because it is not helpful in any way.
use yajl
import yajl/Yajl // into JSON
main: func {
packet := parse("{\"mode\":\"test\"}", ValueMap)
value := packet getValue("mode", String)
}
This snippit compiles under rock but segfaults when ran, after parsing but before printing the value. I know this because ooc-yajl has time to print a debug line and taking out the getValue call stops the segfault. J/ooc compiles/runs this properly, so until this bug is fixed I might dev under that.
rock segfaults during the Parsing stage if the OOC_LIBS environment variable isn't set
The following code causes a segmentation fault in rock but is compiled successfully by ooc. It seems to be the for loop causing the problem...
import structs/ArrayList main : func { addition := "+" subtraction := "-" multiplication := "*" division := "/" operations := ArrayList<String> new() operations add( addition ) . add( subtraction ) . add( multiplication ) . add( division ) for ( oper in operations ) { oper println() } }
http://npaste.de/PS/
causes rock to run in an infinite loop. An error should be thrown instead because the code is wrong.
In ooc-llvm I have a Type cover that has static functions called 'int', 'float', 'double', and some other C keywords. Rock doesn't catch this, instead I get confusing gcc errors. I would be most happy if these names were allowed somehow, but in the least, Rock should catch them and make it's own error instead of gcc errors.
If you use an include such as:
include ./myheader
Rock will generate the wrong C include code:
#include <./myheader>
They ain't working.
either rock is not defining the cover's metaclass correctly or it's not writing the variable access correctly
That oughta be fixed.
That's not an issue in ArrayList, just a symptom of sucky type-checking for generics atm. Should be fixed asap (Would've help find a really annoying bug in rock in much less time - and is generally the right thing to do anyway)
E.g.
MPD: cover from MpdObj* {
verzion: extern(libmpd_version) static String
}
when I try to access that, it ends up like: lang_types__String_println(mpd__MPD_class()>libmpd_version);
either mpd__MPD_class()-> should be gone, or it should add libmpd_version to the struct
in which case it should actually be a member named verzion.
And indeed, mpd__MPD_class()-> should be gone.
I believe the propsed syntax was:
ImageFormat: enum {
unknown: extern(FIF_UNKNOWN)
jpeg: extern(FIF_JPEG)
// ...
}
This would be consistent with other things that always have the name first, and with properties, which do get { ... }
for non-extern and get: extern(...)
for extern.
x: String "hello" toUpper()
This code:
A: cover from Func B: cover from A
fails with:
In file included from rock_tmp/./cover-vol2.h:6:0, from rock_tmp/./cover-vol2.c:3: rock_tmp/./cover-vol2-fwd.h:14:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'cover_vol2__B' rock_tmp/./cover-vol2.c: In function 'cover_vol2__B_class': rock_tmp/./cover-vol2.c:36:44: error: 'cover_vol2__B' undeclared (first use in this function) rock_tmp/./cover-vol2.c:36:44: note: each undeclared identifier is reported only once for each function it appears in C compiler failed, aborting compilation process [FAIL]
and rock_tmp/cover-vol2-fwd.h
is http://bpaste.net/show/6118/
Title says it all.
Mostly a duplicate of the 'silly declaration' bug, but needs a separate fix.
match(2) {
case =>
"hello" println()
}
else {
lang_types__String_println("hello");
};
Note that there's no "if" there.
rock_tmp/./test.c: In function ‘test_load’:
rock_tmp/./test.c:22: error: expected ‘}’ before ‘else’
rock_tmp/./test.c: At top level:
rock_tmp/./test.c:26: error: expected identifier or ‘(’ before ‘}’ token
http://npaste.de/Pj/
Rock refuses to compile this with the following error:
name = testFunction, refScore = -98976, ref = testFunction: func (st : T)
test.ooc:14:5 [ERROR] No such function testFunction(TestCover*)
testFunction(b&)
Doing call-by-value
works fine.
Things like
a : Int* = [1, 2, 3]
Should work, and not create an ArrayList and casting i (O_o).
Mostly 'argument type should be this, not that', remove the (234, 258)-type output.
Especially for init.
import net/ServerSocket
main: func {
server := ServerSocket new()
server bind(8080)
server listen(5)
client := server accept()
client writer() write("Hello World", 11)
client close()
}
./main
[SocketError]: Invalid argument
[1] 12165 floating point exception ./main
The code seems to stop on server bind(8080). Any idea?
Mostly a reminder to nddrylliog that class should have operator overloading internally for instance
operator + (right: Bignum) -> Bignum {
this + right
}
Test: class {} operator as (t: Test) -> String { "Hi there" } main: func { t := Test new() t as String println() }
Outputs :
��b
operator as (t: Float) -> String { "Hi there" } main: func { t := 1.2 t as String println() }
Refuses to compile :
rock_tmp/./test.c: In function ‘main’:
rock_tmp/./test.c:30: error: cannot convert to a pointer type
C compiler failed, aborting compilation process
[FAIL]
Rock 0.9.0 bootstrapped
#gcc -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
First, it's a pain in the ass.
Second, St-Scott_ complained about it, and it makes me sad to see him frustrated :(
No, seriously.
It would be very handy to be able to write methods and static functions on enums. For example, in ooc-freeimage with j/ooc I had a cover of FREE_IMAGE_FORMAT with some extern methods like toString: extern(FreeImage_GetFormatFromFIF) func -> String
which took a FREE_IMAGE_FORMAT as argument. It's much nicer to be able to do fif toString()
instead of FreeImage_GetFormatFromFIF(fif)
, so I think we should be able to add methods to enums.
It seems like this code fails under rock:
use yajl
import yajl/Yajl into JSON
...
info := JSON ValueMap new()
info["real_name"] = "John Doe"
info["age"] = 56
info["is_cool"] = true
secretNames := JSON ValueList new()
secretNames addValue("Herbert YouHaveNoIdeaWhoIAmCauseIGotACoupleOfSecretNames") .addValue("Dohn Joe") .addValue(009)
info["secret_names"] = secretNames
// and now, generate it!
string := JSON generate(info)
string println()
The same code works in j/ooc.
danopia@danopia:~/Dev/fbi/middle$ OOC_DIST=~/Dev/ooc/ooc ooc -r test.ooc
ooc_tmp/sdk/structs/LinkedList.c: In function ‘structs_LinkedList__LinkedList_print_impl’:
ooc_tmp/sdk/structs/LinkedList.c:210: warning: cast from pointer to integer of different size
ooc_tmp/sdk/structs/LinkedList.c:223: warning: cast from pointer to integer of different size
ooc_tmp/sdk/structs/LinkedList.c:233: warning: cast from pointer to integer of different size
ooc_tmp/yajl/yajl/Yajl.c: In function ‘yajl_Yajl__Value_getType_impl’:
ooc_tmp/yajl/yajl/Yajl.c:755: warning: ‘match’ may be used uninitialized in this function
[ OK ]
^C>> KEYS: 0x1761fa0
{"real_name":"John Doe","age":56,"is_cool":true}
KEYS: 0x1766e88
danopia@danopia:~/Dev/fbi/middle$ rock -r test.ooc
trail =
\_, Module client
\_, ClassDecl Nick
\_, ClassDecl NickClass
\_, Nick.toString: func -> String
\_, {info : ValueMap = ValueMap new(), __genArg104 : String = "John Doe", __OP_IDX_ASS_ValueMap_String_T(info, "real_name", __genArg104&), __genArg105 : Int = 56, __OP_IDX_ASS_ValueMap_String_T(info, "age", __genArg105&), __genArg106 : Bool = true, __OP_IDX_ASS_ValueMap_String_T(info, "is_cool", __genArg106&), string : String = JSON generate(info&), return string}
\_, string : String = JSON generate(info&)
\_, JSON generate(info&)
[Exception in Token]: From unknown source [[ERROR]] No such variable ValueMap
Floating point exception
If I take out "into JSON" from the import and "JSON" from the code, it works under rock.
Title says it all (lame, I know)
E:\>rock helloworld.ooc
[Exception in PathList]: Classpath element cannot be found: .
E:\>cd Code
E:\Code>rock helloworld.ooc
Launching gcc.exe -O2 -std=gnu99...
Not only this problem prevents the user from running code in
files in the root folder of a given drive but it also affects
any OOC code that tries to use root folders in Windows systems.
The reason seems to be in that custom-sdk\io\native\FileWin32
uses FindFirstFile in the Windows API to search for files,
but as stated in the MSDN documentation, one can't use it for
root drives, instead "DRIVE:*" and FindNextFile should be used.
Sample code:
add: func(a, b : Int) -> Int {
a + b
}
outer: func -> Func(Int, Int) -> Int {
add
}
test := outer()
printf("%d \n", test(10, 20))
Results in an error at the C level: "undefined reference to test"
As nddrylliog suggests in #ooc-lang it works if we wrap the
last two lines in a main function.
F: cover from Func
throws:
In file included from rock_tmp/./cover.h:6:0, from rock_tmp/./cover.c:3: rock_tmp/./cover-fwd.h:6:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'cover__F' rock_tmp/./cover.c: In function 'cover__F_class': rock_tmp/./cover.c:18:44: error: 'cover__F' undeclared (first use in this function) rock_tmp/./cover.c:18:44: note: each undeclared identifier is reported only once for each function it appears in C compiler failed, aborting compilation process [FAIL]
Blame it on me
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.