from pycket.values import W_Symbol
from pycket.prims.expose import define_nyi, prim_env, expose

DEBUG = False

def make_primitive_table(ls_str):
    table = [None] * len(ls_str)
    for i, exposed_id in enumerate(ls_str):
        table[i] = W_Symbol.make(exposed_id)

    return table

place_str = ["place-break", "place-channel-get", "place-channel-put",
             "place?", "place-enabled?", "place-channel", "place-dead-evt",
             "place-kill", "place-message-allowed?", "place-channel?", "dynamic-place",
             "place-wait", "place-pumper-threads", "place-shared?"]

paramz_str = ["check-for-break", "break-enabled-key", "parameterization-key", "cache-configuration",
              "exception-handler-key", "extend-parameterization", "reparameterize", "security-guard-check-file",
              "security-guard-check-file-link", "security-guard-check-network"]

 # Exports that are not exposed to Racket, but
 # can be used in a linklet:
internal_str = ["call/cm", "extract-procedure", "set-ctl-c-handler!", "register-linklet-instantiate-continuation!",
                "impersonator-val", "impersonate-ref", "impersonate-set!", "struct-type-install-properties!",
                "structure-type-lookup-prefab-uid", "struct-type-constructor-add-guards", "register-struct-constructor!", "register-struct-predicate!",
                "register-struct-field-accessor!", "register-struct-field-mutator!", "struct-property-set!"]

futures_str = ["futures-enabled?", "processor-count", "future", "future?",
               "touch", "would-be-future", "current-future", "make-fsemaphore",
               "fsemaphore?", "fsemaphore-post", "fsemaphore-wait", "fsemaphore-try-wait?",
               "fsemaphore-count", "reset-future-logs-for-tracing!", "mark-future-trace-end!"]

flfxnum_str = ["fx->fl", "fl->fx", "fxabs", "fx+",
               "fx-", "fx*", "fxquotient", "fxremainder",
               "fx+/wraparound", "fx-/wraparound", "fx*/wraparound", "fxlshift/wraparound",
               "fxmodulo", "fxand", "fxior", "fxxor",
               "fxnot", "fxrshift", "fxlshift", "fx>=",
               "fx>", "fx=", "fx<", "fx<=",
               "fxmin", "fxmax", "fxvector?", "fxvector",
               "make-fxvector", "shared-fxvector", "make-shared-fxvector", "fxvector-length",
               "fxvector-ref", "fxvector-set!", "fl+",
               "fl-", "fl*", "fl/", "flabs",
               "flsqrt", "flexp", "fllog", "flsin", "flsingle",
               "flcos", "fltan", "flasin", "flacos",
               "flatan", "flfloor", "flceiling", "flround",
               "fltruncate", "flexpt", "fl=", "fl<",
               "fl<=", "fl>", "fl>=", "flmin",
               "flmax", "->fl", "fl->exact-integer", "flvector?",
               "flvector", "make-flvector", "shared-flvector", "make-shared-flvector",
               "flvector-length", "flvector-ref", "flvector-set!",
               "flreal-part", "flimag-part", "make-flrectangular"]

extfl_str = ["extflmin", "extflatan", "extfl+", "extflmax",
             "extflfloor", "extfl<=", "extflvector", "extfl->floating-point-bytes",
             "extfltruncate", "->extfl", "extflsin", "extflonum?",
             "extflacos", "extflvector-ref", "extflexp", "extflabs",
             "extflonum-available?", "extfl<", "extfl->exact", "extfl->fx",
             "extfl->inexact", "extflvector-set!", "make-extflvector", "extflcos",
             "extflvector-length", "extfl/", "extflceiling", "floating-point-bytes->extfl",
             "extfl>=", "make-shared-extflvector", "extflround", "extfl->exact-integer",
             "real->extfl", "extflexpt", "fx->extfl", "shared-extflvector",
             "extfl>", "extfllog", "extflvector?", "extfl=",
             "extflsqrt", "extfl*", "extfl-", "extfltan",
             "extflasin"]

network_str = ["tcp-abandon-port", "tcp-accept", "tcp-accept-evt", "tcp-accept-ready?",
               "tcp-accept/enable-break", "tcp-addresses", "tcp-close", "tcp-connect",
               "tcp-connect/enable-break", "tcp-listen", "tcp-listener?", "tcp-port?",
               "udp?", "udp-bind!", "udp-bound?", "udp-close",
               "udp-connect!", "udp-connected?", "udp-multicast-interface", "udp-multicast-join-group!",
               "udp-multicast-leave-group!", "udp-multicast-loopback?", "udp-multicast-set-interface!", "udp-multicast-set-loopback!",
               "udp-multicast-set-ttl!", "udp-multicast-ttl", "udp-open-socket", "udp-receive!",
               "udp-receive!*", "udp-receive!-evt", "udp-receive!/enable-break", "udp-receive-ready-evt",
               "udp-set-receive-buffer-size!",
               "udp-send", "udp-send*", "udp-send-evt", "udp-send-ready-evt",
               "udp-send-to", "udp-send-to*", "udp-send-to-evt", "udp-send-to/enable-break",
               "udp-send/enable-break"]

foreign_str = ["_bool", "_bytes", "_double", "_double*",
               "_fixint", "_fixnum", "_float", "_fpointer",
               "_gcpointer", "_int16", "_int32", "_int64",
               "_int8", "_longdouble", "_path", "_pointer",
               "_scheme", "_stdbool", "_string/ucs-4", "_string/utf-16",
               "_symbol", "_ufixint", "_ufixnum", "_uint16",
               "_uint32", "_uint64", "_uint8", "_void",
               "compiler-sizeof", "cpointer-gcable?", "cpointer-tag", "cpointer?",
               "ctype-alignof", "ctype-basetype", "ctype-c->scheme", "ctype-scheme->c",
               "ctype-sizeof", "ctype?", "end-stubborn-change", "extflvector->cpointer",
               "ffi-call", "ffi-callback", "ffi-callback?", "ffi-lib",
               "ffi-lib-name", "ffi-lib?", "ffi-obj", "ffi-obj-lib",
               "ffi-obj-name", "ffi-obj?", "flvector->cpointer", "free",
               "ffi-lib-unload",
               "free-immobile-cell", "lookup-errno", "make-array-type", "make-cstruct-type",
               "make-ctype", "make-late-weak-box", "make-late-weak-hasheq", "make-sized-byte-string",
               "make-stubborn-will-executor", "make-union-type", "malloc", "malloc-immobile-cell",
               "memcpy", "memmove", "memset", "offset-ptr?",
               "prop:cpointer", "ptr-add", "ptr-add!", "ptr-equal?",
               "ptr-offset", "ptr-ref", "ptr-set!", "saved-errno",
               "set-cpointer-tag!", "set-ptr-offset!", "vector->cpointer",
               "ffi-callback-maker", "ffi-call-maker", "make-late-will-executor"]

linklet_str = ["linklet?", "compile-linklet", "recompile-linklet", "eval-linklet", "read-compiled-linklet", "instantiate-linklet",
               "linklet-import-variables", "linklet-export-variables", "instance?", "make-instance", "instance-name", "instance-data",
               "instance-variable-names", "instance-variable-value", "instance-set-variable-value!", "instance-unset-variable!",
               "linklet-directory?", "hash->linklet-directory", "linklet-directory->hash", "linklet-bundle?", "hash->linklet-bundle",
               "linklet-bundle->hash", "variable-reference?", "variable-reference->instance", "variable-reference-constant?",
               "primitive-table", "variable-reference-from-unsafe?",
               "compiled-position->primitive", "linklet-virtual-machine-bytes",
               "read-linklet-bundle-hash", "write-linklet-bundle-hash", "instance-describe-variable!",
               "primitive-lookup"]

unsafe_str = ["unsafe-car", "unsafe-cdr", "unsafe-list-tail",
              "unsafe-list-ref", "unsafe-cons-list", "unsafe-fx+",
              "unsafe-fx-", "unsafe-fx*", "unsafe-fxquotient",
              "unsafe-fxremainder", "unsafe-fxmodulo", "unsafe-fxabs",
              "unsafe-fxand", "unsafe-fxior", "unsafe-fxxor",
              "unsafe-fxnot", "unsafe-fxrshift", "unsafe-fxlshift",
              "unsafe-fx=", "unsafe-fx<", "unsafe-fx>",
              "unsafe-fx>=", "unsafe-fx<=", "unsafe-fxmin",
              "unsafe-fxmax", "unsafe-fl+", "unsafe-fl-",
              "unsafe-fl*", "unsafe-fl/", "unsafe-flabs",
              "unsafe-fl=", "unsafe-fl<", "unsafe-fl>",
              "unsafe-fl>=", "unsafe-fl<=", "unsafe-flmin",
              "unsafe-flmax", "unsafe-fx->fl", "unsafe-fl->fx",
              "unsafe-flrandom", "unsafe-flsqrt", "unsafe-make-flrectangular",
              "unsafe-flreal-part", "unsafe-flimag-part", "unsafe-extfl*",
              "unsafe-extfl+", "unsafe-extfl-", "unsafe-extfl/",
              "unsafe-extfl<", "unsafe-extfl<=", "unsafe-extfl=",
              "unsafe-extfl>", "unsafe-extfl>=", "unsafe-extflabs",
              "unsafe-extflmax", "unsafe-extflmin", "unsafe-extflsqrt",
              "unsafe-extfl->fx", "unsafe-fx->extfl", "unsafe-extflvector-length",
              "unsafe-extflvector-ref", "unsafe-extflvector-set!", "unsafe-unbox*",
              "unsafe-set-box*!", "unsafe-set-box!", "unsafe-unbox",
              "unsafe-box*-cas!", "unsafe-mcar", "unsafe-mcdr",
              "unsafe-set-mcar!", "unsafe-set-mcdr!", "unsafe-vector-ref",
              "unsafe-vector-set!", "unsafe-vector*-ref", "unsafe-vector*-set!",
              "unsafe-vector*-cas!", "unsafe-vector-length", "unsafe-vector*-length",
              "unsafe-fxvector-length", "unsafe-fxvector-ref", "unsafe-fxvector-set!",
              "unsafe-flvector-length", "unsafe-flvector-ref", "unsafe-flvector-set!",
              "unsafe-s16vector-ref", "unsafe-s16vector-set!", "unsafe-u16vector-ref",
              "unsafe-u16vector-set!", "unsafe-f64vector-ref", "unsafe-f64vector-set!",
              "unsafe-f80vector-set!", "unsafe-f80vector-ref", "unsafe-bytes-length",
              "unsafe-bytes-ref", "unsafe-bytes-set!", "unsafe-string-length",
              "unsafe-string-set!", "unsafe-string-ref", "unsafe-struct-ref",
              "unsafe-struct-set!", "unsafe-struct*-ref", "unsafe-struct*-set!",
              "unsafe-immutable-hash-iterate-key+value", "unsafe-immutable-hash-iterate-pair",
              "unsafe-immutable-hash-iterate-value", "unsafe-immutable-hash-iterate-key",
              "unsafe-immutable-hash-iterate-first", "unsafe-immutable-hash-iterate-next",
              "unsafe-mutable-hash-iterate-key+value", "unsafe-mutable-hash-iterate-pair",
              "unsafe-mutable-hash-iterate-value", "unsafe-mutable-hash-iterate-key",
              "unsafe-mutable-hash-iterate-first", "unsafe-mutable-hash-iterate-next",
              "unsafe-weak-hash-iterate-key+value", "unsafe-weak-hash-iterate-pair",
              "unsafe-weak-hash-iterate-value", "unsafe-weak-hash-iterate-key",
              "unsafe-weak-hash-iterate-first", "unsafe-weak-hash-iterate-next",
              "unsafe-ephemeron-hash-iterate-key+value", "unsafe-ephemeron-hash-iterate-pair",
              "unsafe-ephemeron-hash-iterate-value", "unsafe-ephemeron-hash-iterate-key",
              "unsafe-ephemeron-hash-iterate-first", "unsafe-ephemeron-hash-iterate-next",
              "unsafe-chaperone-procedure", "unsafe-impersonate-procedure", "unsafe-impersonate-vector",
              "unsafe-chaperone-vector", "unsafe-undefined", "check-not-unsafe-undefined",
              "check-not-unsafe-undefined/assign", "prop:chaperone-unsafe-undefined",
              "chaperone-struct-unsafe-undefined",
              "unsafe-start-atomic", "unsafe-end-atomic", "unsafe-start-breakable-atomic",
              "unsafe-end-breakable-atomic", "unsafe-in-atomic?", "unsafe-set-on-atomic-timeout!",
              "unsafe-thread-at-root", "unsafe-make-custodian-at-root", "unsafe-custodian-register",
              "unsafe-custodian-unregister", "unsafe-register-process-global", "unsafe-make-security-guard-at-root",
              "unsafe-abort-current-continuation/no-wind", "unsafe-call-with-composable-continuation/no-wind",
              "unsafe-poller", "unsafe-poll-fd",
              "unsafe-poll-ctx-fd-wakeup", "unsafe-poll-ctx-eventmask-wakeup", "unsafe-poll-ctx-milliseconds-wakeup",
              "unsafe-signal-received", "unsafe-set-sleep-in-thread!",
              "unsafe-file-descriptor->port", "unsafe-socket->port",
              "unsafe-file-descriptor->semaphore", "unsafe-socket->semaphore",