Refactored all OP_ functions to vm/CATEGORY/ and renamed the files.
This commit is contained in:
parent
108be8c41e
commit
50a91d0b6f
67 changed files with 91 additions and 92 deletions
13
src/vm/strings/find.c
Normal file
13
src/vm/strings/find.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
case OP_FIND: {
|
||||
Value needle = pop_value(vm);
|
||||
Value hay = pop_value(vm);
|
||||
if (hay.type != VAL_STRING || needle.type != VAL_STRING) {
|
||||
fprintf(stderr, "Runtime type error: FIND expects (string, string)\n");
|
||||
exit(1);
|
||||
}
|
||||
int idx = bi_find(&hay, &needle);
|
||||
free_value(hay);
|
||||
free_value(needle);
|
||||
push_value(vm, make_int(idx));
|
||||
break;
|
||||
}
|
||||
13
src/vm/strings/split.c
Normal file
13
src/vm/strings/split.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
case OP_SPLIT: {
|
||||
Value sep = pop_value(vm);
|
||||
Value str = pop_value(vm);
|
||||
if (str.type != VAL_STRING || sep.type != VAL_STRING) {
|
||||
fprintf(stderr, "Runtime type error: SPLIT expects (string, string)\n");
|
||||
exit(1);
|
||||
}
|
||||
Value out = bi_split(&str, &sep);
|
||||
free_value(str);
|
||||
free_value(sep);
|
||||
push_value(vm, out);
|
||||
break;
|
||||
}
|
||||
15
src/vm/strings/substr.c
Normal file
15
src/vm/strings/substr.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
case OP_SUBSTR: {
|
||||
Value lenv = pop_value(vm);
|
||||
Value startv = pop_value(vm);
|
||||
Value str = pop_value(vm);
|
||||
if (str.type != VAL_STRING || startv.type != VAL_INT || lenv.type != VAL_INT) {
|
||||
fprintf(stderr, "Runtime type error: SUBSTR expects (string, int, int)\n");
|
||||
exit(1);
|
||||
}
|
||||
Value out = bi_substr(&str, (int)startv.i, (int)lenv.i);
|
||||
free_value(str);
|
||||
free_value(startv);
|
||||
free_value(lenv);
|
||||
push_value(vm, out);
|
||||
break;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue