Skip to content

Commit fa96584

Browse files
committed
bah
1 parent 5d882d1 commit fa96584

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

‎v4-cokapi/backends/ruby/pg_logger.rb‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
# - support 'include'-ing a module and bringing in variables into namespace
2222
# - cosmetic issues in the OPT frontend for Ruby:
2323
# - relabel "Global frame" as "Globals" or something
24-
# - display symbol type properly, and maybe range type too?
2524
# - display None values as 'nil'
25+
# - display booleans as 'true' and 'false'
26+
# - rename 'list' as 'array'
27+
# - rename 'dict' as 'hash'
2628
#
2729
# Useful notes from http://phrogz.net/programmingruby/frameset.html:
2830
# - "First, every object has a unique object identifier (abbreviated as
@@ -41,6 +43,7 @@
4143

4244

4345
require 'json'
46+
require 'set'
4447
require 'stringio'
4548

4649
require 'debug_inspector' # gem install debug_inspector, use on Ruby 2.X
@@ -110,7 +113,40 @@ def encode(dat)
110113
# (this way, 3.0 prints as '3.0' and not as 3, which looks like an int)
111114
return dat
112115
else
113-
return dat.inspect # TODO: make into a rich object and fill up the heap
116+
my_id = dat.object_id
117+
118+
my_small_id = @id_to_small_IDs[my_id]
119+
if !my_small_id
120+
my_small_id = @cur_small_ID
121+
@id_to_small_IDs[my_id] = @cur_small_ID
122+
@cur_small_ID += 1
123+
end
124+
125+
ret = ['REF', my_small_id]
126+
127+
# punt early if you've already encoded this object
128+
return ret if @encoded_heap_objects.include? my_small_id
129+
130+
new_obj = []
131+
@encoded_heap_objects[my_small_id] = new_obj
132+
133+
# otherwise encode it in the heap and return ret
134+
if dat.class == Array
135+
new_obj << 'LIST'
136+
dat.each { |e| new_obj << encode(e) }
137+
elsif dat.class == Hash
138+
new_obj << 'DICT'
139+
dat.each { |k, v| new_obj << [encode(k), encode(v)] }
140+
elsif dat.class == Set
141+
new_obj << 'SET'
142+
dat.each { |e| new_obj << encode(e) }
143+
else
144+
# catch-all punting case! includes Range, Symbol, Regexp
145+
new_obj << dat.class.to_s
146+
new_obj << dat.inspect
147+
end
148+
149+
return ret
114150
end
115151
end
116152
end

0 commit comments

Comments
 (0)