From 46a57335a40cd5ef21d2235a7c35d2a9a8a5d07c Mon Sep 17 00:00:00 2001 From: Murangwa Pacifique <96472682+pacifiquem@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:26:57 +0200 Subject: [PATCH] feat: allowed `injiza_amakuru()` to have multiple args (#88) --- src/runtime/globals.ts | 4 ++-- src/runtime/print.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/runtime/globals.ts b/src/runtime/globals.ts index a9e10ce..541da11 100644 --- a/src/runtime/globals.ts +++ b/src/runtime/globals.ts @@ -19,7 +19,7 @@ import { ObjectVal, } from './values'; import Environment from './environment'; -import { printValues } from './print'; +import { makeValues, printValues } from './print'; import moment from 'moment'; import { readFileSync, @@ -75,7 +75,7 @@ export function createGlobalEnv(filename: string): Environment { const MIN_ARGS_LENGTH = 1; if (args.length < MIN_ARGS_LENGTH) LogError('injiza_amakuru expects at least one argument'); - const cmd = (args[0] as StringVal).value; + const cmd = makeValues(args).value; try { const result = prompt()(cmd); diff --git a/src/runtime/print.ts b/src/runtime/print.ts index ffa5259..61ff412 100644 --- a/src/runtime/print.ts +++ b/src/runtime/print.ts @@ -10,6 +10,7 @@ import { BooleanVal, ObjectVal, FunctionValue, + MK_STRING, } from './values'; import { LogMessage } from '../lib/log'; @@ -23,6 +24,16 @@ export function printValues(args: Array) { LogMessage(output); } +// Utility for injiza_amakuru(), helps injiza_amakuru() to have multiple arguments +export function makeValues(args: Array) { + let output = ''; + for (let i = 0; i < args.length; i++) { + const arg = args[i]; + output += matchType(arg); + } + return MK_STRING(output); +} + export function matchType(arg: RuntimeVal) { switch (arg.type) { case 'string':