0.1.7 version released
[syx.git] / tests / testparser.c
blob6358de3b3724a29c8e941602da5a1221a70ec2b2
1 /*
2 Copyright (c) 2007-2008 Luca Bruno
4 This file is part of Smalltalk YX.
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
25 #include <assert.h>
26 #include <stdio.h>
27 #ifdef HAVE_SYS_TIME_H
28 #include <sys/time.h>
29 #endif
30 #include "../syx/syx.h"
32 int SYX_CDECL
33 main (int argc, char *argv[])
35 SyxLexer *lexer;
36 SyxOop method;
37 SyxParser *parser;
38 syx_uint64 start, end;
40 syx_init (0, NULL, "..");
41 syx_memory_load_image ("test.sim");
43 #define PARSE(text) lexer = syx_lexer_new (text); \
44 method = syx_method_new (); \
45 parser = syx_parser_new (lexer, method, syx_undefined_object_class); \
46 syx_parser_parse (parser, FALSE); \
47 syx_parser_free (parser, FALSE); \
48 syx_lexer_free (lexer, FALSE);
50 #define SELECTOR_EQ(expected) (!strcmp (SYX_OBJECT_SYMBOL(SYX_METHOD_SELECTOR(method)), expected))
51 #define NUM_ARGS (SYX_SMALL_INTEGER(SYX_CODE_ARGUMENTS_COUNT (method)))
52 #define NUM_TEMPS (SYX_SMALL_INTEGER(SYX_CODE_TEMPORARIES_COUNT (method)))
54 start = syx_nanotime ();
56 PARSE ("unary");
57 assert (SELECTOR_EQ ("unary"));
58 assert (NUM_ARGS == 0);
60 PARSE ("+ argument");
61 assert (SELECTOR_EQ ("+"));
62 assert (NUM_ARGS == 1);
64 PARSE ("keyword: argument message: other");
65 assert (SELECTOR_EQ ("keyword:message:"));
66 assert (NUM_ARGS == 2);
68 PARSE ("meth | a b c | a := 'asd'");
69 assert (SELECTOR_EQ ("meth"));
70 assert (NUM_ARGS == 0);
71 assert (NUM_TEMPS == 3);
73 PARSE ("meth: anObject self literal: #(a). self array: {anObject}");
75 PARSE ("meth {[self expr: (self sub method: 16r012 + 2.3e6)]}");
77 PARSE ("meth 1, 2, 3 test. (1, 2, 3) test");
79 end = syx_nanotime ();
80 printf ("Time elapsed: %ld nanoseconds\n", end - start);
82 syx_quit ();
84 return 0;