Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
regex_match.c File Reference

VM opcode snippet for OP_REGEX_MATCH (POSIX full-match). More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 if (str.type !=VAL_STRING||pattern.type !=VAL_STRING)
 free_value (pattern)
 free_value (str)
 push_value (vm, make_int(truth))

Variables

case OP_REGEX_MATCH
Value str = pop_value(vm)
int truth = 0
 break

Detailed Description

VM opcode snippet for OP_REGEX_MATCH (POSIX full-match).

This opcode checks whether a regular expression pattern matches the entire input string. It uses POSIX regex APIs on UNIX platforms and provides a graceful fallback elsewhere.

Behavior (stack effects):

  • Pops: pattern (string), input (string)
  • Pushes: result (int) — 1 if the pattern matches the whole input string, 0 otherwise. On invalid regex, returns 0.

Platform notes:

  • On non-UNIX platforms (no POSIX regex available), this opcode returns 0 without error.

Errors:

  • If operands are not strings, the VM prints a runtime type error and exits.

Example:

  • pattern = "[a-z]+", input = "hello" -> 1
  • pattern = "[a-z]+", input = "hello!" -> 0 (not a full match)

Definition in file regex_match.c.

Function Documentation

◆ free_value() [1/2]

free_value ( pattern )

◆ free_value() [2/2]

free_value ( str )

◆ if()

if ( str.type ! = VAL_STRING || pattern.type != VAL_STRING)

Definition at line 43 of file regex_match.c.

◆ push_value()

push_value ( vm ,
make_int(truth)  )

Variable Documentation

◆ break

break

Definition at line 53 of file regex_match.c.

◆ OP_REGEX_MATCH

case OP_REGEX_MATCH

Definition at line 40 of file regex_match.c.

◆ str

Value str = pop_value(vm)

Definition at line 42 of file regex_match.c.

◆ truth

int truth = 0

Definition at line 50 of file regex_match.c.