Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Last active June 6, 2016 20:35
Show Gist options
  • Save yorickpeterse/c52cfedcab97e00bd133be9f34650cc6 to your computer and use it in GitHub Desktop.
Save yorickpeterse/c52cfedcab97e00bd133be9f34650cc6 to your computer and use it in GitHub Desktop.
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment