Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the time is now: fix class static variables #424

Open
gewang opened this issue Jan 11, 2024 · 3 comments
Open

the time is now: fix class static variables #424

gewang opened this issue Jan 11, 2024 · 3 comments
Assignees
Labels
bug high priority pr-lab chuck team pull-request lab primordial something that has existed since time immemorial

Comments

@gewang
Copy link
Member

gewang commented Jan 11, 2024

class Foo
{
    5 => static int x;
    static SinOsc y;
    new SndBuf @=> SndBuf @ z;
}

possible semantics and process:

  1. identify lines with static variables
  2. disallow both static and non-static variables in the same line
  3. disallow time-advance (could be a compiler error or a runtime exception for immediate mode violation)
    (e.g., 1::second => static dur a => now;)
  4. 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;
}
@gewang gewang added bug primordial something that has existed since time immemorial high priority pr-lab chuck team pull-request lab labels Jan 11, 2024
@gewang
Copy link
Member Author

gewang commented Apr 14, 2024

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);
}

@nshaheed
Copy link
Contributor

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;
    }
}

@gewang
Copy link
Member Author

gewang commented Apr 14, 2024

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" >>>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug high priority pr-lab chuck team pull-request lab primordial something that has existed since time immemorial
Projects
None yet
Development

No branches or pull requests

2 participants