Mercurial > repos > rhope
comparison runtime/builtin.c @ 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 | 640f541e9116 |
children | 689fb73e7612 |
comparison
equal
deleted
inserted
replaced
47:6202b866d72c | 48:a24eb366195c |
---|---|
8 void register_builtin_type(uint32_t type) | 8 void register_builtin_type(uint32_t type) |
9 { | 9 { |
10 blueprint * bp; | 10 blueprint * bp; |
11 switch(type) | 11 switch(type) |
12 { | 12 { |
13 case TYPE_INT32: | |
14 bp = register_type_byid(TYPE_INT32, sizeof(int32_t), NULL, NULL, NULL); | |
15 add_method(bp, METHOD_ADD, MethodName(_PL_,Int32)); | |
16 add_method(bp, METHOD_SUB, MethodName(_MN_,Int32)); | |
17 add_method(bp, METHOD_MUL, MethodName(_TM_,Int32)); | |
18 add_method(bp, METHOD_DIV, MethodName(_DV_,Int32)); | |
19 add_method(bp, METHOD_LSHIFT, MethodName(LShift,Int32)); | |
20 add_method(bp, METHOD_RSHIFT, MethodName(RShift,Int32)); | |
21 add_method(bp, METHOD_LESS, MethodName(_LT_,Int32)); | |
22 add_method(bp, METHOD_GREATER, MethodName(_GT_,Int32)); | |
23 break; | |
24 case TYPE_BOOLEAN: | |
25 bp = register_type_byid(TYPE_BOOLEAN, sizeof(int32_t), NULL, NULL, NULL); | |
26 add_method(bp, METHOD_IF, MethodName(If,Boolean)); | |
27 val_yes = (t_Boolean *)new_object(TYPE_BOOLEAN); | |
28 val_yes->val = 1; | |
29 val_no = (t_Boolean *)new_object(TYPE_BOOLEAN); | |
30 val_no->val = 0; | |
31 break; | |
32 case TYPE_BLUEPRINT: | 13 case TYPE_BLUEPRINT: |
33 bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL); | 14 bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL); |
34 break; | 15 break; |
35 } | 16 } |
36 } | 17 } |
47 NumParams 1, | 28 NumParams 1, |
48 CallSpace 0) | 29 CallSpace 0) |
49 | 30 |
50 if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32)) | 31 if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32)) |
51 { | 32 { |
52 printf("%d\n", ((t_Int32 *)(cdata->params[0]))->num); | 33 printf("%d\n", ((t_Int32 *)(cdata->params[0]))->Num); |
53 } else { | 34 } else { |
54 puts("Don't know how to print this type"); | 35 puts("Don't know how to print this type"); |
55 } | 36 } |
56 release_ref(cdata->params[0]); | 37 release_ref(cdata->params[0]); |
57 Ret(0, make_Int32(0)) | 38 Ret(0, make_Int32(0)) |
58 EndFunc | 39 EndFunc |
40 object * make_Int32(int32_t val) | |
41 { | |
42 t_Int32 * obj; | |
43 object * ret = new_object(TYPE_INT32); | |
44 obj = (t_Int32 *)ret; | |
45 obj->Num = val; | |
46 return ret; | |
47 } | |
48 | |
49 #define lval ((t_Boolean *)(cdata->params[0]))->Val | |
50 | |
51 MethodNoLocals(If,Boolean, | |
52 NumParams 1, | |
53 CallSpace 1) | |
54 | |
55 Param(0, TYPE_BOOLEAN) | |
56 | |
57 if(lval) | |
58 { | |
59 Ret(1, NULL) | |
60 } else { | |
61 Ret(1, cdata->params[0]); | |
62 Ret(0, NULL) | |
63 } | |
64 EndFunc | |
65 | |
66 |