marcobambini / gravity

Gravity Programming Language
https://gravity-lang.org
MIT License
4.32k stars 229 forks source link

[Feature] #include guards #402

Open mwasplund opened 1 year ago

mwasplund commented 1 year ago

Including a file multiple times should automatically guard against re-loading the same file multiple times. This is especially important with diamond dependencies.

Main.gravity

#include "A.gravity"
#include "B.gravity"

func main() {
  return A.value() + B.value()
}

A.gravity

#include "C.gravity"

class A {
  static func value() {
    return C.value() + 1
  }
}

B.gravity

#include "C.gravity"

class B {
  static func value() {
    return C.value() + 2
  }
}

C.gravity

class C {
  static func value() {
    return 39
  }
}
marcobambini commented 1 year ago

@mwasplund you are right, it should not be too hard to implement, let me take a look at it.