Permalink
Browse files

Move UUIDs out of the standard library and make them a built-in type

  • Loading branch information...
1 parent 2b30871 commit 0a6e3bc6e1288d23a0a000142c805890cf78265d Tony Arcieri committed Feb 12, 2011
Showing with 14 additions and 10 deletions.
  1. +2 −6 {lib → src/builtins}/uuid.re
  2. +10 −4 src/core/reia.erl
  3. +2 −0 src/core/reia_dispatch.erl
@@ -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
View
@@ -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).
@@ -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}).

0 comments on commit 0a6e3bc

Please sign in to comment.