From 581b2f7bb283e74f73450012206846bacf52b19c Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 4 Oct 2024 13:16:26 +0800 Subject: [PATCH] [standalone] Add demo for global variables --- nac3standalone/demo/src/globals.py | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 nac3standalone/demo/src/globals.py diff --git a/nac3standalone/demo/src/globals.py b/nac3standalone/demo/src/globals.py new file mode 100644 index 00000000..d8b7822d --- /dev/null +++ b/nac3standalone/demo/src/globals.py @@ -0,0 +1,31 @@ +@extern +def output_int32(x: int32): + ... + +@extern +def output_int64(x: int64): + ... + +X: int32 = 0 +Y: int64 = int64(1) + +def f(): + global X, Y + X = 1 + Y = int64(2) + +def run() -> int32: + global X, Y + + output_int32(X) + output_int64(Y) + f() + output_int32(X) + output_int64(Y) + + X = 0 + Y = int64(0) + output_int32(X) + output_int64(Y) + + return 0 \ No newline at end of file