changeset 135:18a4403fe576

Javascript backend can now produce broken output. Needs fixes plus port of standard lib
author Mike Pavone <pavone@retrodev.com>
date Sun, 14 Nov 2010 03:09:49 -0500
parents 386f4a874821
children fc3815b7462f
files backendutils_c.rhope cbackend_c.rhope compile_old_c.rhope jsbackend.rhope number_c.rhope nworker_c.rhope
diffstat 6 files changed, 432 insertions(+), 843 deletions(-) [+]
line wrap: on
line diff
--- a/backendutils_c.rhope	Wed Nov 10 22:29:49 2010 -0500
+++ b/backendutils_c.rhope	Sun Nov 14 03:09:49 2010 -0500
@@ -44,6 +44,11 @@
 	out <- op
 }
 
+Get Type@String[op,func:out]
+{
+	out <- [func]Get Var Type[op]
+}
+
 Make Op@String Cat[string,func:out]
 {
 	out <- [func]Resolve[string]
@@ -54,6 +59,11 @@
 	out <- op
 }
 
+Get Type@String Cat[op,func:out]
+{
+	out <- [func]Get Var Type[op]
+}
+
 Make Op@String Slice[string,func:out]
 {
 	out <- [func]Resolve[string]
@@ -64,6 +74,11 @@
 	out <- op
 }
 
+Get Type@String Slice[op,func:out]
+{
+	out <- [func]Get Var Type[op]
+}
+
 Make Op@Whole Number[num,func:out]
 {
 	out <- num
@@ -120,6 +135,11 @@
 	out <- [func]Lookup Constant[[const]Value >>, [const]Need Addref >>]
 }
 
+Get Type@Constant[const,func:out]
+{
+	out <- [func]Get Constant Type[const]
+}
+
 Strip Addref@Constant[op:out]
 {
 	out <- [op]Need Addref <<[No]
@@ -269,6 +289,11 @@
 	out <- [[Build[Field Ref()]]Variable <<[var]]Field <<[field]
 }
 
+Get Type@Field Ref[ref,func:out]
+{
+	out <- [func]Get Field Type[[[ref]Variable >>]Get Type[func], [ref]Field >>]
+}
+
 Make Op@Field Ref[ref,func:out]
 {
 	out <- [func]Field Result[[ref]Variable >>,[ref]Field >>]
--- a/cbackend_c.rhope	Wed Nov 10 22:29:49 2010 -0500
+++ b/cbackend_c.rhope	Sun Nov 14 03:09:49 2010 -0500
@@ -325,7 +325,7 @@
 			]Set["Blueprint", "TYPE_BLUEPRINT"]	//12
 			]Set["Array", "TYPE_ARRAY"]			//13
 			]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14
-			]Set["Worker", "TYPE_WORKER"]		//15
+			]Set["Worker", "TYPE_WORKER"]			//15
 			]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"]	//16
 			]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"]	//17
 			]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]]		//18
@@ -1134,6 +1134,26 @@
 	out <- [[[[[[Build[C Program()]]Functions <<[Dictionary[]]]Method Registry <<[C Method Registry[]]]Type Registry <<[C Type Registry[p]]]Field Registry <<[C Field Registry[]]]Libraries <<[Dictionary[]]]Escape Pattern <<[p]
 }
 
+Supported Number Types@JS Program[program:out]
+{
+	out <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")
+}
+
+Needed Specials@JS Program[program,typename,makespecial:out]
+{
+	init name <- [" init "]Append[typename]
+	with init <- [()]Append[ [[()]Append[init name]]Append[[makespecial]Index["init"]] ]
+	[("Array","Boxed Array","Worker")]Find[=[?,typename]]
+	{
+		out <- Val[with init]
+	}{
+		copy name <- [" copy "]Append[typename]
+		cleanup name <- [" cleanup "]Append[typename]
+		out <- [[with init]Append[ [[()]Append[copy name]]Append[[makespecial]Index["copy"]] ]
+			]Append[ [[()]Append[cleanup name]]Append[[makespecial]Index["cleanup"]] ]
+	}
+}
+
 Link@C Program[program,language,library:out]
 {
 	If[[library] = ["runtime"]]
@@ -1480,6 +1500,11 @@
 	{ out <- text }
 }
 
+Text Filename@C Program[program,source name:out]
+{
+	out <- [source name]Append[".c"]
+}
+
 Text@C Program[program:out]
 {
 	p <- [program]Escape Pattern >>
--- a/compile_old_c.rhope	Wed Nov 10 22:29:49 2010 -0500
+++ b/compile_old_c.rhope	Sun Nov 14 03:09:49 2010 -0500
@@ -1,9 +1,77 @@
 
 Import parser_old_c.rhope
+Import cbackend_c.rhope
+Import jsbackend.rhope
+
+Other Short[arg,list:out]
+{
+	If[[arg]=["-"]]
+	{
+		out <- list
+	}{
+		rest,last <- [arg]Slice[ [[arg]Length]-[1] ]
+		out <- Other Short[rest, [list]Append[last]]
+	}
+}
+
+Check Short Val[short,args,cur,shortopts,curopts:fname,opts,next,nofname]
+{
+	If[[cur]<[[[args]Length]-[1]]]
+	{
+		val <- [args]Index[cur]
+		nidx <- [cur]+[1]
+	}{
+		val <- Yes
+		nidx <- Val[cur]
+	}
+	fname,opts,next,nofname <- Parse Args[args,nidx,shortopts,_Set Short[shortopts,curopts,short,val]]
+}
+
+_Set Short[shortopts,dict,short,val:out]
+{
+	[shortopts]Index[short]
+	{
+		out <- [dict]Set[~, val]
+	}{
+		Print[["Unrecognized short option: "]Append[short]]
+		out <- dict
+	}
+}
+
+Parse Args[args,cur,shortopts,curopts:fname,opts,next,nofname]
+{
+	arg,nofname <- [args]Index[cur]
+	{
+		If[[~]Starts With["-"]]
+		{
+			If[[arg]Starts With["--"]]
+			{
+				,,after <- [arg]Partition["="]
+				{
+					[~]Slice[2] {}
+					{ nextopts <- [curopts]Set[~, after] }
+				} {} {} {
+					[arg]Slice[2] {}
+					{ nextopts <- [curopts]Set[~, Yes] }
+				}
+				fname,opts,next,nofname <- Parse Args[args,[cur]+[1],shortopts,nextopts]
+			}{
+				rest,last <- [arg]Slice[ [[arg]Length]-[1] ]
+				fname,opts,next,nofname <- Check Short Val[last,args, [cur]+[1], shortopts, 
+											Fold[_Set Short[shortopts,?,?,Yes], curopts, Other Short[rest, ()]]]
+			}
+		}{
+			fname <- Val[arg]
+			opts <- curopts
+			next <- [cur]+[1]
+		}
+	}
+}
 
 Main[args]
 {
-        fname <- [args]Index[1]
+
+        fname,options <- Parse Args[args,1,[Dictionary[]]Set["b", "backend"],Dictionary[]]
         {
                 file <- [File[~]]Open["r"]
                 text <- String[[file]Read[[file]Length]]
@@ -17,13 +85,25 @@
                                 tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ]
                                 { Print["Compiling"] }
                         }
-                        compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]]
+                        backmap <- [[Dictionary[]
+                        	]Set["javascript", JS Program[?]]
+                        	]Set["c", C Program[?]]
+                        sel <- [options]Index["backend"]
+                        {
+	                    	backend <- [backmap]Index[~]{}
+	                    	{
+	                    		Print[[["Unknown backend '"]Append[sel]]Append["' selected. Defaulting to C backend."]]
+	                    		backend <- C Program[?]
+	                    	}
+                        }{ backend <- C Program[?] }
+                        compiled <- [Tree to Program Native[tree]]Compile Program[Call[backend]]
                         { Print["Compiled program to backend"] }
-                        outfile <- [File[ [fname]Append[".c"] ]]Truncate
+                        outfname <- [compiled]Text Filename[fname]
+                        outfile <- [File[outfname]]Truncate
                         [[compiled]Text]Write to File[outfile] 
-                        { Print[["Wrote output to "]Append[ [fname]Append[".c"] ]] }
+                        { Print[["Wrote output to "]Append[outfname]] }
                 }
-        }{
+        }{}{}{
                 Print["You must provide a file name to compile"]
         }
 }
--- a/jsbackend.rhope	Wed Nov 10 22:29:49 2010 -0500
+++ b/jsbackend.rhope	Sun Nov 14 03:09:49 2010 -0500
@@ -114,188 +114,23 @@
 	out <- Fold[_Register Field JS[?], field reg, [ctype]Fields >>]
 }
 
-Rhope Type to JS[type,p:out,array]
+
+Type Init@JS Type[jstype,id,method reg,field reg,p:out]
 {
-	If[[Blueprint Of[type]]=[Type Instance()]]
+	ename <- Escape Rhope Name[[jstype]Name >>,p]
+	
+	[("Array", "Worker")]Find[=[[jstype]Name >>, ?]]
 	{
-		variant <- [type]Variant >>
-		If[[[type]Name >>] = ["Array"]]
-		{
-			[("Naked","Raw Pointer")]Find[=[variant,?]]
-			{
-				/*
-				//Below code assumes that paramaterized types are implemented
-				pre param <- [[type]Params >>]Index[0] {}
-				{ pre param <- Type Instance["Any Type"] }
-				[[type]Params >>]Index[1]
-				{ param,param <- [pre param]Set Variant[~] }
-				{ param <- Val[pre param] }
-				child type <- Rhope Type to JS[param]
-				If[[variant] = ["Naked"]]
-				{
-					out <- Val[child type]
-					array <- "[1]"
-				}{
-					out <- [child type]Append[" *"]
-					array <- ""
-				} */
-				out <- "void *"
-				array <- ""
-			}{
-				typename <- "Array"
-			}
-			primitive <- No
-		}{	
-			,regulartype <- [("Naked","Raw Pointer")]Find[=[variant,?]]
-			{
-				[("Int64","Int32","Int16","Int8")]Find[=[[type]Name >>,?]]
-				{
-					primitive <- Yes
-					[[type]Name >>]Slice[3] {}
-					{ typename <- [["int"]Append[~]]Append["_t"] }
-				}{
-					,regulartype <- [("UInt64","UInt32","UInt16","UInt8")]Find[=[[type]Name >>,?]]
-					{
-						primitive <- Yes
-						[[type]Name >>]Slice[4] {}
-						{ typename <- [["uint"]Append[~]]Append["_t"] }
-					}
-				}
-			}
-			
-			Val[regulartype]
-			{
-				typename <- [type]Name >>
-				primitive <- No
-			}
-		}
-	}{
-		typename <- type
-		param <- "Any Type"
-		variant <- "boxed"
-		primitive <- No
-	}
-	
-	Val[typename]
-	{ array <- "" }
-	If[[typename] = ["Any Type"]]
-	{
-		out <- "struct object *"
-	}{
-		[("Naked","Raw Pointer")]Find[=[variant,?]]
-		{
-			If[primitive]
-			{
-				prefix <- ""
-			}{
-				prefix <- "nt_"
-			}
-		}{
-			prefix <- "t_"
-		}
-		
-		If[[variant]=["Naked"]]
-		{
-			postfix <- ""
-		}{
-			postfix <- " *"
-		}
-	}
-	If[primitive]
-	{
-		escaped <- Val[typename]	
+		constructor <- [[[["var t_"]Append[ename]]Append[" = "]]Append[ [("Array","Function")]Index[~] ]]Append[";\n"]
 	}{
-		escaped <- Escape Rhope Name[typename,p]
-	}
-	out <- [[prefix]Append[escaped]]Append[postfix]
-}
-
-_Type Def JS Type[text,field,p:out]
-{
-	name <- [field]Index[0]
-	,postfix <- Rhope Type to JS[[field]Index[1],p]
-	{ type <- ["\n\t"]Append[~] }
-	
-	out <- [[[[text]Append[type]]Append[" "]]Append[[Escape Rhope Name[name,p]]Append[postfix]]]Append[";"]
-}
-
-Type Def@JS Type[ctype,p:out]
-{
-	If[[[[ctype]Fields >>]Length] = [1]]
-	{
-		out <- [[[[_Type Def JS Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0], p]]Append["\n} t_"]]Append[Escape Rhope Name[[ctype]Name >>,p]]]Append[";"]
-					]Append[ 
-						[[[["typedef "
-							]Append[Rhope Type to JS[ [[[ctype]Fields >>]Index[0]]Index[1],p ]]
-							]Append[" nt_"]
-							]Append[Escape Rhope Name[[ctype]Name >>,p]]
-							]Append[";"] ]
-	}{
-		//HACK!!!
-		If[[[ctype]Name >>]=["Blueprint"]]
-		{
-			out <- ""	
-		}{
-			[("Array","Boxed Array","Worker")]Find[=[[ctype]Name >>,?]]
-			{ oend <- "\nMObject(" }
-			{ oend <- "\nObject(" } 
-			out <- [Fold[_Type Def JS Type[?,?,p], "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[Escape Rhope Name[[ctype]Name >>,p]]]Append[")"] ]
-		}
+		constructor <- [["function t_"]Append[ename]]Append["\n{}\n"]
 	}
-}
-
-_Type Init JS[type name,method reg,text,method,p:out]
-{
-	out <- [[text]Append[[["\n\tadd_method(bp, "]Append[ [method reg]Method ID[method] ]]Append[  [[", MethodName("]Append[Escape Rhope Name[method,p]]]Append[[","]Append[Escape Rhope Name[type name,p]]]]]]Append["));"]
-}
-
-_Type Init JS Field[type name,field reg,text,field,p:out]
-{
-	fname <- [field]Index[0]
-	out <- [[[[text]Append[[["\n\tadd_getter(bp, "]Append[ String[[field reg]Field ID[fname]] ]]Append[  [[", MethodName("]Append[Escape Rhope Name[[fname]Append[" >>"],p]]]Append[[","]Append[Escape Rhope Name[type name,p]]]]]]Append["));"]
-		]Append[[["\n\tadd_setter(bp, "]Append[ String[[field reg]Field ID[fname]] ]]Append[  [[", MethodName("]Append[Escape Rhope Name[[fname]Append[" <<"],p]]]Append[[","]Append[Escape Rhope Name[type name,p]]]]]]Append["));"]
-}
-
-Type Init@JS Type[ctype,id,method reg,field reg,p:out]
-{
-	[("Array","Boxed Array", "Worker")]Find[=[[ctype]Name >>, ?]]
-	{ size <- "-1" }
-	{ 
-		[("Int64","Int32","Int16","Int8")]Find[=[[ctype]Name >>, ?]]
-		{
-			[[ctype]Name >>]Slice[3] {}
-			{ typename <- [["int"]Append[~]]Append["_t"] }
-		}{
-			[("UInt64","UInt32","UInt16","UInt8")]Find[=[[ctype]Name >>, ?]]
-			{
-				[[ctype]Name >>]Slice[4] {}
-				{ typename <- [["uint"]Append[~]]Append["_t"] }
-			}{
-				If[[[ctype]Name >>]=["Blueprint"]]
-				{ typename <- "blueprint *" }
-				{ 
-					If[[[ctype]Name >>]=["Boolean"]]
-					{ typename <- "int32_t" }
-					{ typename <- ["nt_"]Append[Escape Rhope Name[[ctype]Name >>,p]] }
-				}
-			}
-		}
-		size <- [["sizeof("]Append[typename]]Append[")"] 
-	}
-	start <- [["\tbp = register_type_byid("
-		]Append[id]
-		]Append[
-			[[", "]Append[size]
-			]Append[
-				[", (special_func)"]Append[
-					[ 
-						[[[[Escape Rhope Name[[ctype]Init >>,p]
-						]Append[", (special_func)"]
-						]Append[Escape Rhope Name[[ctype]Copy >> ,p]]
-						]Append[", (special_func)"]
-						]Append[Escape Rhope Name[[ctype]Cleanup >>,p]]         
-					]Append[");"]]] ]
-	out <- Val[start]//Fold[[["_Type Init JS Field"]Set Input[0, [ctype]Name >>]]Set Input[1, field reg], Fold[[["_Type Init JS"]Set Input[0, [ctype]Name >>]]Set Input[1, method reg], start, [ctype]Methods >>], [ctype]Fields >>]
+	out <- [[[[[constructor
+		]Append[ [[[["t_"]Append[ename]]Append[".prototype.type_id = "]]Append[id]]Append[";\n"] ]
+		]Append[ [["t_"]Append[ename]]Append[".prototype.conversions = new Array();\n"] ]
+		]Append[ [["t = new t_Blueprint;\nt.id = "]Append[id]]Append[";\n"] ]
+		]Append[ [["t.construct = t_"]Append[ename]]Append[";\n"] ]
+		]Append[ [["registered_types["]Append[id]]Append["] = t;\n\n"] ]
 }
 
 Blueprint JS Type Registry
@@ -309,7 +144,7 @@
 JS Type Registry[p:out]
 {
 	out <- [[[[Build[JS Type Registry()]]Lookup << [
-			[[[[[[[[[[[[[[[[[[[Dictionary[]
+			[[[[[[[[[[[[[[[[[[Dictionary[]
 			]Set["UInt8", "TYPE_UINT8"]			//1
 			]Set["UInt16", "TYPE_UINT16"]		//2
 			]Set["UInt32", "TYPE_UINT32"]		//3
@@ -321,7 +156,6 @@
 			]Set["Boolean", "TYPE_BOOLEAN"]		//9
 			]Set["Float32", "TYPE_FLOAT32"]		//10
 			]Set["Float64", "TYPE_FLOAT64"]		//11
-			]Set["Real Number", "TYPE_FLOAT64"]
 			]Set["Blueprint", "TYPE_BLUEPRINT"]	//12
 			]Set["Array", "TYPE_ARRAY"]			//13
 			]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14
@@ -334,16 +168,6 @@
 		]Escape Pattern <<[p]
 }
 
-_Type Defs JS[text,def,p:out]
-{
-	out <- [[text]Append[[def]Type Def[p]]]Append["\n\n"]
-}
-
-Type Defs@JS Type Registry[reg:out]
-{
-	out <- Fold[_Type Defs JS[?,?,[reg]Escape Pattern >>], "", [reg]Definitions >>]
-}
-
 _Type Inits JS[reg,method reg,field reg,text,def,name:out]
 {
 	out <- [[text]Append[ [def]Type Init[[reg]Type ID[name], method reg, field reg,[reg]Escape Pattern >>] ]]Append["\n\n"]
@@ -491,9 +315,59 @@
 	out <- [func]Add Operator Statement[source1,source2,dest," * "]
 }
 
+Get Constant Type@JS Function[func,const:out]
+{
+	//TODO: Support more types as needed, particularly Float64 when support for that type is added in general
+	val <- [[func]Constants >>]Index[const] {}
+	{ typename <- "Any Type" }
+	[(Int32(),UInt8(),UInt32())]Find[=[val,?]]
+	{ typename <- [("Int32","UInt8","UInt32")]Index[~] }
+	{ typename <- "Any Type" }
+	out <- Type Instance[typename]
+}
+
+Name Match[field,target name:out]
+{
+	out <- [[field]Index[0]]=[target name]
+}
+
+Get Field Type@JS Function[func,otype,field:out]
+{
+	def <- [[[func]Type Registry >>]Definitions >>]Index[[otype]Name >>]
+	{
+		[[~]Fields >>]Find[Name Match[?,field]]
+		{ out <- [[[def]Fields >>]Index[~]]Index[1] }
+		{ out <- Type Instance["Any Type"] }
+	}{
+		out <- Type Instance["Any Type"]
+	}
+}
+
+Get Var Type@JS Function[func,varname:out]
+{
+	[[func]Inputs >>]Find[=[varname,?]]
+	{
+		out <- [[func]Input Types >>]Index[~]
+	}{
+		[[func]Outputs >>]Find[=[varname,?]]
+		{
+			out <- [[func]Output Types >>]Index[~]
+		}{
+			out <- [[func]Variables >>]Index[varname] {}
+			{ out <- Type Instance["Any Type"] }
+		}
+	}
+}
+
 Divide@JS Function[func,source1,source2,dest:out]
 {
-	out <- [func]Add Operator Statement[source1,source2,dest," / "]
+	sourcetype <- [source1]Get Type[func]
+	If[[[sourcetype]Name >>]=["Float64"]]
+	{
+		out <- [func]Add Operator Statement[source1,source2,dest," / "]
+	}{
+		out <- [func]Add Statement[ [[[[[Make Op[dest, func]]Append[" = Math.floor(("]]Append[ Make Op[source1,func] ]]Append[") / ("]]Append[Make Op[source2, func]]]Append["))"]  ]
+	}
 }
 
 DoLShift@JS Function[func,source1,source2,dest:out]
@@ -555,21 +429,17 @@
 
 Do AddRef@JS Function[func,psource,pdest:out]
 {
-    source <- [psource]Make Op[func] 
-    dest <- [pdest]Make Op[func]
-    out <- [func]Add Statement[[[[dest]Append[" = add_ref((object *)"]]Append[source]]Append[")"]]
+	out <- [func]Move[psource,pdest]
 }
 
 AddRef No Dest@JS Function[func,psource:out]
 {
-    source <- [psource]Make Op[func] 
-    out <- [func]Add Statement[[["add_ref((object *)"]Append[source]]Append[")"]]
+	out <- func
 }
 
 Release@JS Function[func,psource:out]
 {
-	source <- [psource]Make Op[func]
-	out <- [func]Add Statement[[["release_ref((object *)"]Append[source]]Append[")"]]
+	out <- func
 }
 
 Set Null@JS Function[func,pdest:out]
@@ -580,59 +450,13 @@
 
 Lookup Constant@JS Function[func,const,doaddref:out]
 {
-	var <- ["_const_"]Append[Escape Rhope Name[const,[func]Escape Pattern >>]]
-	If[doaddref]
-	{
-		out <- [["add_ref("]Append[var]]Append[")"]
-	}{
-		out <- Val[var]
-	}
+	out <- ["_const_"]Append[Escape Rhope Name[const,[func]Escape Pattern >>]]
 }
 
 Field Result@JS Function[func,var,field:out]
 {
 	as op <- [var]Make Op[func]
-	[(String(),String Cat(),String Slice())]Find[=[Blueprint Of[var],?]]
-	{
-		[[func]Inputs >>]Find[=[var,?]]
-		{
-			type <- [[func]Input Types >>]Index[~]
-			
-		}{
-			type <- [[func]Variables >>]Index[var] { Print["op refers to a var"] }
-			{
-				[[func]Outputs >>]Find[=[var,?]]
-				{
-					type <- [[func]Output Types >>]Index[~]
-				}{
-					//Does it make sense for us to do this?
-					type <- Type Instance["Any Type"] 
-				}
-			}
-		}
-	}{
-		type <- Type Instance["Any Type"] 
-	}
-	If[[[func]Convention >>] = ["rhope"]]
-	{
-		If[[type] = ["Any Type"]]
-		{
-			rvar <- Val[as op]
-		}{
-			rvar <- [[[["(("]Append[ Rhope Type to JS[type,[func]Escape Pattern >>] ]]Append[")("]]Append[as op]]Append["))"]
-		}
-	}{
-		rvar <- Val[as op]
-	}
-
-	[[func]Type Registry >>]Simple Type?[[type]Name >>]
-	{ access <- "->" }
-	{ access <- "->payload." }
-	{ 
-		//TODO: Generate some kind of error/exception in this case
-		access <- "->" 
-	}
-	out <- [[rvar]Append[access]]Append[Escape Rhope Name[field,[func]Escape Pattern >>]]
+	out <- [[as op]Append[".p_"]]Append[Escape Rhope Name[field,[func]Escape Pattern >>]]
 }
 
 Read Field@JS Function[func,var,field:out,result op]
@@ -647,9 +471,6 @@
 	result op <- Field Ref[var,field]
 }
 
-
-
-
 Set Field Null@JS Function[func,var,field:out]
 {
 	out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ]
@@ -663,34 +484,17 @@
 
 Box@JS Function[func,psource,pdest,type:out]
 {
-	dest <- [pdest]Make Op[func]
-	source <- [psource]Make Op[func]
-	out <- [func]Add Statement[ 
-		[[[[[dest
-		]Append[" = naked_to_boxed("]
-		]Append[ [[func]Type Registry >>]Type ID[[type]Name >>] ]
-		]Append[", &"]
-		]Append[source]
-		]Append[")"] ]
+	out <- func
 }
 
 Unbox@JS Function[func,psource,pdest:out]
 {
-	dest <- [pdest]Make Op[func]
-	source <- [psource]Make Op[func]
-	out <- [func]Add Statement[ 
-		[[[["boxed_to_naked("
-		]Append[source]
-		]Append[", &"]
-		]Append[dest]
-		]Append[")"] ]
+	out <- func
 }
 
 Get Raw Pointer@JS Function[func,psource,pdest:out]
 {
-	dest <- [pdest]Make Op[func]
-	source <- [psource]Make Op[func]
-	out <- [func]Add Statement[ [[[dest]Append[" = (void*)("]]Append[source]]Append[" + 1)"] ]
+	out <- func
 }
 
 Array Raw Pointer@JS Function[func,psource,pdest:out]
@@ -726,55 +530,29 @@
 
 Method Call@JS Function[func,method,args:out]
 {
-	out <- [func]Call[method,args]
+	If[[method]=["Call"]]
+	{
+		out <- [[[[[func]Add Raw Line[[["if ("]Append[Make Op[[args]Index[0], func]]]Append[".type_id == TYPE_WORKER) {"]]
+			]Val Call[[args]Index[0], Tail[args,1]]
+			]Add Raw Line["} else {"]
+			]Func Base["Call",args, "MCall"]
+			]Add Raw Line["}"]
+	}{
+		out <- [func]Func Base[Escape Rhope Name[method,[func]Escape Pattern >>],args, "MCall"]
+	}
+	
 }
 
 Val Call@JS Function[func,to call,args:out]
 {
-	worker <- Make Op[Strip Addref[to call], func]
+	worker <- Make Op[to call, func]
 	rargs <- Map[args, Make Op[?, func]]
 
-	If[[[func]Last NumParams >>] = [-1]]
-	{
-		prepped <- [[func]Add Raw Line[ 
-			[[[["VCPrepCall("
-				]Append[worker]
-				]Append[", "]
-				]Append[String[[rargs]Length]]
-				]Append[")"] ]
-		]Last NumParams <<[[rargs]Length]
-	}{
-		prepped <- [[func]Add Raw Line[ 
-			[[[[[["VCRePrepCall("
-				]Append[worker]
-				]Append[", "]
-				]Append[String[[rargs]Length]]
-				]Append[", "]
-				]Append[String[[func]Last NumParams >>]]
-				]Append[")"] ]
-		]Last NumParams <<[[rargs]Length]
-	}
-	
-	
-	out <- [[[[Fold[_Val Function Arg JS[?, ?, ?, worker], prepped, rargs]
-	]Add Raw Line[
-		[[[[[[[["ValCall("
-		]Append[worker]
-		]Append[", "]
-		]Append[String[[rargs]Length]]
-		]Append[", "]
-		]Append[String[[func]Resume Index >>]]
-		]Append[", "]
-		]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
-		]Append[")"]]
-	]Add Raw Line["DISPATCH"]
-	]Add Raw Line[
-		[[[["ValCallPostlude("
-		]Append[String[[func]Resume Index >>]]
-		]Append[", "]
-		]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
-		]Append[")"]]
-	]Resume Index <<[ [[func]Resume Index >>]+[1] ]
+	out <- [[[[[func]Add Raw Line[[[[["if ("]Append[worker]]Append[".Args.length > 0 || "]]Append[worker]]Append[".IsMethod) { "]]
+		]Add Statement[[[[["	res = valcall("]Append[worker]]Append["["]]Append[ [rargs]Join[","] ]]Append["])"]]
+		]Add Raw Line["} else {"]
+		]Add Statement[[[[["	res = "]Append[worker]]Append["("]]Append[ [rargs]Join[","] ]]Append[")"]]
+		]Add Raw Line["}"]
 }
 
 Call@JS Function[func,name,args:out]
@@ -784,61 +562,34 @@
 		//TODO: Handle case when user explicitly calls the fully qualified version, but the type of the first arg isn't Worker
 		out <- [func]Val Call[[args]Index[0], Tail[args,1]]
 	}{
-		If[[name]=["Call"]]
-		{
-			to call <- [args]Index[0]
-			last numparams <- [func]Last NumParams >>
-			out <- [[[[[[func]Add Raw Line[[["if (get_blueprint("]Append[Make Op[Strip Addref[to call], func]]]Append[")->type_id == TYPE_WORKER) {"]]
-			]Val Call[to call, Tail[args,1]]
-			]Add Raw Line["} else {"]
-			]Last NumParams <<[last numparams]
-			]Func Base["Call",args, "Call"]
-			]Add Raw Line["}"]
-		}{
-			out <- [func]Func Base[Escape Rhope Name[name,[func]Escape Pattern >>],args, "Call"]
-		}
+		out <- [func]Func Base[Escape Rhope Name[name,[func]Escape Pattern >>],args, "Call"]
 	}
 }
 
 Func Base@JS Function[func,tocall,args,type:out]
 {
+	
 	Print[ [[func]Name >>]Append[ [": Func Base("]Append[tocall] ] ]
 	rargs <- Map[args, Make Op[?, func]]
-
-	If[[[rargs]Length] > [[func]Last NumParams >>]]
-	{	
-		If[[[func]Last NumParams >>] = [-1]]
-		{
-			freed <- Val[func]
-		}{
-			freed <- [func]Add Raw Line["FreeCall"]
-		}
-		prepped <- [[freed]Add Raw Line[ [["PrepCall("]Append[String[[rargs]Length]]]Append[")"] ]
-		]Last NumParams <<[[rargs]Length]
+	
+	If[[type]=["MCall"]]
+	{
+		out <- [func]Add Statement[[[[[[["res = "]Append[[rargs]Index[0]]]Append[".f_"]]Append[tocall]]Append["("]]Append[ [Tail[rargs, 1]]Join[","] ]]Append[")"]]
 	}{
-		prepped <- Val[func]
+		out <- [func]Add Statement[[[[["res = f_"]Append[tocall]]Append["("]]Append[ [rargs]Join[","] ]]Append[")"]]
 	}
-	
-	
-	out <- [[Fold[_Function Arg JS[?], prepped, rargs]
-	]Add Raw Line[
-		[[[[[[[[[type]Append["("]
-		]Append[tocall]
-		]Append[", "]
-		]Append[String[[rargs]Length]]
-		]Append[", "]
-		]Append[String[[func]Resume Index >>]]
-		]Append[", "]
-		]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
-		]Append[")"]]
-	]Resume Index <<[ [[func]Resume Index >>]+[1] ]
 }
 
 Call Foreign@JS Function[func,name,language,args,store result:out]
 {
 	rargs <- Map[args, Make Op[?, func]]
 	//Assume language = "JS" for now
-	base <- [[[name]Append["("]]Append[ Join[rargs, ", "] ]]Append[")"]
+	If[[name]Ends With["@"]]
+	{
+		base <- [[[[[[rargs]Index[0]]Append["."]]Append[ [name]Slice[ [[name]Length]-[1] ] ]]Append["("]]Append[ [Tail[rargs,1]]Join[","] ]]Append[")"]
+	}{
+		base <- [[[name]Append["("]]Append[ Join[rargs, ", "] ]]Append[")"]
+	}
 	,do store <- [(String(), String Slice(), String Cat())]Find[=[Blueprint Of[store result], ?]]
 	{ 
 		,do store <- If[[store result]=[""]]
@@ -852,7 +603,13 @@
 
 Get Field Call@JS Function[func,field,source:out]
 {
-	out <- [func]Func Base[Escape Rhope Name[[field]Append[" >>"],[func]Escape Pattern >>], [()]Append[source], "Call"]
+	//This will need to change later when I add support for "Field Missing"
+	[func]Escape Pattern >>
+	{
+		esource <- Escape Rhope Name[Make Op[source,func], ~]
+		efield <- Escape Rhope Name[field, ~]
+	}
+	out <- [func]Add Statement[[[["res = "]Append[esource]]Append[".p_"]]Append[efield]]
 }
 
 Set Field Call@JS Function[func,field,object,value:out]
@@ -862,24 +619,26 @@
 
 Tail Method Call@JS Function[func,method,args:out]
 {
-	out <- [func]Func Base[[[func]Method Registry >>]Method ID[method],args, "TMCall"]
+	//Javascript doesn't support tail calls, at least not directly anyway
+	out <- [func]Method Call[method,args]
 }
 
 Tail Call@JS Function[func,name,args:out]
 {
-	out <- [func]Func Base[Escape Rhope Name[name,[func]Escape Pattern >>],args, "TCall"]
+	If[[name]=[[func]Name >>]]
+	{
+		//TODO: Support simple tail recursion
+		out <- func
+	}{
+		out <- [func]Call[name,args]
+	}
 }
 
 Resolve@JS Function[func,op:out]
 {
 	If[[[func]Convention >>] = ["rhope"]]
 	{
-		[[func]Inputs >>]Find[=[op,?]]
-		{
-			out <- [["my_cdata->params["]Append[String[~]]]Append["	]"]
-		}{
-			out <- [[["lv_"]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append["->"]]Append[Escape Rhope Name[op,[func]Escape Pattern >>]]
-		}
+		out <- ["lv_"]Append[Escape Rhope Name[op, [func]Escape Pattern >>]]
 	}{
 		out <- Escape Rhope Name[op,[func]Escape Pattern >>]
 	}
@@ -889,10 +648,10 @@
 {
 	If[[[func]Convention >>] = ["rhope"]]
 	{
-		out <- [[["lv_"]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append["->"]]Append[Escape Rhope Name[name,[func]Escape Pattern >>]]
+		out <- ["lv_"]Append[Escape Rhope Name[name, [func]Escape Pattern >>]]
 	}{
 		out <- Escape Rhope Name[name,[func]Escape Pattern >>]
-	} 
+	}
 }
 
 Instruction Stream@JS Function[func:out]
@@ -908,59 +667,47 @@
 Do If@JS Function[func,condition,stream:out]
 {
 	cond <- [condition]Make Op[func]
-	out <- [[Fold[_If JS[?], [[func
+	out <- [Fold[_If JS[?], [[func
 		]Add Raw Line[ [["if("]Append[cond]]Append[")"] ]
 		]Add Raw Line["{"], [stream]Statements >>]
 		]Add Raw Line["}"]
-		]Resume Index <<[[stream]Resume Index >>]
-
 }
 
 Discard Outputs@JS Function[func,first to discard:out]
 {
-	out <- [[[[[func
-		]Add Raw Line[[["for(idx = "]Append[String[first to discard]]]Append["; idx < cdata->num_params; ++idx)"]]
-		]Add Raw Line["{"]
-		]Add Raw Line["	if (cdata->params[idx])"]
-		]Add Raw Line["		release_ref(cdata->params[idx]);"]
-		]Add Raw Line["}"]
+	out <- func
 }
 
 Result Reference@JS Function[func,output:out]
 {
-	out <- [["cdata->params["]Append[String[output]]]Append["]"]
+	out <- [["res["]Append[String[output]]]Append["]"]
 }
 
 Checked Result Reference@JS Function[func,output:out]
 {
-	out <- [[[["("]Append[String[output]]]Append[" < cdata->num_params ? cdata->params["]]Append[String[output]]]Append["] : NULL)"]
+	out <- [func]Result Reference[output]
 }
 
 
 If Null Else@JS Function[func,left,right:out]
 {
-	check <- [[Make Condition[left]]Strip Addref]Make Op[func]
+	check <- [Make Condition[left]]Make Op[func]
 	l <- [left]Make Op[func]
 	r <- [right]Make Op[func]
 	out <- [[[[[["("
 		]Append[check]
-		]Append[" ? "]
+		]Append[" != null ? "]
 		]Append[l]
 		]Append[" : "]
 		]Append[r]
 		]Append[")"]
 }
 
-_Set Outputs JS[string,inputname,inputnum,func:out]
-{
-	out <- [string]Append[[[ [ ["\tRet("]Append[String[inputnum]] ]Append[ [[", lv_"]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append["->"]]]Append[Escape Rhope Name[inputname,[func]Escape Pattern >>]]]Append[")\n"]]
-}
-
 Set Outputs@JS Function[func:out]
 {
 	If[[[func]Convention >>] = ["rhope"]]
 	{
-		out <- [[[Fold[_Set Outputs JS[?, ?, ?, func], "", [func]Outputs >>]]Append["\tNumRet("]]Append[String[[[func]Outputs >>]Length]]]Append[")\n"]
+		out <- [["\treturn ["]Append[ [Map[[func]Outputs >>, Escape Rhope Name[?, [func]Escape Pattern >>]]]Join[","] ]]Append["];\n"]
 	}{
 		[[func]Outputs >>]Index[0]
 		{
@@ -970,76 +717,6 @@
 		}
 	}
 }
-_Output Defs JS[string,varname,index,func:out]
-{
-	out <- [[[string]Append[ ["\t"]Append[Rhope Type to JS[[[func]Output Types >>]Index[index],[func]Escape Pattern >>]] ]]Append[[" "]Append[Escape Rhope Name[varname,[func]Escape Pattern >>]]]]Append[";\n"]
-}
-_Var Defs JS[string,type,varname,p:out]
-{
-	out <- [[[string]Append[ ["\t"]Append[Rhope Type to JS[type,p]] ]]Append[[" "]Append[Escape Rhope Name[varname,p]]]]Append[";\n"]
-}
-
-
-Definitions@JS Function[func:out]
-{
-	Print[["Definitions@JS Function: "]Append[[func]Name >>]]
-	{
-	If[ [[[func]Convention >>] = ["rhope"]] And [[ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] > [0]] ]
-	{
-		localtype <- [[[Fold[_Output Defs JS[?, ?, ?, func], Fold[_Var Defs JS[?,?,?,[func]Escape Pattern >>],"typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} lt_"]]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append[";\n"]
-	}{
-		localtype <- ""
-	}
-	
-	If[ [[func]Convention >>] = ["rhope"] ]
-	{
-		/* parts <- [[func]Name >>]Split["@"]
-		[parts]Index[1]
-		{
-			proto <- [[[["MethodDef("
-				]Append[Escape Rhope Name[[parts]Index[0],[func]Escape Pattern >>]]
-				]Append[", "]
-				]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]
-				]Append[")\n"]
-		}{
-			proto <- [["FuncDef("]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append[")\n"]
-		} */
-		out <- Val[localtype]
-	}{
-		out <- [[func]Naked Proto]Append[";\n"]
-	}
-	}
-}
-
-_Proto Input[list,input,index,types,p:out]
-{
-	out <- [list]Append[ [[Rhope Type to JS[[types]Index[index],p]]Append[" "]]Append[Escape Rhope Name[input,p]] ]
-}
-
-Naked Proto@JS Function[func:out]
-{
-	[[func]Output Types >>]Index[0]
-	{
-		outtype <- [Rhope Type to JS[~,[func]Escape Pattern >>]]Append[" "]
-	}{
-		outtype <- "void "
-	}
-	out <- [[[[outtype
-			]Append[ Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
-			]Append["("]
-			]Append[ [Fold[_Proto Input[?, ?, ?, [func]Input Types >>,[func]Escape Pattern >>], (), [func]Inputs >>]]Join[", "] ]
-			]Append[")"]
-}
-
-Type Check@JS Function[func,text,type,input num:out]
-{
-	If[[type] = ["Any Type"]]
-	{
-		out <- text
-	}{
-		out <- [text]Append[ [["\tParam("]Append[input num]]Append[ [[", "]Append[ [[func]Type Registry >>]Type ID[type] ]]Append[")"] ] ]
-	}
-}
 
 Check Param Type JS[text,type,input num,func:out]
 {
@@ -1053,68 +730,55 @@
 	{
 		out <- text
 	}{
-		out <- [text]Append[[[["\tParam("]Append[String[input num]]]Append[ [","]Append[ [[func]Type Registry >>]Type ID[typename] ] ]]Append[")\n"]]
+		input <- ["lv_"]Append[Escape Rhope Name[[[func]Inputs >>]Index[input num], [func]Escape Pattern >>]]
+		out <- [text]Append[ [[[["\t"]Append[input]]Append["= check_type("]]Append[input]]Append[ [[", "]Append[ [[func]Type Registry >>]Type ID[typename] ]]Append[");"] ] ]
 	}
 }
 
+_Add Prefix[val:out]
+{
+		out <- ["lv_"]Append[val]
+}
+
 Text@JS Function[func:out]
 {	
 	Print[["Text@JS Function: "]Append[[func]Name >>]]
 	If[ [[func]Convention >>] = ["rhope"] ]
 	{
+		
 		before <- [[func]Name >>]Partition["@"] {} {}
 		{
-			type <- "MethodImpl"
-			cname <- [[[[Escape Rhope Name[before,[func]Escape Pattern >>]
-				]Append[", "]
-				]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]
-				]Append[", "]
-				]Append[ [[func]Type Registry >>]Type ID[~] ]
-		}{
-			type <- "Func"
-			cname <- Val[fname]
-		}
-		fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]
-		param check <- Fold[Check Param Type JS[?, ?, ?, func], "", [func]Input Types >>]
-		If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ]
-		{
-			out <- [[[[[[[[ [type]Append["NoLocals("]
-				]Append[cname]
-				]Append[",\n\tNumParams "]
-				]Append[ String[[[func]Inputs >>]Length] ]
-				]Append[")\n\n"]
-				]Append[param check]
-				]Append[ [[func]Statements >>]Join[""] ]
-				]Append["EndFuncNoLocals\n"]
-				]Append["DISPATCH"]
+			ivars <- Tail[[func]Inputs >>, 1]
+			cname <- [["t_"]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]
+				]Append[[".f_"]Append[Escape Rhope Name[before,[func]Escape Pattern >>]]]
+			[[func]Inputs >>]Index[0]
+			{ move this <- ["\tlv_"]Append[[Escape Rhope Name[~, [func]Escape Pattern >>]]Append[" = this;"]] }
+			{ move this <- "" }
 		}{
-			If[[[func]Last NumParams >>] = [-1]]
-			{
-				freecall <- ""
-			}{
-				freecall <- "\n\tFreeCall\n"
-			}
-			out <- [[[[[[[[[[ [type]Append["("]
-				]Append[cname]
-				]Append[",\n\tNumParams "]
-				]Append[ String[[[func]Inputs >>]Length] ]
-				]Append[")\n\n"]
-				]Append[param check]
-				]Append[ [[func]Statements >>]Join[""] ]
-				]Append[freecall]
-				]Append[[func]Set Outputs]
-				]Append[[["EndFunc("]Append[fname]]Append[")\n"]]
-				]Append["DISPATCH"]
+			ivars <- [func]Inputs >>
+			fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]
+			move this <- ""
 		}
+		inproc <- Val[Map[?, _Add Prefix[?]]]
 	}{
-		
-		out <- [[[
-				Fold[_Output Defs JS[?, ?, ?, func],
-					Fold[_Var Defs JS[?], [[func]Naked Proto]Append["\n{"], [func]Variables >>], [func]Outputs >>]
-			]Append[[[func]Statements >>]Join[""]]
-			]Append[[func]Set Outputs]
-			]Append["}"]
+		fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]
+		ivars <- Inputs >>[func]
+		move this <- ""
+		inproc <- Val[Val[?]]
 	}
+	cname <- ["var "]Append[fname]
+	param check <- Fold[Check Param Type JS[?, ?, ?, func], "", [func]Input Types >>]
+
+	out <- [[[[[[[[[cname
+		]Append[" = function("]
+		]Append[ [[inproc]Call[Map[ivars, Escape Rhope Name[?, [func]Escape Pattern >>]]]]Join[","] ]
+		]Append[")\n{\n"]
+		]Append[move this]
+		]Append[param check]
+		]Append[ [["\tvar "]Append[ [ [inproc]Call[Concatenate[[func]Outputs >>, Keys[[func]Variables >>]]] ]Join[","] ]]Append[";\n"] ]
+		]Append[ [[func]Statements >>]Join[""] ]
+		]Append[[func]Set Outputs]
+		]Append["}"]
 }
 
 Blueprint JS Program
@@ -1134,6 +798,16 @@
 	out <- [[[[[[Build[JS Program()]]Functions <<[Dictionary[]]]Method Registry <<[JS Method Registry[]]]Type Registry <<[JS Type Registry[p]]]Field Registry <<[JS Field Registry[]]]Libraries <<[Dictionary[]]]Escape Pattern <<[p]
 }
 
+Supported Number Types@JS Program[program:out]
+{
+	out <- ("Int32","UInt8","UInt32")
+}
+
+Needed Specials@JS Program[program,typename,makespecial:out]
+{
+	out <- ()
+}
+
 Link@JS Program[program,language,library:out]
 {
 	If[[library] = ["runtime"]]
@@ -1173,17 +847,6 @@
 	is,isnot <- [[program]Method Registry >>]Method ID[funcname]
 }
 
-_Defs JS Program[text,func:out]
-{
-	def <- [func]Definitions
-	If[[def]=[""]]
-	{
-		out <- text
-	}{
-		out <- [text]Append[[def]Append["\n\n"]]
-	}
-}
-
 _Text JS Program[text,func,type reg:out]
 {
 	out <- [text]Append[[[ [func]Type Registry <<[type reg] ]Text]Append["\n\n"]]
@@ -1194,16 +857,6 @@
 	out <- Combine[[func]Constants >>, consts]
 }
 
-_Consts JS Program[text,value,name,p:out]
-{
-	out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name,p]]]Append[";\n"] ]
-}
-
-_Consts JS Release[text,value,name,p:out]
-{
-	out <- [text]Append[ [["\trelease_ref(_const_"]Append[Escape Rhope Name[name,p]]]Append[");\n"] ]
-}
-
 _List Literal El[text,val,index,type reg:out]
 {
 	out <- [[[[text
@@ -1242,9 +895,9 @@
 			{
 				If[value]
 				{
-					out <- "make_Bool(1)"
+					out <- "make_Bool(true)"
 				}{
-					out <- "make_Bool(0)"
+					out <- "make_Bool(false)"
 				}
 			}{
 
@@ -1259,7 +912,7 @@
 						[[value]Args >>]Last
 						{ size <- String[[~]+[1]] }
 						{ size <- "0" }
-						out <- [[[[[["make_Worker(FUNC_"
+						out <- [[[[[["make_Worker(f_"
 								]Append[Escape Rhope Name[[value]Name >>,[type reg]Escape Pattern >>]]
 								]Append[", "]
 								]Append[size]
@@ -1298,11 +951,10 @@
 	valtype <- Blueprint Of[value]
 	[(String(),String Cat(),String Slice(),Worker Literal(),List(),List Leaf())]Find[=[valtype,?]]
 	{
-		Print[[name]Append[" is not of an early constant type"]]
 		out <- text
 	}{
 		Const Construct JS[value,type reg]
-		{ out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] }
+		{ out <- [text]Append[ [[[["var _const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] }
 	}
 }
 
@@ -1326,10 +978,10 @@
 		If[[~]>[3]]
 		{
 			out <- [Fold[_Set List Els[?, ?, ?, type reg], [text]Append["\trhope(FUNC_List, inout, 0, 1);\n"], value]
-				]Append[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = inout[0];\n"]]
+				]Append[[["var _const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = inout[0];\n"]]
 		}{
 			Const Construct JS[value,type reg]
-			{ init <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] }
+			{ init <- [text]Append[ [[[["var _const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] }
 		
 			If[[valtype]=[Worker Literal()]]
 			{
@@ -1343,318 +995,131 @@
 	}
 }
 
-_Dispatch Switch Sub[text, num, name:out]
-{
-	out <- [[[[[text
-		]Append["\tResumeEntry("]
-		]Append[String[num]]
-		]Append[","]
-		]Append[name]
-		]Append[")\\\n"]
-}
-
-_Dispatch Switch[text,func,raw name:out]
-{
-	If[[[func]Convention >>] = ["rhope"]]
-	{
-		name <- Escape Rhope Name[raw name,[func]Escape Pattern >>]
-		out <- [[text]Append[ [["\tDispatchEntry("]Append[name]]Append[")\\\n"] ]
-			]Append[Fold[_Dispatch Switch Sub[?, ?, name], "", Range[1, [func]Resume Index >>]]]
-	}{
-		out <- text
-	}
-}
-
-_Dispatch Switch Methods[p,text,id,raw name:out]
-{
-	name <- Escape Rhope Name[raw name,p]
-	out <- [text]Append[ [["\tDispatchEntry("]Append[name]]Append[")\\\n"] ]
-}
-
-_Dispatch Enum Sub[text, num, name:out]
-{
-	out <- [[[[[text
-		]Append["\tRES_"]
-		]Append[String[num]]
-		]Append["_"]
-		]Append[name]
-		]Append[",\n"]
-}
-
-_Dispatch Enum[text,func,raw name:out]
-{
-	If[[[func]Convention >>] = ["rhope"]]
-	{
-		name <- Escape Rhope Name[raw name,[func]Escape Pattern >>]
-		out <- [[text]Append[ [["\tFUNC_"]Append[name]]Append[",\n"] ]
-			]Append[Fold[_Dispatch Enum Sub[?, ?, name], "", Range[1, [func]Resume Index >>]]]
-	}{
-		out <- text
-	}
-}
-
-_Dispatch Enum Methods[p,text,types,name:out]
-{
-	out <- [text]Append[ [["\tFUNC_"]Append[Escape Rhope Name[name,p]]]Append[",\n"] ]
-}
-
-Dispatch@JS Program[program,all methods:out]
+Text Filename@JS Program[program,source name:out]
 {
-	out <- [[[[["typedef enum {\n"
-		]Append[Fold[_Dispatch Enum[?], 
-			[Fold[_Dispatch Enum Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n\tFUNC_BlueprintSP_FromSP_ID,\n"], 
-			[program]Functions >>]]
-		]Append["\tEND\n} funcids;\n\n"]
-		]Append["#define DispatchEntries \\\n"] 
-		]Append[Fold[_Dispatch Switch[?], 
-			[Fold[_Dispatch Switch Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tDispatchEntry(Build)\\\n\tDispatchEntry(BlueprintSP_Of)\\\n\tDispatchEntry(ID)\\\n\tDispatchEntry(BlueprintSP_FromSP_ID)\\\n"], 
-			[program]Functions >>]]
-		]Append["\tEndEntry\n\n"]
-}
-
-Not Native[func:out]
-{
-	If[[[func]Convention >>] = ["rhope"]]
-	{ out <- No }
-	{ out <- Yes }
-}
-
-Native[func:out]
-{
-	out <- [[func]Convention >>] = ["rhope"]
-}
-
-Local Pointers[text,func:out]
-{
-	If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ]
-	{
-		out <- text
-	}{
-		out <- [text]Append[[["\tFuncDef("]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append[")\n"]]
-	}
-}
-
-_Method to Types[dict,name,type:out]
-{
-	typelist <- [dict]Index[name] {}
-	{ typelist <- () }
-
-	out <- [dict]Set[name, [typelist]Append[[type]Name >>]]
-
-}
-
-_Field to Types[dict,field,type:out]
-{
-	name <- [field]Index[0]
-	out <- _Method to Types[_Method to Types[dict, [name]Append[" >>"], type], [name]Append[" <<"], type]
-
-}
-
-Method to Types[dict,type:out]
-{
-	out <- Fold[_Method to Types[?, ?, type], dict, [type]Methods >>]
-}
-
-Field to Types[dict,type:out]
-{
-	out <- Fold[_Field to Types[?, ?, type], dict, [type]Fields >>]
-}
-
-_Method Dispatch[text, type, method, reg: out]
-{
-	out <- [[[[[[[text]Append["\tMethodDispatch("]]Append[ [reg]Type ID[type] ]]Append[","]]Append[Escape Rhope Name[method,[reg]Escape Pattern >>]]]Append[","]]Append[Escape Rhope Name[type,[reg]Escape Pattern >>]]]Append[")\n"]
-}
-
-Method Dispatch[text, types, method, reg: out]
-{
-	out <- [[[Fold[_Method Dispatch[?, ?, method, reg], [[[text]Append["Method("]]Append[ Escape Rhope Name[method,[reg]Escape Pattern >>] ]]Append[")\n"], types]
-		]Append["EndMethod("]
-		]Append[Escape Rhope Name[method,[reg]Escape Pattern >>]]
-		]Append[")\n\n"]
-}
-
-Init Type Names[text,typeid,name,reg:out]
-{
-	[reg]Defined?[name]
-	{ out <- [text]Append[ [[[["\tregistered_types["]Append[typeid]]Append["]->name = "]]Append[Const Construct JS[name, reg]]]Append[";\n"] ] }
-	{ out <- text }
+	out <- [source name]Append[".js"]
 }
 
 Text@JS Program[program:out]
 {
 	p <- [program]Escape Pattern >>
-	type defs <- [[program]Type Registry >>]Definitions >>
 	constants <- Fold[Combine Consts[?], Dictionary[], [program]Functions >>]
-	all methods <- Fold[Field to Types[?], Fold[Method to Types[?], Dictionary[], type defs], type defs]
-	headers <- "#include <stdio.h>
-#include <stdlib.h>
-#include \"builtin.h\"
-#include \"object.h\"
-#include \"context.h\"
-#include \"func.h\"
-#include \"integer.h\"
-#include \"blueprint.h\"
-#include \"array.h\"
-#include \"worker.h\"
-#include \"bool.h\"
-#include <sys/time.h>\n\n"
-	out <- [[[[[[[[[[[[[[[[[[headers
-		]Append[[program]Dispatch[all methods]]
-		]Append[[[program]Type Registry >>]Type Defs]
-		]Append[Fold[_Consts JS Program[?,?,?,p], 
-					Fold[_Defs JS Program[?], "", [program]Functions >>], 
-					constants]]
-		]Append[Fold[_Text JS Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Not Native[?]]]]
-		]Append["\n
-#ifdef ENABLE_PROFILING
-uint64_t profile_counts[END];
-uint64_t profile_nestedcounts[END];
-uint64_t profile_totals[END];
-uint64_t profile_selftotals[END];
-uint64_t profile_activationlevel[END];
-#endif
+
+	out <- [[[[[["
+var i = 0;
+var TYPE_ANY = i++;
+var TYPE_INT32 = i++;
+var TYPE_UINT8 = i++;
+var TYPE_UINT32 = i++;
+var TYPE_BOOLEAN = i++;
+var TYPE_FLOAT64 = i++;
+var TYPE_BLUEPRINT = i++;
+var TYPE_ARRAY = i++;
+var TYPE_WORKER = i++;
+var TYPE_FIRST_USER = i;
 
-int32_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace)
+registered_types = new Array();
+
+function t_Blueprint()
 {
-#ifdef ENABLE_PROFILING
-	struct timeval time;
-#endif
-	uint16_t resume,idx, vcparam_offset, last_vcparam;
-	context * ct;
-	calldata * cdata, *temp_cdata, *my_cdata;
-	DispatchVar
-	FuncDef(Build)
-	FuncDef(BlueprintSP_Of)
-	FuncDef(ID)
-	FuncDef(BlueprintSP_FromSP_ID)\n"]
-		]Append[Fold[Local Pointers[?], "", [program]Functions >>]]
-		]Append["
-	ct = new_context();
-	cdata = alloc_cdata(ct, NULL, callspace);
-	cdata->num_params = numparams;
-	for(idx = 0; idx < numparams; ++idx)
-		cdata->params[idx] = params[idx];
-	cdata->func = END;
-DISPATCH\n"]
-		]Append[Fold[Method Dispatch[?, ?, ?, [program]Type Registry >>], "", all methods]]
+}
+
+t_Blueprint.prototype.type_id = TYPE_BLUEPRINT;
+t_Blueprint.prototype.conversions = new Array();
+var t = new t_Blueprint;
+t.id = TYPE_BLUEPRINT;
+t.construct = t_Blueprint;
+registered_types[TYPE_BLUEPRINT] = t;\n\n"
+		]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
 		]Append["
-Func(Build,
-	NumParams 1)
-	
-	Param(0, TYPE_BLUEPRINT)
-	
-	lv_Build->bp = ((t_Blueprint *)(cdata->params[0]))->bp;
-	release_ref(cdata->params[0]);
-	
-	Ret(0, new_object_bp(lv_Build->bp))
-EndFunc(Build)
-DISPATCH
 
-Func(BlueprintSP_Of,
-	NumParams 1)
-	
-	lv_BlueprintSP_Of->bp = get_blueprint(cdata->params[0]);
-	release_ref(cdata->params[0]);
-	
-	Ret(0, new_object(TYPE_BLUEPRINT))
-	((t_Blueprint *)cdata->params[0])->bp = lv_BlueprintSP_Of->bp;
-EndFunc(BlueprintSP_Of)
-DISPATCH
-
-Func(ID, NumParams 1)
-
-	Param(0, TYPE_BLUEPRINT)
-
-	lv_ID->id = new_object(TYPE_UINT32);
-	((t_UInt32 *)lv_ID->id)->Num = ((t_Blueprint *)cdata->params[0])->bp->type_id;
-	release_ref(cdata->params[0]);
-	Ret(0, lv_ID->id)
-EndFunc(ID)
-DISPATCH
+function make_Int32(val)
+{
+	var out = new t_Int32;
+	out.p_Val = val;
+	return out;
+}
 
-Func(BlueprintSP_FromSP_ID, NumParams 1)
-
-	Param(0, TYPE_UINT32)
+function make_UInt8(val)
+{
+	var out = new t_UInt8;
+	out.p_Val = val & 255;
+	return out;
+}
 
-	lv_BlueprintSP_FromSP_ID->type = ((t_UInt32 *)cdata->params[0])->Num;
-	if (lv_BlueprintSP_FromSP_ID->type >= max_registered_type || !registered_types[lv_BlueprintSP_FromSP_ID->type]) {
-		Ret(1, cdata->params[0])
-		Ret(0, NULL)
-	} else {
-		release_ref(cdata->params[0]);	
-		Ret(0, new_object(TYPE_BLUEPRINT))
-		((t_Blueprint *)cdata->params[0])->bp = registered_types[lv_BlueprintSP_FromSP_ID->type];
-		Ret(1, NULL)
-	}
-	
-EndFunc(BlueprintSP_FromSP_ID)
-DISPATCH\n"]
-		]Append[Fold[_Text JS Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Native[?]]]]
-		]Append["
-DO_END:
-	for(idx = 0; idx < cdata->num_params; ++idx)	
-		params[idx] = cdata->params[idx];
-	free_context(ct);
-	return cdata->num_params;
+function make_UInt32(val)
+{
+	var out = new t_UInt32;
+	out.p_Val = val;
+	return out;
+}
 
-_exception:
-	puts(\"Exception! Trace follows:\");
-	while(cdata && cdata->func != END)
-	{
-		printf(\"%d\\n\", cdata->func);
-		cdata = cdata->lastframe;
-	}
-	return -1;
+function make_Boolean(val)
+{
+	var out = new t_Boolean;
+	out.p_Val = val;
+	return out;
 }
 
-#include \"builtin.c\"
-#include \"array.c\"
-#include \"worker.c\"
+function make_Float64(val)
+{
+	var out = new t_Float64;
+	out.p_Val = val;
+	return out;
+}
+
+function make_Blueprint(typeid)
+{
+	return registered_types[typeid];
+}
 
-int main(int argc, char **argv)
+function check_type(val,typeid)
+{
+	if (val.type_id = typeid) {
+		return val;
+	}
+	if (val.conversions[type_id] != undefined) {
+		var out = val.conversions[type_id](val);
+		return out[0];
+	}
+	throw new Error(\"Conversion needed\");
+}
+
+function f_Build(type)
 {
-	blueprint * bp;
-	int numret;
-	int idx;
-	object * inout[3];
-	register_builtin_types();\n\n"]
-		]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
+	type = check_type(type, TYPE_BLUEPRINT);
+	return [new type.construct()];
+}
+
+function f_BlueprintSP_Of(val)
+{
+	return [registered_types[val.type_id]];
+}
+
+function f_ID(type)
+{
+	type = check_type(type, TYPE_BLUEPRINT);
+	return [type.id];
+}
+
+function f_BlueprintSP_FromSP_ID(id)
+{
+	id = check_type(id, TYPE_UINT32);
+	if (id.p_Val > 0 && registered_types[id.p_Val] != null) {
+		return [registered_types[id.p_Val], null];
+	} else {
+		return [null,id];
+	}
+}\n"]
+		]Append[Fold[_Text JS Program[?, ?, [program]Type Registry >>], "", [program]Functions >>]]
 		]Append[Fold[_Set Consts JS Program[?, ?, ?, [program]Type Registry >>], "", constants]]
 		]Append[Fold[_Set Late Consts JS[?, ?, ?, [program]Type Registry >>], "", constants]]
-		]Append[Fold[Init Type Names[?, ?, ?, [program]Type Registry >>], "", [[program]Type Registry >>]Lookup >>]]
 		]Append["
-	rhope(FUNC_List, inout, 0, 1);
-	for (idx = 0; idx < argc; ++idx)
-	{
-		inout[1] = make_String(argv[idx]);
-		rhope(FUNC_Append, inout, 2, 2);
-	}
-	numret = rhope(FUNC_Main, inout, 1, 1);"]
-		]Append[Fold[_Consts JS Release[?, ?, ?, p], "", constants]]
-		]Append[
-	"
-	print_mem_info(manager);
-	print_live_object_types(manager);
-	
-#ifdef ENABLE_PROFILING
-	for (idx = 0; idx < END; ++idx)
-	{
-		if(profile_counts[idx])
-			printf(\"Func: %d\tCount: %llu\tTime: %llu\tAvg: %f\tSelf: %llu\tAvg: %f\tNested Count: %llu\\n\", idx, profile_counts[idx], profile_totals[idx], ((double)profile_totals[idx])/((double)profile_counts[idx]), profile_selftotals[idx], ((double)profile_selftotals[idx])/((double)profile_counts[idx]), profile_nestedcounts[idx]);
-	}
-#endif
-	if (!numret)
-		return 0;
-	if (numret < 0)
-		return numret;
-	if (get_blueprint(inout[0])->type_id == TYPE_INT32)
-		return ((t_Int32 *)inout[0])->Num;
-
-	rhope(FUNC_If, inout, 1, 2);
-	if (inout[0])
-		return 0;
-	return 1;
-}\n\n"]
+var args = f_List()[0];
+for (var i in arguments) {
+	args = args.f_Append(make_String(arguments[i]))[0];
+}
+f_Main(args);"]
 
 }
 
--- a/number_c.rhope	Wed Nov 10 22:29:49 2010 -0500
+++ b/number_c.rhope	Sun Nov 14 03:09:49 2010 -0500
@@ -118,10 +118,8 @@
 }
 		
 Generate Number Methods[backend:out]
-{	
-	numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")
-	
-	out <- Fold[_Generate Number Methods[?], backend, numtypes]
+{
+	out <- Fold[_Generate Number Methods[?], backend, [backend]Supported Number Types]
 }
 
 Register Number Method[program, method, type, outtype:out]
--- a/nworker_c.rhope	Wed Nov 10 22:29:49 2010 -0500
+++ b/nworker_c.rhope	Sun Nov 14 03:09:49 2010 -0500
@@ -1,4 +1,3 @@
-Import cbackend_c.rhope
 Import number_c.rhope
 Import boolean.rhope
 
@@ -1353,8 +1352,10 @@
 	}
 }
 
-Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out]
+Make Special@NBlueprint[bp,backend,info,bp name:out]
 {
+	func name <- [info]Index[0]
+	pop worker <- [info]Index[1]
 	func <- [[backend]Create Function[func name,("obj"),(),"cdecl"]
 		]Set Input Type[Type Instance[bp name], 0]
 	out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]]
@@ -1434,18 +1435,13 @@
 
 Compile Special@NBlueprint[bp,backend,name:out]
 {
-	init name <- [" init "]Append[name]
-	[("Array","Boxed Array","Worker")]Find[=[?,name]]
-	{
-		after copyclean <- Val[backend]
-	}{		
-		copy name <- [" copy "]Append[name]
-		cleanup name <- [" cleanup "]Append[name]
-		after copyclean <- [bp]Make Special[
-					[bp]Make Special[backend, copy name, name, Make Copy[?]], 
-				cleanup name, name, Make Cleanup[?]]
-	}
-	out <- Fold[Getters Setters[?, ?, name], [bp]Make Special[after copyclean, init name, name, Make Init[?]], [bp]Fields >>]
+	makespecial <- [[[Dictionary[]	
+		]Set["init", Make Init[?]]
+		]Set["copy", Make Copy[?]]
+		]Set["cleanup", Make Cleanup[?]]
+		
+	after specials <- Fold[[bp]Make Special[?, ?, name], backend, [backend]Needed Specials[name,makespecial]]
+	out <- Fold[Getters Setters[?, ?, name], after specials, [bp]Fields >>]
 }
 
 Blueprint NProgram