arturo
arturo copied to clipboard
[Core\module] should show error in case magic methods are included
[Core\module] should show error in case magic methods are included magic methods are of no use in that case
https://github.com/arturo-lang/arturo/blob/dad64b1fb55a075657e30ed54fbcee38a1c6cc19/src/library/Core.nim#L1020
builtin "module",
alias = unaliased,
op = opNop,
rule = PrefixPrecedence,
description = "create new module with given contents",
args = {
"contents" : {Block, Dictionary}
},
attrs = {
"with" : ({Block},"use given initialization parameters"),
},
returns = {Module},
# TODO(Core\module) add documentation example
# labels: library, documentation, easy
example = """
""":
#=======================================================
var definitions: ValueDict = newOrderedTable[string,Value]()
var inherits: Value = VNULL
var super: ValueDict = newOrderedTable[string,Value]()
var initUsing: ValueArray = @[]
if checkAttr("with"):
initUsing = aWith.a
if xKind == Block:
if (let constructorMethod = generatedConstructor(x.a); not constructorMethod.isNil):
definitions[$ConstructorM] = constructorMethod
else:
for k,v in newDictionary(execDictionary(x)).d:
definitions[k] = v
elif xKind == Dictionary:
for k,v in x.d:
definitions[k] = copyValue(v)
# TODO(Core\module) should show error in case magic methods are included
# magic methods are of no use in that case
# labels: vm, error handling
# Get fields
let fieldTable = getFieldTable(definitions)
# Generate internal module identifier
when not defined(WEB):
let moduleId = "module" & "_" & $(genOid())
else:
let moduleId = "module" & "_" & $(rand(1_000_000_000..2_000_000_000))
let proto = newPrototype(moduleId, definitions, inherits, fieldTable, super)
let singleton = generateNewObject(proto, initUsing)
push(newModule(singleton))
builtin "new",
alias = unaliased,
op = opNop,
6e3268d8c3f72a9a01e1529beba5e7af85adbae1