Datatype byte and print function
This commit is contained in:
parent
3f05fa5141
commit
4fae5d63a6
6 changed files with 42 additions and 15 deletions
|
@ -74,6 +74,8 @@ int BuiltinFunction_Plus(CallFrame* top_frame)
|
|||
break;
|
||||
case VALUETYPE_OBJECT:
|
||||
return EXIT_FAILURE;
|
||||
case VALUETYPE_BYTE:
|
||||
return v1.get.byte + v2.get.byte;
|
||||
}
|
||||
|
||||
top_frame->instruction_pointer++;
|
||||
|
@ -109,6 +111,8 @@ int BuiltinFunction_Multiply(CallFrame* top_frame)
|
|||
break;
|
||||
case VALUETYPE_OBJECT:
|
||||
return EXIT_FAILURE;
|
||||
case VALUETYPE_BYTE:
|
||||
return v1.get.byte * v2.get.byte;
|
||||
}
|
||||
|
||||
top_frame->instruction_pointer++;
|
||||
|
@ -144,14 +148,15 @@ int BuiltinFunction_Minus(CallFrame* top_frame)
|
|||
break;
|
||||
case VALUETYPE_OBJECT:
|
||||
return EXIT_FAILURE;
|
||||
case VALUETYPE_BYTE:
|
||||
return v1.get.byte - v2.get.byte;
|
||||
}
|
||||
|
||||
top_frame->instruction_pointer++;
|
||||
return CallFrame_StackPush(top_frame, &result);
|
||||
}
|
||||
|
||||
|
||||
int BuiltinFunction_PrintLine(CallFrame* top_frame)
|
||||
int BuiltinFunction_Print(CallFrame* top_frame)
|
||||
{
|
||||
Value v1;
|
||||
|
||||
|
@ -161,34 +166,47 @@ int BuiltinFunction_PrintLine(CallFrame* top_frame)
|
|||
|
||||
switch (v1.type) {
|
||||
case VALUETYPE_INT64:
|
||||
printf("%" PRIi64 "\n", v1.get.i64);
|
||||
printf("%" PRIi64, v1.get.i64);
|
||||
break;
|
||||
case VALUETYPE_DOUBLE:
|
||||
printf("%f\n", v1.get.f64);
|
||||
printf("%f", v1.get.f64);
|
||||
break;
|
||||
case VALUETYPE_BOOLEAN:
|
||||
if (v1.get.boolean) {
|
||||
printf("true\n");
|
||||
printf("true");
|
||||
} else {
|
||||
printf("false\n");
|
||||
printf("false");
|
||||
}
|
||||
break;
|
||||
case VALUETYPE_OBJECT:
|
||||
if (v1.get.object != NULL) {
|
||||
StringView type_name_view = v1.get.object->type->name;
|
||||
char type_name[type_name_view.length];
|
||||
type_name[type_name_view.length] = '\0';
|
||||
StringView_Paste(type_name, type_name_view);
|
||||
printf("object (%s) at %p\n", type_name, (void*) v1.get.object);
|
||||
if (v1.get.object != NULL) {
|
||||
StringView type_name_view = v1.get.object->type->name;
|
||||
char type_name[type_name_view.length];
|
||||
type_name[type_name_view.length] = '\0';
|
||||
StringView_Paste(type_name, type_name_view);
|
||||
printf("object (%s) at %p\n", type_name, (void*) v1.get.object);
|
||||
} else {
|
||||
puts("null");
|
||||
}
|
||||
break;
|
||||
case VALUETYPE_BYTE:
|
||||
printf("%c", v1.get.byte);
|
||||
break;
|
||||
} else {
|
||||
puts("null");
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int BuiltinFunction_PrintLine(CallFrame* top_frame)
|
||||
{
|
||||
if (BuiltinFunction_Print(top_frame)) {
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
puts("");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int BuiltinFunction_Duplicate(CallFrame* top_frame)
|
||||
{
|
||||
Value v1;
|
||||
|
|
|
@ -28,6 +28,7 @@ int BuiltinFunction_Minus(CallFrame* top_frame);
|
|||
int BuiltinFunction_Plus(CallFrame* top_frame);
|
||||
int BuiltinFunction_Multiply(CallFrame* top_frame);
|
||||
int BuiltinFunction_Equality(CallFrame* top_frame);
|
||||
int BuiltinFunction_Print(CallFrame* top_frame);
|
||||
int BuiltinFunction_PrintLine(CallFrame* top_frame);
|
||||
int BuiltinFunction_Duplicate(CallFrame* top_frame);
|
||||
|
||||
|
|
|
@ -20,12 +20,14 @@ static FlupFunctionAlternative* FlupFunctionAlternative_Malloc(size_t condition_
|
|||
const char* standard_builtin_names[] = {
|
||||
"println",
|
||||
"duplicate",
|
||||
"print",
|
||||
NULL
|
||||
};
|
||||
|
||||
const BuiltinFunction standard_builtin_functions[] = {
|
||||
BuiltinFunction_PrintLine,
|
||||
BuiltinFunction_Duplicate,
|
||||
BuiltinFunction_Print,
|
||||
};
|
||||
|
||||
int Interpreter_Create(Interpreter* self, DynamicArray* tokens)
|
||||
|
|
|
@ -28,6 +28,7 @@ union ValueContent {
|
|||
int64_t i64;
|
||||
double f64;
|
||||
bool boolean;
|
||||
uint8_t byte;
|
||||
Object* object;
|
||||
};
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ bool Value_IsTruthy(Value* v)
|
|||
return v->get.boolean;
|
||||
case VALUETYPE_OBJECT:
|
||||
return v->get.object != NULL;
|
||||
case VALUETYPE_BYTE:
|
||||
return v->get.byte != '\0';
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -48,6 +50,8 @@ bool Value_Equal(Value* v1, Value* v2)
|
|||
return v1->get.boolean == v2->get.boolean;
|
||||
case VALUETYPE_OBJECT:
|
||||
return v1->get.object == v2->get.object;
|
||||
case VALUETYPE_BYTE:
|
||||
return v1->get.byte == v2->get.byte;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "../submodules/utilitiec/src/StringView/StringView.h"
|
||||
|
||||
enum ValueType {
|
||||
VALUETYPE_BYTE,
|
||||
VALUETYPE_INT64,
|
||||
VALUETYPE_DOUBLE,
|
||||
VALUETYPE_OBJECT,
|
||||
|
|
Loading…
Reference in a new issue