Skip to content

Instantly share code, notes, and snippets.

macro{
//In here, we could get involved with the parsing and output of the file we are in
//Executed at compile time by the compiler
//The code in here would be considered an extension of rock
//We could use rock classes and such, like VariableAccess or VariableDecl, whatever
//Imagine that I am just switching a function call of ZombyWoof with FrankZappa within here
//A very trivial usage, but shows a point
}
FrankZappa: func(string: String){
- Parsing source/rock/middle/FunctionCall.ooc
rock/middle/FunctionCall.ooc:553:17 [ERROR] Expected statement or a closing bracket
result := typeResult instanceOf(FuncType) ?
Now I get:
In file included from c-source/source/rock/middle/Module-fwd.h:27,
from c-source/source/rock/frontend/BuildParams-fwd.h:24,
Allocator: cover{
mallocPtr: Func(SizeT)->Pointer
callocPtr: Func(Int,SizeT)->Pointer
reallocPtr: Func(Pointer,SizeT)->Pointer
freePtr: Func(Pointer)
new: static func()->This{
allocator: This
allocator mallocPtr=null
allocator callocPtr=null
Test.ooc:9:11 [ERROR] Expected include, import, statement or declaration
afunction=func(x:Float)->Float{x*x}
alloca: extern func(SizeT)->Pointer
Vec2: class{
x, y: Float
init: func(=x,=y){}
print: func{"(%f, %f)\n" format(x, y) println()}
}
object:=alloca(Vec2 instanceSize) as Vec2
object class=Vec2
import memory/Allocator
printf: extern func(String,...)->Int
Vec3: class{
x, y, z: Float
init: func(=x,=y,=z){}
println: func{
printf("(%f,%f,%f)\n",x,y,z)
}
}
Vec3 setAllocator(Allocator manual)
Vec3: inline cover<T>{
x, y, z: T
init: func@(=x, =y, =z)
plus: func(v: This) -> This{
new(x + v x, y + v y, z+ v z)
}
print: func{
printf("Vec3("(%s, %s, %s)\n", x as String, y as String, z as String)
}
}
dereferenceIntPointer: func(pointer: Int*, jmpbufstate: JmpBuf){
if(pointer==NULL) jmpbufstate restore(Exception new("Woah dude, assign your pointers!"))
return pointer@
}
try(|state|
i = 0 : Int
printf("%i\n",dereferenceIntPointer(i&,state))
)//Returns an Exception
catch(Exception /*The class that this catch will catch*/,|exception,stateForRethrowing|
dereferenceIntPointer: func(pointer: Int*, jmpbufstate: JmpBuf){
if(pointer==NULL) jmpbufstate restore(Exception new("Woah dude, assign your pointers!"))
return pointer@
}
try(|state|
i = 0 : Int
printf("%i\n",dereferenceIntPointer(i&,state))
)//Returns an Exception
catch(Exception /*The class that this catch will catch*/,|exception,stateForRethrowing|
/opt/rock/sdk/threading/native/MutexUnix.ooc: In function ‘threading_native_MutexUnix__MutexUnix_new’:
/opt/rock/sdk/threading/native/MutexUnix.ooc:32: error: ‘__SIZEOF_PTHREAD_MUTEX_T’ undeclared (first use in this function)
/opt/rock/sdk/threading/native/MutexUnix.ooc:32: error: (Each undeclared identifier is reported only once
/opt/rock/sdk/threading/native/MutexUnix.ooc:32: error: for each function it appears in.)
/opt/rock/sdk/threading/native/MutexUnix.ooc: In function ‘threading_native_MutexUnix__RecursiveMutexUnix_new’:
/opt/rock/sdk/threading/native/MutexUnix.ooc:54: error: ‘__SIZEOF_PTHREAD_MUTEX_T’ undeclared (first use in this function)
C compiler failed (with code 1), aborting compilation process