Skip to content

make "global const" work #248

Closed
Closed
@StefanKarpinski

Description

@StefanKarpinski

Tried this:

diff --git a/j/client.j b/j/client.j
index 1e0d5f9..0776a85 100644
--- a/j/client.j
+++ b/j/client.j
@@ -93,21 +93,21 @@ function _start()
     try
         ccall(:jl_register_toplevel_eh, Void, ())
         ccall(:jl_start_io_thread, Void, ())
-        global Workqueue = {}
-        global Waiting = HashTable(64)
+        global const Workqueue = empty(WorkItem)
+        global const Waiting = HashTable(64)

         if !anyp(a->(a=="--worker"), ARGS)
             # start in "head node" mode
-            global Scheduler = Task(()->event_loop(true), 1024*1024)
-            global PGRP = ProcessGroup(1, {LocalProcess()}, {Location("",0)})
+            global const Scheduler = Task(()->event_loop(true), 1024*1024)
+            global const PGRP = ProcessGroup(1, {LocalProcess()}, {Location("",0)})
             # make scheduler aware of current (root) task
             enq_work(roottask_wi)
             yield()
         else
-            global PGRP = ProcessGroup(0, {}, {})
+            global const PGRP = ProcessGroup(0, {}, {})
         end

-        global VARIABLES = {}
+        global const VARIABLES = empty(Symbol)

         # Load customized startup
         try
diff --git a/j/multi.j b/j/multi.j
index a093941..f36e7e1 100644
--- a/j/multi.j
+++ b/j/multi.j
@@ -991,7 +991,7 @@ function start_worker(wrfd)
     # close stdin; workers will not use it
     ccall(dlsym(libc, :close), Int32, (Int32,), int32(0))

-    global Scheduler = current_task()
+    global const Scheduler = current_task()

     worker_sockets = HashTable()
     add_fd_handler(sockfd, fd->accept_handler(fd, worker_sockets))
diff --git a/j/process.j b/j/process.j
index 33ea6b4..db5a0fe 100644
--- a/j/process.j
+++ b/j/process.j
@@ -29,9 +29,9 @@ process_success(s::ProcessExited) = (s.status == 0)

 type FileDes; fd::Int32; end

-global STDIN  = FileDes(ccall(:jl_stdin,  Int32, ()))
-global STDOUT = FileDes(ccall(:jl_stdout, Int32, ()))
-global STDERR = FileDes(ccall(:jl_stderr, Int32, ()))
+global const STDIN = FileDes(ccall(:jl_stdin,  Int32, ()))
+global const STDOUT = FileDes(ccall(:jl_stdout, Int32, ()))
+global const STDERR = FileDes(ccall(:jl_stderr, Int32, ()))

 isequal(fd1::FileDes, fd2::FileDes) = (fd1.fd == fd2.fd)

Doesn't work since global and const don't appear to play nicely together. Not sure all of this diff is correct, but the construct makes sense, at least — it should allow an inner scope to declare a global constant. The opposite order const global should probably also work (or be illegal).

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions