Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
cast.c File Reference

Implements the OP_CAST opcode for converting a value to a target type. More...

Go to the source code of this file.

Functions

 if (tn)
 if (!tn)
else if (strcmp(target, "number")==0)
else if (strcmp(target, "string")==0)
else if (strcmp(target, "array")==0)
else if (strcmp(target, "map")==0)
else if (strcmp(target, "nil")==0)
else if (strcmp(target, "function")==0)
else if (strcmp(target, "boolean")==0)
 free_value (t)
 free_value (v)
 push_value (vm, out)

Variables

case OP_CAST
Value v = pop_value(vm)
const char * tn = (t.type == VAL_STRING && t.s) ? t.s : NULL
Value out = make_nil()
char target [32] = '\0'
int k = 0
 else
 break

Detailed Description

Implements the OP_CAST opcode for converting a value to a target type.

Stack contract:

  • Pops: typeName (String), value (any)
  • Pushes: converted value (or Nil on unsupported target)

Definition in file cast.c.

Function Documentation

◆ free_value() [1/2]

free_value(t)

◆ free_value() [2/2]

free_value(v)

◆ if() [1/9]

if(!tn)

Definition at line 40 of file cast.c.

Here is the call graph for this function:

◆ if() [2/9]

else if(strcmp(target, "array") = = 0)

Definition at line 65 of file cast.c.

◆ if() [3/9]

else if(strcmp(target, "boolean") = = 0)

Definition at line 83 of file cast.c.

◆ if() [4/9]

else if(strcmp(target, "function") = = 0)

Definition at line 81 of file cast.c.

◆ if() [5/9]

else if(strcmp(target, "map") = = 0)

Definition at line 73 of file cast.c.

◆ if() [6/9]

else if(strcmp(target, "nil") = = 0)

Definition at line 79 of file cast.c.

◆ if() [7/9]

else if(strcmp(target, "number") = = 0)

Definition at line 42 of file cast.c.

◆ if() [8/9]

else if(strcmp(target, "string") = = 0)

Definition at line 61 of file cast.c.

◆ if() [9/9]

if(tn)

Definition at line 30 of file cast.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ break

break

Definition at line 92 of file cast.c.

◆ else

else
Initial value:
{
Value out
Definition apop.c:38
Value make_nil(void)
Construct a nil Value.
Definition value.c:126

Definition at line 85 of file cast.c.

◆ k

int k = 0

Definition at line 29 of file cast.c.

◆ OP_CAST

case OP_CAST

Definition at line 19 of file cast.c.

◆ out

Value out = make_nil()

Definition at line 25 of file cast.c.

◆ target

target[k] = '\0'

Definition at line 28 of file cast.c.

◆ tn

const char* tn = (t.type == VAL_STRING && t.s) ? t.s : NULL

Definition at line 24 of file cast.c.

◆ v

Value v = pop_value(vm)

Definition at line 22 of file cast.c.