Mercurial > repos > rhope
diff cbackend.rhope @ 48:a24eb366195c
Fixed some bugs introduced in previous commit and moved definition of integer methods out of runtime and into the compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 02 Mar 2010 00:18:49 -0500 |
parents | aabda74c7a88 |
children | 3e20ed8959c4 |
line wrap: on
line diff
--- a/cbackend.rhope Tue Dec 22 01:22:09 2009 -0500 +++ b/cbackend.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -1,5 +1,6 @@ Import extendlib.rhope -Import backendutils.rhope +Import backendutils.rhope +Import number.rhope Blueprint Blueprint Def { @@ -11,7 +12,7 @@ Blueprint Def[name] { - out <- [[[[Build["Blueprint Def"]]Name <<[name]]Fixed Size <<[0]]Fields <<[()]]Methods <<[New@Dictionary[]] + out <- [[[[Build["Blueprint Def"]]Name <<[name]]Fixed Size <<[0]]Fields <<[()]]Methods <<[Dictionary[]] } Blueprint C Method Registry @@ -22,7 +23,7 @@ C Method Registry[:out] { - builtins <- [[[[[[[[[[[[[New@Dictionary[] + builtins <- [[[[[[[[[[[[[Dictionary[] ]Set["+", "METHOD_ADD"] ]Set["-", "METHOD_SUB"] ]Set["/", "METHOD_DIV"] @@ -65,7 +66,7 @@ C Field Registry[:out] { - out <- [[Build["C Field Registry"]]Lookup <<[New@Dictionary[]]]Next ID<<[1] + out <- [[Build["C Field Registry"]]Lookup <<[Dictionary[]]]Next ID<<[1] } @@ -280,7 +281,7 @@ C Type Registry[:out] { out <- [[[Build["C Type Registry"]]Lookup << [ - [[[[[[[[[[[[[[[[New@Dictionary[] + [[[[[[[[[[[[[[[[Dictionary[] ]Set["UInt8", "TYPE_UINT8"] ]Set["UInt16", "TYPE_UINT16"] ]Set["UInt32", "TYPE_UINT32"] @@ -289,7 +290,7 @@ ]Set["Int16", "TYPE_INT16"] ]Set["Int32", "TYPE_INT32"] ]Set["Int64", "TYPE_INT64"] - ]Set["Yes No", "TYPE_BOOLEAN"] + ]Set["Boolean", "TYPE_BOOLEAN"] ]Set["Float32", "TYPE_FLOAT32"] ]Set["Float64", "TYPE_FLOAT64"] ]Set["Real Number", "TYPE_FLOAT64"] @@ -297,7 +298,7 @@ ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] - ]Definitions << [New@Dictionary[]] + ]Definitions << [Dictionary[]] ]Next ID <<[0] } @@ -325,8 +326,14 @@ { name <- [def]Name >> [[reg]Lookup >>]Index[name] - { - out <- reg + { + [[reg]Definitions >>]Index[name] + { + out <- reg + }{ + Print[["Registered def for "]Append[name]] + out <- [reg]Definitions <<[[[reg]Definitions >>]Set[name, def]] + } }{ out <- [[[reg]Lookup <<[ [[reg]Lookup >>]Set[name, ["TYPE_FIRST_USER+"]Append[[reg]Next ID >>]] ] ]Definitions <<[ [[reg]Definitions >>]Set[name, def] ] @@ -346,6 +353,8 @@ { Print["found type"] yep,nope <- If[[[[~]Fields >>]Length] = [1]] + }{ + Pretty Print[reg, ""] } } @@ -377,12 +386,12 @@ ]Inputs <<[inputs] ]Outputs <<[outputs] ]Convention <<[convention] - ]Variables <<[New@Dictionary[]] + ]Variables <<[Dictionary[]] ]Statements <<[()] ]Method Registry <<[registry] ]Field Registry <<[field reg] ]Type Registry <<[type reg] - ]Constants <<[New@Dictionary[]] + ]Constants <<[Dictionary[]] ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] } @@ -447,6 +456,46 @@ Divide@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," / "] +} + +DoLShift@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," << "] +} + +DoRShift@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," >> "] +} + +CompLess@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," < "] +} + +CompGreater@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," > "] +} + +CompEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," == "] +} + +CompLessEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," <= "] +} + +CompGreaterEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," >= "] +} + +CompNotEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," != "] } Move@C Function[func,psource,pdest:out] @@ -497,9 +546,14 @@ type <- [[func]Input Types >>]Index[~] }{ type <- [[func]Variables >>]Index[var] {} - { - //Does it make sense for us to do this? - type <- Type Instance["Any Type"] + { + [[func]Outputs >>]Find[var] + { + type <- [[func]Output Types >>]Index[~] + }{ + //Does it make sense for us to do this? + type <- Type Instance["Any Type"] + } } } }{ @@ -832,7 +886,7 @@ C Program[:out] { - out <- [[[[Build["C Program"]]Functions <<[New@Dictionary[]]]Method Registry <<[C Method Registry[]]]Type Registry <<[C Type Registry[]]]Field Registry <<[C Field Registry[]] + out <- [[[[Build["C Program"]]Functions <<[Dictionary[]]]Method Registry <<[C Method Registry[]]]Type Registry <<[C Type Registry[]]]Field Registry <<[C Field Registry[]] } Register Type@C Program[program,def:out] @@ -918,7 +972,7 @@ Text@C Program[program:out] { Print["Text@C Program"] - constants <- Fold["Combine Consts", New@Dictionary[], [program]Functions >>] + constants <- Fold["Combine Consts", Dictionary[], [program]Functions >>] headers <- "#include <stdio.h> #include \"builtin.h\" #include \"object.h\" @@ -934,7 +988,7 @@ Fold["_Defs C Program", "", [program]Functions >>], constants ], [program]Functions >>]] - ]Append["int main(int argc, char **argv) + ]Append["#include \"builtin.c\"\n\nint main(int argc, char **argv) { returntype ret; calldata *cdata;