StaticScript icon indicating copy to clipboard operation
StaticScript copied to clipboard

Lexical scoping is not supported

Open jiachen247 opened this issue 4 years ago • 0 comments

Hi can I check if this is intended?

Lexical scoping is a big part of Ecmascript / JS / TS

For example,

{
    const x = 1;
    function a() : number {
        return x + 1;
    }

    console_log(a());
}

compiles to invalid llvm ir

; ModuleID = 'test'
source_filename = "test"

define i64 @main() {
entry:
  %x = alloca double
  store double 1.000000e+00, double* %x
  %0 = call double @a()
  call void @_Z11console_logd(double %0)
  ret i64 0
}

define double @a() {
Entry:
  %0 = load double, double* %x
  %1 = fadd double %0, 1.000000e+00
  ret double %1
}

declare void @_Z11console_logd(double)

jiachen247 avatar Feb 22 '21 12:02 jiachen247