Last active
June 6, 2016 20:35
-
-
Save yorickpeterse/c52cfedcab97e00bd133be9f34650cc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The __foo stuff is a compiler hack for running raw instructions, | |
# so __foo runs the "foo" instruction. The single "_" stuff is to | |
# tell the compiler to automatically generate a register for a value. | |
class Pid: | |
def construct(id): | |
let @id = id | |
pub def id: | |
@id | |
class Process: | |
pub def self.spawn(code): | |
Pid.new(__spawn_process(_, code)) | |
pub def self.receive: | |
__receive_process_message(_) | |
pub def self.send(pid, message): | |
__send_process_message(_, pid.id, message) | |
pub def self.current: | |
Pid.new(__get_current_pid(_)) | |
let pong = Process.spawn: | |
let received = Process.receive | |
let pid = received[0] | |
let msg = received[1] | |
STDOUT.puts(msg) | |
Process.send(pid, "pong") | |
Process.send(pong, [Process.current, "ping"]) | |
STDOUT.puts(Process.receive) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ping | |
pong |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment