about summary refs log blame commit diff stats
path: root/cpp/.traces/parse_multiple_ingredients
blob: 5a71e51043badce219d5ba67b3583f3307201f9f (plain) (tree)
1
2
3
4
5
                          



                                                                                     
parse/0: instruction: copy
parse/0:   ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
parse/0:   ingredient: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}
parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
5 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Example program showing exceptions built out of delimited continuations.

# Since Mu is statically typed, we can't build an all-purpose higher-order
# function called 'try'; it wouldn't know how many arguments the function
# passed to it needs to take, what their types are, etc. Instead, until Mu
# gets macros we'll directly use the continuation primitives.

def main [
  local-scope
  foo false/no-exception
  foo true/raise-exception
]

# example showing exception handling
def foo raise-exception?:bool [
  local-scope
  load-inputs
  # To run an instruction of the form:
  #   try f ...
  # write this:
  #   call-with-continuation-mark 999/exception-tag, f, ...
  # By convention we reserve tag 999 for exceptions.
  #
  # 'f' above may terminate at either a regular 'return' or a 'return-with-continuation-mark'.
  # We never re-call the continuation returned in the latter case;
  # its existence merely signals that an exception was raised.
  # So just treat it as a boolean.
  # The other inputs and outputs to 'call-with-continuation-mark' depend on
  # the function it is called with.
  exception-raised?:bool, err:text, result:num <- call-with-continuation-mark 999/exception-tag, f, raise-exception?
  {
    break-if exception-raised?
    $print [normal exit; result ] result 10/newline
  }
  {
    break-unless exception-raised?
    $print [error caught: ] err 10/newline
  }
]

# A callee function that can raise an exception has some weird constraints at
# the moment.
#
# The caller's 'call-with-continuation-mark' instruction may return with
# either a regular 'return' or a 'return-continuation-until-mark'.
# To handle both cases, regular 'return' instructions in the callee must
# prepend an extra 0 result, in place of the continuation that may have been
# returned.
# This change to number of outputs violates our type system, so the call has
# to be dynamically typed. The callee can't have a header.
def f [
  local-scope
  raise-exception?:bool <- next-input
  {
    break-unless raise-exception?
    # throw/raise: 2 results + implicit continuation (ignoring the continuation tag)
    return-continuation-until-mark 999/exception-tag, [error will robinson!], 0/unused
  }
  # normal return: 3 results including 0 continuation placeholder at start
  return 0/continuation-placeholder, null/no-error, 34/regular-result
]