5afe8e3f26 2010-11-13 kinaba: @@type = fun(x){ 5afe8e3f26 2010-11-13 kinaba: if( _isint(x) ) { "int" } 5afe8e3f26 2010-11-13 kinaba: else { if( _isstr(x) ) { "str" } 5afe8e3f26 2010-11-13 kinaba: else { if( _isfun(x) ) { x } 5afe8e3f26 2010-11-13 kinaba: else { if( _isundefined(x) ) { "undefined" } 5afe8e3f26 2010-11-13 kinaba: else { "any" }}}} 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: def binop(a,b,c) { 5afe8e3f26 2010-11-13 kinaba: fun(x,y){@v( 5afe8e3f26 2010-11-13 kinaba: if( @type(x)=="undefined" || @type(y)=="undefined" ) { "undefined" } else { 5afe8e3f26 2010-11-13 kinaba: if( @type(x)==a && @type(y)==b ) { c } else { "error" } 5afe8e3f26 2010-11-13 kinaba: } 5afe8e3f26 2010-11-13 kinaba: )} 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: @type "+" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type "-" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type "<" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type ">" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: def mergeType(a,b) { 5afe8e3f26 2010-11-13 kinaba: if( a == "undefined" ) { if(b=="undefined"){"error"}else{b} } else { a } 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: @type "if" = fun(c,t,e) {@v( 5afe8e3f26 2010-11-13 kinaba: if(@type(c)=="int" ) { mergeType(@type(t()), @type(e())) } else { "error" } 5afe8e3f26 2010-11-13 kinaba: )};