AndreGarzia.Com all we do is code

Runtime Revolution

Rockets RPC Demo

Introducing Rockets RPC


What is Rockets RPC?


It is a simple library that makes it to create web services. It allows you to share revolution handlers with web-savvy application. Most web application involves calling a server side component and using the output from that call somewhere, instead of reinventing the wheel, RocketsRPC provides an easy way to share handlers and does all the output piping for you.

Add Two Numbers Example

Suppose you have the following handler which you want to share:

on addTwoNumbers pNumber1, pNumber2
return (pNumber1 + pNumber2)
end addTwoNumbers

With RocketsRPC you can expose this handler so that a web page or network aware application can call your code directly by accessing a url like:

http://andregarzia.com/cgi-bin/addTwoDemos.cgi?func=addTwoNumbers&pNumber1=2&pNumber2=2

if you try that url, you'll see it outputs the result from calling addTwoNumbers with pNumber1 = 2 and pNumber2 = 2. To see a live demo of this code, go to http://andregarzia.com/addTwoDemos.html , try it for I'll explain it piece by piece below.

The addTwoDemos.cgi




addTwoDemos.cgi

The web page


FirefoxSnapz004

http://andregarzia.com/addTwoDemos.html


The web page source


FirefoxSnapz005

You can see there's a minimal javascript to call 'addTwoNumbers' with the form parameters and glue the result into the 'span' tag. You may be thinking, how does javascript can call 'addTwoNumbers' like that, where is all the xmlHttpRequest part?

Well, RocketsRPC will generate javascript libraries for your CGI at runtime. If you call your CGI passing a param "func" with value "jslib", RocketsRPC will return a javascript library with proxy functions with the same name and parameters as the functions you exposed in your code. When you call those proxy functions, they go to the server, call the correct handler and return the result.

If you want to see the javascript library generated for AddTwoNumber.cgi just browse to http://andregarzia.com/cgi-bin/addTwoDemos.cgi?func=jslib

FirefoxSnapz006

We can simply include the runtime generated library using a script tag with a source value such as we did on the web page source.

FirefoxSnapz005.jpg

So, in the end, it is just a matter of exposing functions with the 'addFunction' call, including the javascript library in the webpage and then calling the functions as they were javascript native functions.

Can it get any easier?

Andre
|

Coding an Assembler Interpreter in Runtime Revolution

The problem

Since the beggining of the year, I am a computer science undergrad student. There in my new university, they are teaching me the joys and pains of learning about programming, hardware architecture and the like. Most of my fellow classmates never coded in their life and actually, some had no clue about how programming languages work. They teach us, two chairs in the first semester that involves programming.

Programming Techniques 101: Our first formal introduction to programming and the newbie friendly and very readable language they choose to use was C, and it gets even better, we're using Turbo C from Borland circa 1991. I am only able to follow it because I actually learned to program using Turbo C in *1993* (give or take couple years). But that is not a post about C, it is about the other chair.

Computer Architecture 101: Here we learn about bits and bytes, cpus, memories and all the hardware that is made in china, sold in the us and smuggled to brazil. And here we learn Assembler. Students are supposed to learn to code in assembler for a non-existant x86 machine. For that we use some simulator called SIMx86 that has a newbie oriented assembler with commands such as GET that requests a numerical input from the keyboard. Our second examination was just made of assembler questions.

The problem, I skipped the assembler classes, I didn't knew how to code in SIMx86 assembler! The bigger problem, SIMx86 just run on Win32 machines and I have four macs. It was 10:00 PM, the exam was in 10 hours, I decided that learning that assembler using my paper lectures was not as good because I couldn't test to see if my code was really working and then I decided to undertake a huge project, code my own assembler simulator for the language used in SIMx86.

The result

A picture is worth a thousand typos, here goes a shot

RevolutionSnapz004

This is my finished assembler simulator, it can run all the examples we learned in class, it has a poor man debugger that allow me to step thru the code line by line checking registers. The missing part is memory access, right now I just implemented the registers, no access and manipulation of memory addresses but I'll in the future add a 64k memory.

The whole interpreter code is just 164 lines of transcript. It was fairly easy to do, the hardest part was the fact that SIMx86 math is all hexadecimal based and rev is all base 10, so I had to convert numbers before displaying and after input, that is not a problem *if you think of it before coding* it took me two hours to remember that values should be hexadecimal and that was why my code was failing.

My interpreter has functions for adding and subtracting, conditional jumps, labels, some bitwise operations and variable copying. It can run all code we used in the class and even better, it allows one to step thru. I also added context sensitive help, when stepping thru, a little field contains all the info available for the current command being executed.

I finished coding this at 2:00 AM, the examination was at 7:30 AM.... it was not the wisest decision on earth, I used many hours to code and fine tune my own assembler interpreter when I should be studying. I am waiting for my grade on that examination, but no matter if I have a good or bad grade, I am proud of my silly interpreter, it even sports a nice eMac monitor for displaying the output.

The implementation

Implementing this interpreter was easy. There are couple script local variables:

  • theSource - holds the source being executed.
  • tCL - the current line we're executing.
  • ax, bx, cx, dx - the registers.
  • t1, t2 - holds values for conditional implementation such as CMP AX, BX.

Then it is all done with two main functions - ExecuteASM and GetNextLine.

GetNextLine
it picks the line tCL of theSource and passes to ExecuteASM, it increments tCL then. Simple as that.

ExecuteASM
This function executes one Assembly instruction, it uses some helper functions such as ParseRegister to find values for the register and SetRegister to push back the values but it is all a big switch statement. If the "step line by line" checkmark button is not hilited, this function will call GetNextLine before finishing, if it is hilited then it just finishes and you can move to the next line by pressing the execute button which calls GetNextLine.

Interpreter is initialized by a function called StartASM, this function zeroes the registers and move tCL (the current line) to the first line in the source. This is called on closeField of field "source" and also when tCL is the first line. This is how we refresh the interpreter after execution, when the HALT command is found we put 1 into tCL, so when GetNextLine happens, it will call StartASM for it is on the first line.

I am very proud of my conditionals and jumping. It was so easy to implement that in Revolution, I simply use lineOffset to find the line that contains the label and then change tCL to be that line, the next call to GetNextLine will execute from that line. All jumps, switches and loops are now easy to implement.

This is a simple story of how someone with raw knowledge of Assembly and some better knowledge of Revolution was able to implement in less than five hours, a simple intepreter to help him study for an examination. This is what I think Dan Shafer called the inventive user, that creates impromptu tools as the need arises, my own Assembly interpreter is not a product, it is a simple tool that helped me get a better grasp of how that language works and allowed me to experiment before an examination. Bonus it works on Macs, Windows and probably linux (without the blends).
|

Cool Web Resources for Runtime Revolution developers

Introduction



Hello friends, today I decided to make a list of resources I think are invaluable for the wannabe Runtime Revolution Web Application developer. I'll put the resources in the following categories: education, libraries and tools. This list is not complete and the items were placed in the list most because I like them and they serve me well.

The idea behind this little article is to become a hub serving useful resources locations.

Education


We all love the learn-by-doing method and we all know that the best way to learn something is with a practical project but there's a limit for what a person can learn just by himself. There's a new bubble in town, it's the web 2.0 and AJAX bubble, everyone is building their services, some will last, most will not. If you have an idea, chances are that you have three to four competitors already implementing their services. Startups are like mushrooms after rain, you blink and there are bunch of them just at your door step. There are many things a developer can do to keep on the bleeding edge and have a competitive advantage over his competitors, one of them is always learn more, keep learning and your mind will keep fresh and you'll have new views to tackle old problems, also it helps to see the big picture. When all your competitors are looking at the landscape thru a straw, it's very good to have the panorama lens.

To new webapp developers, I recommend:
http://www.jmarshall.com/easy/http/ - Learn about the HTTP protocol. This is what drives the web, your application will ride on the HTTP waves. Understand the protocol and how it works with this easy to follow text.
Introduction to Revolution CGIs - CGIs provide dynamic content to web sites, and allow flexible delivery of information. This tutorial explains how to use Runtime Revolution as a CGI engine on your server, and walks you through several CGI examples written in Revolution's easy Transcript language.
w3schools XSLT tutorial - tutorial on XML Stylesheet transformations, best way to generate the HTML for your apps.
w3schools Javascript tutorial - one can't build web applications by using Runtime Revolution alone, the knowledge of javascript is essential, even if only to glue some libraries to server side data servers.

PS: w3schools has a lots of tutorials, all for free on topics such as XHTML, SQL, SOAP.

Libraries



Code reuse is the key to web development, using good libraries (or creating them) is a must. Libraries keep development costs down and productivity high since less time is spent reinventing the wheel. I'll list first some Runtime Revolution libraries to be used on the server side for your CGIs, then I'll list some javascript libraries to be used on the client side to create effects and all the things expected of the next AJAX killer app.

Runtime Revolution CGI libraries:
LibCGI - Monte and Rodney library for building CGIs using stacks.
EasyCGI - My own suite of libraries.

PS: both libraries are bundled with RevOnRockets.

Javascript libraries
Scriptaculous - One of the most useful and popular libraries out there. Lots of features from animation effects, to user interface manipulation and AJAX. I use Scriptaculous for my webapps and I am very happy with it.
Prototype - Prototype library is bundled with scriptaculous, it's like scriptaculous is the user interface library and prototype is the backend stuff. When not using scriptaculous interface features, you can simply use prototype for your AJAX needs.
MooTools - This is a very compact library, it features all you need to build AJAX apps.
Yahoo! Interface Library - A very complete and mature library for building AJAX apps. It has everything, from calendar controls, drag & drop routines to connection management and data brokers.

Tools


I mostly work on macintosh computers so forgive me for not talking about windows tools, if anyone send me notes on windows tools, I'll be happy to put them here.

wireshark - a TCP sniffer makes it easier to debug your webapp because you can view all the traffic coming and going on the HTTP port. Some nasty bugs can easily be tracked down by using regular expressions and a sniffer. Wireshark has versions for popular unices and windows.
firebug - Firefox is the web developer best friend due to firebug, a wonderful extension that allows you to inspect and fiddle with everything, the DOM, the httprequesters, css, javascript. You can launch debuggers, watch your routines working. Firebug will help you make sure the client side is working.
RevOnRockets - A 100% transcript based suite of tools including Runtime Revolution libraries, a web server for local development and examples! All with source, all free (yes, I am the author, so this is a shameless plug).

Conclusion


This is just a simple list, to get you interested. Leave feedback using the comments links.

|

web application done with Runtime Revolution

The Online Hindu Lexicon
http://www.himalayanacademy.com/resources/lexicon

This is a web application that uses AJAX techniques to create a very easy to use lexicon for those interested in Hinduism. It features word definitions in english and cross-references allowing the curious user to jump from word to word as he explores the lexicon.

It was created with Runtime Revolution
|