annotate modules/jsonEncoder.tp @ 347:ff7ea11b4b60

Add length method to executable bytearrays
author Michael Pavone <pavone@retrodev.com>
date Fri, 10 Apr 2015 00:48:12 -0700
parents eef8a5cea812
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
329
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 //this module exists to break a circular dependency between the json module
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 //and container types like dictionaries
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 encode <- :value {
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 if: (object does: value understand?: "jsonEncode") {
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 value jsonEncode
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 } else: {
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 toEncode <- #[]
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 if: (object does: value understand?: "serializeFields") {
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 toEncode <- value serializeFields
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 } else: {
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 toEncode <- object propertiesOf: value
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 }
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 parts <- #[]
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 foreach: toEncode :idx field {
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 fieldVal <- object sendMessage: field to: value
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 parts append: (field jsonEncode) . ":" . (encode: fieldVal)
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 }
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 "{" . (parts join: ",") . "}"
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 }
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 }
eef8a5cea812 Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 }