天道酬勤,学无止境

compiler-construction

C# 'is' 类型检查结构 - 奇怪的 .NET 4.0 x86 优化行为(C# 'is' type check on struct - odd .NET 4.0 x86 optimization behavior)

问题 更新:我已经向 Microsoft Connect 提交了错误报告,请投赞成票! 更新 2: Microsoft 已将错误报告标记为已修复 由 Microsoft 于 2010 年 8 月 18 日 17:25 发表此错误将在运行时的未来版本中修复。 恐怕现在判断它是在服务包中还是在下一个主要版本中还为时过早。 自从升级到 VS2010 后,'is' 关键字出现了一些非常奇怪的行为。 下面的程序 (test.cs) 在调试模式下编译时输出 True(适用于 x86),在优化编译时输出 False(适用于 x86)。 在 x64 或 AnyCPU 中编译所有组合会给出预期结果 True。 在 .NET 3.5 下编译的所有组合都给出了预期的结果,True。 我正在使用下面的批处理文件 (runtest.bat) 使用编译器 .NET 框架的各种组合来编译和测试代码。 有没有其他人在 .NET 4.0 下看到过​​这类问题? 其他人在运行 runtests.bat 时是否在他们的计算机上看到与我相同的行为? @$@#$?? 有没有办法解决这个问题? 测试文件 using System; public class Program { public static bool IsGuid(object item) { return item is Guid; } public

2021-06-21 12:31:41    分类:技术分享    c#   optimization   compiler-construction   casting   struct

Why compiling into intermediate code?

Why do Actionscript, Java, C#, etc. compile into intermediate code? I'm aware of cross-platform benefits of using intermediate code. The question is: What is the benefit of compiling to intermediate code, compared to scripts (JS, Python, PHP, Perl, etc.) that are interpreted? Is it just for code obfuscation? Or what? In addition what is the benefit compared to compiling to native code?

2021-06-15 13:05:42    分类:问答    c#   java   actionscript   compiler-construction

Java compiler fails to recognise static inner class

This is quite a complicated error, so please bear with me. I am seeing a weird error when trying to compile some Java code. The compiler fails to recognise a static inner class. Let us say that I am working on a class MyClass. The static inner class which I need to use has an FQN of x.y.z.Parent.DesiredClass. This inner class is explicitly imported using its FQN. The parent is also imported using its FQN. Now there exists another package with (another, different FQN) which has a class DesiredClass. This other DesiredClass is on the classpath, but it is not being explicitly imported. Before I

2021-06-15 12:55:20    分类:问答    java   compiler-construction   static   inner-classes

Higher-order functions in C as a syntactic sugar with minimal effort

I want to implement higher-order functions (HOFs) in C as a syntactic sugar with minimal effort. For example, for the following code function add(int x) { return int(int y) { return x + y; }; } int main() { function add1 = add(1); return add1(2); } it is transcompiled into pure C as #include <stdlib.h> typedef struct { void *ctx; void* (*fun)(void *arg, void *ctx); } function; function new_function(void *ctx, void* (*fun)(void *, void *)) { function f = {.ctx=ctx, .fun=fun}; return f; } void* apply(function f, void *arg) { return (*(f.fun))(arg, f.ctx); } typedef struct { int x; } context$1

2021-06-15 12:05:43    分类:问答    c   compiler-construction   higher-order-functions

How to create AST parser which allows syntax errors?

First, what to read about parsing and building AST? How to create parser for a language (like SQL) that will build an AST and allow syntax errors? For example, for "3+4*5": + / \ 3 * / \ 4 5 And for "3+4*+" with syntax error, parser would guess that the user meant: + / \ 3 * / \ 4 + / \ ? ? Where to start? SQL: SELECT_________________ / \ \ . FROM JOIN / \ | / \ a city_name people address ON | =______________ / \ .____ . / \ / \ p address_id a id

2021-06-15 10:57:08    分类:问答    algorithm   compiler-construction   language-agnostic   abstract-syntax-tree

How a JIT compiler helps performance of applications?

I just read that Android has a 450% performance improvement because it added a JIT compiler, I know what JIT is, but I don't really understand why is it faster than normal compiled code? or what's the difference with the older approach from the Android platform (the Java like run compiled bytecode). Thanks! EDIT: This is hugely interesting, thanks!, I wish I could pick every answer as correct :)

2021-06-15 10:34:06    分类:问答    android   jit   compiler-construction

Assembly language and compiled languages

How is assembly faster than compiled languages if both are translated to machine code? I'm talking about truly compiled languages which are translated to machine code. Not C# or Java which are compiled to an intermediate language first and then compiled to native code by a software interpreter, etc. On Wikipedia, I found something which I'm not sure if it's in any way related to this. Is it because that translation from a higher level language generates extra machine code? Or is my understanding wrong? A utility program called an assembler is used to translate assembly language statements into

2021-06-15 07:57:59    分类:问答    performance   compiler-construction   assembly

In the C if-else statement, should the condition which is more likely to be true come first?

I happened to write a if-else statement, the condition would be false at most time(check a static pointer is assigned or not). Which one would be better for the compiler to optimize? Or they are just equal?. The function would be called so many times, so it is critical to optimize its performance. void foo() { static int * p = NULL; if (p == NULL) { p = (int *) malloc( SIZE * sizeof(int)); } //do something here } void foo() { static int * p = NULL; if (p != NULL) { //do something here } else { p = (int *) malloc( SIZE * sizeof(int)); //do something } }

2021-06-15 07:42:31    分类:问答    c   performance   compiler-construction

I need a tree dump option, which doesn't exist any more in current gcc versions

Older versions of gcc (for example 4.0.2 or 4.1.2) had the option -df (see http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Debugging-Options.html#index-fdump_002drtl_002dcfg-357). I used this option to dump the files filename.c.134r.life2 and filename.c.126r.life1, because I want to extract some values out of these files (for example the register count for every method). The problem is, that in current versions of gcc (for example 4.2.2) this option doesn't exist any more. There are other options and the tree dump with the name filename.c.135r.jump is pretty much the same. But the register count

2021-06-15 04:55:27    分类:问答    c++   c   gcc   compiler-construction

Java compiler super() constructor generals [duplicate]

This question already has answers here: Closed 8 years ago. Possible Duplicate: Use of ‘super’ keyword when accessing non-overridden superclass methods I'm new to Java and have been reading a lot about it lately to get more knowledge and experience about the language. I have a question about inherited methods and extending classes when the compiler inserts automatic code. I've been reading that if I create class A with some methods including lets say a method called checkDuePeriod(), and then create a class B which extends class A and its methods. If I then call the method checkDuePeriod()

2021-06-15 03:56:44    分类:问答    java   class   inheritance   compiler-construction   constructor