Beispiel #1
0
        public static string GetClassTagName(string class_name)
        {
            string tag    = "_" + class_name + "_" + "tag";
            var    c_syms = new ConstantSymbol();

            if (class_name == c_syms.Bool.str_ || class_name == c_syms.Int.str_ || class_name == c_syms.Str.str_)
            {
                tag = tag.ToLower();
                //std::transform(tag.begin(), tag.end(), tag.begin(), ::tolower);
            }
            return(tag);
        }
Beispiel #2
0
        public void InitBasicClasses()
        {
            var constants  = new ConstantSymbol();
            var arg        = constants.arg;
            var arg2       = constants.arg2;
            var Bool       = constants.Bool;
            var concat     = constants.concat;
            var cool_abort = constants.cool_abort;
            var copy       = constants.copy;
            var Int        = constants.Int;
            var in_int     = constants.in_int;
            var in_string  = constants.in_string;
            var IO         = constants.IO;
            var length     = constants.length;
            var Main       = constants.Main;
            var main_meth  = constants.main_meth;
            var No_class   = constants.No_class;
            var No_type    = constants.No_type;
            var Object     = constants.Object;
            var out_int    = constants.out_int;
            var out_string = constants.out_string;
            var prim_slot  = constants.prim_slot;
            var self       = constants.self;
            var SELF_TYPE  = constants.SELF_TYPE;
            var Str        = constants.Str;
            var str_field  = constants.str_field;
            var substr     = constants.substr;
            var type_name  = constants.type_name;
            var val        = constants.val;
            var basic_fn   = constants.basic_fn;

            #region installing baisics into ast
            Class Object_class =
                CGUtils.CreateClass(Object,
                                    No_class,
                                    basic_fn,
                                    CGUtils.AppendFeature(
                                        CGUtils.AppendFeature(
                                            CGUtils.CreateSingleFeatures(
                                                CGUtils.CreateMethod(cool_abort, Object,
                                                                     CGUtils.CreateNilFormals(), CGUtils.CreateNoExpr())),
                                            CGUtils.CreateMethod(type_name, Str,
                                                                 CGUtils.CreateNilFormals(), CGUtils.CreateNoExpr())
                                            ),
                                        CGUtils.CreateMethod(copy, SELF_TYPE,
                                                             CGUtils.CreateNilFormals(), CGUtils.CreateNoExpr())
                                        )
                                    );


            Class IO_class =
                CGUtils.CreateClass(IO,
                                    Object,
                                    basic_fn,
                                    CGUtils.AppendFeature(
                                        CGUtils.AppendFeature(
                                            CGUtils.AppendFeature(
                                                CGUtils.CreateSingleFeatures(
                                                    CGUtils.CreateMethod(out_string, SELF_TYPE,
                                                                         CGUtils.CreateSingleFormals(CGUtils.CreateFormal(arg, Str)),
                                                                         CGUtils.CreateNoExpr())
                                                    ),
                                                CGUtils.CreateMethod(out_int, SELF_TYPE,
                                                                     CGUtils.CreateSingleFormals(CGUtils.CreateFormal(arg, Int)),
                                                                     CGUtils.CreateNoExpr())

                                                ),
                                            CGUtils.CreateMethod(in_string, Str, CGUtils.CreateNilFormals(),
                                                                 CGUtils.CreateNoExpr())
                                            ),
                                        CGUtils.CreateMethod(in_int, Int, CGUtils.CreateNilFormals(), CGUtils.CreateNoExpr())
                                        )
                                    );

            Class Int_class =
                CGUtils.CreateClass(Int,
                                    Object,
                                    basic_fn,
                                    CGUtils.CreateSingleFeatures(CGUtils.CreateAttr(val, prim_slot, CGUtils.CreateNoExpr()))
                                    );

            Class Bool_class =
                CGUtils.CreateClass(Bool,
                                    Object,
                                    basic_fn,
                                    CGUtils.CreateSingleFeatures(
                                        CGUtils.CreateAttr(val, prim_slot, CGUtils.CreateNoExpr())
                                        )
                                    );

            Class Str_class =
                CGUtils.CreateClass(
                    Str,
                    Object,
                    basic_fn,
                    CGUtils.AppendFeature(
                        CGUtils.AppendFeature(
                            CGUtils.AppendFeature(
                                CGUtils.AppendFeature(
                                    CGUtils.CreateSingleFeatures(CGUtils.CreateAttr(val, Int, CGUtils.CreateNoExpr())),
                                    CGUtils.CreateAttr(str_field, prim_slot, CGUtils.CreateNoExpr())),
                                CGUtils.CreateMethod(length, Int, CGUtils.CreateNilFormals(), CGUtils.CreateNoExpr())
                                ),
                            CGUtils.CreateMethod(concat,
                                                 Str,
                                                 CGUtils.CreateSingleFormals(CGUtils.CreateFormal(arg, Str)),
                                                 CGUtils.CreateNoExpr())
                            ),
                        CGUtils.CreateMethod(
                            substr,
                            Str,
                            CGUtils.AppendFormal(CGUtils.CreateSingleFormals(CGUtils.CreateFormal(arg, Int)),
                                                 CGUtils.CreateFormal(arg2, Int)),
                            CGUtils.CreateNoExpr())
                        )
                    );
            #endregion

            basic_classes_ = CGUtils.CreateSingleClasses(Object_class);
            basic_classes_ = CGUtils.AppendClass(basic_classes_, IO_class);
            basic_classes_ = CGUtils.AppendClass(basic_classes_, Int_class);
            basic_classes_ = CGUtils.AppendClass(basic_classes_, Bool_class);
            basic_classes_ = CGUtils.AppendClass(basic_classes_, Str_class);

            SymbolUtils.StrTable.AddString(constants.Object.str_);
            SymbolUtils.StrTable.AddString(constants.IO.str_);
            SymbolUtils.StrTable.AddString(constants.Int.str_);
            SymbolUtils.StrTable.AddString(constants.Bool.str_);
            SymbolUtils.StrTable.AddString(constants.Str.str_);
        }