How Do REPL Interpreters For Compiled Languages Work? [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I cant even begin to understand how they work, its a very broad question i guess. How is it possible that one could take a language such as C# which is compiled to IL for the CLR, then further JIT compiled into machine code at run time, and write an Interpreter or REPL for it as implemented in the mono project. How did they get that right?

What is the issue? Machine code is just some data (laying in virtual memory pages which are executable). You can produce that data, then, since it is also code, run it.
You can produce machine code in memory in various ways. For example, you could use LLVM or libjit or many other libraries (or even make your own).
Some implementations of some langauges (I was thinking of the SBCL implementation of Common Lisp) are even able to translate to machine code every line you are interactively typing. And this is not new, some 1957 computers did it (e.g. the French CAB500 for PAF).
You can even generate some source code (e.g. in C), fork a compilation process, then dynamically load that code, e.g. with dlopen(3). Current compilers and processors are fast enough to make that compatible with delays for user-friendly interaction. My MELT domain specific language (to extend GCC) does that successfully.
AS commented by millimoose, Mono is free software, so you can study its code.
The equivalence of code and data is a fundamental property of computers. Likewise the equivalence of numbers and demonstrations in a fundamental insight of Gödel and Turing (and when you hear your favorite MP3 music, you use that too).

Related

Running native Delphi code in dot net environment with c sharp [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a Delphi program consisting of mostly Visual Interface(Buttons, TextBoxes etc.) and a little bit business logic.
The business logic is mostly included in Pl-Sql of Oracle Database running by Delphi.
I want to carry the project in Delphi to C Sharp but i want to do this part by part.
What i think is to create a C Sharp project in Visual Studio and to run it with Delphi code(including Visual Interfaces) and part by part replace the code and the Visual Interface in Delphi with C Sharp.
Is it possible?
Mixing Delphi and C# GUI in the same application is possible, but hard to achieve. You'll need to set up a whole infrastructure to organise interop between the two languages. You'll end up creating a huge amount of interop code that you will subsequently abandon. Even worse, the interop code will need to be two way. You'll sometimes have C# visual code talking to Delphi non-visual. And vice-versa. The idea of converting the code module by module sounds good, but I predict it will entail vast amounts of interop scaffolding.
It would be easier to slice it along the visual/non-visual divide, but that's not what you are proposing. So frankly I think your current plan is far from optimal. I would not entertain it. I think a clean port is the best option.
Remobjects Hydra seems to be exactly what you are looking for.

Reflecting a way for decompiling? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
If so, how can i protect my code from being decompiled?
Or from being reflected? If actually the two are very different from each other.
Tools like Dotfuscator for the .Net framework, do they help your code from being decompiled? Does that mean that i can still reflect on it and see it's contents??
You can't ever stop either. You can make it so that decompiling the program returns incomprehensible and confusing code, but it still will be valid code that results in a program that functions identically to yours. Making subtle changes will be harder, but not impossible. Doing that is called obfuscation, which is what those tools are.
Obfuscators go around doing things like changing all variable names to meaningless alphanumeric values, performing all sorts of code refactors that don't change how the code works, but just are things that do the same thing in a different way (and is somehow harder for humans to understand, but not computers). They can also add in code that doesn't do anything, just to confuse people, etc. Different obfuscators will do all sorts of different things, and they can have some differences such as, whether or not they accidentally introduce bugs, what their effect is on the size of the compiled program, and how close the compiled program is from the original source (which, granted, is somewhat subjective).
It has the same effect on reflection, although reflecting and decompiling are completely different.
First, let's go over the difference between the two terms.
Reflection provides the ability to discover type information within an assembly at runtime. This is part of the framework, and makes possible features such as code completion in the IDE, references between assemblies, etc. It's also used in frameworks, such as ASP.NET (you can basically refer to classes, or web controls, in markup and instances will be dynamically created at runtime using reflection). This is also used in serialization, which is the core of web services, WCF, the web part framework, session state, AJAX, and more.
Decompiling is a term for converting machine code to a higher-level, human readable code. The .NET framework uses an intermediary language (IL) which is a machine-agnostic low level language somewhat similar to assembly, minus CPU specific things like registers. The runtime itself is what actually takes this IL and compiles it to the code that's actually specific to the local machine through a process called JIT'ing. Obviously, your code has to be in IL for the runtime to understand it (though there are processes to pre-compile or pre-JIT IL code).
There is no overlap between the two. Reflection only uses the metadata stored in the assembly's manifest, it does not look at the actual IL code the compiler generated. You'd never be able to use reflection to infer how a method was actually implemented
With that said, there are various tools to obfuscate IL code, making it harder to understand. One popular one tool Dotfuscator.

What are the Dotfuscator known issues [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Are there any known issues to using the Dotfuscator community edition except for it slowing down the execution speed a little bit?
Is there any thing that I should change in my code before using the dotfuscator?
I am not sure but once a client reported a strange behavior that was not happen before a release with dotfuscator, so I give the client the SAME release but without a dotfuscator and every thing return to normal.
Thanks in advanced.
If you are using Dotfuscator Community Edition (which only supports renaming), there will not be any hit to performance. Transforms that can negatively impact performance such as control flow obfuscation and string encryption are unfortunately not included in the Community Edition.
As Stecya explained however, renaming can break all sorts of scenarios where the behavior is determined at run-time instead of during static analysis. Just off the top of my head, scenarios that can break include using reflection (either directly, or indirectly by for example using Enum.Parse), having code references in non-code files (such as XAML), and automatic serialization (without explicitly naming data members).
You should carefully use dotfuscator, and obfuscate only that parts that need to be hidden.
For example obfuscation may break code if you are using Reflection

OS(Operating System) Programming in C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I know this project.The question is that "Can we create a real OS with Managed Code or the os that will create with this project is a hello world os?"
Operating Systems need to have full control on hardware.Can we do it with this one?
If there are any another project please tell me
Cosmos Project
Yes it can be done - see Singularity which is (was) a Microsoft research project to create an entirely managed operating system in "Sing#" (an extended version of "Spec#" which is itself an extension of C#). Its worth stressing that this was just a research project into the concept, and was never intended as a "full" operating system of the likes of Windows or Max OSX.
The source code is available on CodePlex - you can download the code, build it and run it yourself in an emulator (I've done it myself, its well documented and relativley easy although I can't remember the exact steps myself).
Parts of the system were written in assembly / C, specifically the bootloader and the lowest level x86 interupt dispatch code however this is essentially all but unavoidable (it is by its very nature very platform dependant - something needs to write the x86 instructions to control and respond to basic hardware). The low level interrupts are also not particularly interesting in terms of how the operating system actually functions, so I personally don't consider this as cheating the "entirely managed" definition.
Looking on the Wikipedia page for Singularity there are also 5-6 similar projects, including Cosmos and a couple of similar attempts that use Java instead of C#.
The focus of Singularity OS was on security and dependency, however whats also impressive is that according to some basic benchmarks in An Overview of the Singularity Project1 (PDF) the performance of their archetecture was actually comparable to that of other "more conventional" operating systems:
... these numbers demonstrate that architecture that we
proposed not only does not incur a performance penalty, but is often as fast as or faster than more
conventional architecture. In other words, it is a practical basis on which to build a system.

How to write another Debugger for .NET using CLR [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I want to implement another debugger (language) for .NET (it's just for academic reason, so that it can implement just a part of a language). I myself like to implement NS2 (network Simlator 2) script for .NET in which anybody can write ns2 script and debug it with .NET
I read this article in stackoverflow and it is far from what I'm looking for.
Here is the requirement
have some predefined keywords (e.g: for, while, if ...)
check the correct form of the statements (e.g: for(start;end;counter){commands} ...)
diffferent colour for different types of statements
ability to add to any IDE (e.g: implementatin like add-in or as a dll or ...(I have no idea))
many other thing that is not necessary for now
How can I do this?
Update : I'm not sure that you got my point, take a look at this, it is very close to what I am looking for.
It will not be an easy task. However: The Dragon Book is probably a good place to start (assuming you've got sufficient computer science background for a compiler theory book to make much sense to you). Compiler Construction: Principles and Practice is also a good text.
You'll want to compile to CIL (common intermediary language). This handy wiki article outlines the CIL instruction set. Debugging your intermediate code against the CLR... well, that's where the StackOverflow article you've linked will come in handy =)
That'll cover your first two bullets (and consume a big chunk of your life).
The next two are different issues, but the easiest way to 'make it go' would probably be to define a syntax for an existing text editor, and set up a macro in the program to call your compiler. I'd recommend TextPad, though I'm sure opinions on a configurable general-purpose text editor will vary among the community ;)
Designing a full IDE with all of the features you've come to know and love in your environment could be quite a task ... or you could try to build an eclipse plugin. Personally (assuming you can design your language and learn something from it), I'd just stick with syntax highlighting in TextPad.
There is more and more interest in this area and in fact there is an active project by Microsoft Research that is looking at this on building a common infrastructure to build compiler (and debugger) for custom languages targetting .NET
http://cciast.codeplex.com/
I have used the infrastructure myself but not an expert in compiler technology. Hope this gives you a good starting point and you may find the discussion forum useful to share idea with like minded people.

Categories