1 //: Boolean primitives
  2 
  3 :(before "End Primitive Recipe Declarations")
  4 AND,
  5 :(before "End Primitive Recipe Numbers")
  6 put(Recipe_ordinal, "and", AND);
  7 :(before "End Primitive Recipe Checks")
  8 case AND: {
  9   for (int i = 0;  i < SIZE(inst.ingredients);  ++i) {
 10     if (!is_mu_scalar(inst.ingredients.at(i))) {
 11       raise << maybe(get(Recipe, r).name) << "'and' requires boolean ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
 12       goto finish_checking_instruction;
 13     }
 14   }
 15   if (SIZE(inst.products) > 1) {
 16     raise << maybe(get(Recipe, r).name) << "'and' yields exactly one product in '" << inst.original_string << "'\n" << end();
 17     break
type
  csize = int
  
  HttpDataProc* = proc (a2: ptr THttpParser, at: cstring, length: csize): cint {.cdecl.}
  HttpProc* = proc (a2: ptr THttpParser): cint {.cdecl.}

  THttpMethod* = enum
    HTTP_DELETE = 0, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_CONNECT,
    HTTP_OPTIONS, HTTP_TRACE, HTTP_COPY, HTTP_LOCK, HTTP_MKCOL, HTTP_MOVE,
    HTTP_PROPFIND, HTTP_PROPPATCH, HTTP_UNLOCK, HTTP_REPORT, HTTP_MKACTIVITY,
    HTTP_CHECKOUT, HTTP_MERGE, HTTP_MSEARCH, HTTP_NOTIFY, HTTP_SUBSCRIBE,
    HTTP_UNSUBSCRIBE, HTTP_PATCH

  THttpParserType* = enum
    HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH

  TParserFlag* = enum
    F_CHUNKED = 1 shl 0,
    F_CONNECTION_KEEP_ALIVE = 1 shl 1,
    F_CONNECTION_CLOSE = 1 shl 2,
    F_TRAILING = 1 shl 3,
    F_UPGRADE = 1 shl 4,
    F_SKIPBODY = 1 shl 5

  THttpErrNo* = enum
    HPE_OK, HPE_CB_message_begin, HPE_CB_path, HPE_CB_query_string, HPE_CB_url,
    HPE_CB_fragment, HPE_CB_header_field, HPE_CB_header_value,
    HPE_CB_headers_complete, HPE_CB_body, HPE_CB_message_complete,
    HPE_INVALID_EOF_STATE, HPE_HEADER_OVERFLOW, HPE_CLOSED_CONNECTION,
    HPE_INVALID_VERSION, HPE_INVALID_STATUS, HPE_INVALID_METHOD,
    HPE_INVALID_URL, HPE_INVALID_HOST, HPE_INVALID_PORT, HPE_INVALID_PATH,
    HPE_INVALID_QUERY_STRING, HPE_INVALID_FRAGMENT, HPE_LF_EXPECTED,
    HPE_INVALID_HEADER_TOKEN, HPE_INVALID_CONTENT_LENGTH,
    HPE_INVALID_CHUNK_SIZE, HPE_INVALID_CONSTANT, HPE_INVALID_INTERNAL_STATE,
    HPE_STRICT, HPE_UNKNOWN

  THttpParser*{.pure, final, importc: "http_parser", header: "http_parser.h".} = object
    typ {.importc: "type".}: char
    flags {.importc: "flags".}: char
    state*{.importc: "state".}: char
    header_state*{.importc: "header_state".}: char
    index*{.importc: "index".}: char
    nread*{.importc: "nread".}: cint
    content_length*{.importc: "content_length".}: int64
    http_major*{.importc: "http_major".}: cshort
    http_minor*{.importc: "http_minor".}: cshort
    status_code*{.importc: "status_code".}: cshort
    http_method*{.importc: "method".}: cshort
    http_errno_bits {.importc: "http_errno".}: char
    upgrade {.importc: "upgrade".}: bool
    data*{.importc: "data".}: pointer

  THttpParserSettings*{.pure, final, importc: "http_parser_settings", header: "http_parser.h".} = object
    on_message_begin*{.importc: "on_message_begin".}: HttpProc
    on_url*{.importc: "on_url".}: HttpDataProc
    on_header_field*{.importc: "on_header_field".}: HttpDataProc
    on_header_value*{.importc: "on_header_value".}: HttpDataProc
    on_headers_complete*{.importc: "on_headers_complete".}: HttpProc
    on_body*{.importc: "on_body".}: HttpDataProc
    on_message_complete*{.importc: "on_message_complete".}: HttpProc

proc http_parser_init*(parser: var THttpParser, typ: THttpParserType){.
    importc: "http_parser_init", header: "http_parser.h".}

proc http_parser_execute*(parser: var THttpParser,
                          settings: var THttpParserSettings, data: cstring,
                          len: csize): csize {.
    importc: "http_parser_execute", header: "http_parser.h".}

proc http_should_keep_alive*(parser: var THttpParser): cint{.
    importc: "http_should_keep_alive", header: "http_parser.h".}

proc http_method_str*(m: THttpMethod): cstring{.
    importc: "http_method_str", header: "http_parser.h".}

proc http_errno_name*(err: THttpErrNo): cstring{.
    importc: "http_errno_name", header: "http_parser.h".}

proc http_errno_description*(err: THttpErrNo): cstring{.
    importc: "http_errno_description", header: "http_parser.h".}
r">(inst.products); ++i) { 136 if (is_dummy(inst.products.at(i))) continue; 137 if (!is_mu_boolean(inst.products.at(i))) { 138 raise << maybe(get(Recipe, r).name) << "'not' should yield a boolean, but got '" << inst.products.at(i).original_string << "'\n" << end(); 139 goto finish_checking_instruction; 140 } 141 } 142 break; 143 } 144 :(before "End Primitive Recipe Implementations") 145 case NOT: { 146 products.resize(SIZE(ingredients)); 147 for (int i = 0; i < SIZE(ingredients); ++i) { 148 products.at(i).push_back(!ingredients.at(i).at(0)); 149 } 150 break; 151 } 152 153 :(scenario not) 154 def main [ 155 1:bool <- copy 1 156 2:bool <- not 1:bool 157 ] 158 +mem: storing 0 in location 2 159 160 :(scenario not_multiple) 161 def main [ 162 1:bool, 2:bool, 3:bool <- not 1, 0, 1 163 ] 164 +mem: storing 0 in location 1 165 +mem: storing 1 in location 2 166 +mem: storing 0 in location 3