Skip to content

Commit 1c2b4a8

Browse files
authored
Fix missing __UPPER & __LOWER intrinsics. (#174)
- fix: fixed `to-upper` and `to-lower` prelude functions broken since 0.2
1 parent 68c4785 commit 1c2b4a8

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

harness/test/016_string_fns.eu

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ checks4: {
5353
trues: [ip-components = ["192", "168", "0", "1"]]
5454
}
5555

56-
pass: checks.trues ++ checks2.trues ++ checks3.trues ++ checks4.trues all-true?
56+
case-tests: {
57+
α: "hello" str.to-upper //= "HELLO"
58+
β: "GOODBYE" str.to-lower //= "goodbye"
59+
}
5760

58-
RESULT: if(pass, :PASS, :FAIL)
61+
RESULT: checks.trues ++ checks2.trues ++ checks3.trues ++ checks4.trues ++ (case-tests values)
62+
all-true?
63+
then(:PASS, :FAIL)

src/eval/stg/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ pub fn make_standard_runtime(source_map: &mut SourceMap) -> Box<runtime::Standar
106106
rt.add(Box::new(string::Fmt));
107107
rt.add(Box::new(string::Letters));
108108
rt.add(Box::new(string::Dq));
109+
rt.add(Box::new(string::Upper));
110+
rt.add(Box::new(string::Lower));
109111
rt.add(Box::new(force::SeqStrList));
110112
rt.add(Box::new(meta::Meta));
111113
rt.add(Box::new(meta::WithMeta));

src/eval/stg/string.rs

+40
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,43 @@ impl StgIntrinsic for Dq {
450450
}
451451

452452
impl CallGlobal0 for Dq {}
453+
454+
/// __UPPER(s) - convert to upper case
455+
pub struct Upper;
456+
457+
impl StgIntrinsic for Upper {
458+
fn name(&self) -> &str {
459+
"UPPER"
460+
}
461+
462+
fn execute<'guard>(
463+
&self,
464+
machine: &mut dyn IntrinsicMachine,
465+
view: MutatorHeapView<'guard>,
466+
_emitter: &mut dyn Emitter,
467+
args: &[Ref],
468+
) -> Result<(), ExecutionError> {
469+
let string = str_arg(machine, view, &args[0])?;
470+
machine_return_str(machine, view, string.to_uppercase())
471+
}
472+
}
473+
474+
/// __LOWER(s) - convert to lower case
475+
pub struct Lower;
476+
477+
impl StgIntrinsic for Lower {
478+
fn name(&self) -> &str {
479+
"LOWER"
480+
}
481+
482+
fn execute<'guard>(
483+
&self,
484+
machine: &mut dyn IntrinsicMachine,
485+
view: MutatorHeapView<'guard>,
486+
_emitter: &mut dyn Emitter,
487+
args: &[Ref],
488+
) -> Result<(), ExecutionError> {
489+
let string = str_arg(machine, view, &args[0])?;
490+
machine_return_str(machine, view, string.to_lowercase())
491+
}
492+
}

0 commit comments

Comments
 (0)