1.1 --- a/generator.py Mon Oct 31 21:50:41 2016 +0100
1.2 +++ b/generator.py Mon Oct 31 21:53:38 2016 +0100
1.3 @@ -886,8 +886,9 @@
1.4 print >>f_signatures, "void %s();" % function_name
1.5
1.6 # Emit the main module's function last.
1.7 + # Omit the native module.
1.8
1.9 - if name != "__main__":
1.10 + if name not in ("__main__", "native"):
1.11 print >>f_code, """\
1.12 %s();""" % function_name
1.13
2.1 --- a/lib/__builtins__/list.py Mon Oct 31 21:50:41 2016 +0100
2.2 +++ b/lib/__builtins__/list.py Mon Oct 31 21:53:38 2016 +0100
2.3 @@ -33,7 +33,7 @@
2.4
2.5 # Reserve space for a fragment reference.
2.6
2.7 - self.__data__ = native._list_init(args) # reserve space for elements
2.8 + self.__data__ = native._list_init(len(args)) # reserve space for elements
2.9
2.10 if args is not None:
2.11 self.extend(args)
3.1 --- a/lib/__builtins__/tuple.py Mon Oct 31 21:50:41 2016 +0100
3.2 +++ b/lib/__builtins__/tuple.py Mon Oct 31 21:53:38 2016 +0100
3.3 @@ -31,7 +31,7 @@
3.4
3.5 "Initialise the tuple."
3.6
3.7 - self.__data__ = native._tuple_init(args) # allocate and copy elements
3.8 + self.__data__ = native._tuple_init(args, len(args)) # allocate and copy elements
3.9
3.10 def __getitem__(self, index):
3.11
4.1 --- a/lib/native.py Mon Oct 31 21:50:41 2016 +0100
4.2 +++ b/lib/native.py Mon Oct 31 21:53:38 2016 +0100
4.3 @@ -48,14 +48,14 @@
4.4 def _str_len(self): pass
4.5 def _str_nonempty(self): pass
4.6
4.7 -def _list_init(args): pass
4.8 +def _list_init(size): pass
4.9 def _list_len(self): pass
4.10 def _list_nonempty(self): pass
4.11 def _list_element(self, index): pass
4.12
4.13 def _list_to_tuple(l): pass
4.14
4.15 -def _tuple_init(args): pass
4.16 +def _tuple_init(args, size): pass
4.17 def _tuple_len(self): pass
4.18 def _tuple_element(self, index): pass
4.19
5.1 --- a/templates/Makefile Mon Oct 31 21:50:41 2016 +0100
5.2 +++ b/templates/Makefile Mon Oct 31 21:53:38 2016 +0100
5.3 @@ -1,4 +1,4 @@
5.4 -SRC = exceptions.c main.c ops.c progops.c progtypes.c $(wildcard src/*.c)
5.5 +SRC = exceptions.c main.c native.c ops.c progops.c progtypes.c $(wildcard src/*.c)
5.6 OBJ = $(SRC:.c=.o)
5.7 CFLAGS = -I.
5.8
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/templates/native.c Mon Oct 31 21:53:38 2016 +0100
6.3 @@ -0,0 +1,363 @@
6.4 +#include <stdlib.h>
6.5 +#include "types.h"
6.6 +#include "exceptions.h"
6.7 +#include "ops.h"
6.8 +#include "progconsts.h"
6.9 +#include "progops.h"
6.10 +#include "progtypes.h"
6.11 +#include "main.h"
6.12 +
6.13 +__attr __fn_native__is(__attr __args[])
6.14 +{
6.15 + #define x (__args[1])
6.16 + #define y (__args[2])
6.17 +
6.18 + return x.value == y.value ? __builtins___boolean_True : __builtins___boolean_False;
6.19 + #undef x
6.20 + #undef y
6.21 +}
6.22 +
6.23 +__attr __fn_native__is_not(__attr __args[])
6.24 +{
6.25 + #define x (__args[1])
6.26 + #define y (__args[2])
6.27 +
6.28 + return x.value != y.value ? __builtins___boolean_True : __builtins___boolean_False;
6.29 + #undef x
6.30 + #undef y
6.31 +}
6.32 +
6.33 +__attr __fn_native__int_add(__attr __args[])
6.34 +{
6.35 + #define self (__args[1])
6.36 + #define other (__args[2])
6.37 +
6.38 + /* NOTE: To be written. */
6.39 + return __builtins___none_None;
6.40 + #undef self
6.41 + #undef other
6.42 +}
6.43 +
6.44 +__attr __fn_native__int_sub(__attr __args[])
6.45 +{
6.46 + #define self (__args[1])
6.47 + #define other (__args[2])
6.48 +
6.49 + /* NOTE: To be written. */
6.50 + return __builtins___none_None;
6.51 + #undef self
6.52 + #undef other
6.53 +}
6.54 +
6.55 +__attr __fn_native__int_mul(__attr __args[])
6.56 +{
6.57 + #define self (__args[1])
6.58 + #define other (__args[2])
6.59 +
6.60 + /* NOTE: To be written. */
6.61 + return __builtins___none_None;
6.62 + #undef self
6.63 + #undef other
6.64 +}
6.65 +
6.66 +__attr __fn_native__int_div(__attr __args[])
6.67 +{
6.68 + #define self (__args[1])
6.69 + #define other (__args[2])
6.70 +
6.71 + /* NOTE: To be written. */
6.72 + return __builtins___none_None;
6.73 + #undef self
6.74 + #undef other
6.75 +}
6.76 +
6.77 +__attr __fn_native__int_mod(__attr __args[])
6.78 +{
6.79 + #define self (__args[1])
6.80 + #define other (__args[2])
6.81 +
6.82 + /* NOTE: To be written. */
6.83 + return __builtins___none_None;
6.84 + #undef self
6.85 + #undef other
6.86 +}
6.87 +
6.88 +__attr __fn_native__int_pow(__attr __args[])
6.89 +{
6.90 + #define self (__args[1])
6.91 + #define other (__args[2])
6.92 +
6.93 + /* NOTE: To be written. */
6.94 + return __builtins___none_None;
6.95 + #undef self
6.96 + #undef other
6.97 +}
6.98 +
6.99 +__attr __fn_native__int_and(__attr __args[])
6.100 +{
6.101 + #define self (__args[1])
6.102 + #define other (__args[2])
6.103 +
6.104 + /* NOTE: To be written. */
6.105 + return __builtins___none_None;
6.106 + #undef self
6.107 + #undef other
6.108 +}
6.109 +
6.110 +__attr __fn_native__int_or(__attr __args[])
6.111 +{
6.112 + #define self (__args[1])
6.113 + #define other (__args[2])
6.114 +
6.115 + /* NOTE: To be written. */
6.116 + return __builtins___none_None;
6.117 + #undef self
6.118 + #undef other
6.119 +}
6.120 +
6.121 +__attr __fn_native__int_xor(__attr __args[])
6.122 +{
6.123 + #define self (__args[1])
6.124 + #define other (__args[2])
6.125 +
6.126 + /* NOTE: To be written. */
6.127 + return __builtins___none_None;
6.128 + #undef self
6.129 + #undef other
6.130 +}
6.131 +
6.132 +__attr __fn_native__int_rsub(__attr __args[])
6.133 +{
6.134 + #define self (__args[1])
6.135 + #define other (__args[2])
6.136 +
6.137 + /* NOTE: To be written. */
6.138 + return __builtins___none_None;
6.139 + #undef self
6.140 + #undef other
6.141 +}
6.142 +
6.143 +__attr __fn_native__int_rdiv(__attr __args[])
6.144 +{
6.145 + #define self (__args[1])
6.146 + #define other (__args[2])
6.147 +
6.148 + /* NOTE: To be written. */
6.149 + return __builtins___none_None;
6.150 + #undef self
6.151 + #undef other
6.152 +}
6.153 +
6.154 +__attr __fn_native__int_rmod(__attr __args[])
6.155 +{
6.156 + #define self (__args[1])
6.157 + #define other (__args[2])
6.158 +
6.159 + /* NOTE: To be written. */
6.160 + return __builtins___none_None;
6.161 + #undef self
6.162 + #undef other
6.163 +}
6.164 +
6.165 +__attr __fn_native__int_rpow(__attr __args[])
6.166 +{
6.167 + #define self (__args[1])
6.168 + #define other (__args[2])
6.169 +
6.170 + /* NOTE: To be written. */
6.171 + return __builtins___none_None;
6.172 + #undef self
6.173 + #undef other
6.174 +}
6.175 +
6.176 +__attr __fn_native__int_lt(__attr __args[])
6.177 +{
6.178 + #define self (__args[1])
6.179 + #define other (__args[2])
6.180 +
6.181 + /* NOTE: To be written. */
6.182 + return __builtins___none_None;
6.183 + #undef self
6.184 + #undef other
6.185 +}
6.186 +
6.187 +__attr __fn_native__int_gt(__attr __args[])
6.188 +{
6.189 + #define self (__args[1])
6.190 + #define other (__args[2])
6.191 +
6.192 + /* NOTE: To be written. */
6.193 + return __builtins___none_None;
6.194 + #undef self
6.195 + #undef other
6.196 +}
6.197 +
6.198 +__attr __fn_native__int_eq(__attr __args[])
6.199 +{
6.200 + #define self (__args[1])
6.201 + #define other (__args[2])
6.202 +
6.203 + /* NOTE: To be written. */
6.204 + return __builtins___none_None;
6.205 + #undef self
6.206 + #undef other
6.207 +}
6.208 +
6.209 +__attr __fn_native__str_add(__attr __args[])
6.210 +{
6.211 + #define self (__args[1])
6.212 + #define other (__args[2])
6.213 +
6.214 + /* NOTE: To be written. */
6.215 + return __builtins___none_None;
6.216 + #undef self
6.217 + #undef other
6.218 +}
6.219 +
6.220 +__attr __fn_native__str_lt(__attr __args[])
6.221 +{
6.222 + #define self (__args[1])
6.223 + #define other (__args[2])
6.224 +
6.225 + /* NOTE: To be written. */
6.226 + return __builtins___none_None;
6.227 + #undef self
6.228 + #undef other
6.229 +}
6.230 +
6.231 +__attr __fn_native__str_gt(__attr __args[])
6.232 +{
6.233 + #define self (__args[1])
6.234 + #define other (__args[2])
6.235 +
6.236 + /* NOTE: To be written. */
6.237 + return __builtins___none_None;
6.238 + #undef self
6.239 + #undef other
6.240 +}
6.241 +
6.242 +__attr __fn_native__str_eq(__attr __args[])
6.243 +{
6.244 + #define self (__args[1])
6.245 + #define other (__args[2])
6.246 +
6.247 + /* NOTE: To be written. */
6.248 + return __builtins___none_None;
6.249 + #undef self
6.250 + #undef other
6.251 +}
6.252 +
6.253 +__attr __fn_native__str_len(__attr __args[])
6.254 +{
6.255 + #define self (__args[1])
6.256 +
6.257 + /* NOTE: To be written. */
6.258 + return __builtins___none_None;
6.259 + #undef self
6.260 +}
6.261 +
6.262 +__attr __fn_native__str_nonempty(__attr __args[])
6.263 +{
6.264 + #define self (__args[1])
6.265 +
6.266 + /* NOTE: To be written. */
6.267 + return __builtins___none_None;
6.268 + #undef self
6.269 +}
6.270 +
6.271 +__attr __fn_native__list_init(__attr __args[])
6.272 +{
6.273 + #define size (__args[1])
6.274 + /* size.__data__ interpreted as int */
6.275 + __fragment *data = calloc(__load_via_object(size.value, __pos___data__).intvalue, sizeof(__attr));
6.276 + __attr attr = {0, .data=data};
6.277 +
6.278 + return attr;
6.279 + #undef size
6.280 +}
6.281 +
6.282 +__attr __fn_native__list_len(__attr __args[])
6.283 +{
6.284 + #define self (__args[1])
6.285 +
6.286 + /* NOTE: To be written. */
6.287 + return __builtins___none_None;
6.288 + #undef self
6.289 +}
6.290 +
6.291 +__attr __fn_native__list_nonempty(__attr __args[])
6.292 +{
6.293 + #define self (__args[1])
6.294 +
6.295 + /* NOTE: To be written. */
6.296 + return __builtins___none_None;
6.297 + #undef self
6.298 +}
6.299 +
6.300 +__attr __fn_native__list_element(__attr __args[])
6.301 +{
6.302 + #define self (__args[1])
6.303 + #define index (__args[2])
6.304 +
6.305 + /* NOTE: To be written. */
6.306 + return __builtins___none_None;
6.307 + #undef self
6.308 + #undef index
6.309 +}
6.310 +
6.311 +__attr __fn_native__list_to_tuple(__attr __args[])
6.312 +{
6.313 + #define l (__args[1])
6.314 +
6.315 + /* NOTE: To be written. */
6.316 + return __builtins___none_None;
6.317 + #undef l
6.318 +}
6.319 +
6.320 +__attr __fn_native__tuple_init(__attr __args[])
6.321 +{
6.322 + #define size (__args[1])
6.323 + /* size.__data__ interpreted as int */
6.324 + __fragment *data = calloc(__load_via_object(size.value, __pos___data__).intvalue, sizeof(__attr));
6.325 + __attr attr = {0, .data=data};
6.326 +
6.327 + return attr;
6.328 + #undef size
6.329 +}
6.330 +
6.331 +__attr __fn_native__tuple_len(__attr __args[])
6.332 +{
6.333 + #define self (__args[1])
6.334 +
6.335 + /* NOTE: To be written. */
6.336 + return __builtins___none_None;
6.337 + #undef self
6.338 +}
6.339 +
6.340 +__attr __fn_native__tuple_element(__attr __args[])
6.341 +{
6.342 + #define self (__args[1])
6.343 + #define index (__args[2])
6.344 +
6.345 + /* NOTE: To be written. */
6.346 + return __builtins___none_None;
6.347 + #undef self
6.348 + #undef index
6.349 +}
6.350 +
6.351 +__attr __fn_native__isinstance(__attr __args[])
6.352 +{
6.353 + #define obj (__args[1])
6.354 + #define cls (__args[2])
6.355 +
6.356 + if (__HASATTR(obj.value, __TYPEPOS(cls.value), __TYPECODE(cls.value)))
6.357 + return obj;
6.358 + else
6.359 + return __builtins___none_None;
6.360 + #undef obj
6.361 + #undef cls
6.362 +}
6.363 +
6.364 +void __main_native()
6.365 +{
6.366 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/templates/native.h Mon Oct 31 21:53:38 2016 +0100
7.3 @@ -0,0 +1,39 @@
7.4 +#ifndef __NATIVE_H__
7.5 +#define __NATIVE_H__
7.6 +
7.7 +__attr __fn_native__is(__attr __args[]);
7.8 +__attr __fn_native__is_not(__attr __args[]);
7.9 +__attr __fn_native__int_add(__attr __args[]);
7.10 +__attr __fn_native__int_sub(__attr __args[]);
7.11 +__attr __fn_native__int_mul(__attr __args[]);
7.12 +__attr __fn_native__int_div(__attr __args[]);
7.13 +__attr __fn_native__int_mod(__attr __args[]);
7.14 +__attr __fn_native__int_pow(__attr __args[]);
7.15 +__attr __fn_native__int_and(__attr __args[]);
7.16 +__attr __fn_native__int_or(__attr __args[]);
7.17 +__attr __fn_native__int_xor(__attr __args[]);
7.18 +__attr __fn_native__int_rsub(__attr __args[]);
7.19 +__attr __fn_native__int_rdiv(__attr __args[]);
7.20 +__attr __fn_native__int_rmod(__attr __args[]);
7.21 +__attr __fn_native__int_rpow(__attr __args[]);
7.22 +__attr __fn_native__int_lt(__attr __args[]);
7.23 +__attr __fn_native__int_gt(__attr __args[]);
7.24 +__attr __fn_native__int_eq(__attr __args[]);
7.25 +__attr __fn_native__str_add(__attr __args[]);
7.26 +__attr __fn_native__str_lt(__attr __args[]);
7.27 +__attr __fn_native__str_gt(__attr __args[]);
7.28 +__attr __fn_native__str_eq(__attr __args[]);
7.29 +__attr __fn_native__str_len(__attr __args[]);
7.30 +__attr __fn_native__str_nonempty(__attr __args[]);
7.31 +__attr __fn_native__list_init(__attr __args[]);
7.32 +__attr __fn_native__list_len(__attr __args[]);
7.33 +__attr __fn_native__list_nonempty(__attr __args[]);
7.34 +__attr __fn_native__list_element(__attr __args[]);
7.35 +__attr __fn_native__list_to_tuple(__attr __args[]);
7.36 +__attr __fn_native__tuple_init(__attr __args[]);
7.37 +__attr __fn_native__tuple_len(__attr __args[]);
7.38 +__attr __fn_native__tuple_element(__attr __args[]);
7.39 +__attr __fn_native__isinstance(__attr __args[]);
7.40 +void __main_native();
7.41 +
7.42 +#endif /* __NATIVE_H__ */
8.1 --- a/translator.py Mon Oct 31 21:50:41 2016 +0100
8.2 +++ b/translator.py Mon Oct 31 21:53:38 2016 +0100
8.3 @@ -45,8 +45,9 @@
8.4 self.check_output()
8.5
8.6 for module in self.importer.modules.values():
8.7 - tm = TranslatedModule(module.name, self.importer, self.deducer, self.optimiser)
8.8 - tm.translate(module.filename, join(output, "%s.c" % module.name))
8.9 + if module.name != "native":
8.10 + tm = TranslatedModule(module.name, self.importer, self.deducer, self.optimiser)
8.11 + tm.translate(module.filename, join(output, "%s.c" % module.name))
8.12
8.13 # Classes representing intermediate translation results.
8.14