Skip to content

Commit

Permalink
Move UUIDs out of the standard library and make them a built-in type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Arcieri committed Feb 12, 2011
1 parent 2b30871 commit 0a6e3bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 2 additions & 6 deletions lib/uuid.re → src/builtins/uuid.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
# Redistribution is permitted under the MIT license. See LICENSE for details.
#

class UUID
def initialize
@ref = erl.make_ref()
end

class UUID
def to_s()
"#<UUID:#{erl.ref_to_list(@ref).to_string().sub('#Ref<', '')}"
"#<UUID:#{erl.ref_to_list(self).to_string().sub('#Ref<', '')}"
end
def inspect(); to_s(); end
Expand Down
14 changes: 10 additions & 4 deletions src/core/reia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ eval(String, Binding) ->
% Create a new instance of the given class
inst(Class, Arguments) -> inst(Class, Arguments, nil).
inst(Class, Arguments, Block) ->
% FIXME: initial object construction should thunk to the metaclass, not be
% spelled out explicitly here.
Object = #reia_object{class=Class, ivars=dict:new()},
Class:call({Object, initialize, Arguments}, Block).
% FIXME: initial object construction should be factored into class objects

case Class of
% Special hax for creating new UUIDs since they have no literal syntax
'UUID' ->
erlang:make_ref();
_ ->
Object = #reia_object{class=Class, ivars=dict:new()},
Class:call({Object, initialize, Arguments}, Block)
end.

% Invoke the given method on the given object
invoke(Receiver, Method, Arguments) -> invoke(Receiver, Method, Arguments, nil).
Expand Down
2 changes: 2 additions & 0 deletions src/core/reia_dispatch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ call(Receiver, Method, Arguments, Block) when is_pid(Receiver) ->
'Pid':call({Receiver, Method, Arguments}, Block);
call(Receiver, Method, Arguments, Block) when is_port(Receiver) ->
'Channel':call({Receiver, Method, Arguments}, Block);
call(Receiver, Method, Arguments, Block) when is_reference(Receiver) ->
'UUID':call({Receiver, Method, Arguments}, Block);
call(Receiver, _, _, _) ->
throw({error, unknown_receiver, Receiver}).

Expand Down

0 comments on commit 0a6e3bc

Please sign in to comment.