about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xapps/mubin396171 -> 396315 bytes
-rw-r--r--apps/mu.subx29
2 files changed, 29 insertions, 0 deletions
diff --git a/apps/mu b/apps/mu
index 3578f813..9b66a156 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index 683df3be..4d842f32 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -8245,6 +8245,8 @@ test-function-header-with-arg:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "foo n: int {\n")
     # var result/ecx: function
@@ -8283,6 +8285,8 @@ test-function-header-with-multiple-args:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "foo a: int, b: int c: int {\n")
     # result/ecx: function
@@ -8354,6 +8358,8 @@ test-function-header-with-multiple-args-and-outputs:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "foo a: int, b: int, c: int -> x/ecx: int y/edx: int {\n")
     # result/ecx: function
@@ -9018,6 +9024,9 @@ test-parse-var-with-type:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
+    # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     # (eax..ecx) = "x:"
     b8/copy-to-eax "x:"/imm32
     8b/-> *eax 1/r32/ecx
@@ -9056,6 +9065,9 @@ test-parse-var-with-type-and-register:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
+    # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     # (eax..ecx) = "x/eax:"
     b8/copy-to-eax "x/eax:"/imm32
     8b/-> *eax 1/r32/ecx
@@ -9097,6 +9109,9 @@ test-parse-var-with-trailing-characters:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
+    # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     # (eax..ecx) = "x:"
     b8/copy-to-eax "x:"/imm32
     8b/-> *eax 1/r32/ecx
@@ -9137,6 +9152,9 @@ test-parse-var-with-register-and-trailing-characters:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
+    # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     # (eax..ecx) = "x/eax:"
     b8/copy-to-eax "x/eax:"/imm32
     8b/-> *eax 1/r32/ecx
@@ -9178,6 +9196,9 @@ test-parse-var-with-compound-type:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
+    # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     # (eax..ecx) = "x:"
     b8/copy-to-eax "x:"/imm32
     8b/-> *eax 1/r32/ecx
@@ -10050,6 +10071,8 @@ test-parse-mu-var-def:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "n: int\n")  # caller has consumed the 'var'
     c7 0/subop/copy *Curr-block-depth 1/imm32
@@ -10096,6 +10119,8 @@ test-parse-mu-reg-var-def:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "n/eax: int <- copy 0\n")  # caller has consumed the 'var'
     c7 0/subop/copy *Curr-block-depth 1/imm32
@@ -11021,6 +11046,8 @@ test-parse-mu-stmt:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "increment n\n")
     # var vars/ecx: (stack (addr var) 16)
@@ -11077,6 +11104,8 @@ test-parse-mu-stmt-with-comma:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # setup
+    8b/-> *Primitive-type-ids 0/r32/eax
+    89/<- *Type-id 0/r32/eax  # stream-write
     (clear-stream _test-input-stream)
     (write _test-input-stream "copy-to n, 3\n")
     # var vars/ecx: (stack (addr var) 16)
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 */
/*********************************************************************
 * NAN - Native Abstractions for Node.js
 *
 * Copyright (c) 2018 NAN contributors
 *
 * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
 ********************************************************************/

#ifndef NAN_JSON_H_
#define NAN_JSON_H_

#if NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION
#define NAN_JSON_H_NEED_PARSE 1
#else
#define NAN_JSON_H_NEED_PARSE 0
#endif  // NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION

#if NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION
#define NAN_JSON_H_NEED_STRINGIFY 0
#else
#define NAN_JSON_H_NEED_STRINGIFY 1
#endif  // NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION

class JSON {
 public:
  JSON() {
#if NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
    Nan::HandleScope scope;

    Nan::MaybeLocal<v8::Value> maybe_global_json = Nan::Get(
      Nan::GetCurrentContext()->Global(),
      Nan::New("JSON").ToLocalChecked()
    );

    assert(!maybe_global_json.IsEmpty() && "global JSON is empty");
    v8::Local<v8::Value> val_global_json = maybe_global_json.ToLocalChecked();

    assert(val_global_json->IsObject() && "global JSON is not an object");
    Nan::MaybeLocal<v8::Object> maybe_obj_global_json =
      Nan::To<v8::Object>(val_global_json);

    assert(!maybe_obj_global_json.IsEmpty() && "global JSON object is empty");
    v8::Local<v8::Object> global_json = maybe_obj_global_json.ToLocalChecked();

#if NAN_JSON_H_NEED_PARSE
    Nan::MaybeLocal<v8::Value> maybe_parse_method = Nan::Get(
      global_json, Nan::New("parse").ToLocalChecked()
    );

    assert(!maybe_parse_method.IsEmpty() && "JSON.parse is empty");
    v8::Local<v8::Value> parse_method = maybe_parse_method.ToLocalChecked();

    assert(parse_method->IsFunction() && "JSON.parse is not a function");
    parse_cb_.Reset(parse_method.As<v8::Function>());
#endif  // NAN_JSON_H_NEED_PARSE

#if NAN_JSON_H_NEED_STRINGIFY
    Nan::MaybeLocal<v8::Value> maybe_stringify_method = Nan::Get(
      global_json, Nan::New("stringify").ToLocalChecked()
    );

    assert(!maybe_stringify_method.IsEmpty() && "JSON.stringify is empty");
    v8::Local<v8::Value> stringify_method =
      maybe_stringify_method.ToLocalChecked();

    assert(
      stringify_method->IsFunction() && "JSON.stringify is not a function"
    );
    stringify_cb_.Reset(stringify_method.As<v8::Function>());
#endif  // NAN_JSON_H_NEED_STRINGIFY
#endif  // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
  }

  inline
  Nan::MaybeLocal<v8::Value> Parse(v8::Local<v8::String> json_string) {
    Nan::EscapableHandleScope scope;
#if NAN_JSON_H_NEED_PARSE
    return scope.Escape(parse(json_string));
#else
    Nan::MaybeLocal<v8::Value> result;
#if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && \
    NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION
    result = v8::JSON::Parse(json_string);
#else
#if NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
    v8::Local<v8::Context> context_or_isolate = Nan::GetCurrentContext();
#else
    v8::Isolate* context_or_isolate = v8::Isolate::GetCurrent();
#endif  // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
    result = v8::JSON::Parse(context_or_isolate, json_string);
#endif  // NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION &&
        // NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION
    if (result.IsEmpty()) return v8::Local<v8::Value>();
    return scope.Escape(result.ToLocalChecked());
#endif  // NAN_JSON_H_NEED_PARSE
  }

  inline
  Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> json_object) {
    Nan::EscapableHandleScope scope;
    Nan::MaybeLocal<v8::String> result =
#if NAN_JSON_H_NEED_STRINGIFY
      Nan::To<v8::String>(stringify(json_object));
#else
      v8::JSON::Stringify(Nan::GetCurrentContext(), json_object);
#endif  // NAN_JSON_H_NEED_STRINGIFY
    if (result.IsEmpty()) return v8::Local<v8::String>();
    return scope.Escape(result.ToLocalChecked());
  }

  inline
  Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> json_object,
    v8::Local<v8::String> gap) {
    Nan::EscapableHandleScope scope;
    Nan::MaybeLocal<v8::String> result =
#if NAN_JSON_H_NEED_STRINGIFY
      Nan::To<v8::String>(stringify(json_object, gap));
#else
      v8::JSON::Stringify(Nan::GetCurrentContext(), json_object, gap);
#endif  // NAN_JSON_H_NEED_STRINGIFY
    if (result.IsEmpty()) return v8::Local<v8::String>();
    return scope.Escape(result.ToLocalChecked());
  }

 private:
  NAN_DISALLOW_ASSIGN_COPY_MOVE(JSON)
#if NAN_JSON_H_NEED_PARSE
  Nan::Callback parse_cb_;
#endif  // NAN_JSON_H_NEED_PARSE
#if NAN_JSON_H_NEED_STRINGIFY
  Nan::Callback stringify_cb_;
#endif  // NAN_JSON_H_NEED_STRINGIFY

#if NAN_JSON_H_NEED_PARSE
  inline v8::Local<v8::Value> parse(v8::Local<v8::Value> arg) {
    assert(!parse_cb_.IsEmpty() && "parse_cb_ is empty");
    AsyncResource resource("nan:JSON.parse");
    return parse_cb_.Call(1, &arg, &resource).FromMaybe(v8::Local<v8::Value>());
  }
#endif  // NAN_JSON_H_NEED_PARSE

#if NAN_JSON_H_NEED_STRINGIFY
  inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg) {
    assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");
    AsyncResource resource("nan:JSON.stringify");
    return stringify_cb_.Call(1, &arg, &resource)
        .FromMaybe(v8::Local<v8::Value>());
  }

  inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg,
    v8::Local<v8::String> gap) {
    assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");

    v8::Local<v8::Value> argv[] = {
      arg,
      Nan::Null(),
      gap
    };
    AsyncResource resource("nan:JSON.stringify");
    return stringify_cb_.Call(3, argv, &resource)
        .FromMaybe(v8::Local<v8::Value>());
  }
#endif  // NAN_JSON_H_NEED_STRINGIFY
};

#endif  // NAN_JSON_H_