Skip to content

Commit

Permalink
WIP: Add global function call logic to meta examples
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 9, 2017
1 parent 728a9f5 commit bc8aee1
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/meta/generator/parse.py
Expand Up @@ -213,6 +213,10 @@ def p_staticCall(self, p):
"staticCall : type COLON identifier LPAREN argumentList RPAREN"
p[0] = {"StaticCall": [p[1], p[3], p[5]]}

def p_globalCall(self, p):
"globalCall : identifier LPAREN argumentList RPAREN"
p[0] = {"GlobalCall": [p[1], p[3]]}

def p_indexList(self, p):
"""
indexList : int
Expand Down Expand Up @@ -262,6 +266,7 @@ def p_expr(self, p):
expr : enum
| methodCall
| staticCall
| globalCall
| elementAccess
| string
| char
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/cpp.json
Expand Up @@ -85,6 +85,7 @@
"FloatLiteral": "${number}f",
"MethodCall": "$object->$method($arguments)",
"StaticCall": "C$typeName::$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"$typeName::$value"
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/csharp.json
Expand Up @@ -70,6 +70,7 @@
"FloatLiteral": "${number}f",
"MethodCall": "$object.$method($arguments)",
"StaticCall": "$typeName.$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"$typeName.$value"
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/java.json
Expand Up @@ -75,6 +75,7 @@
"FloatLiteral": "${number}f",
"MethodCall": "$object.$method($arguments)",
"StaticCall": "$typeName.$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"$typeName.$value"
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/lua.json
Expand Up @@ -22,6 +22,7 @@
"FloatLiteral": "$number",
"MethodCall": "$object:$method($arguments)",
"StaticCall": "$typeName:$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"shogun.$value"
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/octave.json
Expand Up @@ -40,6 +40,7 @@
"FloatLiteral": "$number",
"MethodCall": "$object.$method($arguments)",
"StaticCall": "$typeName.$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"$value"
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/python.json
Expand Up @@ -50,6 +50,7 @@
"FloatLiteral": "$number",
"MethodCall": "$object.$method($arguments)",
"StaticCall": "$typeName.$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"$value"
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/r.json
Expand Up @@ -22,6 +22,7 @@
"FloatLiteral": "$number",
"MethodCall": "$object$$$method($arguments)",
"StaticCall": "$typeName$$$method($arguments)",
"GlobalCall": "$method($arguments)",
"Identifier": "$identifier",
"Enum":"\"$value\""
},
Expand Down
1 change: 1 addition & 0 deletions examples/meta/generator/targets/ruby.json
Expand Up @@ -42,6 +42,7 @@
"FloatLiteral": "$number",
"MethodCall": "$object.$method $arguments",
"StaticCall": "Shogun::$typeName.$method $arguments",
"GlobalCall": "Shogun::$method $arguments",
"Identifier": "$identifier",
"Enum":"Shogun::$value"
},
Expand Down
13 changes: 13 additions & 0 deletions examples/meta/generator/translate.py
Expand Up @@ -465,6 +465,19 @@ def translateExpr(self, expr):
method=method,
arguments=translatedArgsList)

elif key == "GlobalCall":
template = Template(self.targetDict["Expr"]["GlobalCall"])
method = expr[key][0]["Identifier"]
argsList = None
try:
argsList = expr[key][2]
except IndexError:
pass
translatedArgsList = self.translateArgumentList(argsList)

return template.substitute(method=method,
arguments=translatedArgsList)

elif key == "ElementAccess":
return self.translateElementAccess(expr[key])

Expand Down
@@ -1,8 +1,10 @@
Math:init_random(1)
get_global_io()

CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
Math:init_random(1)

#![create_features]
RealFeatures features_train(f_feats_train)
Expand Down

0 comments on commit bc8aee1

Please sign in to comment.