Li Chen's Blog

  • Using custom .net classes in ASP Classic Compiler

    To use custom .net classes, I extended VBScript syntax with the Imports statement. The Imports statement introduce the top namespace to the VBScript, as in the example below. The following example demonstrates using ADO.NET in ASP Classic Compiler:

    <%
        imports system
        dim filePath = Server.MapPath("/Database/authors.mdb")
        dim oleConn = new system.data.oledb.oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath)
        oleConn.Open()

        dim cmd = new system.data.oledb.OleDbCommand("SELECT * From authors", oleConn)
        dim dr = cmd.ExecuteReader()
        do while dr.Read()
            response.Write(dr.GetString(1) & "<br/>")
        loop
    %>

    In the example above, “imports system” instructs VBScript.net that system is a namespace rather than an object. When VBScript.net encounters system.data.oledb.oledbconnection, it follows the namespace hierarchy to find the oledbconnection class.

    However, VBScript.net does not automatically search all the loaded assemblies. Instead, it only searches the assemblies it was instructed search. VBScript.net will always search the system.dll assembly. However, to instruct VBScript.net to also search in the system.data.dll, we need to add the following code to global.asax.cs:

    using System.Reflection;
    using Dlrsoft.Asp;

    protected void Application_Start(object sender, EventArgs e)
    {
        Assembly a1 = Assembly.Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
        AspHandlerConfiguration.Assemblies.Add(a1);
    }

    The above code tells AspHandler to search the System.Data.dll assembly for classes.

    Lastly, to saves the typing of the fully qualified class name, the “imports” statement also supports alias. The following code demonstrates using alias to save typing:

    <%
    imports t = system.text

    dim sb = new t.StringBuilder()
    sb.append("this")
    sb.append(" is ")
    sb.append(" stringbuilder!")
    response.write sb.toString()

    %>

  • Uploaded ASP Classic Compiler Build 0.6.1.34834

    It has been a long time without a new release. This release contains only a few small fixes, but it is a change in the strategy. I decided to branch the code: one branch to stabilize the VBScript 4.0 features and the other branch to implement the VBScript 5.0 features such as Eval/Execute and VBScript classes.

    The reason is that not all users need VBScript 5.0 features. Some users have only a small number of VBScript classes and can easily convert them to C# classes as VBScript.net can use .net classes. Although I still have a lot to do to reach a mature release, some users only use limited VBScript features so they can use ASP Classic Compiler first. I will issue a license under the “Early Access Program” for those users who want to go live with pre-release versions of ASP Classic Compiler.

    The “Early Access Program” is an enterprise/ISV class of program with source code access. It allows participating users to self-support under emergency situations with source code access. Although the compiler code may have a steep learning curve, many users can learn simple bug fixes fairly quickly by following bug fixes in the source control system. The remaining users can still get the binaries from the Codeplext site http://aspclassiccompiler.codeplex.com without warranty. If you are interested in the program, please contact me using the contact user form.

  • When will the next version of ASP Classic Compiler be released?

    I am not released a new version for a while. I received a few inquires regarding the next release. The answer is a few weeks to a few months.

    The first reason is that I have a fulltime job working for a software development company as an ASP.NET developer. We are in a very busy phase in the past couple of months. On top of that, my kids have several major math competitions coming up and I had to spend sometime to help them. So I have less time and that breaks my momentum.

    The second reason is that I am actually planning a moderate rewrite. My original plan was to implement the features up to VBScript 4.0 in the first version. However, I got feedback from users that they have to have Eval/Execute feature in VBScript 5.0. That would requires me to lift stack variables to heap so that they can be consumed by Eval/Execute. I found that I have to implement the variable lifting myself to handle the language semantics accurately, just like Iron Python and Iron Ruby teams have done. So I am in fact taking over the memory management from DLR. I will have a much more flexible architecture, be able to do the runtime debugging and be able to optimize the code with many techniques. As this is the second iteration, I want to do things much better. I have been doing lots of theoretical studies and benchmark works lately. I think I will be able to put together a much better product when I get my next break.

  • To talk about C# 4.0 dynamic feature and the Dynamic Language Runtime at SoCal Code Camp

    I am very excited that I will be giving a talk at SoCal Code Camp tomorrow, Jan. 31, 2010. I am going to talk about C# 4.0 dynamic feature and Dynamic Language Runtime, the same subject that I talked about 3 months ago at LA Code Camp. But this time, I am going to put it under the context of building extensible application and present road map and options. I will also talk about the ASP Classic Compiler (http://aspclassiccompiler.codeplex.com) implemented using Dynamic Language Runtime. The presentation material can be downloaded here.

    I added a couple new samples:

    1. Anonymous: Show how to leak anonymous type using dynamic type.
    2. Overload: Show the difference between compile time and run time method resolution.
  • Installing FMStocks 1.0 on later platforms

    My latest version ASP Classic Compiler can now run FMStocks 1.0, an end-to-end sample application. I have uploaded a version of FMStocks at http://aspclassiccompiler.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=98236. The version that I uploaded already has the web.config file as well as the bin directory containing the necessary dlls. To run it, you need to map a virtual directory to the website directory. Use IIS manager to map the ISAPI dll for the .asp extension to the same DLL used by the .aspx extension on your virtual directory. You still need to create the database and register the COM objects. Since the setup program was written for Windows 2000/SQL Server 2003, it may not work correctly for later platforms. The following procedure shows how to install them on a later platform manually.

    1. To install the COM objects, just use regsvr32 to register the FMStocks_Bus.dll and FMStocks_DB.dll in the objects\Distribution directory.
    2. To create the database, first useISQL to open the schema.sql file and run it. This will create the database, login and the tables. Note that your sql server must be in mixed security mode.
    3. Next, open Create 10,000 test accounts.sql with ISQL and execute it. This will create the sample accounts.
    4. Lastly, use import feature to import the data in rawdata.mdb into the stocks database.
  • ASP Classic Compiler 0.6.0 released. It can run FMStocks 1.0

    I uploaded ASP Classic Compiler 0.6.0 to http://aspclassiccompiler.codeplex.com. We reached a small milestone: it can run Fitch and Mather Stocks 1.0 now. This is the first end-to-end example that we can run with ASP Classic Compiler. Our goal is to be able to run most of ASP classic applications under ASP.NET without modifications, but we actually need to make two minor modifications. Both cases are due to the difference between interpreter and compiler. With interpreter, you can have syntax error in dead code (unreached code); with compiler, the entire code has to be syntactically correct for the code to compile.

    The first change is at t_head.asp line 71, we added "dim i". That is because we have undeclared variable when the option explicit is on. Since the procedure was never executed, the ASP interpreter never caught the error but we have to fix it for the ASP Classic Compiler.

    The second change is at SellStockAction.asp line 17. We added  "dim m_strMainPrompt". Again, this is an undeclared variable. Since the “on error resume next” is on, the VBScript interpreter would actually skip over the syntactical errors but the code will never work correctly. For the compiler, “on error resume next” cannot trap compilation errors.

    In addition, several pages use @Transaction declaration. They are ignored since we do not have Com+ transaction support at the page level. Transaction for objects in Com+ packages are supported. 

    I have uploaded preconfigured FMStocks with web.config and .net DLLs to http://aspclassiccompiler.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=98236. It is still necessary to register the COM objects and install the SQL database. Since the setup program was written for Windows 2000/SQL Server 2000, it does not work correctly for the later platforms. I will document how to install it in a later platform in a separate blog entry.

    Here is the plan and call for action:

    1. I will come out with some debugging aid in the next version. Trouble shooting both asp problem and the compiler problem without debugging aid is painful.
    2. The parser is 90% done. If you use ASP Classic Compiler to run your application, I do want you to report all syntax errors so that I can fix them.
    3. The code generator quality is at 60-70% level. I want you to hold on the report of runtime errors until I provide better debugging aid.
    4. I will continue test ASP Classic Compiler using some open source samples/applications. Drop me a not if you have any suggestion.
    5. I originally envision to have class support after the 1.0 release, but it looks like now that I will implement the Class feature before the 1.0 release.
  • Uploaded ASP Classic Compiler Version 0.5.6.34834 to http://aspclassiccompiler.codeplex.com

    With feedbacks from several enthusiastic users, I have fixed many little bugs. Give the latest version a try. Post bugs on the forum as usual. Happy computing!

    I am running into a little bit of difficulty with CLR debugger integration. In order to generate the debug symbol, I need to use LambdaExpression.CompileToMethod(). However, this method does not support DynamicExpression that I heavily rely on. So I am back to research and trying to figure out how to use Microsoft.Scripting.Debugging.dll. In the mean time, I am going to enable tracing in near future so that at least we can figure out problems through tracing.

  • C# 4.0 dynamic and Dynamic Language Runtime presentation at LA Code Camp

    I did a two session presentation at LA Code Camp today to talk about the C# 4.0 dynamic feature and the dynamic language runtime. The presentation materials could be downloaded here.

    The zip file contains the source code of several demos that I did today:

    1. DynamicTest: A simple C# dynamic example.
    2. BoxUnbox: Example demonstrates the boxing/unboxing behavior of C# dynamic variables.
    3. PrivateMember: Example demonstrate that code in full-trust can access private member but it will throw exception when running in partial-trust. A partial-trust sandbox is used to simulate the partial-trust environment in the demo.
    4. MultipleDispatch: This example was from Curt Hagenlocher’s blog.
    5. MOR: This example demonstrates accessing unknown type or dynamic object using dynamic variable. The MOR means minimalist OR Mapper; it converts query results in anonymous types dynamically.
    6. TypeModel: This demo shows how to access static members of a unknown type using dynamic variable. The unknow type is wrapper in the TypeModel object which implements IDynamicMetaObjectProvider interface. The TypeModel class is extracted out of the DLR Symbl example.
    7. DLRTreeTest: This example demonstrate factorial function implemented using System.Linq.Expression (Microsoft.Script.AST in .NET 3.5 version of DLR).
  • Execution Assisted Code Converter

    As I am working on my VBScript.net and ASP Classic Compiler, I came the realization why the existing asp classic to ASP.NET converters do not work very well. The primary difficulty is those converter do not get many type information during static analysis when converting a scripting language such as VBScript to strongly-typed VB.NET or C#. For the same reason, editor intellisence usually does not go very far when editing VBScript or Javascript.

    Executing the dynamic code will bring in the type information at runtime. I think that I just need to enhance my callsite binder to capture some information and then I will be able to convert the code that flow through my binder much more accurately. Mostly likely the converted code should work correctly right away. So I will just give it a name called Execution Assisted Code Converter. I will try to put together a prototype if I get a little bit of time.

    Note: There are refinements to the thought through discussions of this post below.

  • Uploaded Asp Classic Compiler Build 0.5.5.34834

    I just uploaded ASP Classic Compiler Build 0.5.5.34834 to http://www.codeplex.com/aspclassiccompiler.

    In this release, I have:

    1. Setup the infrastructure to map from generated code back to the source code so that we can report the location accurately in asp files. With that, I will be able to provide debugging experience using either Visual Studio or another CLR debugger fairly soon.
    2. If a file has multiple syntax errors, chances are that we are able to report all the errors at once. In contrast, Asp Classic only reports one error at a time. That is because our parser attempts to recover from the error and continue parsing the file. This is also essential for intellisence support in VS integration that will come in the near future.

    The next build will be in two weeks as I am preparing for my presentations at the LA Code Camp right after PDC. I have blocked two sessions to discuss the C# dynamic feature and the Dynamic Language Runtime. My first talk will be mainly on the C# dynamic feature and the second talk will be mainly on the Dynamic Language Runtime. Here are the abstract of the sessions:

    http://www.socalcodecamp.com/session.aspx?sid=ecbdbbc5-844b-4024-9012-b6ad8827546d and http://www.socalcodecamp.com/session.aspx?sid=7af7eb5a-913d-46fb-a3f8-144fdc77ed3c