aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-01-25 22:42:11 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2013-01-25 22:42:11 +0200
commit5269885f16867330f9655316bfb64b631782342f (patch)
tree92f925fded309e33b5be8dc5765491f33d2873ef
parentd5c50ce60afc49bde361455fddc9b030ded72ffa (diff)
downloadmeson-5269885f16867330f9655316bfb64b631782342f.zip
meson-5269885f16867330f9655316bfb64b631782342f.tar.gz
meson-5269885f16867330f9655316bfb64b631782342f.tar.bz2
Added array support.
-rwxr-xr-xinterpreter.py20
-rw-r--r--nodes.py8
-rwxr-xr-xparser.py6
-rw-r--r--test cases/20 array/builder.txt6
-rw-r--r--test cases/20 array/func.c1
-rw-r--r--test cases/20 array/prog.c3
6 files changed, 42 insertions, 2 deletions
diff --git a/interpreter.py b/interpreter.py
index db570c7..e12e4f2 100755
--- a/interpreter.py
+++ b/interpreter.py
@@ -286,6 +286,8 @@ class Interpreter():
raise InvalidCode('Line %d: unknown variable "%s".' % (cur.lineno(), varname))
elif isinstance(cur, nodes.Comparison):
return self.evaluate_comparison(cur)
+ elif isinstance(cur, nodes.ArrayStatement):
+ return self.evaluate_arraystatement(cur)
else:
raise InvalidCode("Line %d: Unknown statement." % cur.lineno())
@@ -394,7 +396,17 @@ class Interpreter():
c = ConfigureFile(self.subdir, args[0], args[1])
self.build.configure_files.append(c)
+ def flatten(self, args):
+ result = []
+ for a in args:
+ if isinstance(a, list):
+ result = result + self.flatten(a)
+ else:
+ result.append(a)
+ return result
+
def build_target(self, node, args, targetclass):
+ args = self.flatten(args)
for a in args:
if not isinstance(a, str):
raise InvalidArguments('Line %d: Argument %s is not a string.' % (node.lineno(), str(a)))
@@ -421,7 +433,8 @@ class Interpreter():
if isinstance(value, InterpreterObject) or \
isinstance(value, environment.PkgConfigDependency) or\
isinstance(value, nodes.StringStatement) or\
- isinstance(value, nodes.BoolStatement):
+ isinstance(value, nodes.BoolStatement) or\
+ isinstance(value, list):
return True
return False
@@ -500,6 +513,11 @@ class Interpreter():
return val1 != val2
else:
raise InvalidCode('You broke me.')
+
+ def evaluate_arraystatement(self, cur):
+ arguments = self.reduce_arguments(cur.get_args())
+ return arguments
+
if __name__ == '__main__':
code = """project('myawesomeproject')
message('I can haz text printed out?')
diff --git a/nodes.py b/nodes.py
index da2ab6c..e141eba 100644
--- a/nodes.py
+++ b/nodes.py
@@ -99,6 +99,14 @@ class Comparison(Statement):
def get_second(self):
return self.second
+class ArrayStatement(Statement):
+ def __init__(self, args, lineno):
+ Statement.__init__(self, lineno)
+ self.args = args
+
+ def get_args(self):
+ return self.args
+
class StringStatement(Statement):
def __init__(self, value, lineno):
assert(type(value) == type(''))
diff --git a/parser.py b/parser.py
index ad2e87f..ce01011 100755
--- a/parser.py
+++ b/parser.py
@@ -119,11 +119,15 @@ def p_statement_assign(t):
'statement : expression ASSIGN statement'
t[0] = nodes.Assignment(t[1], t[3], t.lineno(1))
-def p_statement_equals(t):
+def p_statement_comparison(t):
'''statement : statement EQUALS statement
| statement NEQUALS statement'''
t[0] = nodes.Comparison(t[1], t[2], t[3], t.lineno(1))
+def p_statement_array(t):
+ '''statement : LBRACKET args RBRACKET'''
+ t[0] = nodes.ArrayStatement(t[2], t.lineno(1))
+
def p_statement_func_call(t):
'statement : expression LPAREN args RPAREN'
t[0] = nodes.FunctionCall(t[1], t[3], t.lineno(1))
diff --git a/test cases/20 array/builder.txt b/test cases/20 array/builder.txt
new file mode 100644
index 0000000..f12ca5b
--- /dev/null
+++ b/test cases/20 array/builder.txt
@@ -0,0 +1,6 @@
+project('array test', 'c')
+
+arr = ['func.c', 'prog.c']
+
+exe = executable('prog', arr)
+add_test('arr test', exe)
diff --git a/test cases/20 array/func.c b/test cases/20 array/func.c
new file mode 100644
index 0000000..7412372
--- /dev/null
+++ b/test cases/20 array/func.c
@@ -0,0 +1 @@
+int func() { return 0; }
diff --git a/test cases/20 array/prog.c b/test cases/20 array/prog.c
new file mode 100644
index 0000000..ad58a0b
--- /dev/null
+++ b/test cases/20 array/prog.c
@@ -0,0 +1,3 @@
+extern int func();
+
+int main(int argc, char **argv) { return func(); }