Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the assumption of programming-free binding generative language system of front-end metalangsys back-end uniform backend in terracling

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces how to analyze the terracling front-end metalangsys back-end uniform backend programming-free binding generative language system, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Js, a language that can be used for full-stack development of web stack, has even evolved to H5 and mobile,desktop native, which is often called the representative of some kind of integrated web,mobile,native language, and the way it uses functions to simulate programs and OO is also a manifestation of some kind of "grammatical" integration, which is the maximization of the internal level of the language.

Later, we jumped out of the monolingual and mono-ecological consideration and focused on some integrated language systems, and made new discoveries. For example, in "releasing qtcling", we mentioned cling and rootsys, which is a branch of llvm based that integrates cpp,c scripting and is free of binding, and is really integrated in the whole C system. In "releasing monosys", we mentioned unified back-end languages such as java,net, which, as the name suggests, has the characteristics of an integrated language backend. There are also some unified backends implemented using translator compiler rather than independent compilers that are often language-specific, such as vala, as well as synthesis types such as zephir,rust, dynamic and static combination belt let, and so on, all of which have a tendency to greatly integrate and transform beyond their inherent fields.

However, after careful analysis, we will find that the maximization (generalization) of any language system is actually the process in which they attempt to include all kinds of DSL. It is mentioned in bcxszy part2 that the invention of various DSL is one of the software patterns. Since ancient times, DSL has proposed various intra-language mechanisms or various scripting languages and new language systems, that is, they are all subsets of DSL technology.

And they all have limitations.

And QT is too simple for CPP, and its use of pme and type reflection extension type system also implies that other extensions to it are secondary's business. Although js has a good degree of integration in syntax and problem domains, it is ultimately built on the single standard and single language implementation of ECMA. Qtcling inevitably does not include non-C series, and direct rootsys is also single ecological. Its binding library has a great ability to form a new cling language system, because it is a pyroot from the library before binding, and llvm also has the characteristics of free back end, but the front end of cling/rootsys is only clang, and monosys is not a virtual machine-free. C # has an intra-language compilation service but lacks the features of a real language development generator that supports this language. Converters tend to be fixed and hybrid dynamic and static typed languages often fail to extend to other front-end and back-end combinations.

All in all, what they have in common is that the span from a more reasonable language structure and usage is always too large, or the defect is too obvious, and this idea of "more reasonable and more integrated" is what I hope to get next. I hope to have a kind of: the existing facts that do not destroy the multi-ecology of the existing factual language can be skillfully integrated. There is also an interface that can be extended at this primitive level in the traditional way of inventing a language (while common mechanisms like providing type modification in a language, such as py decorators) can be extended at this primitive level and can be done within the language to form an one-to-many, preferably one-host, multi-homing solution (hosts can be dynamically plugged and extended relative to the host).

And all of these languages, all of these features, cannot support true metaprogramming and automatic code generation in a conventional way. If the shortcomings of a single language are always so obvious, then maybe a mixed language of at least two languages is another way out (of course, it should also support as many extensions as possible to support the reasonable, minimum correction-free integration I mentioned above).

From 1ddlang to anylang, from single lang to DSL mixed langsys

To sum up: a more scientific assumption requires that we need an integrated language system that is truly integrated into supporting the creation of user DSL. Most scientifically, we need to keep the existing different runtimes and then make a truly available unified backend, such as colinux as xaas, here is onelang as langsys.

At least if it is something unified back-end or front-end, users can generate new languages in an elegant and natural way. As a pluggable part of this new language system, new languages really allow users to use these two meta-languages (as host) to integrate the languages they need as guest language as language comopent or lib plugin.

For example, our goal is at least: to be able to develop arbitrary zend php and other logic in this language, so that a language, with or without modification backend. Can glue together to work, for example, I can use cling to write php wp program.

The biggest integration solutions so far, such as monosys and llvm based langsys like cling/rootsys, are the things closest to my idea, but they are often strong enough not to have too many projects around them, and finally I found terra:

It is the unified back end of these languages.

Its three analogies: using function to invent DSL, class js to create OO system with function, codegen to generate code, and CPP-like template. Vala, wait.

In my enhanced terra idea, I use cling as a unified metalang to replace lua, responsible for generating a variety of specific front-end languages. It can be made that lua is a host,terra is a complex of multiple languages or a language in a way that guest,guest can be extended. There is an one-master-one-guest two-door system, which can be used for metaprogramming and guest for compatibility with the backend, just like colinux. The following details are given:

Terra:a multiple stage langsys that can micic js,cpp,etc..

Basic description of terra:

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language: We use LLVM to compile Terra code since it can JIT-compile its intermediate representation directly to machine code. To implement backwards compatibility with C, we use Clang,a C front-end that is part of LLVM. Clang is used to compile the C code into LLVM and generate Terra function wrappers that will invoke the C code when called.

The most basic research is that lua acts as the front end of the converter, translates the code into terra representation, and then runs terra. Because the terra is llvm based and the converter is lua based, the front and rear ends have a main conversion and a main run, which has both writing efficiency and runtime efficiency.

Understanding path 1): a dynamic language for controlling the LLVM

The whole langys, it uses the head of the dynamic language and the tail of the local language to form a mixed front and back end (at first glance it is more like something like c preprocesser+vala translator). In fact, things like llvm with jit, intermediate code and native code gen can be mixed with front and rear components, which can avoid VM and achieve the efficiency of local code. Achieve the effect of abi linking with cling and C module (Terra code is JIT compiled to machine code when the function is first called). Terra is actually another kind of cling+clang.

Understanding path 2): a dynamic language for controlling the LLVM-> using a dynamic language to control code generation of static one

Multiple stage programming, which is the technology of code generate in metaprogramming. It is very popular in some fields of numerical programming. Its essence:

Multi-stage programming (MSP) is a variety of metaprogramming in which compilation is divided into a series of intermediate phases, allowing typesafe run-time code generation.Statically defined types are used to verify that dynamically constructed types are valid and do not violate the type system.

A multi-stage program is one that involves the generation, compilation, and execution of code, all inside the same process

The The staged programming of Terra from Lua, note is the staging from terra to lua. In terms of the incompatibility of the two, distinguish between the two languages, terra core and full terra langsys, and a specific code written in that language is terra-lua code.

Because in fact, lua and C are two completely different languages, their interportable is only their external attribute, and internally they are not communicable, so how are the two connected? What is the nature and process of technology? These two languages have a common lexical scope, so it ensures the seamless interaction (interpreter) of the two languages, and tries to make them look like a language (the variable scope processing part of the). In addition, the different parts of the other two languages are still what the two independent languages should have (c/terra and lua have a very wide range of integration interopable). Basically you use lua programming (lua), and the part that involves control terra to codegen is c (terra) / lua.

Understanding path 3): a dynamic language for controlling the LLVM-> using a dynamic language to control code generation of static one-> a low-level system programming language embedded in and meta-programmed by Lua

The essence of the unified terra langsys is that they are integrated and unified at the level of metaprogramming.

An important application for MSP is the implementation of domain-specific languages,languages can be implemented in a variety of ways,for examples,a language can be implemented by an interpreter or by a compiler.

We think that having DSLs share the same lexical environment during compilation will open up more opportunities for interoperability between different languages

So how does terra use lua+c as a meta to generate any other medium-to-high-level language support? This is because lua's data structure precisely supports the metaprogramming features needed to recreate a language, such as function support for first-level types, table support for AST representation, and so on. I mentioned earlier that js is a language that can write programs directly on AST.

Js:

In the previous introduction of js, we talked about functional language is the AST language, because it can write programs directly on the syntax tree, now terra, further clear it, combined with type reflection to achieve the limit. It can use function derivation to generate various procedures and OO, and simulate C/cpp from lua.

Cpp:

In fact, it is also some kind of preprocessor maximization, such as for CPP. You can use lua itself to simulate better and more uniform preprocessing, much like when writing a compiler in C, which is dynamic. Use this language to write extensions within an implementation of this language and load them as libraries. In terra, of course, it's lua code.

For example, it is used to implement a type system like CPP.

Objectoriented frameworks usually offer a type introspection or reflection capability to discover information about types at run-time. Metaphor allows this reflection system to be incorporated into the language's staging constructs, thus allowing the generation of code based on the structure of types-a common application for code generation in these environments.

This is why only c+lua is needed, not c/cpp+lua, because CPP as a whole can be extended. This is better than building clang++ directly on llvm, because we can use c+lua 's terra to build a more scientific terra version of cpp.

Terracling, the architecture is more scientific, the front end is transformed into CLING based, and the back end maintains the terra of llvm based.

So can you transform terra into cling based? That is, replace lua+terra with cling+c, because C supports the function pointer to be of first-level type. The advantages of this are: directly using C series as the metalang control language, generating extended cpp,py,php, and so on.

With the addition of the metaprogramming feature of cling+llvm, its front and rear ends can be generated automatically without extra programming work. For example, the parse of the front end of the language can be generated by binding c dll, and then connected to the back end, the library can also be integrated in C module, and it can be implemented directly in zend php or php on llvm, such as roadsend php and so on.

Meaning:

Cling, as a scripting language, is very good at automating the generation process of C code, and the extended CPP belongs to C series, so metaprogramming can disperse the characteristics of one language in CPP style (such as making C++ template a simple language feature Terra's type reflection allows the creation of class-systems as libraries.), which can prevent QT from aggregating PME support into another QTcpp. CPP preprocessing can also be imported in a more scientific architecture, and can be introduced through programming and in-program methods, rather than prefabricated to serve libraries such as reflection, or as a basic component such as a compiler front end, rather than hybrid into a composite language like CPP.

You can directly binding existing programming languages, whether it is llvm based or llvm non based, as long as it exists in c dll.

Also, in fact, lua and openresty,gbc are closely linked to the things I mentioned earlier. The whole lua+c reveals the fact that almost two must-learn languages. Terra is very much like the architecture of linux and can produce various encapsulated variants / new language systems like linux. And easy to customize / easy to customize naturally.

This is the idea of how to analyze the front-end metalangsys back-end uniform backend programming-free binding generative language system in terracling. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report