Mercurial > repos > rhope
view runtime/builtin.c @ 44:a7c79ac22efc
Beginning of basic type inference
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 31 Oct 2009 21:28:28 -0400 |
parents | 640f541e9116 |
children | a24eb366195c d2f9b0a9403d |
line wrap: on
line source
#include "builtin.h" #include "object.h" #include "integer.h" #include "bool.h" #include <stddef.h> #include <stdio.h> void register_builtin_type(uint32_t type) { blueprint * bp; switch(type) { case TYPE_INT32: bp = register_type_byid(TYPE_INT32, sizeof(int32_t), NULL, NULL, NULL); add_method(bp, METHOD_ADD, MethodName(_PL_,Int32)); add_method(bp, METHOD_SUB, MethodName(_MN_,Int32)); add_method(bp, METHOD_MUL, MethodName(_TM_,Int32)); add_method(bp, METHOD_DIV, MethodName(_DV_,Int32)); add_method(bp, METHOD_LSHIFT, MethodName(LShift,Int32)); add_method(bp, METHOD_RSHIFT, MethodName(RShift,Int32)); add_method(bp, METHOD_LESS, MethodName(_LT_,Int32)); add_method(bp, METHOD_GREATER, MethodName(_GT_,Int32)); break; case TYPE_BOOLEAN: bp = register_type_byid(TYPE_BOOLEAN, sizeof(int32_t), NULL, NULL, NULL); add_method(bp, METHOD_IF, MethodName(If,Boolean)); val_yes = (t_Boolean *)new_object(TYPE_BOOLEAN); val_yes->val = 1; val_no = (t_Boolean *)new_object(TYPE_BOOLEAN); val_no->val = 0; break; case TYPE_BLUEPRINT: bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL); break; } } void register_builtin_types() { uint32_t i; for(i = 0; i < TYPE_FIRST_USER; ++i) register_builtin_type(i); } //TODO: Remove this when it's possible to write Print in Rhope FuncNoLocals(Print, NumParams 1, CallSpace 0) if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32)) { printf("%d\n", ((t_Int32 *)(cdata->params[0]))->num); } else { puts("Don't know how to print this type"); } release_ref(cdata->params[0]); Ret(0, make_Int32(0)) EndFunc