the time is now: fix class static variables
class Foo
{
5 => static int x;
static SinOsc y;
new SndBuf @=> SndBuf @ z;
}
possible semantics and process:
- identify lines with
staticvariables - disallow both
staticand non-static variables in the same line - disallow time-advance (could be a compiler error or a runtime exception for immediate mode violation)
(e.g.,
1::second => static dur a => now;) - run the static lines a) at compile-time if public class OR b) at run-time if non-public class
int x;
fun int bar()
{
return x+5;
}
class Foo
{
bar() => static int z;
}
more thinking from PR Lab hackathon edition @nshaheed @AndrewAday @gewang 5. disallow time via run-time time police 6. possibly disallow all function calls (except for constructors of static variable being declared 7. OR use dependency system to sort it out
class X
{
fun static int go() { <<< "go" >>>; return 1; }
}
X x;
class Y
{
fun Y(float val)
{
X.go(); // this should be okay
x.go(); // this would not be okay, due to dependency
<<< val >>>;
}
}
class Z
{
fun int nooooo() { return 2; }
// this probably can't work, as static init happens
// after compile but before run code
x.go() => static int z;
// calling a member function is not allowed
nooooo() => static int a;
// this is okay because it would just be part of pre-ctor
nooooo() => a;
// constructor
// could throw runtime exception if time-advance detect
// compile time if dependencies don't work out
// this line needs to be marked as being run before this file
// need to generate a VM-code-block to run static stuff immediate
// after compile, before file code is run
static Y why(440);
}
Java allows static function calls and constructors in static variable declarations, but not member functions. Static variables can also be modified in static functions,
public class MyClass {
static int p = 0;
static MyClass fajioe = new MyClass();
public static void main(String args[]) {
int x=10;
int y=25;
int z=x+y;
System.out.println("Sum of x+y = " + z);
}
public static int test() {
System.out.println("jfioesjfioe");
System.out.println(p);
return 11;
}
public static int foo = test();
public MyClass() {
System.out.println("ssssss");
p = 4;
}
}
for class static UGen connect or constructors in general, detect for time-advance and throw exception if detected
class DEELAY extends UGen
{
fun DEELAY()
{
2::second => now;
<<< "constructor" >>>;
}
}
DEELAY dl => dac;
<<< "after connect" >>>;
pretty much all of the design points @AndrewAday @nshaheed have been addressed and implemented in https://github.com/ccrma/chuck/commit/6b8acda214c0b0b4c0a3dcc8f3202515c58c6bac #2024-static-init (also #2024-Thanksgiving lol), and will be introduced the next chuck release (1.5.4.3)