Merge branch 'develop' into method_missing
This commit is contained in:
commit
cbeeadd6f3
29
LICENSE
Normal file
29
LICENSE
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Copyright 2009-2015 Jason Turner
|
||||||
|
Copyright 2009-2012 Jonathan Turner.
|
||||||
|
|
||||||
|
All Rights Reserved.
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer in the documentation and/or other materials provided
|
||||||
|
with the distribution.
|
||||||
|
* Neither the name of Jason Turner nor Jonathan Turner nor the
|
||||||
|
name of contributors may be used to endorse or promote products derived
|
||||||
|
from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -258,4 +258,15 @@ print(get_value(m)); // prints "Value Is: a"
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Built In Functions
|
||||||
|
|
||||||
|
## Evaluation
|
||||||
|
|
||||||
|
```
|
||||||
|
eval("4 + 5") // dynamically eval script string and returns value of last statement
|
||||||
|
eval_file("filename") // evals file and returns value of last statement
|
||||||
|
use("filename") // evals file exactly once and returns value of last statement
|
||||||
|
// if the file had already been 'used' nothing happens and undefined is returned
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
93
contrib/sublimetext/ChaiScript.YAML-tmLanguage
Normal file
93
contrib/sublimetext/ChaiScript.YAML-tmLanguage
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
# [PackageDev] target_format: plist, ext: tmLanguage
|
||||||
|
---
|
||||||
|
comment: 'ChaiScript Syntax: version 2.0'
|
||||||
|
fileTypes: [chai]
|
||||||
|
firstLineMatch: ^#!/usr/bin/env node
|
||||||
|
foldingStartMarker: ^.*\bdef\s*(\w+\s*)?\([^\)]*\)(\s*\{[^\}]*)?\s*$
|
||||||
|
foldingStopMarker: ^\s*\}
|
||||||
|
keyEquivalent: ^~J
|
||||||
|
name: ChaiScript
|
||||||
|
patterns:
|
||||||
|
- {comment: chaiscript shebang, match: ^#, name: comment.line.chai}
|
||||||
|
- {match: '\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b', name: constant.numeric.chai}
|
||||||
|
- begin: ''''
|
||||||
|
beginCaptures:
|
||||||
|
'0': {name: punctuation.definition.string.begin.chai}
|
||||||
|
end: ''''
|
||||||
|
endCaptures:
|
||||||
|
'0': {name: punctuation.definition.string.end.chai}
|
||||||
|
name: string.quoted.single.chai
|
||||||
|
patterns:
|
||||||
|
- {match: '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)', name: constant.character.escape.chai}
|
||||||
|
- begin: '"'
|
||||||
|
beginCaptures:
|
||||||
|
'0': {name: punctuation.definition.string.begin.chai}
|
||||||
|
end: '"'
|
||||||
|
endCaptures:
|
||||||
|
'0': {name: punctuation.definition.string.end.chai}
|
||||||
|
name: string.quoted.double.chai
|
||||||
|
patterns:
|
||||||
|
- {match: '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)', name: constant.character.escape.chai}
|
||||||
|
- begin: /\*\*(?!/)
|
||||||
|
captures:
|
||||||
|
'0': {name: punctuation.definition.comment.chai}
|
||||||
|
end: \*/
|
||||||
|
name: comment.block.documentation.chai
|
||||||
|
- begin: /\*
|
||||||
|
captures:
|
||||||
|
'0': {name: punctuation.definition.comment.chai}
|
||||||
|
end: \*/
|
||||||
|
name: comment.block.chai
|
||||||
|
- captures:
|
||||||
|
'1': {name: punctuation.definition.comment.chai}
|
||||||
|
match: (//).*$\n?
|
||||||
|
name: comment.line.double-slash.chai
|
||||||
|
- captures:
|
||||||
|
'0': {name: punctuation.definition.comment.html.chai}
|
||||||
|
'2': {name: punctuation.definition.comment.html.chai}
|
||||||
|
match: (<!--|-->)
|
||||||
|
name: comment.block.html.chai
|
||||||
|
- {match: \b(boolean|byte|char|class|double|enum|float|fun|def|int|interface|long|short|var|auto|attr)\b,
|
||||||
|
name: storage.type.chai}
|
||||||
|
- {match: \b(break|case|catch|continue|default|do|else|finally|else if|for|goto|if|return|switch|throw|try|while)\b,
|
||||||
|
name: keyword.control.chai}
|
||||||
|
- {match: \b(delete|in|instanceof|new|typeof|with)\b, name: keyword.operator.chai}
|
||||||
|
- {match: \btrue\b, name: constant.language.boolean.true.chai}
|
||||||
|
- {match: \bfalse\b, name: constant.language.boolean.false.chai}
|
||||||
|
- {match: \bnull\b, name: constant.language.null.chai}
|
||||||
|
- {match: \b(Anchor|Applet|Area|Array|Boolean|Button|Checkbox|Date|document|event|FileUpload|Form|Frame|Function|Hidden|History|Image|JavaArray|JavaClass|JavaObject|JavaPackage|java|Layer|Link|Location|Math|MimeType|Number|navigator|netscape|Object|Option|Packages|Password|Plugin|Radio|RegExp|Reset|Select|String|Style|Submit|screen|sun|Text|Textarea|window|XMLHttpRequest)\b,
|
||||||
|
name: support.class.chai}
|
||||||
|
- {match: '\b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack))\b(?=\()',
|
||||||
|
name: support.function.chai}
|
||||||
|
- {match: '\b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\b(?=\()',
|
||||||
|
name: support.function.dom.chai}
|
||||||
|
- {match: '(?<=\.)(s(ystemLanguage|cr(ipts|ollbars|een(X|Y|Top|Left))|t(yle(Sheets)?|atus(Text|bar)?)|ibling(Below|Above)|ource|uffixes|e(curity(Policy)?|l(ection|f)))|h(istory|ost(name)?|as(h|Focus))|y|X(MLDocument|SLDocument)|n(ext|ame(space(s|URI)|Prop))|M(IN_VALUE|AX_VALUE)|c(haracterSet|o(n(structor|trollers)|okieEnabled|lorDepth|mp(onents|lete))|urrent|puClass|l(i(p(boardData)?|entInformation)|osed|asses)|alle(e|r)|rypto)|t(o(olbar|p)|ext(Transform|Indent|Decoration|Align)|ags)|SQRT(1_2|2)|i(n(ner(Height|Width)|put)|ds|gnoreCase)|zIndex|o(scpu|n(readystatechange|Line)|uter(Height|Width)|p(sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(i(splay|alog(Height|Top|Width|Left|Arguments)|rectories)|e(scription|fault(Status|Ch(ecked|arset)|View)))|u(ser(Profile|Language|Agent)|n(iqueID|defined)|pdateInterval)|_content|p(ixelDepth|ort|ersonalbar|kcs11|l(ugins|atform)|a(thname|dding(Right|Bottom|Top|Left)|rent(Window|Layer)?|ge(X(Offset)?|Y(Offset)?))|r(o(to(col|type)|duct(Sub)?|mpter)|e(vious|fix)))|e(n(coding|abledPlugin)|x(ternal|pando)|mbeds)|v(isibility|endor(Sub)?|Linkcolor)|URLUnencoded|P(I|OSITIVE_INFINITY)|f(ilename|o(nt(Size|Family|Weight)|rmName)|rame(s|Element)|gColor)|E|whiteSpace|l(i(stStyleType|n(eHeight|kColor))|o(ca(tion(bar)?|lName)|wsrc)|e(ngth|ft(Context)?)|a(st(M(odified|atch)|Index|Paren)|yer(s|X)|nguage))|a(pp(MinorVersion|Name|Co(deName|re)|Version)|vail(Height|Top|Width|Left)|ll|r(ity|guments)|Linkcolor|bove)|r(ight(Context)?|e(sponse(XML|Text)|adyState))|global|x|m(imeTypes|ultiline|enubar|argin(Right|Bottom|Top|Left))|L(N(10|2)|OG(10E|2E))|b(o(ttom|rder(Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(Color|Image)))\b',
|
||||||
|
name: support.constant.chai}
|
||||||
|
- {match: '(?<=\.)(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\b',
|
||||||
|
name: support.constant.dom.chai}
|
||||||
|
- {match: \b(ELEMENT_NODE|ATTRIBUTE_NODE|TEXT_NODE|CDATA_SECTION_NODE|ENTITY_REFERENCE_NODE|ENTITY_NODE|PROCESSING_INSTRUCTION_NODE|COMMENT_NODE|DOCUMENT_NODE|DOCUMENT_TYPE_NODE|DOCUMENT_FRAGMENT_NODE|NOTATION_NODE|INDEX_SIZE_ERR|DOMSTRING_SIZE_ERR|HIERARCHY_REQUEST_ERR|WRONG_DOCUMENT_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR|NOT_SUPPORTED_ERR|INUSE_ATTRIBUTE_ERR)\b,
|
||||||
|
name: support.constant.dom.chai}
|
||||||
|
- {match: '\bon(R(ow(s(inserted|delete)|e(nter|xit))|e(s(ize(start|end)?|et)|adystatechange))|Mouse(o(ut|ver)|down|up|move)|B(efore(cut|deactivate|u(nload|pdate)|p(aste|rint)|editfocus|activate)|lur)|S(croll|top|ubmit|elect(start|ionchange)?)|H(over|elp)|C(hange|ont(extmenu|rolselect)|ut|ellchange|l(ick|ose))|D(eactivate|ata(setc(hanged|omplete)|available)|r(op|ag(start|over|drop|en(ter|d)|leave)?)|blclick)|Unload|P(aste|ropertychange)|Error(update)?|Key(down|up|press)|Focus|Load|A(ctivate|fter(update|print)|bort))\b',
|
||||||
|
name: support.function.event-handler.chai}
|
||||||
|
- {match: '!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|void)\b',
|
||||||
|
name: keyword.operator.chai}
|
||||||
|
- {match: \b(Infinity|NaN|undefined)\b, name: constant.language.chai}
|
||||||
|
- begin: (?<=[=(:]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?])
|
||||||
|
beginCaptures:
|
||||||
|
'1': {name: punctuation.definition.string.begin.chai}
|
||||||
|
end: (/)[igm]*
|
||||||
|
endCaptures:
|
||||||
|
'1': {name: punctuation.definition.string.end.chai}
|
||||||
|
name: string.regexp.chai
|
||||||
|
patterns:
|
||||||
|
- {match: \\., name: constant.character.escape.chai}
|
||||||
|
- {match: \;, name: punctuation.terminator.statement.chai}
|
||||||
|
- {match: ',[ |\t]*', name: meta.delimiter.object.comma.chai}
|
||||||
|
- {match: \., name: meta.delimiter.method.period.chai}
|
||||||
|
- {match: '\{|\}', name: meta.brace.curly.chai}
|
||||||
|
- {match: \(|\), name: meta.brace.round.chai}
|
||||||
|
- {match: '\[|\]', name: meta.brace.square.chai}
|
||||||
|
scopeName: source.chai
|
||||||
|
uuid: 93E017CC-6F27-11D9-90EB-000D93589AF6
|
||||||
|
|
||||||
|
...
|
333
contrib/sublimetext/ChaiScript.tmLanguage
Normal file
333
contrib/sublimetext/ChaiScript.tmLanguage
Normal file
@ -0,0 +1,333 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>comment</key>
|
||||||
|
<string>ChaiScript Syntax: version 2.0</string>
|
||||||
|
<key>fileTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>chai</string>
|
||||||
|
</array>
|
||||||
|
<key>firstLineMatch</key>
|
||||||
|
<string>^#!/usr/bin/env node</string>
|
||||||
|
<key>foldingStartMarker</key>
|
||||||
|
<string>^.*\bdef\s*(\w+\s*)?\([^\)]*\)(\s*\{[^\}]*)?\s*$</string>
|
||||||
|
<key>foldingStopMarker</key>
|
||||||
|
<string>^\s*\}</string>
|
||||||
|
<key>keyEquivalent</key>
|
||||||
|
<string>^~J</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>ChaiScript</string>
|
||||||
|
<key>patterns</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>comment</key>
|
||||||
|
<string>chaiscript shebang</string>
|
||||||
|
<key>match</key>
|
||||||
|
<string>^#</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>comment.line.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.numeric.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>begin</key>
|
||||||
|
<string>'</string>
|
||||||
|
<key>beginCaptures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.string.begin.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>end</key>
|
||||||
|
<string>'</string>
|
||||||
|
<key>endCaptures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.string.end.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>string.quoted.single.chai</string>
|
||||||
|
<key>patterns</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.character.escape.chai</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>begin</key>
|
||||||
|
<string>"</string>
|
||||||
|
<key>beginCaptures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.string.begin.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>end</key>
|
||||||
|
<string>"</string>
|
||||||
|
<key>endCaptures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.string.end.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>string.quoted.double.chai</string>
|
||||||
|
<key>patterns</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.character.escape.chai</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>begin</key>
|
||||||
|
<string>/\*\*(?!/)</string>
|
||||||
|
<key>captures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.comment.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>end</key>
|
||||||
|
<string>\*/</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>comment.block.documentation.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>begin</key>
|
||||||
|
<string>/\*</string>
|
||||||
|
<key>captures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.comment.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>end</key>
|
||||||
|
<string>\*/</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>comment.block.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>captures</key>
|
||||||
|
<dict>
|
||||||
|
<key>1</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.comment.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>(//).*$\n?</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>comment.line.double-slash.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>captures</key>
|
||||||
|
<dict>
|
||||||
|
<key>0</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.comment.html.chai</string>
|
||||||
|
</dict>
|
||||||
|
<key>2</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.comment.html.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>(<!--|-->)</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>comment.block.html.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(boolean|byte|char|class|double|enum|float|fun|def|int|interface|long|short|var|auto|attr)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>storage.type.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(break|case|catch|continue|default|do|else|finally|else if|for|goto|if|return|switch|throw|try|while)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>keyword.control.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(delete|in|instanceof|new|typeof|with)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>keyword.operator.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\btrue\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.language.boolean.true.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\bfalse\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.language.boolean.false.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\bnull\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.language.null.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(Anchor|Applet|Area|Array|Boolean|Button|Checkbox|Date|document|event|FileUpload|Form|Frame|Function|Hidden|History|Image|JavaArray|JavaClass|JavaObject|JavaPackage|java|Layer|Link|Location|Math|MimeType|Number|navigator|netscape|Object|Option|Packages|Password|Plugin|Radio|RegExp|Reset|Select|String|Style|Submit|screen|sun|Text|Textarea|window|XMLHttpRequest)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.class.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack))\b(?=\()</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.function.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\b(?=\()</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.function.dom.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>(?<=\.)(s(ystemLanguage|cr(ipts|ollbars|een(X|Y|Top|Left))|t(yle(Sheets)?|atus(Text|bar)?)|ibling(Below|Above)|ource|uffixes|e(curity(Policy)?|l(ection|f)))|h(istory|ost(name)?|as(h|Focus))|y|X(MLDocument|SLDocument)|n(ext|ame(space(s|URI)|Prop))|M(IN_VALUE|AX_VALUE)|c(haracterSet|o(n(structor|trollers)|okieEnabled|lorDepth|mp(onents|lete))|urrent|puClass|l(i(p(boardData)?|entInformation)|osed|asses)|alle(e|r)|rypto)|t(o(olbar|p)|ext(Transform|Indent|Decoration|Align)|ags)|SQRT(1_2|2)|i(n(ner(Height|Width)|put)|ds|gnoreCase)|zIndex|o(scpu|n(readystatechange|Line)|uter(Height|Width)|p(sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(i(splay|alog(Height|Top|Width|Left|Arguments)|rectories)|e(scription|fault(Status|Ch(ecked|arset)|View)))|u(ser(Profile|Language|Agent)|n(iqueID|defined)|pdateInterval)|_content|p(ixelDepth|ort|ersonalbar|kcs11|l(ugins|atform)|a(thname|dding(Right|Bottom|Top|Left)|rent(Window|Layer)?|ge(X(Offset)?|Y(Offset)?))|r(o(to(col|type)|duct(Sub)?|mpter)|e(vious|fix)))|e(n(coding|abledPlugin)|x(ternal|pando)|mbeds)|v(isibility|endor(Sub)?|Linkcolor)|URLUnencoded|P(I|OSITIVE_INFINITY)|f(ilename|o(nt(Size|Family|Weight)|rmName)|rame(s|Element)|gColor)|E|whiteSpace|l(i(stStyleType|n(eHeight|kColor))|o(ca(tion(bar)?|lName)|wsrc)|e(ngth|ft(Context)?)|a(st(M(odified|atch)|Index|Paren)|yer(s|X)|nguage))|a(pp(MinorVersion|Name|Co(deName|re)|Version)|vail(Height|Top|Width|Left)|ll|r(ity|guments)|Linkcolor|bove)|r(ight(Context)?|e(sponse(XML|Text)|adyState))|global|x|m(imeTypes|ultiline|enubar|argin(Right|Bottom|Top|Left))|L(N(10|2)|OG(10E|2E))|b(o(ttom|rder(Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(Color|Image)))\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.constant.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>(?<=\.)(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.constant.dom.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(ELEMENT_NODE|ATTRIBUTE_NODE|TEXT_NODE|CDATA_SECTION_NODE|ENTITY_REFERENCE_NODE|ENTITY_NODE|PROCESSING_INSTRUCTION_NODE|COMMENT_NODE|DOCUMENT_NODE|DOCUMENT_TYPE_NODE|DOCUMENT_FRAGMENT_NODE|NOTATION_NODE|INDEX_SIZE_ERR|DOMSTRING_SIZE_ERR|HIERARCHY_REQUEST_ERR|WRONG_DOCUMENT_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR|NOT_SUPPORTED_ERR|INUSE_ATTRIBUTE_ERR)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.constant.dom.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\bon(R(ow(s(inserted|delete)|e(nter|xit))|e(s(ize(start|end)?|et)|adystatechange))|Mouse(o(ut|ver)|down|up|move)|B(efore(cut|deactivate|u(nload|pdate)|p(aste|rint)|editfocus|activate)|lur)|S(croll|top|ubmit|elect(start|ionchange)?)|H(over|elp)|C(hange|ont(extmenu|rolselect)|ut|ellchange|l(ick|ose))|D(eactivate|ata(setc(hanged|omplete)|available)|r(op|ag(start|over|drop|en(ter|d)|leave)?)|blclick)|Unload|P(aste|ropertychange)|Error(update)?|Key(down|up|press)|Focus|Load|A(ctivate|fter(update|print)|bort))\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>support.function.event-handler.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|void)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>keyword.operator.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\b(Infinity|NaN|undefined)\b</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.language.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>begin</key>
|
||||||
|
<string>(?<=[=(:]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?])</string>
|
||||||
|
<key>beginCaptures</key>
|
||||||
|
<dict>
|
||||||
|
<key>1</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.string.begin.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>end</key>
|
||||||
|
<string>(/)[igm]*</string>
|
||||||
|
<key>endCaptures</key>
|
||||||
|
<dict>
|
||||||
|
<key>1</key>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.definition.string.end.chai</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>string.regexp.chai</string>
|
||||||
|
<key>patterns</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\\.</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>constant.character.escape.chai</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\;</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>punctuation.terminator.statement.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>,[ |\t]*</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>meta.delimiter.object.comma.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\.</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>meta.delimiter.method.period.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\{|\}</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>meta.brace.curly.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\(|\)</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>meta.brace.round.chai</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>match</key>
|
||||||
|
<string>\[|\]</string>
|
||||||
|
<key>name</key>
|
||||||
|
<string>meta.brace.square.chai</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
<key>scopeName</key>
|
||||||
|
<string>source.chai</string>
|
||||||
|
<key>uuid</key>
|
||||||
|
<string>93E017CC-6F27-11D9-90EB-000D93589AF6</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
@ -7,6 +7,7 @@
|
|||||||
#ifndef CHAISCRIPT_THREADING_HPP_
|
#ifndef CHAISCRIPT_THREADING_HPP_
|
||||||
#define CHAISCRIPT_THREADING_HPP_
|
#define CHAISCRIPT_THREADING_HPP_
|
||||||
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
@ -16,6 +17,8 @@
|
|||||||
#pragma message ("ChaiScript is compiling without thread safety.")
|
#pragma message ("ChaiScript is compiling without thread safety.")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "chaiscript_defines.hpp"
|
||||||
|
|
||||||
/// \file
|
/// \file
|
||||||
///
|
///
|
||||||
/// This file contains code necessary for thread support in ChaiScript.
|
/// This file contains code necessary for thread support in ChaiScript.
|
||||||
|
@ -136,10 +136,14 @@ namespace chaiscript
|
|||||||
ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
m->add(user_type<T>(), name);
|
m->add(user_type<T>(), name);
|
||||||
m->add(constructor<T ()>(), name);
|
m->add(constructor<T()>(), name);
|
||||||
construct_pod<T>(name, m);
|
construct_pod<T>(name, m);
|
||||||
|
|
||||||
m->add(fun(&to_string<T>), "to_string");
|
auto to_s = fun(&to_string<T>);
|
||||||
|
|
||||||
|
if (!m->has_function(to_s, "to_string")) {
|
||||||
|
m->add(to_s, "to_string");
|
||||||
|
}
|
||||||
m->add(fun(&parse_string<T>), "to_" + name);
|
m->add(fun(&parse_string<T>), "to_" + name);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@ -471,7 +475,6 @@ namespace chaiscript
|
|||||||
m->add(chaiscript::fun(&has_parse_tree), "has_parse_tree");
|
m->add(chaiscript::fun(&has_parse_tree), "has_parse_tree");
|
||||||
m->add(chaiscript::fun(&get_parse_tree), "get_parse_tree");
|
m->add(chaiscript::fun(&get_parse_tree), "get_parse_tree");
|
||||||
|
|
||||||
m->add(chaiscript::user_type<chaiscript::exception::eval_error>(), "eval_error");
|
|
||||||
m->add(chaiscript::base_class<std::runtime_error, chaiscript::exception::eval_error>());
|
m->add(chaiscript::base_class<std::runtime_error, chaiscript::exception::eval_error>());
|
||||||
|
|
||||||
m->add(chaiscript::user_type<chaiscript::exception::arithmetic_error>(), "arithmetic_error");
|
m->add(chaiscript::user_type<chaiscript::exception::arithmetic_error>(), "arithmetic_error");
|
||||||
|
@ -267,7 +267,7 @@ namespace chaiscript
|
|||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
ModulePtr assignable_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr assignable_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
basic_constructors<ContainerType>(type, m);
|
copy_constructor<ContainerType>(type, m);
|
||||||
operators::assign<ContainerType>(m);
|
operators::assign<ContainerType>(m);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@ -443,6 +443,7 @@ namespace chaiscript
|
|||||||
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");
|
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");
|
||||||
|
|
||||||
container_type<MapType>(type, m);
|
container_type<MapType>(type, m);
|
||||||
|
default_constructible_type<MapType>(type, m);
|
||||||
assignable_type<MapType>(type, m);
|
assignable_type<MapType>(type, m);
|
||||||
unique_associative_container_type<MapType>(type, m);
|
unique_associative_container_type<MapType>(type, m);
|
||||||
pair_associative_container_type<MapType>(type, m);
|
pair_associative_container_type<MapType>(type, m);
|
||||||
|
@ -65,21 +65,11 @@ namespace chaiscript
|
|||||||
typedef const Result * Result_Type;
|
typedef const Result * Result_Type;
|
||||||
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
|
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
|
||||||
{
|
{
|
||||||
if (ob.is_ref())
|
if (ob.get_type_info().bare_equal_type_info(typeid(Result)))
|
||||||
{
|
{
|
||||||
if (!ob.get_type_info().is_const())
|
return static_cast<const Result *>(throw_if_null(ob.get_const_ptr()));
|
||||||
{
|
|
||||||
return &(ob.get().cast<std::reference_wrapper<Result> >()).get();
|
|
||||||
} else {
|
|
||||||
return &(ob.get().cast<std::reference_wrapper<const Result> >()).get();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!ob.get_type_info().is_const())
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
{
|
|
||||||
return (ob.get().cast<std::shared_ptr<Result> >()).get();
|
|
||||||
} else {
|
|
||||||
return (ob.get().cast<std::shared_ptr<const Result> >()).get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -101,6 +91,7 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Cast_Helper_Inner for casting to a & type
|
/// Cast_Helper_Inner for casting to a & type
|
||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper_Inner<Result &>
|
struct Cast_Helper_Inner<Result &>
|
||||||
|
@ -199,6 +199,14 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_function(const Proxy_Function &new_f, const std::string &name)
|
||||||
|
{
|
||||||
|
return std::any_of(m_funcs.begin(), m_funcs.end(), [&](const std::pair<Proxy_Function, std::string> &existing_f) {
|
||||||
|
return existing_f.second == name && *(existing_f.first) == *(new_f);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::pair<Type_Info, std::string> > m_typeinfos;
|
std::vector<std::pair<Type_Info, std::string> > m_typeinfos;
|
||||||
std::vector<std::pair<Proxy_Function, std::string> > m_funcs;
|
std::vector<std::pair<Proxy_Function, std::string> > m_funcs;
|
||||||
@ -580,7 +588,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the type info for a named type
|
/// Returns the type info for a named type
|
||||||
Type_Info get_type(const std::string &name) const
|
Type_Info get_type(const std::string &name, bool t_throw = true) const
|
||||||
{
|
{
|
||||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
@ -591,7 +599,11 @@ namespace chaiscript
|
|||||||
return itr->second;
|
return itr->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::range_error("Type Not Known");
|
if (t_throw) {
|
||||||
|
throw std::range_error("Type Not Known");
|
||||||
|
} else {
|
||||||
|
return Type_Info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the registered name of a known type_info object
|
/// Returns the registered name of a known type_info object
|
||||||
@ -1018,14 +1030,6 @@ namespace chaiscript
|
|||||||
|
|
||||||
static bool function_less_than(const Proxy_Function &lhs, const Proxy_Function &rhs)
|
static bool function_less_than(const Proxy_Function &lhs, const Proxy_Function &rhs)
|
||||||
{
|
{
|
||||||
const auto &lhsparamtypes = lhs->get_param_types();
|
|
||||||
const auto &rhsparamtypes = rhs->get_param_types();
|
|
||||||
|
|
||||||
const auto lhssize = lhsparamtypes.size();
|
|
||||||
const auto rhssize = rhsparamtypes.size();
|
|
||||||
|
|
||||||
CHAISCRIPT_CONSTEXPR auto boxed_type = user_type<Boxed_Value>();
|
|
||||||
CHAISCRIPT_CONSTEXPR auto boxed_pod_type = user_type<Boxed_Number>();
|
|
||||||
|
|
||||||
auto dynamic_lhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(lhs));
|
auto dynamic_lhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(lhs));
|
||||||
auto dynamic_rhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(rhs));
|
auto dynamic_rhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(rhs));
|
||||||
@ -1055,6 +1059,14 @@ namespace chaiscript
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto &lhsparamtypes = lhs->get_param_types();
|
||||||
|
const auto &rhsparamtypes = rhs->get_param_types();
|
||||||
|
|
||||||
|
const auto lhssize = lhsparamtypes.size();
|
||||||
|
const auto rhssize = rhsparamtypes.size();
|
||||||
|
|
||||||
|
CHAISCRIPT_CONSTEXPR auto boxed_type = user_type<Boxed_Value>();
|
||||||
|
CHAISCRIPT_CONSTEXPR auto boxed_pod_type = user_type<Boxed_Number>();
|
||||||
|
|
||||||
for (size_t i = 1; i < lhssize && i < rhssize; ++i)
|
for (size_t i = 1; i < lhssize && i < rhssize; ++i)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ namespace chaiscript
|
|||||||
const Proxy_Function &t_func,
|
const Proxy_Function &t_func,
|
||||||
const Type_Info &t_ti)
|
const Type_Info &t_ti)
|
||||||
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti), t_func->get_arity()),
|
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti), t_func->get_arity()),
|
||||||
m_type_name(std::move(t_type_name)), m_func(t_func), m_ti(new Type_Info(t_ti)), m_doti(user_type<Dynamic_Object>())
|
m_type_name(std::move(t_type_name)), m_func(t_func), m_ti(t_ti.is_undef()?nullptr:new Type_Info(t_ti)), m_doti(user_type<Dynamic_Object>())
|
||||||
{
|
{
|
||||||
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
|
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
|
||||||
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
|
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "boxed_number.hpp"
|
#include "boxed_number.hpp"
|
||||||
#include "boxed_value.hpp"
|
#include "boxed_value.hpp"
|
||||||
@ -33,15 +34,19 @@ namespace chaiscript
|
|||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return
|
struct Handle_Return
|
||||||
{
|
{
|
||||||
static Boxed_Value handle(const Ret &r)
|
template<typename T,
|
||||||
{
|
typename = typename std::enable_if<std::is_pod<typename std::decay<T>::type>::value>::type>
|
||||||
return const_var(r);
|
static Boxed_Value handle(T r)
|
||||||
}
|
|
||||||
|
|
||||||
static Boxed_Value handle(Ret &&r)
|
|
||||||
{
|
{
|
||||||
return Boxed_Value(std::move(r));
|
return Boxed_Value(std::move(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T,
|
||||||
|
typename = typename std::enable_if<!std::is_pod<typename std::decay<T>::type>::value>::type>
|
||||||
|
static Boxed_Value handle(T &&r)
|
||||||
|
{
|
||||||
|
return Boxed_Value(std::make_shared<T>(std::forward<T>(r)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
|
@ -529,12 +529,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
|
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
|
||||||
{
|
{
|
||||||
if (static_cast<int>(vals.size()) != get_arity())
|
return static_cast<int>(vals.size()) == get_arity() && (compare_types(m_types, vals) || compare_types_with_cast(vals, t_conversions));
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return compare_types(m_types, vals) || compare_types_with_cast(vals, t_conversions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const = 0;
|
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const = 0;
|
||||||
@ -722,8 +717,18 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
matching_func = begin;
|
matching_func = begin;
|
||||||
} else {
|
} else {
|
||||||
// More than one function matches, not attempting
|
// handle const members vs non-const member, which is not really ambiguous
|
||||||
throw exception::dispatch_error(plist, std::vector<Const_Proxy_Function>(orig, end));
|
const auto &mat_fun_param_types = (*matching_func)->get_param_types();
|
||||||
|
const auto &next_fun_param_types = (*begin)->get_param_types();
|
||||||
|
|
||||||
|
if (plist[0].is_const() && !mat_fun_param_types[1].is_const() && next_fun_param_types[1].is_const()) {
|
||||||
|
matching_func = begin; // keep the new one, the const/non-const matchup is correct
|
||||||
|
} else if (!plist[0].is_const() && !mat_fun_param_types[1].is_const() && next_fun_param_types[1].is_const()) {
|
||||||
|
// keep the old one, it has a better const/non-const matchup
|
||||||
|
} else {
|
||||||
|
// ambiguous function call
|
||||||
|
throw exception::dispatch_error(plist, std::vector<Const_Proxy_Function>(orig, end));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,12 +813,6 @@ namespace chaiscript
|
|||||||
return (*(func.second))(plist, t_conversions);
|
return (*(func.second))(plist, t_conversions);
|
||||||
}
|
}
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
//std::cout << "Bad Boxed Cast: " << func.second->get_arity() << '(';
|
|
||||||
//for (const auto &p : plist) {
|
|
||||||
// std::cout << p.get_type_info().name() << ',';
|
|
||||||
//}
|
|
||||||
//std::cout << ")\n";
|
|
||||||
|
|
||||||
//parameter failed to cast, try again
|
//parameter failed to cast, try again
|
||||||
} catch (const exception::arity_error &) {
|
} catch (const exception::arity_error &) {
|
||||||
//invalid num params, try again
|
//invalid num params, try again
|
||||||
|
@ -119,24 +119,27 @@ namespace chaiscript
|
|||||||
// Dynamic cast out the contained boxed value, which we know is the type we want
|
// Dynamic cast out the contained boxed value, which we know is the type we want
|
||||||
if (t_from.is_const())
|
if (t_from.is_const())
|
||||||
{
|
{
|
||||||
std::shared_ptr<const To> data
|
return Boxed_Value(
|
||||||
= std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr));
|
[&]()->std::shared_ptr<const To>{
|
||||||
if (!data)
|
if (auto data = std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
throw std::bad_cast();
|
return data;
|
||||||
}
|
} else {
|
||||||
|
throw std::bad_cast();
|
||||||
return Boxed_Value(data);
|
}
|
||||||
|
}()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
std::shared_ptr<To> data
|
return Boxed_Value(
|
||||||
= std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr));
|
[&]()->std::shared_ptr<To>{
|
||||||
|
if (auto data = std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
||||||
if (!data)
|
{
|
||||||
{
|
return data;
|
||||||
throw std::bad_cast();
|
} else {
|
||||||
}
|
throw std::bad_cast();
|
||||||
|
}
|
||||||
return Boxed_Value(data);
|
}()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Pull the reference out of the contained boxed value, which we know is the type we want
|
// Pull the reference out of the contained boxed value, which we know is the type we want
|
||||||
@ -439,9 +442,7 @@ namespace chaiscript
|
|||||||
static_assert(std::is_convertible<From, To>::value, "Types are not automatically convertible");
|
static_assert(std::is_convertible<From, To>::value, "Types are not automatically convertible");
|
||||||
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
||||||
// not even attempting to call boxed_cast so that we don't get caught in some call recursion
|
// not even attempting to call boxed_cast so that we don't get caught in some call recursion
|
||||||
auto &&from = detail::Cast_Helper<From>::cast(t_bv, nullptr);
|
return chaiscript::Boxed_Value(To(detail::Cast_Helper<From>::cast(t_bv, nullptr)));
|
||||||
To to(from);
|
|
||||||
return chaiscript::Boxed_Value(to);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return std::make_shared<detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
|
return std::make_shared<detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
|
||||||
|
@ -499,7 +499,7 @@ namespace chaiscript
|
|||||||
struct Return_Value {
|
struct Return_Value {
|
||||||
Boxed_Value retval;
|
Boxed_Value retval;
|
||||||
|
|
||||||
Return_Value(const Boxed_Value &t_return_value) : retval(t_return_value) { }
|
Return_Value(Boxed_Value t_return_value) : retval(std::move(t_return_value)) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -297,6 +297,15 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Evaluates the given string, used during eval() inside of a script
|
||||||
|
const Boxed_Value internal_eval_file(const std::string &t_filename) {
|
||||||
|
try {
|
||||||
|
return do_eval(load_file(t_filename), t_filename, true);
|
||||||
|
} catch (const exception::eval_error &t_ee) {
|
||||||
|
throw Boxed_Value(t_ee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Evaluates the given string, used during eval() inside of a script
|
/// Evaluates the given string, used during eval() inside of a script
|
||||||
@ -353,7 +362,9 @@ namespace chaiscript
|
|||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name");
|
||||||
|
|
||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type, std::ref(m_engine)), "type");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type, std::ref(m_engine)), "type");
|
||||||
m_engine.add(fun<void (const Type_Info &, const Type_Info &, const std::function<Boxed_Value (const Boxed_Value &)> &)> (
|
m_engine.add(fun<chaiscript::Type_Info (const std::string &)>([this](const std::string &t_type_name){ return this->m_engine.get_type(t_type_name, true); }), "type");
|
||||||
|
|
||||||
|
m_engine.add(fun<void(const Type_Info &, const Type_Info &, const std::function<Boxed_Value(const Boxed_Value &)> &)>(
|
||||||
[=](const Type_Info &t_from, const Type_Info &t_to, const std::function<Boxed_Value (const Boxed_Value &)> &t_func) {
|
[=](const Type_Info &t_from, const Type_Info &t_to, const std::function<Boxed_Value (const Boxed_Value &)> &t_func) {
|
||||||
m_engine.add(chaiscript::type_conversion(t_from, t_to, t_func));
|
m_engine.add(chaiscript::type_conversion(t_from, t_to, t_func));
|
||||||
}
|
}
|
||||||
@ -367,6 +378,7 @@ namespace chaiscript
|
|||||||
m_engine.add(fun(static_cast<load_mod_2>(&ChaiScript::load_module), this), "load_module");
|
m_engine.add(fun(static_cast<load_mod_2>(&ChaiScript::load_module), this), "load_module");
|
||||||
|
|
||||||
m_engine.add(fun(&ChaiScript::use, this), "use");
|
m_engine.add(fun(&ChaiScript::use, this), "use");
|
||||||
|
m_engine.add(fun(&ChaiScript::internal_eval_file, this), "eval_file");
|
||||||
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
|
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
|
||||||
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
|
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
|
||||||
|
|
||||||
@ -455,7 +467,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
union cast_union
|
union cast_union
|
||||||
{
|
{
|
||||||
void (ChaiScript::*in_ptr)(const std::string&);
|
Boxed_Value (ChaiScript::*in_ptr)(const std::string&);
|
||||||
void *out_ptr;
|
void *out_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -529,7 +541,7 @@ namespace chaiscript
|
|||||||
/// requested file.
|
/// requested file.
|
||||||
///
|
///
|
||||||
/// \param[in] t_filename Filename to load and evaluate
|
/// \param[in] t_filename Filename to load and evaluate
|
||||||
void use(const std::string &t_filename)
|
Boxed_Value use(const std::string &t_filename)
|
||||||
{
|
{
|
||||||
for (const auto &path : m_usepaths)
|
for (const auto &path : m_usepaths)
|
||||||
{
|
{
|
||||||
@ -539,15 +551,17 @@ namespace chaiscript
|
|||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
|
||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
|
||||||
|
|
||||||
|
Boxed_Value retval;
|
||||||
|
|
||||||
if (m_used_files.count(appendedpath) == 0)
|
if (m_used_files.count(appendedpath) == 0)
|
||||||
{
|
{
|
||||||
l2.unlock();
|
l2.unlock();
|
||||||
eval_file(appendedpath);
|
retval = eval_file(appendedpath);
|
||||||
l2.lock();
|
l2.lock();
|
||||||
m_used_files.insert(appendedpath);
|
m_used_files.insert(appendedpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return; // return, we loaded it, or it was already loaded
|
return retval; // return, we loaded it, or it was already loaded
|
||||||
} catch (const exception::file_not_found_error &) {
|
} catch (const exception::file_not_found_error &) {
|
||||||
// failed to load, try the next path
|
// failed to load, try the next path
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
return t_node->eval(t_ss);
|
return t_node->eval(t_ss);
|
||||||
} catch (detail::Return_Value &rv) {
|
} catch (detail::Return_Value &rv) {
|
||||||
return rv.retval;
|
return std::move(rv.retval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -517,11 +517,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return std::pair<std::string, Type_Info>();
|
return std::pair<std::string, Type_Info>();
|
||||||
} else {
|
} else {
|
||||||
try {
|
return std::pair<std::string, Type_Info>(t_node->children[0]->text, t_ss.get_type(t_node->children[0]->text, false));
|
||||||
return std::pair<std::string, Type_Info>(t_node->children[0]->text, t_ss.get_type(t_node->children[0]->text));
|
|
||||||
} catch (const std::range_error &) {
|
|
||||||
return std::pair<std::string, Type_Info>(t_node->children[0]->text, Type_Info());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,13 +703,14 @@ namespace chaiscript
|
|||||||
|
|
||||||
fpp.save_params(params);
|
fpp.save_params(params);
|
||||||
|
|
||||||
std::string fun_name;
|
std::string fun_name = [&](){
|
||||||
if ((this->children[i]->identifier == AST_Node_Type::Fun_Call) || (this->children[i]->identifier == AST_Node_Type::Array_Call)) {
|
if ((this->children[i]->identifier == AST_Node_Type::Fun_Call) || (this->children[i]->identifier == AST_Node_Type::Array_Call)) {
|
||||||
fun_name = this->children[i]->children[0]->text;
|
return this->children[i]->children[0]->text;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fun_name = this->children[i]->text;
|
return this->children[i]->text;
|
||||||
}
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chaiscript::eval::detail::Stack_Push_Pop spp(t_ss);
|
chaiscript::eval::detail::Stack_Push_Pop spp(t_ss);
|
||||||
@ -728,7 +725,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(detail::Return_Value &rv) {
|
catch(detail::Return_Value &rv) {
|
||||||
retval = rv.retval;
|
retval = std::move(rv.retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->children[i]->identifier == AST_Node_Type::Array_Call) {
|
if (this->children[i]->identifier == AST_Node_Type::Array_Call) {
|
||||||
@ -1171,14 +1168,11 @@ namespace chaiscript
|
|||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::File, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
|
AST_Node(std::move(t_ast_node_text), AST_Node_Type::File, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
|
||||||
virtual ~File_AST_Node() {}
|
virtual ~File_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
|
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
|
||||||
const size_t size = this->children.size();
|
const auto num_children = children.size();
|
||||||
for (size_t i = 0; i < size; ++i) {
|
for (size_t i = 0; i < num_children-1; ++i) {
|
||||||
Boxed_Value retval(this->children[i]->eval(t_ss));
|
children[i]->eval(t_ss);
|
||||||
if (i + 1 == size) {
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Boxed_Value();
|
return children.back()->eval(t_ss);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1486,30 +1480,19 @@ namespace chaiscript
|
|||||||
static_cast<int>(numparams), this->children.back(), param_types, l_annotation, guard)),
|
static_cast<int>(numparams), this->children.back(), param_types, l_annotation, guard)),
|
||||||
function_name);
|
function_name);
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
try {
|
|
||||||
// Do know type name (if this line fails, the catch block is called and the
|
|
||||||
// other version is called, with no Type_Info object known)
|
|
||||||
auto type = t_ss.get_type(class_name);
|
|
||||||
param_types.push_front(class_name, type);
|
|
||||||
|
|
||||||
t_ss.add(
|
// if the type is unknown, then this generates a function that looks up the type
|
||||||
std::make_shared<dispatch::detail::Dynamic_Object_Function>(class_name,
|
// at runtime. Defining the type first before this is called is better
|
||||||
std::make_shared<dispatch::Dynamic_Proxy_Function>(std::bind(chaiscript::eval::detail::eval_function,
|
auto type = t_ss.get_type(class_name, false);
|
||||||
std::ref(t_ss), this->children.back(),
|
param_types.push_front(class_name, type);
|
||||||
t_param_names, std::placeholders::_1, std::map<std::string, Boxed_Value>()), static_cast<int>(numparams), this->children.back(),
|
|
||||||
param_types, l_annotation, guard), type), function_name);
|
t_ss.add(
|
||||||
} catch (const std::range_error &) {
|
std::make_shared<dispatch::detail::Dynamic_Object_Function>(class_name,
|
||||||
param_types.push_front(class_name, Type_Info());
|
std::make_shared<dispatch::Dynamic_Proxy_Function>(std::bind(chaiscript::eval::detail::eval_function,
|
||||||
// Do not know type name
|
std::ref(t_ss), this->children.back(),
|
||||||
t_ss.add(
|
t_param_names, std::placeholders::_1, std::map<std::string, Boxed_Value>()), static_cast<int>(numparams), this->children.back(),
|
||||||
std::make_shared<dispatch::detail::Dynamic_Object_Function>(class_name,
|
param_types, l_annotation, guard), type), function_name);
|
||||||
std::make_shared<dispatch::Dynamic_Proxy_Function>(std::bind(chaiscript::eval::detail::eval_function,
|
|
||||||
std::ref(t_ss), this->children.back(),
|
|
||||||
t_param_names, std::placeholders::_1, std::map<std::string, Boxed_Value>()), static_cast<int>(numparams), this->children.back(),
|
|
||||||
param_types, l_annotation, guard)), function_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const exception::reserved_word_error &e) {
|
catch (const exception::reserved_word_error &e) {
|
||||||
|
@ -617,14 +617,16 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t size = sizeof(int) * 8;
|
const size_t size = [&](){
|
||||||
|
if (longlong_)
|
||||||
if (longlong_)
|
{
|
||||||
{
|
return sizeof(int64_t) * 8;
|
||||||
size = sizeof(int64_t) * 8;
|
} else if (long_) {
|
||||||
} else if (long_) {
|
return sizeof(long) * 8;
|
||||||
size = sizeof(long) * 8;
|
} else {
|
||||||
}
|
return sizeof(int) * 8;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
if ( (u >> (size - 1)) > 0)
|
if ( (u >> (size - 1)) > 0)
|
||||||
{
|
{
|
||||||
@ -794,17 +796,19 @@ namespace chaiscript
|
|||||||
return Id_();
|
return Id_();
|
||||||
} else {
|
} else {
|
||||||
const auto start = m_input_pos;
|
const auto start = m_input_pos;
|
||||||
const int prev_col = m_col;
|
const auto prev_col = m_col;
|
||||||
const int prev_line = m_line;
|
const auto prev_line = m_line;
|
||||||
if (Id_()) {
|
if (Id_()) {
|
||||||
std::string match;
|
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
|
||||||
if (*start == '`') {
|
[&](){
|
||||||
//Id Literal
|
if (*start == '`') {
|
||||||
match = std::string(start+1, m_input_pos-1);
|
//Id Literal
|
||||||
} else {
|
return std::string(start+1, m_input_pos-1);
|
||||||
match = std::string(start, m_input_pos);
|
} else {
|
||||||
}
|
return std::string(start, m_input_pos);
|
||||||
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
|
}
|
||||||
|
}(),
|
||||||
|
m_filename, prev_line, prev_col, m_line, m_col));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -1114,8 +1118,8 @@ namespace chaiscript
|
|||||||
const auto prev_col = m_col;
|
const auto prev_col = m_col;
|
||||||
const auto prev_line = m_line;
|
const auto prev_line = m_line;
|
||||||
if (Char_(t_c)) {
|
if (Char_(t_c)) {
|
||||||
std::string match(start, m_input_pos);
|
m_match_stack.push_back(
|
||||||
m_match_stack.push_back(std::make_shared<eval::Char_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
|
std::make_shared<eval::Char_AST_Node>(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -1159,8 +1163,8 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( t_capture && retval ) {
|
if ( t_capture && retval ) {
|
||||||
std::string match(start, m_input_pos);
|
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>(
|
||||||
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
|
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -1202,8 +1206,8 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( t_capture && retval ) {
|
if ( t_capture && retval ) {
|
||||||
std::string match(start, m_input_pos);
|
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>(
|
||||||
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
|
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
@ -1235,8 +1239,8 @@ namespace chaiscript
|
|||||||
const auto prev_col = m_col;
|
const auto prev_col = m_col;
|
||||||
const auto prev_line = m_line;
|
const auto prev_line = m_line;
|
||||||
if (Eol_()) {
|
if (Eol_()) {
|
||||||
std::string match(start, m_input_pos);
|
m_match_stack.push_back(std::make_shared<eval::Eol_AST_Node>(
|
||||||
m_match_stack.push_back(std::make_shared<eval::Eol_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
|
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1 +1,3 @@
|
|||||||
assert_equal(7, eval("3 + 4"))
|
assert_equal(7, eval("3 + 4"))
|
||||||
|
|
||||||
|
|
||||||
|
10
unittests/eval_file.chai
Normal file
10
unittests/eval_file.chai
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
try {
|
||||||
|
eval_file("use.inc")
|
||||||
|
assert(true)
|
||||||
|
|
||||||
|
//we expect this second eval_file to fail because of a function redefinition
|
||||||
|
eval_file("use.inc")
|
||||||
|
assert(false)
|
||||||
|
} catch (e) {
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
use("use.inc")
|
var newfun = use("use.inc");
|
||||||
|
|
||||||
|
|
||||||
assert_equal("hello", greet())
|
assert_equal("hello", greet())
|
||||||
|
|
||||||
@ -7,3 +8,4 @@ use("use.inc")
|
|||||||
|
|
||||||
assert_equal("hello", greet())
|
assert_equal("hello", greet())
|
||||||
|
|
||||||
|
assert_equal("world", newfun())
|
||||||
|
@ -2,3 +2,4 @@ def greet {
|
|||||||
return("hello")
|
return("hello")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun(){ "world" }
|
||||||
|
@ -1,2 +1,10 @@
|
|||||||
auto x = [1, 2, 3]
|
auto x = [1, 2, 3]
|
||||||
assert_equal(3, x[2])
|
assert_equal(3, x[2])
|
||||||
|
|
||||||
|
|
||||||
|
for (auto i = x.size()-1; i > 0; --i)
|
||||||
|
{
|
||||||
|
print("Index: " + to_string(i))
|
||||||
|
print(x[i]);
|
||||||
|
x[i] = 23;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user