LINUX.ORG.RU

Ищу компактный язык для скриптования

 ,


1

1

Где «компактный» есть язык, минимальный набор пакетов для выполнения которого в Debian займёт мегабайт пять. Задача – в гитлабовском пайплайне обойти кучу файлов, распарсить и выплюнуть шаблонизированный отчёт, в идеале на манер Mustache.

Перл и питон не хочу. Круто, если найдётся что-нибудь лисповое, хотя не уверен, что кроме GNU CLISP что-то вообще есть.

Искаробочные в Debian, если есть, ещё круче, но емнип, того же Guile там нет.

★★★★

Последнее исправление: Princesska (всего исправлений: 1)

Ответ на: комментарий от Princesska

Вы просите малый и удобный язык, да ещё и для обработки и вывода текста - луа лучший вариант.

AKonia ★★
()
Последнее исправление: AKonia (всего исправлений: 1)

Круто, если найдётся что-нибудь лисповое, хотя не уверен, что кроме GNU CLISP что-то вообще есть.

Ну, Guile

Zubok ★★★★★
()
Ответ на: комментарий от Zubok

А сколько там нужно будет качать? Или он из коробки? Есть возможность как-то через браузер посмотреть, сколько места сожрёт дебиановский пакет? А то у меня шляпа.

Princesska ★★★★
() автор топика

mruby https://github.com/mruby/mruby

5 лет назад собранный бинарник интерпретатора без дополнительных вшитых библиотек в пожатом виде весил 300Кб, а обвешанный - 700. Кроме интепретатора можно собирать бинари, или вместо скриптов запускать сгенерированный байткод.

Встраивается тоже без проблем.

Без проблем работал на i386, amd64, mipsel, mips64.

OSBuster
()
Последнее исправление: OSBuster (всего исправлений: 1)

Искаробочные в Debian, если есть, ещё круче, но емнип, того же Guile там нет.

$ aptitude search guile
[...]
i   guile-2.0    - GNU extension language and Scheme interpreter
[...]
Zubok ★★★★★
()
Последнее исправление: Zubok (всего исправлений: 1)
Ответ на: комментарий от Princesska

Здесь i значит, что он установлен?

У меня да.

Zubok ★★★★★
()
Ответ на: комментарий от anonymous

метапрог awk-овый + TXR-ный

https://stackoverflow.com/questions/41684176/metaprogramming-in-awk-convert-file-to-html-table-format/43440063#43440063

ассемблер на awk

http://doc.cat-v.org/henry_spencer/amazing_awk_assembler/ http://doc.cat-v.org/henry_spencer/amazing_awk_assembler/aaa.tar.gz

https://ia802309.us.archive.org/25/items/pdfy-MgN0H1joIoDVoIC7/The_AWK_Programming_Language.pdf

Chapter 6 is about «little languages,» that is, specialized languages that focus on a narrow domain. Awk is convenient for writing small translators because its basic operations support many of the lexical and table-management tasks encountered in translation. The chapter includes an assembler, a graphics language, and several calculators.

ещё есть

https://github.com/phillbush/legv8

, там тоже какой-то ассемблер на awk

по легенде, ещё была какая-то реализация ассемблера на awk от основателей – Кена Томпсона или Брайана Кернигана ъ awk

но так сходу эту реализацию чего-то не найду.

Ken Thomson on Unix

• I allocated a week each to the operating system, the shell, the editor, and the assembler… Yeh, essentially one person for a month.

• If I had to do it over again? Hmm… I guess I’d spell ‘creat’ with ‘create’

via

computing at cern

anonymous
()
Ответ на: комментарий от anonymous

Chapter 6 is about «little languages,» that is, specialized languages that focus on a narrow domain. Awk is convenient for writing small translators because its basic operations support many of the lexical and table-management tasks encountered in translation. The chapter includes an assembler, a graphics language, and several calculators.

гы, там простой ассемблер

TABLE 6-1. AssEMBLY-LANGUAGE INSTRUCTIONS

0PCODEINSTRUCTION MEANING
001get read a number from the input into the accumulator
01get read a number from the input into the accumulator
02put write the contents of the accumulator to the output
03ld M load accumulator with contents of memory location M
04st M store contents of accumulator in location M
05add M add contents of location M to accumulator
06sub M subtract contents of location Mfrom accumulator
07jpos M jump to location M if accumulator is positive
08jz M jump to location M is accumulator is zero
09j M jump to location M
10halt stop execution
const cassembler pseudo-operation to define a constant c
An assembly-language program is a sequence of statements, each consisting
of three fields: label, operation, and operand. Any field may be empty; labels
must begin in column one. A program may also contain comments like those in
awk programs. Here is a sample assembly-language program that prints the
sum of a sequence of integers; the end of the input is marked by a zero.

SECTION 6.1 AN ASSEMBLER AND INTERPRETER 

# print sum of input numbers (terminated by zero)
ld zero # initialize sum to zero
st sum
loop get # read a number
jz done # no more input if number is zero
add sum # add in accumulated sum
st sum # store new value back in sum
j loop # go back and read another number
done ld sum # print sum
put
halt
zero const 0
sum const

The target program resulting from translating this program into machine
language is a sequence of integers that represents the contents of memory when
the target program is ready to be run. For this program, memory looks like
this:
0: 03010 ld zero # initialize sum to zero
1: 04011 st sum
2: 01000 loop get # read a number
3: 08007 jz done # no more input if number is zero
4: 05011 add sum # add in accumulated sum
5: 04011 st sum # store new value back in sum
6: 09002 j loop # go back and read another number
7: 03011 done ld sum # print sum
8: 02000 put
9: 10000 halt
10: 00000 zero canst 0
11: 00000 sum const
# asm - assembler and interpreter for simple computer
# usage: awk -f asm program-file data-files ••.
BEGIN {
srcfile = ARGV[1]
ARGV[ 1] = '"' # remaining
tempfile = "asm.temp"
files are data
n = split{"const get put
for {i = 1; i <= n; i++)
ld st add sub jpos jz j halt", x)
# create table of op codes
op[x[i]] = i-1
# ASSEMBLER PASS
FS = "[ \t]+"
while {getline <srcfile > 0) {
sub{/#.•/, "") #strip comments
symtab[$1] = nextmem #remember label location
if {$2 I= "") { # save op, addr if present
print S2 "\t" $3 >tempfile
nextmem++
}
}
close{tempfile)
# ASSEMBLER PASS 2
nextmem = 0
0) {
# if symbolic addr,
# replace by numeric value
while (getline <tempfile >
if ($2 I• /A[0-9]•$/)
$2 = symtab[$2]
mem[nextmem++] = 1000 * op[$1] + $2 # pack into word
# INTERPRETER
for {pc = 0; pc >= 0; ) {
addr = mem[pc] % 1000
code = int(mem[pc++] I 1000)
if (code -- op[ "get"]) { getline ace
else if {code -- op[ "put"]) { print ace }
else if {code -- op[ "st"]) { mem[addr] = ace }
else if (code -- op["ld"]) { ace = mem[addr] }
else if {code -- op[ "add"]) { ace += mem[addr] }
else if (code == op["sub"]) { ace -= mem[addr] }
else if (code -- op["jpos"]) { if (ace > 0) pc = addr
else if (code -- op["jz"]) { if (ace == 0) pc = addr
else if (code == op["j"]) { pc = addr }
else if (code -- op[ "halt"]) { pc = -1 }
else { pc = -1 }
}
anonymous
()
Ответ на: комментарий от anonymous

fixed ocr text layer copy/paste typos

# asm - assembler and interpreter for simple computer
# usage: awk -f asm program-file data-files ...

BEGIN {
	srcfile = ARGV[1]
	ARGV[ 1] = "" # remaining files are data
	tempfile = "asm.temp"
	n = split("const get put ld st add sub jpos jz j halt", x)
	for {i = 1; i <= n; i++) # create table of op codes
	op[x[i]] = i-1
	
# ASSEMBLER PASS 1
	FS = "[ \t]+"
	while (getline <srcfile > 0) {
		sub(/#.*/, "") 		#strip comments
		symtab[$1] = nextmem 	#remember label location
		if ($2 != "") { # save op, addr if present
		print $2 "\t" $3 >tempfile
		nextmem++
		}
	}
	close(tempfile)

# ASSEMBLER PASS 2
	nextmem = 0
	while (getline <tempfile > 0) {
	if ($2 !~ /^[0-9]*$/)	# if symbolic addr,
	$2 = symtab[$2]		# replace by numeric value
	mem[nextmem++] = 1000 * op[$1] + $2 # pack into word

# INTERPRETER
	for (pc = 0; pc >= 0; ) {
		addr = mem[pc] % 1000
		code = int(mem[pc++] / 1000)
		if (code == op["get"]) { getline acc }
		else if (code == op["put"]) { print acc }
		else if (code == op["st"]) { mem[addr] = acc }
		else if (code == op["ld"]) { acc = mem[addr] }
		else if (code == op["add"]) { acc += mem[addr] }
		else if (code == op["sub"]) { acc -= mem[addr] }
		else if (code == op["jpos"]) { if (acc > 0) pc = addr
		else if (code == op["jz"]) { if (acc == 0) pc = addr
		else if (code == op["j"]) { pc = addr }
		else if (code == op[ "halt"]) { pc = -1 }
		else { pc = -1 }
	}
}
anonymous
()
Ответ на: fixed ocr text layer copy/paste typos от anonymous
# asm - assembler and interpreter for simple computer
# usage: awk -f asm program-file data-files ...

BEGIN {
	srcfile = ARGV[1]
	ARGV[1] = "" # remaining files are data
	tempfile = "asm.temp"
	n = split("const get put ld st add sub jpos jz j halt", x)
	for (i = 1; i <= n; i++) # create table of op codes
	op[x[i]] = i-1
	
# ASSEMBLER PASS 1
	FS = "[ \t]+"
	while (getline <srcfile > 0) {
		sub(/#.*/, "") 		#strip comments
		symtab[$1] = nextmem 	#remember label location
		if ($2 != "") { # save op, addr if present
		print $2 "\t" $3 >tempfile
		nextmem++
		}
	}
	close(tempfile)

# ASSEMBLER PASS 2
	nextmem = 0
	while (getline <tempfile > 0) {
	if ($2 !~ /^[0-9]*$/)	# if symbolic addr,
	$2 = symtab[$2]		# replace by numeric value
	mem[nextmem++] = 1000 * op[$1] + $2 # pack into word
}

# INTERPRETER
	for (pc = 0; pc >= 0; ) {
		addr = mem[pc] % 1000
		code = int(mem[pc++] / 1000)
		if (code == op["get"]) { getline acc }
		else if (code == op["put"]) { print acc }
		else if (code == op["st"]) { mem[addr] = acc }
		else if (code == op["ld"]) { acc = mem[addr] }
		else if (code == op["add"]) { acc += mem[addr] }
		else if (code == op["sub"]) { acc -= mem[addr] }
		else if (code == op["jpos"]) { if (acc > 0) pc = addr
		else if (code == op["jz"]) { if (acc == 0) pc = addr
		else if (code == op["j"]) { pc = addr }
		else if (code == op[ "halt"]) { pc = -1 }
		else { pc = -1 }
	}
}	
anonymous
()
Ответ на: комментарий от anonymous
# asm - assembler and interpreter for simple computer
# usage: awk -f asm program-file data-files ...

BEGIN {
	srcfile = ARGV[1]
	ARGV[1] = "" # remaining files are data
	tempfile = "asm.temp"
	n = split("const get put ld st add sub jpos jz j halt", x)
	for (i = 1; i <= n; i++) # create table of op codes
	op[x[i]] = i-1
	
# ASSEMBLER PASS 1
	FS = "[ \t]+"
	while (getline <srcfile > 0) {
		sub(/#.*/, "") 		#strip comments
		symtab[$1] = nextmem 	#remember label location
		if ($2 != "") { # save op, addr if present
		print $2 "\t" $3 >tempfile
		nextmem++
		}
	}
	close(tempfile)

# ASSEMBLER PASS 2
	nextmem = 0
	while (getline <tempfile > 0) {
	if ($2 !~ /^[0-9]*$/)	# if symbolic addr,
	$2 = symtab[$2]		# replace by numeric value
	mem[nextmem++] = 1000 * op[$1] + $2 # pack into word
}

# INTERPRETER
	for (pc = 0; pc >= 0; ) {
		addr = mem[pc] % 1000
		code = int(mem[pc++] / 1000)
		if (code == op["get"]) { getline acc }
		else if (code == op["put"]) { print acc }
		else if (code == op["st"]) { mem[addr] = acc }
		else if (code == op["ld"]) { acc = mem[addr] }
		else if (code == op["add"]) { acc += mem[addr] }
		else if (code == op["sub"]) { acc -= mem[addr] }
		else if (code == op["jpos"]) { if (acc > 0) pc = addr }
		else if (code == op["jz"]) { if (acc == 0) pc = addr }
		else if (code == op["j"]) { pc = addr }
		else if (code == op[ "halt"]) { pc = -1 }
		else { pc = -1 }
	}
}
anonymous
()
Ответ на: комментарий от anonymous

это был Керниган.

Jon Bentley and John Dallen «Exercises in software design»

https://s3.amazonaws.com/ieeecs.cdn.csdl.content/trans/ts/1987/11/01702163.pdf

Assemblers of this complexity used to be standard fare in «systems programming» courses; they taught several important lessons, including lexical analysis, symbol tables, and multiple-pass algorithms. They also taught how to organize a large program (as a college junior, one of us wrote an assembler and interpreter for a similar machine in about 1000 lines of ALGOLW).

A Monday lecture described the assembler and the target machine; the assignment due Wednesday was to implement them both in the simplest possible code (we encouraged the cadets to concentrate on correct inputs and ignore issues of error handling). Our implementation of the assembler and the interpreter required 30 lines of AWK; the cadets took under 50 lines. (The emphasis on small size was a response to ornate solutions to previous problems.) In Wednesday’s class, we discussed the students’ solutions, reviewed our program, and presented a larger program (80 lines) with thorough error checking. On a Friday field trip to Bell Labs, Brian Kernighan described to the cadets how he used similar techniques to build a microcode assembler in AWK for a special-purpose simulation machine.

anonymous
()

micropython

anonymous
()

вагон.

quickjs, lua, Oberon(script), scheme, tcl, postscript - да блин хватит троллить?!

ps. go(lang) как ни странно - в сборке без батареек оно таки да

qulinxao3
()
Последнее исправление: qulinxao3 (всего исправлений: 1)

обойти кучу файлов, распарсить и выплюнуть шаблонизированный отчёт

Ну если Practical Extraction and Report Language не подходит по религиозным соображениям, то…

что-нибудь лисповое

Бабашка.

https://github.com/babashka/babashka

Nervous ★★★★★
()
Последнее исправление: Nervous (всего исправлений: 1)
Ответ на: комментарий от Nervous

Точно, совсем про неё забыл. Очень годный вариант.

Princesska ★★★★
() автор топика

PicoLisp, NewLISP

anonymous
()

плюсую за то чтобы написать это на go. Парсить файлы, готовить шаблоны, деплоиться на сервер - оно прямо создано для этого. Плюс в получившемся коде будет очень просто разобраться другим, в отличие от лиспового непонятно чего

Lrrr ★★★★★
()
Ответ на: комментарий от Princesska

достаточно существования подходящего язычка под ваши\наши критерии

итак?

qulinxao3
()
Ответ на: комментарий от Princesska

Жирновато будет.

qjs же худой и няшный.

Tanger ★★★★★
()

мегабайт пять гитлабовском

А почему такое ограничение для гитлаба?

in_dance
()

Что такое «гитлабовский пайплайн»?

Vlad-76 ★★★★
()
Ответ на: комментарий от Princesska

Жирновато будет

QuickJS вполне компактно.

Круто, если найдётся что-нибудь лисповое

picolisp

Искаробочные в Debian

tinyscheme

no-such-file ★★★★★
()

Brainfuck уже предлагали?

Dog ★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.