9front - general discussion about 9front
 help / color / mirror / Atom feed
From: mia soweli <inbox@tachibana-labs.org>
To: 9front@9front.org
Subject: [9front] [PATCH] libaml: implement ConcatRes and Mid opcodes.
Date: Sat, 20 May 2023 01:04:26 +0000	[thread overview]
Message-ID: <E41FB9E77B9A1092F95B86824855A4DA@tachibana-labs.org> (raw)


ConcatRes concatenates two resources, and appends the end tag.
Mid takes the substring of a string or buffer.
---
diff 4c533e7c453a5b48b1bb4088f2f7fdb6df6a48c2 f27164167a90a7bc8613375a2d90f2438625518b
--- a/sys/src/libaml/aml.c
+++ b/sys/src/libaml/aml.c
@@ -150,7 +150,7 @@
 	Oindex, Omatch, Omutex, Oevent,
 	Ocfld, Ocfld0, Ocfld1, Ocfld2, Ocfld4, Ocfld8,
 	Oif, Oelse, Owhile, Obreak, Oret, Ocall, 
-	Ostore, Oderef, Ootype, Osize, Oref, Ocref, Ocat,
+	Ostore, Oderef, Ootype, Osize, Oref, Ocref, Ocat, Ocatr, Omid,
 	Oacq, Osignal, Orel, Ostall, Osleep, Oload, Ounload,
 	Otodec, Otohex, Otoint, Otostr,
 };
@@ -1711,6 +1711,66 @@
 }
 
 static void*
+evalcatres(void)
+{
+	void *r, *a, *b;
+	int n, m;
+	uchar c[2];
+
+	a = FP->arg[0];
+	b = FP->arg[1];
+	if(a == nil)
+		a = copy('b', a);
+	if(b == nil)
+		b = copy('b', b);
+	if(TAG(a) != 'b' || TAG(b) != 'b')
+		return nil;
+
+	n = SIZE(a);
+	m = SIZE(b);
+	r = mk('b', n + m + 2);
+	memmove(r, a, n);
+	memmove((uchar*)r + n, b, m);
+
+	c[0] = ResEnd;
+	c[1] = 0;
+	memmove((uchar*)r + n + m, c, 2);
+
+	store(r, FP->arg[2]);
+	return r;
+}
+
+static void*
+evalmid(void)
+{
+	void *r, *a;
+	int n, m;
+
+	a = FP->arg[1];
+	n = ival(FP->arg[1]);
+	m = ival(FP->arg[2]);
+	if(a == nil)
+		a = copy('b', a);
+
+	switch(TAG(a)) {
+	default:
+		return nil; /* botch */
+	case 's':
+	case 'b':
+		if(n > SIZE(a))
+			n = SIZE(a);
+		if((n + m) > SIZE(a))
+			m = SIZE(a) - n;
+
+		r = mk(TAG(a), m); memmove(r, (uchar*)a + n, m);
+		break;
+	}
+
+	store(r, FP->arg[3]);
+	return r;
+}
+
+static void*
 evalindex(void)
 {
 	Field *f;
@@ -2150,6 +2210,8 @@
 	[Ocref]		"CondRefOf",		"@@",		evalcondref,
 	[Oderef]	"DerefOf",		"@",		evalderef,
 	[Ocat]		"Concatenate",		"**@",		evalcat,
+	[Ocatr]		"ConcatenateRes",	"***",		evalcatres,
+	[Omid]		"Mid",				"*ii@",		evalmid,
 
 	[Oacq]		"Acquire",		"@2",		evalnop,
 	[Osignal]	"Signal",		"@",		evalnop,
@@ -2182,10 +2244,10 @@
 /* 68 */	Oenv,	Oenv,	Oenv,	Oenv,	Oenv,	Oenv,	Oenv,	Obad,
 /* 70 */	Ostore,	Oref,	Oadd,	Ocat,	Osub,	Oinc,	Odec,	Omul,
 /* 78 */	Odiv,	Oshl,	Oshr,	Oand,	Onand,	Oor,	Onor,	Oxor,
-/* 80 */	Onot,	Olbit,	Orbit,	Oderef,	Obad,	Omod,	Obad,	Osize,
+/* 80 */	Onot,	Olbit,	Orbit,	Oderef,	Ocatr,	Omod,	Obad,	Osize,
 /* 88 */	Oindex,	Omatch,	Ocfld4,	Ocfld2,	Ocfld1,	Ocfld0,	Ootype,	Ocfld8,
 /* 90 */	Oland,	Olor,	Olnot,	Oleq,	Olgt,	Ollt,	Obad,	Otodec,
-/* 98 */	Otohex,	Otoint,	Obad,	Obad,	Otostr,	Obad,	Obad,	Obad,
+/* 98 */	Otohex,	Otoint,	Obad,	Obad,	Otostr,	Obad,	Omid,	Obad,
 /* A0 */	Oif,	Oelse,	Owhile,	Onop,	Oret,	Obreak,	Obad,	Obad,
 /* A8 */	Obad,	Obad,	Obad,	Obad,	Obad,	Obad,	Obad,	Obad,
 /* B0 */	Obad,	Obad,	Obad,	Obad,	Obad,	Obad,	Obad,	Obad,

                 reply	other threads:[~2023-05-21 13:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E41FB9E77B9A1092F95B86824855A4DA@tachibana-labs.org \
    --to=inbox@tachibana-labs.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).