Vczh Library ++ 3.0-mscorlib. dll

Source: Internet
Author: User
Tags mscorlib

Because the managed language ManagedX of Vczh Library ++ 3.0 is designed to compile to the local language NativeX, it is essential to copy a mscorlib. dll. However, my mscorlib. dll only contains the minimum code. For example, a string, an array, for example, the function type and so on. These classes cannot be implemented by the hosting language itself (C ++ is the only language in which everything can be compensated by class libraries ). Therefore, it took several days to use ManagedX to implement its declaration and some code, and then some external functions. Eventually, mscorlib written by ManagedX will be compiled into NativeX, while several external functions will naturally be written by NativeX. For example, how to compare the size of two strings is obviously different for the hosting language.

So it is quite troublesome here, and some Engineering troubles need to be done. First, several ManagedX files are compiled into a separate NativeX file, and then the generated NativeX file is compiled into an assembly together with another handwritten NativeX file. This is similar to compiling C # into C.

The first version of ManagedX also requires a compromise. For example, the dimension of the array cannot exceed 10. The dimension here refers to a [,], instead of a [] [] [] [] [] [] [] [] [] []. For example, the number of parameters of the function type cannot exceed 10 (but the number of parameters of the function can be, here only for the function type ). The main reason is that, in order for ManagedX to be compiled into NativeX, it is impossible to dynamically generate a class during running (except for the template, because my NativeX = C + template ). Therefore, arrays of one dimension, two dimensions, or even ten dimensions are of course 10 different classes (you can use an array of two-dimensional ten dimensions to simulate an array of twelve dimensions, ). However, to prevent me from repeating a batch of similar classes for 10 times, I used Fpmacro developed more than a year ago. Fpmacro is an extension similar to the C language macro with different syntaxes, but it does not have all the traps of the C language macro. In fact, a function is actually a language with something similar to lambda expressions, each function is designed as a function that returns a string. The parameter can be an array, string, or another function. In addition, the syntax has been optimized, so there is nothing redundant. Here is an example, for example, to declare the Fpmacro Code of 10 Arrays: 1 $ include: Common. fpm
2
3 $ define $ DIMENTION_FIELD_NAME ($ element) dimSize $ element
4 $ define $ DIMENTION_PARAMETER_NAME ($ element) _ $ element
5 $ define $ DIMENTION_PARAMETER_DEFINITION ($ element) int $ DIMENTION_PARAMETER_NAME ($ element)
6 $ define $ DIMENTION_PARAMETER_NAME_IN_ARRAY ($ element) indices [$ element]
7
8 $ define $ DIMENTION_FIELD ($ element) $ begin
9 private int $ DIMENTION_FIELD_NAME ($ element );
10 $ ()
11 $ end
12
13 $ define $ DIMENTION_FIELD_SETTER ($ element) $ begin
14 $ DIMENTION_FIELD_NAME ($ element) = $ DIMENTION_PARAMETER_NAME ($ element );
15 $ ()
16 $ end
17
18 $ define $ DIMENTION_SIZE_CASE ($ element) $ begin
19 case $ element:
20 return $ DIMENTION_FIELD_NAME ($ element );
21 $ ()
22 $ end
23
24 $ define $ DIMENTION_CHECK ($ element) $ begin
25 if ($ DIMENTION_PARAMETER_NAME ($ element) <0 | $ DIMENTION_PARAMETER_NAME ($ element) >=$ DIMENTION_FIELD_NAME ($ element ))
26 throw new ArgumentOutOfRangeException ($ (") $ DIMENTION_PARAMETER_NAME ($ element) $ ("));
27 $ ()
28 $ end
29
30 $ define $ DIMENTION_SUMMERS ($ elements) $ begin
31 $ define $ DIMENTION_SUMMER ($ index) $ begin
32 sum * = $ DIMENTION_FIELD_NAME ($ sub ($ elements, 1), $ index ));
33 index + = sum * $ DIMENTION_PARAMETER_NAME ($ sub ($ elements, 2), $ index ));
34 $ ()
35 $ end
36 $ loop ($ sub ($ elements, 1), 0, $ DIMENTION_SUMMER)
37 $ end
38
39 $ define $ ARRAY_IMPLEMENTATION ($ elements) $ begin
40 $ ()
41 generic <inout T>
42 public sealed class Array $ elements: Array
43 {
44 $ ()
45 public constructor ($ loopsep ($ elements, 0, $ DIMENTION_PARAMETER_DEFINITION, $ (,), Array <T> src = null, bool copy = true)
46 {
47 $ loop ($ elements, 0, $ DIMENTION_FIELD_SETTER)
48 Initialize (this. Length, src, copy );
49}
50 $ ()
51 $ loop ($ elements, 0, $ DIMENTION_FIELD)
52 public override int GetDimCount ()
53 {
54 return $ elements;
55}
56 $ ()
57 public override int GetDimSize (int dim)
58 {
59 switch (dim)
60 {
61 $ loop ($ elements, 0, $ DIMENTION_SIZE_CASE)
62 default:
63 throw new ArgumentOutOfRangeException ("dim ");
64}
65}
66 $ ()
67 public override int Length
68 {
69 get
70 {
71 return $ loopsep ($ elements, 0, $ DIMENTION_FIELD_NAME, $ (*));
72}
73}
74 $ ()
75 public override int GetStartIndexFromIndices (params int [] indices)
76 {
77 if (indices. Length! = $ Elements)
78 {
79 throw new ArgumentOutOfRangeException ("indices ");
80}
81 return GetStartIndex [$ loopsep ($ elements, 0, $ DIMENTION_PARAMETER_NAME_IN_ARRAY, $ (,)];
82}
83 $ ()
84 public int GetStartIndex ($ loopsep ($ elements, 0, $ DIMENTION_PARAMETER_DEFINITION, $ (,)))
85 {
86 $ loop ($ elements, 0, $ DIMENTION_CHECK)
87 int index = $ DIMENTION_PARAMETER_NAME ($ sub ($ elements, 1 ));
88 int sum = 1;
89 & nb

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.