release winning entries of IOCCC28 under the year 2024

Congratulations to:

* 2024/anders - Prize in sound coding - layered music generator
* 2024/burton - Prize in pentagrammatology - wordle hard mode solver
* 2024/cable1 - Prize in bot talk - LLM inference engine
* 2024/cable2 - Prize in murky waters - salmon recipe
* 2024/carlini - Prize in perfect timing - Intel 4004 emulation
* 2024/codemeow - Prize in tray planting - bonsai generator
* 2024/endoh1 - Prize in patient pointillism - slow ray tracer in CPP
* 2024/endoh2 - Prize in solid body physics - rotating rigid body simulation
* 2024/ferguson1 - Prize in diabolical logistics - Oregon trail pact with the devil
* 2024/ferguson2 - Prize in yil-tas - Navajo code talker translator
* 2024/howe - Nice accent eh-ward - mini vi
* 2024/kramer - Prize in linguistic arithmetic - natural language numerical calculator
* 2024/kurdyukov1 - Prize in phased periodicity - phase of the Moon
* 2024/kurdyukov2 - Prize in art restoration - JPEG artifact removal
* 2024/kurdyukov3 - Prize in virtual quietus - gaming VM and doom
* 2024/kurdyukov4 - Prize in embiggening - encode without literals
* 2024/maffiodo - Prize in creative interpretation - Jav\*script interpreter
* 2024/mills - Prize in ℤ₃ - Infocom v3 story interpreter
* 2024/stedolan - Best one liner - icon from MD5
* 2024/straadt - Prize in imitative rebooting - OpenRISC CPU and Linux
* 2024/tmarrec - Prize in cyclonic coding - 3D tornado simulation
* 2024/tompng - Prize in quasi bijection - vortex encryptor decryptor
* 2024/weaver - Sur prize - rickroll

Ran `make update` to perform the above.
 	new file:   2024/burton/.entry.json
This commit is contained in:
Landon Curt Noll committed 2025-08-02 14:43:07 -07:00
1 parent 10512e6c79
commit 09750f8899
443 files changed
+182938 -231

No files matched your search

+169
View File
@@ -0,0 +1,169 @@
{
"no_comment" : "mandatory comment: because comments were removed from the original JSON spec",
"entry_JSON_format_version" : "1.2 2024-09-25",
"award" : "Prize in creative interpretation",
"year" : 2024,
"dir" : "maffiodo",
"entry_id" : "2024_maffiodo",
"title" : "js25",
"abstract" : "Jav*script interpreter",
"author_set" : [
{
"author_handle" : "Sandro_Maffiodo"
}
],
"manifest" : [
{
"file_path" : "prog.c",
"inventory_order" : 20,
"OK_to_edit" : true,
"display_as" : "c",
"display_via_github" : true,
"entry_text" : "entry source code"
},
{
"file_path" : "Makefile",
"inventory_order" : 30,
"OK_to_edit" : true,
"display_as" : "makefile",
"display_via_github" : true,
"entry_text" : "entry Makefile"
},
{
"file_path" : "prog.orig.c",
"inventory_order" : 50,
"OK_to_edit" : false,
"display_as" : "c",
"display_via_github" : true,
"entry_text" : "original source code"
},
{
"file_path" : "array.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript array test"
},
{
"file_path" : "console.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript console implementation"
},
{
"file_path" : "fibo.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript fibonacci test"
},
{
"file_path" : "gc.png",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "image",
"display_via_github" : true,
"entry_text" : "garbage Collector actions inside internal tests"
},
{
"file_path" : "math.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript math test"
},
{
"file_path" : "string.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript forrest test"
},
{
"file_path" : "test.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript test setup"
},
{
"file_path" : "try.sh",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "shellscript",
"display_via_github" : true,
"entry_text" : "script to try entry"
},
{
"file_path" : "utils.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "javascript utility test"
},
{
"file_path" : "verify.js",
"inventory_order" : 100,
"OK_to_edit" : true,
"display_as" : "javascript",
"display_via_github" : true,
"entry_text" : "verify javascript test execution"
},
{
"file_path" : "2024_maffiodo.tar.bz2",
"inventory_order" : 1415926535,
"OK_to_edit" : false,
"display_as" : "tbz2",
"display_via_github" : false,
"entry_text" : "download entry tarball"
},
{
"file_path" : ".entry.json",
"inventory_order" : 4000000000,
"OK_to_edit" : true,
"display_as" : "json",
"display_via_github" : true,
"entry_text" : "entry summary and manifest in JSON"
},
{
"file_path" : ".gitignore",
"inventory_order" : 4000000000,
"OK_to_edit" : true,
"display_as" : "gitignore",
"display_via_github" : true,
"entry_text" : "list of files that should not be committed under git"
},
{
"file_path" : ".path",
"inventory_order" : 4000000000,
"OK_to_edit" : false,
"display_as" : "path",
"display_via_github" : false,
"entry_text" : "directory path from top level directory"
},
{
"file_path" : "README.md",
"inventory_order" : 4000000000,
"OK_to_edit" : true,
"display_as" : "markdown",
"display_via_github" : true,
"entry_text" : "markdown source for this web page"
},
{
"file_path" : "index.html",
"inventory_order" : 4294967295,
"OK_to_edit" : false,
"display_as" : "html",
"display_via_github" : false,
"entry_text" : "this web page"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
#
# sort with: ../../bin/sgi.sh
*~
*.dSYM
*.o
.DS_Store
.*.swp
+1
View File
@@ -0,0 +1 @@
2024/maffiodo
Binary file not shown.
+219
View File
@@ -0,0 +1,219 @@
#!/usr/bin/env make
#
# 2024/maffiodo
#############################
# shell used by this Makefile
#############################
SHELL= bash
#######################
# common tool locations
#######################
include ../../var.mk
#####################
# C compiler settings
#####################
# Common C compiler warnings to silence
#
# Example: CSILENCE= -Wno-poison-system-directories
#
CSILENCE= -Wno-deprecated-non-prototype -Wno-implicit-int \
-Wno-incompatible-function-pointer-types -Wno-parentheses \
-Wno-strict-prototypes -Wno-unused-variable -Wno-return-type \
-Wno-misleading-indentation -Wno-incompatible-pointer-types \
-Wno-maybe-uninitialized
# Attempt to silence unknown warning options
#
CUNKNOWN= -Wno-unknown-warning-option
# Common C compiler warning flags
#
# NOTE: The addition of -pedantic to CWARN is a challenge that
# You may wish to avoid if it proves too problematic.
# There is NO penalty for removing -pedantic from CWARN.
#
CWARN= -Wall -Wextra -pedantic ${CSILENCE} ${CUNKNOWN}
# Compiler standard
#
CSTD= -std=gnu17
# Compiler bit architecture
#
# Example for 32-bitness: ARCH= -m32
# Example for 64-bitness: ARCH= -m64
#
# NOTE: Normally one should NOT specify a specific architecture.
#
ARCH=
# Defines that are needed to compile
#
# Example: -Dfoo -Dbar=baz
#
CDEFINE=
# Include files that are needed to compile
#
# Example: CINCLUDE= -include stdio.h
#
CINCLUDE= -include stdio.h -include string.h -include stdlib.h -include ctype.h
# Other flags to pass to the C compiler
#
# Example: COTHER= -fno-math-errno
#
COTHER=
# Optimization
#
# NOTE: Feel free to change the level of compiler optimization.
# The "-O3" is just a friendly default you might wish to try.
#
# Example: OPT= -O0 -g
#
OPT= -O3
# Default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${COTHER} ${OPT}
# Libraries needed to build
#
# Example: LDFLAGS= -lncurses -lm
#
LDFLAGS=
# C compiler to use
#
# NOTE: The IOCCC Judges recommend you leave CC as just "cc"
# and NOT set it to clang, or gcc, or something else
# unless you have a STRONG reason to do so.
#
# Setting CC to something other than "cc" makes your
# code less portable to those who do not have your
# particular C compiler. **hint**
#
# If you want to test your code with a particular C compiler,
# use the make command line. For example:
#
# make all CC=clang
# make all CC=gcc
#
CC= cc
# Compiler add-ons or replacements for clang only
#
ifeq "$(findstring $(CLANG),${CC})" "$(CLANG)"
#
# NOTE: This code is only invoked when CC is "clang"
# such as when you use the make command line:
#
# make all CC=clang
#
CSILENCE+= -Wno-declaration-after-statement -Wno-deprecated-non-prototype \
-Wno-float-conversion -Wno-implicit-int -Wno-implicit-int-conversion \
-Wno-incompatible-function-pointer-types-strict -Wno-missing-prototypes \
-Wno-missing-variable-declarations -Wno-padded -Wno-parentheses \
-Wno-poison-system-directories -Wno-shadow -Wno-shorten-64-to-32 \
-Wno-sign-conversion -Wno-strict-prototypes -Wno-unused-variable \
-Wno-conditional-uninitialized -Wno-unsafe-buffer-usage
#
CWARN+= -Weverything
#
endif
# Specific add-ons or replacements for gcc only
#
ifeq "$(findstring $(GCC),${CC})" "$(GCC)"
#
# NOTE: This code is only invoked when CC is "gcc"
# such as when you use the make command line:
#
# make all CC=gcc
#
CSILENCE+=
#
CWARN+=
#
endif
###########################################
# Special Makefile variables for this entry
###########################################
ENTRY= prog
PROG= ${ENTRY}
#
OBJ= ${PROG}.o
TARGET= ${PROG}
#
ALT_OBJ=
ALT_TARGET=
# list any data files supplied with your submission
#
# Example: DATA= curds whey
#
DATA=
#################
# build the entry
#################
all: data ${TARGET}
@${TRUE}
.PHONY: all alt data everything clean clobber
# how to compile
#
${PROG}: ${PROG}.c
${CC} ${CFLAGS} ${PROG}.c -o $@ ${LDFLAGS}
# alternative executable
#
alt: data ${ALT_TARGET}
@${TRUE}
${PROG}.alt: ${PROG}.alt.c
${CC} ${CFLAGS} ${PROG}.alt.c -o $@ ${LDFLAGS}
# data files
#
data: ${DATA}
@${TRUE}
# both all and alt
#
everything: all alt
@${TRUE}
###############
# utility rules
###############
#
clean:
${RM} -f ${OBJ} ${ALT_OBJ}
clobber: clean
${RM} -f ${TARGET} ${ALT_TARGET}
${RM} -rf *.dSYM
######################################
# optional include of 1337 hacker rulz
######################################
-include 1337.mk ../1337.mk ../../1337.mk
File diff suppressed because it is too large. Load diff
+176
View File
@@ -0,0 +1,176 @@
var Array = {};
// at(array, index)
// return element at array index
Array.at = function () {
var array = arguments[0];
var index = arguments[1];
return array[index];
};
// join(array, separator)
// return a string there all array items has been concatenated using separator
Array.join = function () {
var array = arguments[0];
var separator = arguments[1];
var i = 0;
var o = '';
while (i < array.length) {
o += array[i];
if (i + 1 < array.length)
o += separator;
i += 1;
}
return o;
};
// push(array, item1..itemN)
// return the array element with item1..itemN added to it
Array.push = function () {
var array = arguments[0];
var j = array.length;
var i = 1;
while (i < arguments.length) {
//print("apush " + j + "\n");
array[j] = arguments[i];
i += 1;
j += 1;
}
return array;
};
// pop(array)
// return an object with the removed element and a new array
Array.pop = function () {
var array = arguments[0];
var i = 0;
var newArray = [];
var results = {};
var alen = array.length;
if (alen == 0) {
return results;
}
//print("alen-1 = " + (alen -1) + '\n');
var removed = array[alen - 1];
while (i < alen - 1) {
newArray[i] = array[i];
i += 1;
}
results.removed = removed;
results.new = newArray;
return results;
};
// concat(array1, array2)
// return a new array concatenation of array1 and array2
Array.concat = function () {
var array1 = arguments[0];
var array2 = arguments[1];
var i = 0;
var newArray = [];
while (i < array1.length) {
newArray[i] = array1[i];
i += 1;
}
var j = 0;
while (j < array2.length) {
newArray[i] = array2[j];
i += 1;
j += 1;
}
return newArray;
};
// slice(array, start, end)
// return a slice of the array from start to end
Array.slice = function () {
if (arguments.length < 2) {
return [];
}
var s = arguments[0];
var from = arguments[1];
var to;
if (arguments.length > 2) {
to = arguments[2];
//print("slice case0 " + to + '\n');
} else {
to = s.length;
}
var o = [];
var j = 0;
var i = from;
print("to=" + to + ", sl=" + s.length + "\n");
while (i < to && i < s.length) {
//print("slice loop [" + s[i] + "]\n");
o[j] = s[i];
j += 1;
i += 1;
}
return o;
};
// toString(array)
// return array join with comma
Array.toString = function () {
var array = arguments[0];
return Array.join(array, ',');
};
// filter(array, callback)
// return array elements where callback(item) return 1 (true)
Array.filter = function () {
var array = arguments[0];
var callback = arguments[1];
var i = 0;
var j = 0;
var out = [];
while (i < array.length) {
if (callback(array[i])) {
out[j] = array[i];
j += 1;
}
i += 1;
}
return out;
};
if (test) {
var a0 = [];
a0[0] = 123;
a0[1] = 'H2o';
var temp = a0[0 + 1];
print("temp: " + temp + '\n');
print(a0.length + '\n');
print(Array.join(a0, " , ") + '\n');
Array.push(a0, 1, 2, 3);
print(Array.join(a0, " ") + '\n');
print("pop tests\n");
var popResults = Array.pop(a0);
//print(popResults.length + '\n');
print(popResults.removed + '\n');
//print(popResults.new + '\n');
print(Array.join(popResults.new, " ") + '\n');
print("concat tests\n");
var ct = Array.concat(popResults.new, a0);
print(Array.toString(ct) + '\n');
print("slice tests\n");
print(Array.toString(Array.slice(ct, 0, 2)) + '\n');
print(Array.toString(Array.slice(ct, 5, 8)) + '\n');
print(Array.toString(Array.slice(ct, 5)) + '\n');
print("filter tests\n");
print(Array.toString(Array.filter(ct, function () {
return arguments[0] > 1;
})) + '\n');
var matrix = [];
matrix[0] = [];
matrix[0][0] = 1;
matrix[0][1] = 2;
matrix[0][2] = 3;
matrix[1] = [];
matrix[1][0] = 11;
matrix[1][1] = 12;
matrix[1][2] = 13;
print("matrix: \n" +
" " + Array.toString(matrix[0]) + '\n' +
" " + Array.toString(matrix[1]) + '\n');
}
+18
View File
@@ -0,0 +1,18 @@
var console = {};
console.log = function () {
var i = 0;
while (i < arguments.length) {
var arg = "" + arguments[i];
print(arg);
i += 1;
if (i == arguments.length) {
break;
}
print(' ');
}
print('\n');
};
if (test) {
console.log(123, "ABC", {}, []);
}
+16
View File
@@ -0,0 +1,16 @@
var number = 20,
n1 = 0,
n2 = 1,
i = 0,
nextTerm;
console.log('fibonacci series:');
while (i < number) {
console.log(i, '=', n1);
nextTerm = n1 + n2;
n1 = n2;
n2 = nextTerm;
i += 1;
}
console.log('end', n1);
Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

File diff suppressed because it is too large. Load diff
+43
View File
@@ -0,0 +1,43 @@
var Math = {};
Math.E = 2.718281828459045;
Math.e = Math.E;
Math.LN2 = 0.6931471805599453;
Math.LN10 = 2.302585092994046;
Math.LOG2E = 1.4426950408889634;
Math.LOG10E = 0.4342944819032518;
Math.phi = 1.618033988749895;
Math.PI = 3.141592653589793;
Math.pi = Math.PI;
Math.SQRT1_2 = 0.7071067811865476;
Math.SQRT2 = 1.4142135623730951;
Math.tau = 6.283185307179586;
Math.sign = function () {
var x = arguments[0];
//print("dbgsign?" + x + '\n');
if (x < 0) {
print("case0\n");
return -1;
}
return 1;
};
Math.abs = function () {
var x = arguments[0];
if (x < 0)
return -x;
return x;
};
if (test) {
print("pi = " + Math.pi + '\n');
print("sign(-32) = " + Math.sign(-32) + '\n');
print("abs(-32) = " + Math.abs(-32) + '\n');
}
+63
View File
@@ -0,0 +1,63 @@
#define a(x) } else p b(#x)){
#define I ; } else p i==j++){
#define c sprintf
#define o ->
#define p if(
#define t f++
#define s ( )
#define z x o
typedef struct d* e; struct d{ union{ char*f; double n; } ; char*g,h
,l,m; e e,x,b,q,( *r) s; int u; } ; e q,v; int y,(*w) s=strlen, (*A)
s=strcmp; char*B, *f,C, r=0, g[99], *(*D) s=strdup; e E(int m){ e x=
calloc(1, sizeof( struct d)); z b=v; z m=m; return v=x; } e F(e q) {
while(q){ p !A(g, q o g)){ return q; } q=q o b; } return 0; } e G(e*
q){ e x=E(4); z g=D(g) ; z b=*q; z x = E(0); return *q = x; } H s{ int x;
while((x=*f==47 & f[1] ==47) |isspace(*f)){ p x){ while(*f && *f!=10)t; }
else t; } } J s { H s; p*f)t; } K(char*K){ char*d=strchr(K,*f); return d?
d-K:-1; } L s{ return K(";)]") != -1; } M(char*x){
return!A(x,g); } b(char*x){ int u=w(x); p !strncmp
(x,f,u)&!isalnum(f[u])){ f+=u; return 1; } return 0; } N s{ int x=1; while(*f&&x
){ C=*t; x+=C-123?C-125?0:-1:1; } } double O(e x){ char*P; return z m&1?z n:z m&
2?strtod(z f,&P) :0; } e Q(e x){ e n=E(2); char*f="[object]",m=z m; p m&1){ c(g,
"%g",z n); f=g; } p m &2)f=z f; n o f=D(f); return n; } e R(int); S s{ return 95
==*f||isalnum(*f); } T s{ char*d=g; while(S s)*d++=*t; *d=0; } e U(int h){ int i
=0,j,n,P,V; double X,Y; char*d,b; e l,y, x=E(0),u; H s; p L s){ return x; } i=K(
"-+!~"); p i>-1){ t; } C=*f; p C==40){ t; x=U(0); J s; } else p C==91|C==123){ z
m=4; t; J s; } else p C==34|C==39){ d=g; t; z m=2; while(* f!=C){ char P=*t; p P
==92){ P=*t; P=P==110?10:P==120?strtol(f,&f,16):P; } *d++=P; } *d=0; t; z f=D(g)
; } else p isdigit(*f)){ z m=1; z n=strtod(f,&f); } else p S s){ int W=0; g:T s;
p M("function")){ J s; J s; J s; d=f-1; x=E(2); N s; z f=strndup(d,f-d); } else{
p M("var")){ t; W=1; goto g; } u=F(q); p W|!u)u=G (&q); x=u o x; z e=u; } } p i>
-1){ X=O(x); n=X; p j=0){ I X=-X I I X=!n I X=~n; } x=E (1); z n=X; } while(*f){
H s; p L s)break; i=K(",=!&|><-+*/%[(."); p i>-1){ b=*f; p i<h){ break; } int W=
0,k=0,h=0; t; p *f==61){ W=2; t; } else p *f==b){ h=1; t; } y=0; l=E(1); X=O(x);
double*Z=&l o n; char m=z m; n=X; p i<13){ y=U(i==12?0:i); Y=O(y); P=Y; } p j=0)
{ I l=y I p W){ V:p m==y o m){ p m&4)V=x!=y; else p m &1) goto O; else goto Q; }
else p (m|y o m)==2){ Q:V=A(Q(x) o f,Q(y) o f); } else{ O:V=X-Y; } i=k; p j=0) {
I V=V==0 I V=V>=0 I V=V<=0 I V=V>0 I V=V<0 I V=V!=0; } *Z=V; W=0; } else{ W=1; p
y o m&4){ l=y; } else{ l=E(y o m); l o r=y o r; p y o m&2)l o f=D(y o f); else l
o n=y o n; } } I k=5; goto V I*Z=h?n&&P : n &P I*Z=h?n||P:n|P I p h){ *Z=n>>P; }
else{ k=3-W; goto V; } I p h){ *Z=n<<P; } else{ k=4-W; goto V; } I*Z=X-Y I p (m|
y o m)&2){ e u=Q(x); y=Q(y); d=malloc(w(u o f)+w(y o f)+1); c(d,"%s%s",u o f,y o
f); l o m=2; l o f=d; } else{ *Z=X+Y; } I*Z=X*Y I*Z=X/Y I*Z=n%P I J s; p m&2){ c
(g,"%c",P<w (z f)?z f [P]:0); l o m=2; l o f=D (g); } else{ c(g,"%s",Q (y) o f);
goto q; } I c(g,"arguments"); e B=q,u=G(&q) o x; i=0; while(*f){ H s; y=U (1); p
!r){ c(g,"%d",i++); G(&u o q) o x=y; u o u++; } p *f==41)break; t; } t; i=r; p z
r){ p !r)l=z r(u o q); } else{ d=f; f=z f; l=R (0); f=d; } p !i){ r=i&~1; } q=B;
I H s; T s; p M("length")){ *Z=m&2?w(z f):z u; } else{ q:y=F(z q); p !y){ y=G(&z
q ); z u ++; } l=y o x; p !l o e)l o e = y; } } p W){ p !r){ l=z e o x=l; } else
continue; } x=l; } else t; } return x; } h(e x,e l,int b){ p x&&x !=l){ e u=z x;
z h=y; p u){ p u o h!=y)h(u,0,0); h(u o q,0,1); } h(z q,0,1); p b)h (z b,l,1); }
} _(e l){ y=1; h(v,l,1); y=0; h(q,0,1); e*B=&v,x=v; while(x){ e*b=&z b; p z h&!z
l){ *B=*b; p z m&2)free(z f); p z g)free(z g); free(x); } else{ z h=0; B=b; } x=
*b; } } e R(int h){ e x=E(0),y,l,d=q,u=v; while(*f){ H s; p *f==123){ t; p !r)x=
R(1); else N s; } else{ int u=0,d; p *f==125){ t; break; a(if)char*B; int P; u:d
=r; j:B=f; J s; l=U (0); J s; p !(int)l o n)r=4; P=r; y=R(0); p *f==59)t; p !P){
x=y; } H s; p u){ p !r&!P){ x=y; f=B; goto j; } else{ } a(else)r=(!P&!d)*4; P=r;
y=R(0); p !P){ x=y; } } r=u?d&~2:d|(r&3); a(while)u=1; goto u; a(return)y=U (0);
p !r){ x=y; r|=1; } a(break)p !r)r|=2; } else p *f){ y=U (0); p !r)x=y; J s; } }
p !h)break; } z l=1; z l=0; q=d; return x; } e ba(e x){ printf("%s",Q(z x) o f);
return E(0); } main s{ c(g,"print"); e x=G(&q); z m=2; z z r=ba; char u [1<<16];
B = f = u ; while ( ( C = getchar s ) > 0 ) * t = C ; * f = 0 ; f = B ; R (1); }
+63
View File
@@ -0,0 +1,63 @@
#define a(x) } else p b(#x)){
#define I ; } else p i==j++){
#define c sprintf
#define o ->
#define p if(
#define t f++
#define s ( )
#define z x o
typedef struct d* e; struct d{ union{ char*f; double n; } ; char*g,h
,l,m; e e,x,b,q,( *r) s; int u; } ; e q,v; int y,(*w) s=strlen, (*A)
s=strcmp; char*B, *f,C, r=0, g[99], *(*D) s=strdup; e E(int m){ e x=
calloc(1, sizeof( struct d)); z b=v; z m=m; return v=x; } e F(e q) {
while(q){ p !A(g, q o g)){ return q; } q=q o b; } return 0; } e G(e*
q){ e x=E(4); z g=D(g) ; z b=*q; z x = E(0); return *q = x; } H s{ int x;
while((x=*f==47 & f[1] ==47) |isspace(*f)){ p x){ while(*f && *f!=10)t; }
else t; } } J s { H s; p*f)t; } K(char*K){ char*d=strchr(K,*f); return d?
d-K:-1; } L s{ return K(";)]") != -1; } M(char*x){
return!A(x,g); } b(char*x){ int u=w(x); p !strncmp
(x,f,u)&!isalnum(f[u])){ f+=u; return 1; } return 0; } N s{ int x=1; while(*f&&x
){ C=*t; x+=C-123?C-125?0:-1:1; } } double O(e x){ char*P; return z m&1?z n:z m&
2?strtod(z f,&P) :0; } e Q(e x){ e n=E(2); char*f="[object]",m=z m; p m&1){ c(g,
"%g",z n); f=g; } p m &2)f=z f; n o f=D(f); return n; } e R(int); S s{ return 95
==*f||isalnum(*f); } T s{ char*d=g; while(S s)*d++=*t; *d=0; } e U(int h){ int i
=0,j,n,P,V; double X,Y; char*d,b; e l,y, x=E(0),u; H s; p L s){ return x; } i=K(
"-+!~"); p i>-1){ t; } C=*f; p C==40){ t; x=U(0); J s; } else p C==91|C==123){ z
m=4; t; J s; } else p C==34|C==39){ d=g; t; z m=2; while(* f!=C){ char P=*t; p P
==92){ P=*t; P=P==110?10:P==120?strtol(f,&f,16):P; } *d++=P; } *d=0; t; z f=D(g)
; } else p isdigit(*f)){ z m=1; z n=strtod(f,&f); } else p S s){ int W=0; g:T s;
p M("function")){ J s; J s; J s; d=f-1; x=E(2); N s; z f=strndup(d,f-d); } else{
p M("var")){ t; W=1; goto g; } u=F(q); p W|!u)u=G (&q); x=u o x; z e=u; } } p i>
-1){ X=O(x); n=X; p j=0){ I X=-X I I X=!n I X=~n; } x=E (1); z n=X; } while(*f){
H s; p L s)break; i=K(",=!&|><-+*/%[(."); p i>-1){ b=*f; p i<h){ break; } int W=
0,k=0,h=0; t; p *f==61){ W=2; t; } else p *f==b){ h=1; t; } y=0; l=E(1); X=O(x);
double*Z=&l o n; char m=z m; n=X; p i<13){ y=U(i==12?0:i); Y=O(y); P=Y; } p j=0)
{ I l=y I p W){ V:p m==y o m){ p m&4)V=x!=y; else p m &1) goto O; else goto Q; }
else p (m|y o m)==2){ Q:V=A(Q(x) o f,Q(y) o f); } else{ O:V=X-Y; } i=k; p j=0) {
I V=V==0 I V=V>=0 I V=V<=0 I V=V>0 I V=V<0 I V=V!=0; } *Z=V; W=0; } else{ W=1; p
y o m&4){ l=y; } else{ l=E(y o m); l o r=y o r; p y o m&2)l o f=D(y o f); else l
o n=y o n; } } I k=5; goto V I*Z=h?n&&P : n &P I*Z=h?n||P:n|P I p h){ *Z=n>>P; }
else{ k=3-W; goto V; } I p h){ *Z=n<<P; } else{ k=4-W; goto V; } I*Z=X-Y I p (m|
y o m)&2){ e u=Q(x); y=Q(y); d=malloc(w(u o f)+w(y o f)+1); c(d,"%s%s",u o f,y o
f); l o m=2; l o f=d; } else{ *Z=X+Y; } I*Z=X*Y I*Z=X/Y I*Z=n%P I J s; p m&2){ c
(g,"%c",P<w (z f)?z f [P]:0); l o m=2; l o f=D (g); } else{ c(g,"%s",Q (y) o f);
goto q; } I c(g,"arguments"); e B=q,u=G(&q) o x; i=0; while(*f){ H s; y=U (1); p
!r){ c(g,"%d",i++); G(&u o q) o x=y; u o u++; } p *f==41)break; t; } t; i=r; p z
r){ p !r)l=z r(u o q); } else{ d=f; f=z f; l=R (0); f=d; } p !i){ r=i&~1; } q=B;
I H s; T s; p M("length")){ *Z=m&2?w(z f):z u; } else{ q:y=F(z q); p !y){ y=G(&z
q ); z u ++; } l=y o x; p !l o e)l o e = y; } } p W){ p !r){ l=z e o x=l; } else
continue; } x=l; } else t; } return x; } h(e x,e l,int b){ p x&&x !=l){ e u=z x;
z h=y; p u){ p u o h!=y)h(u,0,0); h(u o q,0,1); } h(z q,0,1); p b)h (z b,l,1); }
} _(e l){ y=1; h(v,l,1); y=0; h(q,0,1); e*B=&v,x=v; while(x){ e*b=&z b; p z h&!z
l){ *B=*b; p z m&2)free(z f); p z g)free(z g); free(x); } else{ z h=0; B=b; } x=
*b; } } e R(int h){ e x=E(0),y,l,d=q,u=v; while(*f){ H s; p *f==123){ t; p !r)x=
R(1); else N s; } else{ int u=0,d; p *f==125){ t; break; a(if)char*B; int P; u:d
=r; j:B=f; J s; l=U (0); J s; p !(int)l o n)r=4; P=r; y=R(0); p *f==59)t; p !P){
x=y; } H s; p u){ p !r&!P){ x=y; f=B; goto j; } else{ } a(else)r=(!P&!d)*4; P=r;
y=R(0); p !P){ x=y; } } r=u?d&~2:d|(r&3); a(while)u=1; goto u; a(return)y=U (0);
p !r){ x=y; r|=1; } a(break)p !r)r|=2; } else p *f){ y=U (0); p !r)x=y; J s; } }
p !h)break; } z l=1; z l=0; q=d; return x; } e ba(e x){ printf("%s",Q(z x) o f);
return E(0); } main s{ c(g,"print"); e x=G(&q); z m=2; z z r=ba; char u [1<<16];
B = f = u ; while ( ( C = getchar s ) > 0 ) * t = C ; * f = 0 ; f = B ; R (1); }
+285
View File
@@ -0,0 +1,285 @@
var String = {};
// slice(string, from, to)
// return substring
String.slice = function () {
if (arguments.length < 2) {
return '';
}
var s = arguments[0];
var from = arguments[1];
var to;
if (arguments.length > 2) {
to = arguments[2];
//print("slice case0 " + to + '\n');
} else {
to = s.length;
}
var o = '';
var i = from;
while (i < to && i < s.length) {
//print("slice loop [" + s[i] + "]\n");
o += s[i];
i += 1;
}
return o;
};
// split(string, singleCharSeparator)
// return array of strings
String.split = function () {
var o = [];
var s = arguments[0];
var delimiter = arguments[1];
var start = 0;
var i = 0;
var oindex = 0;
while (i < s.length) {
if (s[i] == delimiter) {
o[oindex] = String.slice(s, start, i);
start = i + 1;
oindex += 1;
}
i += 1;
}
if (start < s.length) {
o[oindex] = String.slice(s, start);
}
return o;
};
// startsWith(s, prefix)
// return 1 if s starts with prefix substring
String.startsWith = function () {
var s = arguments[0];
var prefix = arguments[1];
return String.slice(s, 0, prefix.length) == prefix;
};
var _cm = {}; // map from character to ASCII code
_cm["\x00"] = 0; _cm["\x01"] = 1; _cm["\x02"] = 2; _cm["\x03"] = 3;
_cm["\x04"] = 4; _cm["\x05"] = 5; _cm["\x06"] = 6; _cm["\x07"] = 7;
_cm["\x08"] = 8; _cm["\x09"] = 9; _cm["\x0a"] = 10; _cm["\x0b"] = 11;
_cm["\x0c"] = 12; _cm["\x0d"] = 13; _cm["\x0e"] = 14; _cm["\x0f"] = 15;
_cm["\x10"] = 16; _cm["\x11"] = 17; _cm["\x12"] = 18; _cm["\x13"] = 19;
_cm["\x14"] = 20; _cm["\x15"] = 21; _cm["\x16"] = 22; _cm["\x17"] = 23;
_cm["\x18"] = 24; _cm["\x19"] = 25; _cm["\x1a"] = 26; _cm["\x1b"] = 27;
_cm["\x1c"] = 28; _cm["\x1d"] = 29; _cm["\x1e"] = 30; _cm["\x1f"] = 31;
_cm["\x20"] = 32; _cm[ "!"] = 33; _cm[ '"'] = 34; _cm[ "#"] = 35;
_cm[ "$"] = 36; _cm[ "%"] = 37; _cm[ "&"] = 38; _cm[ "'"] = 39;
_cm[ "("] = 40; _cm[ ")"] = 41; _cm[ "*"] = 42; _cm[ "+"] = 43;
_cm[ ","] = 44; _cm[ "-"] = 45; _cm[ "."] = 46; _cm[ "/"] = 47;
_cm[ "0"] = 48; _cm[ "1"] = 49; _cm[ "2"] = 50; _cm[ "3"] = 51;
_cm[ "4"] = 52; _cm[ "5"] = 53; _cm[ "6"] = 54; _cm[ "7"] = 55;
_cm[ "8"] = 56; _cm[ "9"] = 57; _cm[ ":"] = 58; _cm[ ";"] = 59;
_cm[ "<"] = 60; _cm[ "="] = 61; _cm[ ">"] = 62; _cm[ "?"] = 63;
_cm[ "@"] = 64; _cm[ "A"] = 65; _cm[ "B"] = 66; _cm[ "C"] = 67;
_cm[ "D"] = 68; _cm[ "E"] = 69; _cm[ "F"] = 70; _cm[ "G"] = 71;
_cm[ "H"] = 72; _cm[ "I"] = 73; _cm[ "J"] = 74; _cm[ "K"] = 75;
_cm[ "L"] = 76; _cm[ "M"] = 77; _cm[ "N"] = 78; _cm[ "O"] = 79;
_cm[ "P"] = 80; _cm[ "Q"] = 81; _cm[ "R"] = 82; _cm[ "S"] = 83;
_cm[ "T"] = 84; _cm[ "U"] = 85; _cm[ "V"] = 86; _cm[ "W"] = 87;
_cm[ "X"] = 88; _cm[ "Y"] = 89; _cm[ "Z"] = 90; _cm[ "["] = 91;
_cm[ "\\"] = 92; _cm[ "]"] = 93; _cm[ "^"] = 94; _cm[ "_"] = 95;
_cm[ "`"] = 96; _cm[ "a"] = 97; _cm[ "b"] = 98; _cm[ "c"] = 99;
_cm[ "d"] = 100; _cm[ "e"] = 101; _cm[ "f"] = 102; _cm[ "g"] = 103;
_cm[ "h"] = 104; _cm[ "i"] = 105; _cm[ "j"] = 106; _cm[ "k"] = 107;
_cm[ "l"] = 108; _cm[ "m"] = 109; _cm[ "n"] = 110; _cm[ "o"] = 111;
_cm[ "p"] = 112; _cm[ "q"] = 113; _cm[ "r"] = 114; _cm[ "s"] = 115;
_cm[ "t"] = 116; _cm[ "u"] = 117; _cm[ "v"] = 118; _cm[ "w"] = 119;
_cm[ "x"] = 120; _cm[ "y"] = 121; _cm[ "z"] = 122; _cm[ "{"] = 123;
_cm[ "|"] = 124; _cm[ "}"] = 125; _cm[ "~"] = 126; _cm["\x7f"] = 127;
_cm["\x80"] = 128; _cm["\x81"] = 129; _cm["\x82"] = 130; _cm["\x83"] = 131;
_cm["\x84"] = 132; _cm["\x85"] = 133; _cm["\x86"] = 134; _cm["\x87"] = 135;
_cm["\x88"] = 136; _cm["\x89"] = 137; _cm["\x8a"] = 138; _cm["\x8b"] = 139;
_cm["\x8c"] = 140; _cm["\x8d"] = 141; _cm["\x8e"] = 142; _cm["\x8f"] = 143;
_cm["\x90"] = 144; _cm["\x91"] = 145; _cm["\x92"] = 146; _cm["\x93"] = 147;
_cm["\x94"] = 148; _cm["\x95"] = 149; _cm["\x96"] = 150; _cm["\x97"] = 151;
_cm["\x98"] = 152; _cm["\x99"] = 153; _cm["\x9a"] = 154; _cm["\x9b"] = 155;
_cm["\x9c"] = 156; _cm["\x9d"] = 157; _cm["\x9e"] = 158; _cm["\x9f"] = 159;
_cm["\xa0"] = 160; _cm["\xa1"] = 161; _cm["\xa2"] = 162; _cm["\xa3"] = 163;
_cm["\xa4"] = 164; _cm["\xa5"] = 165; _cm["\xa6"] = 166; _cm["\xa7"] = 167;
_cm["\xa8"] = 168; _cm["\xa9"] = 169; _cm["\xaa"] = 170; _cm["\xab"] = 171;
_cm["\xac"] = 172; _cm["\xad"] = 173; _cm["\xae"] = 174; _cm["\xaf"] = 175;
_cm["\xb0"] = 176; _cm["\xb1"] = 177; _cm["\xb2"] = 178; _cm["\xb3"] = 179;
_cm["\xb4"] = 180; _cm["\xb5"] = 181; _cm["\xb6"] = 182; _cm["\xb7"] = 183;
_cm["\xb8"] = 184; _cm["\xb9"] = 185; _cm["\xba"] = 186; _cm["\xbb"] = 187;
_cm["\xbc"] = 188; _cm["\xbd"] = 189; _cm["\xbe"] = 190; _cm["\xbf"] = 191;
_cm["\xc0"] = 192; _cm["\xc1"] = 193; _cm["\xc2"] = 194; _cm["\xc3"] = 195;
_cm["\xc4"] = 196; _cm["\xc5"] = 197; _cm["\xc6"] = 198; _cm["\xc7"] = 199;
_cm["\xc8"] = 200; _cm["\xc9"] = 201; _cm["\xca"] = 202; _cm["\xcb"] = 203;
_cm["\xcc"] = 204; _cm["\xcd"] = 205; _cm["\xce"] = 206; _cm["\xcf"] = 207;
_cm["\xd0"] = 208; _cm["\xd1"] = 209; _cm["\xd2"] = 210; _cm["\xd3"] = 211;
_cm["\xd4"] = 212; _cm["\xd5"] = 213; _cm["\xd6"] = 214; _cm["\xd7"] = 215;
_cm["\xd8"] = 216; _cm["\xd9"] = 217; _cm["\xda"] = 218; _cm["\xdb"] = 219;
_cm["\xdc"] = 220; _cm["\xdd"] = 221; _cm["\xde"] = 222; _cm["\xdf"] = 223;
_cm["\xe0"] = 224; _cm["\xe1"] = 225; _cm["\xe2"] = 226; _cm["\xe3"] = 227;
_cm["\xe4"] = 228; _cm["\xe5"] = 229; _cm["\xe6"] = 230; _cm["\xe7"] = 231;
_cm["\xe8"] = 232; _cm["\xe9"] = 233; _cm["\xea"] = 234; _cm["\xeb"] = 235;
_cm["\xec"] = 236; _cm["\xed"] = 237; _cm["\xee"] = 238; _cm["\xef"] = 239;
_cm["\xf0"] = 240; _cm["\xf1"] = 241; _cm["\xf2"] = 242; _cm["\xf3"] = 243;
_cm["\xf4"] = 244; _cm["\xf5"] = 245; _cm["\xf6"] = 246; _cm["\xf7"] = 247;
_cm["\xf8"] = 248; _cm["\xf9"] = 249; _cm["\xfa"] = 250; _cm["\xfb"] = 251;
_cm["\xfc"] = 252; _cm["\xfd"] = 253; _cm["\xfe"] = 254; _cm["\xff"] = 255;
var _rcm = {};
_rcm[ 0] = "\x00"; _rcm[ 1] = "\x01"; _rcm[ 2] = "\x02"; _rcm[ 3] = "\x03";
_rcm[ 4] = "\x04"; _rcm[ 5] = "\x05"; _rcm[ 6] = "\x06"; _rcm[ 7] = "\x07";
_rcm[ 8] = "\x08"; _rcm[ 9] = "\x09"; _rcm[ 10] = "\x0a"; _rcm[ 11] = "\x0b";
_rcm[ 12] = "\x0c"; _rcm[ 13] = "\x0d"; _rcm[ 14] = "\x0e"; _rcm[ 15] = "\x0f";
_rcm[ 16] = "\x10"; _rcm[ 17] = "\x11"; _rcm[ 18] = "\x12"; _rcm[ 19] = "\x13";
_rcm[ 20] = "\x14"; _rcm[ 21] = "\x15"; _rcm[ 22] = "\x16"; _rcm[ 23] = "\x17";
_rcm[ 24] = "\x18"; _rcm[ 25] = "\x19"; _rcm[ 26] = "\x1a"; _rcm[ 27] = "\x1b";
_rcm[ 28] = "\x1c"; _rcm[ 29] = "\x1d"; _rcm[ 30] = "\x1e"; _rcm[ 31] = "\x1f";
_rcm[ 32] = "\x20"; _rcm[ 33] = "!"; _rcm[ 34] = '"'; _rcm[ 35] = "#";
_rcm[ 36] = "$"; _rcm[ 37] = "%"; _rcm[ 38] = "&"; _rcm[ 39] = "'";
_rcm[ 40] = "("; _rcm[ 41] = ")"; _rcm[ 42] = "*"; _rcm[ 43] = "+";
_rcm[ 44] = ","; _rcm[ 45] = "-"; _rcm[ 46] = "."; _rcm[ 47] = "/";
_rcm[ 48] = "0"; _rcm[ 49] = "1"; _rcm[ 50] = "2"; _rcm[ 51] = "3";
_rcm[ 52] = "4"; _rcm[ 53] = "5"; _rcm[ 54] = "6"; _rcm[ 55] = "7";
_rcm[ 56] = "8"; _rcm[ 57] = "9"; _rcm[ 58] = ":"; _rcm[ 59] = ";";
_rcm[ 60] = "<"; _rcm[ 61] = "="; _rcm[ 62] = ">"; _rcm[ 63] = "?";
_rcm[ 64] = "@"; _rcm[ 65] = "A"; _rcm[ 66] = "B"; _rcm[ 67] = "C";
_rcm[ 68] = "D"; _rcm[ 69] = "E"; _rcm[ 70] = "F"; _rcm[ 71] = "G";
_rcm[ 72] = "H"; _rcm[ 73] = "I"; _rcm[ 74] = "J"; _rcm[ 75] = "K";
_rcm[ 76] = "L"; _rcm[ 77] = "M"; _rcm[ 78] = "N"; _rcm[ 79] = "O";
_rcm[ 80] = "P"; _rcm[ 81] = "Q"; _rcm[ 82] = "R"; _rcm[ 83] = "S";
_rcm[ 84] = "T"; _rcm[ 85] = "U"; _rcm[ 86] = "V"; _rcm[ 87] = "W";
_rcm[ 88] = "X"; _rcm[ 89] = "Y"; _rcm[ 90] = "Z"; _rcm[ 91] = "[";
_rcm[ 92] = "\\"; _rcm[ 93] = "]"; _rcm[ 94] = "^"; _rcm[ 95] = "_";
_rcm[ 96] = "`"; _rcm[ 97] = "a"; _rcm[ 98] = "b"; _rcm[ 99] = "c";
_rcm[100] = "d"; _rcm[101] = "e"; _rcm[102] = "f"; _rcm[103] = "g";
_rcm[104] = "h"; _rcm[105] = "i"; _rcm[106] = "j"; _rcm[107] = "k";
_rcm[108] = "l"; _rcm[109] = "m"; _rcm[110] = "n"; _rcm[111] = "o";
_rcm[112] = "p"; _rcm[113] = "q"; _rcm[114] = "r"; _rcm[115] = "s";
_rcm[116] = "t"; _rcm[117] = "u"; _rcm[118] = "v"; _rcm[119] = "w";
_rcm[120] = "x"; _rcm[121] = "y"; _rcm[122] = "z"; _rcm[123] = "{";
_rcm[124] = "|"; _rcm[125] = "}"; _rcm[126] = "~"; _rcm[127] = "\x7f";
_rcm[128] = "\x80"; _rcm[129] = "\x81"; _rcm[130] = "\x82"; _rcm[131] = "\x83";
_rcm[132] = "\x84"; _rcm[133] = "\x85"; _rcm[134] = "\x86"; _rcm[135] = "\x87";
_rcm[136] = "\x88"; _rcm[137] = "\x89"; _rcm[138] = "\x8a"; _rcm[139] = "\x8b";
_rcm[140] = "\x8c"; _rcm[141] = "\x8d"; _rcm[142] = "\x8e"; _rcm[143] = "\x8f";
_rcm[144] = "\x90"; _rcm[145] = "\x91"; _rcm[146] = "\x92"; _rcm[147] = "\x93";
_rcm[148] = "\x94"; _rcm[149] = "\x95"; _rcm[150] = "\x96"; _rcm[151] = "\x97";
_rcm[152] = "\x98"; _rcm[153] = "\x99"; _rcm[154] = "\x9a"; _rcm[155] = "\x9b";
_rcm[156] = "\x9c"; _rcm[157] = "\x9d"; _rcm[158] = "\x9e"; _rcm[159] = "\x9f";
_rcm[160] = "\xa0"; _rcm[161] = "\xa1"; _rcm[162] = "\xa2"; _rcm[163] = "\xa3";
_rcm[164] = "\xa4"; _rcm[165] = "\xa5"; _rcm[166] = "\xa6"; _rcm[167] = "\xa7";
_rcm[168] = "\xa8"; _rcm[169] = "\xa9"; _rcm[170] = "\xaa"; _rcm[171] = "\xab";
_rcm[172] = "\xac"; _rcm[173] = "\xad"; _rcm[174] = "\xae"; _rcm[175] = "\xaf";
_rcm[176] = "\xb0"; _rcm[177] = "\xb1"; _rcm[178] = "\xb2"; _rcm[179] = "\xb3";
_rcm[180] = "\xb4"; _rcm[181] = "\xb5"; _rcm[182] = "\xb6"; _rcm[183] = "\xb7";
_rcm[184] = "\xb8"; _rcm[185] = "\xb9"; _rcm[186] = "\xba"; _rcm[187] = "\xbb";
_rcm[188] = "\xbc"; _rcm[189] = "\xbd"; _rcm[190] = "\xbe"; _rcm[191] = "\xbf";
_rcm[192] = "\xc0"; _rcm[193] = "\xc1"; _rcm[194] = "\xc2"; _rcm[195] = "\xc3";
_rcm[196] = "\xc4"; _rcm[197] = "\xc5"; _rcm[198] = "\xc6"; _rcm[199] = "\xc7";
_rcm[200] = "\xc8"; _rcm[201] = "\xc9"; _rcm[202] = "\xca"; _rcm[203] = "\xcb";
_rcm[204] = "\xcc"; _rcm[205] = "\xcd"; _rcm[206] = "\xce"; _rcm[207] = "\xcf";
_rcm[208] = "\xd0"; _rcm[209] = "\xd1"; _rcm[210] = "\xd2"; _rcm[211] = "\xd3";
_rcm[212] = "\xd4"; _rcm[213] = "\xd5"; _rcm[214] = "\xd6"; _rcm[215] = "\xd7";
_rcm[216] = "\xd8"; _rcm[217] = "\xd9"; _rcm[218] = "\xda"; _rcm[219] = "\xdb";
_rcm[220] = "\xdc"; _rcm[221] = "\xdd"; _rcm[222] = "\xde"; _rcm[223] = "\xdf";
_rcm[224] = "\xe0"; _rcm[225] = "\xe1"; _rcm[226] = "\xe2"; _rcm[227] = "\xe3";
_rcm[228] = "\xe4"; _rcm[229] = "\xe5"; _rcm[230] = "\xe6"; _rcm[231] = "\xe7";
_rcm[232] = "\xe8"; _rcm[233] = "\xe9"; _rcm[234] = "\xea"; _rcm[235] = "\xeb";
_rcm[236] = "\xec"; _rcm[237] = "\xed"; _rcm[238] = "\xee"; _rcm[239] = "\xef";
_rcm[240] = "\xf0"; _rcm[241] = "\xf1"; _rcm[242] = "\xf2"; _rcm[243] = "\xf3";
_rcm[244] = "\xf4"; _rcm[245] = "\xf5"; _rcm[246] = "\xf6"; _rcm[247] = "\xf7";
_rcm[248] = "\xf8"; _rcm[249] = "\xf9"; _rcm[250] = "\xfa"; _rcm[251] = "\xfb";
_rcm[252] = "\xfc"; _rcm[253] = "\xfd"; _rcm[254] = "\xfe"; _rcm[255] = "\xff";
// charAt(s, index)
// return character of s at index
String.charAt = function () {
var s = arguments[0];
var i = arguments[1];
// print("debug2 " + s + ':' + i + '\n');
return String.slice(s, i, i+1);
};
// charCodeAt(s, index)
// return ASCII character code of s at index
String.charCodeAt = function () {
var s = arguments[0];
var i = arguments[1];
var c = String.charAt(s, i);
// print("debug? " + c + '\n');
return _cm[c];
};
// fromCharCode(code)
// return a new string with one character from given ASCII code
String.fromCharCode = function () {
var code = arguments[0];
return _rcm[code];
};
// trimStart(s)
// return s with left side trimmable characters removed
String.trimStart = function () {
var s = arguments[0];
var o = "";
var i = 0;
while (1) {
var code = String.charCodeAt(s, i);
// print("code? " + code + '\n');
if ((code == 32) || (code == 9) || (code == 10) || (code == 13))
i += 1;
else
break;
}
// print("trim res " + i + '\n');
return String.slice(s, i);
};
// trimEnd(s)
// return s with right side trimmable characters removed
String.trimEnd = function () {
var s = arguments[0];
var o = "";
var i = s.length - 1;
while (i >= 0) {
var code = String.charCodeAt(s, i);
// print("code? " + code + '\n');
if ((code == 32) || (code == 9) || (code == 10) || (code == 13))
i -= 1;
else
break;
}
// print("trim res " + i + '\n');
return String.slice(s, 0, i+1);
};
// trim(s)
// return s with left+right side trimmable characters removed
String.trim = function () {
var s = arguments[0];
s = String.trimStart(s);
s = String.trimEnd(s);
return s;
};
if (test) {
var test = "hello world!";
print(String.slice(test, 1) + "\n");
print(String.slice(test, 1, 5) + "\n");
var test2 = "abc, d, e f";
var splitted = String.split(test2, ",");
print(splitted.length + "\n");
print('[' + splitted[0] + "]\n");
print('[' + splitted[1] + "]\n");
print('[' + splitted[2] + "]\n");
print(String.slice('a', 0, 5) + '\n');
print(String.startsWith('abc', 'ab') + '\n');
print(String.startsWith('abc', 'abcd') + '\n');
print(String.fromCharCode(112) + '\n');
print(String.charCodeAt('p', 0) + '\n');
print(String.trimStart(" \n \x09 hello! ") + '\n');
print(String.trimEnd(" \n \x09 hello! \n \x0a ") + '|\n');
print(String.trim(" \n \x09 hello! \n \x0a ") + '|\n');
}
+1
View File
@@ -0,0 +1 @@
test = 1;
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate 2024/maffiodo
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy way.
#
[[ -z "$CC" ]] && CC="cc"
# make sure the program and the alt program have been built
#
make CC="$CC" everything >/dev/null || exit 1
# clear the screen
#
clear
# try the program
#
echo "Are you ready? Let's go!" 1>&2
echo 1>&2
read -r -n 1 -p "## Forrest test: Press any key to run: cat test.js string.js | ./prog "
echo 1>&2
echo 1>&2
cat test.js string.js | ./prog
echo 1>&2
read -r -n 1 -p "## Array tests: Press any key to run: cat test.js array.js | ./prog"
echo 1>&2
echo 1>&2
cat test.js array.js | ./prog
echo 1>&2
read -r -n 1 -p "## Math tests: Press any key to run: cat test.js math.js | ./prog"
echo 1>&2
echo 1>&2
cat test.js math.js | ./prog
echo 1>&2
read -r -n 1 -p "## Utils tests: Press any key to run: cat test.js utils.js | ./prog"
echo 1>&2
echo 1>&2
cat test.js utils.js | ./prog
echo 1>&2
read -r -n 1 -p "## Verify tests: Press any key to run: cat utils.js verify.js | ./prog"
echo 1>&2
echo 1>&2
cat utils.js verify.js | ./prog
echo 1>&2
read -r -n 1 -p "## Fibonacci tests: Press any key to run: cat console.js fibo.js | ./prog"
echo 1>&2
echo 1>&2
cat console.js fibo.js | ./prog
echo 1>&2
+26
View File
@@ -0,0 +1,26 @@
var eval = function () {
var f = arguments[0];
return f();
};
if (test) {
print(eval("1+2") + '\n');
print(eval("(function () { return 10 + 2; })()") + '\n');
var obj = {};
var src = "{\n";
var i = 0;
while (i < 10) {
src += " obj[" + i + "] = 'temp-string-" + i + "';\n";
i += 1;
}
src += '}';
print("dynamic generated src:\n" + src + "\n");
eval(src);
print("eval results:\n");
print('obj-length = ' + obj.length + '\n');
print('obj.0 = ' + obj[0] + '\n');
print('obj.4 = ' + obj[4] + '\n');
print('obj.9 = ' + obj[9] + '\n');
print(obj['9'] + '\n');
}
+71
View File
@@ -0,0 +1,71 @@
var testCounter = 0;
var verify = function () {
var src = '{' + arguments[0] + '}';
print("test " + testCounter + ": " + src + " ");
testCounter += 1;
var expected = arguments[1];
var res = eval(src);
if (res == expected) {
print("\x1b[32;1mOK\x1b[0m");
} else {
print("\x1b[31;1mKO\x1b[0m");
}
print(" (exp=" + expected + " res=" + res + ")\n");
};
var x = 0;
verify(";", "[object]");
verify("; 2; 3", "3");
verify("2*(2+3)-1", 9);
verify("'' + 32", "32");
verify("\"\" + 32", "32");
verify("x + 32", 32);
verify("x = 3", 3);
verify("x", 3);
verify("var y = 11", 11);
verify("var y = 11, z = 22", 22);
verify("var foo = function () { 2; }; return foo;", "{ 2; }");
verify("' 1 2 \\n 23 \\' '", " 1 2 \n 23 \' ");
verify(" 'hello' == 'hello'; ", 1);
verify(" 'hello' == 'hello2'; ", 0);
verify(" 'hello' != 'hello2'; ", 1);
verify(" '32' == 32; ", 1);
verify(" '32' == 33; ", 0);
verify(" '32' <= 33; ", 1);
verify(" '32' <= 2; ", 0);
verify(" '2' >= 32; ", 0);
verify(" '32' >= 2; ", 1);
verify(" 32 == 32; ", 1);
verify(" 32 >= 0; ", 1);
verify(" 0 <= 32; ", 1);
verify(" 1+4 && 3-3; ", 0);
verify(" 1+4 || 3-3; ", 1);
verify(" 1<<3; ", 8);
verify(" 8>>3; ", 1);
verify(" -6; ", -6);
verify(" +'6'; ", 6);
verify(" ~'6'; ", -7);
verify(" !'6'; ", 0);
verify(" !'0'; ", 1);
verify(" !(1 && 2); ", 0);
verify(" 0.1 + 0.2 == 0.3; ", 1); // this is different from nodejs!! <<<<<<<<<<
verify(" 'hello'.length; ", 5);
verify(" [].length; ", 0);
verify(" {}.length; ", 0); // this is strange but usefull? <<<<<<<<<<<<<<<<<<<<
var obj = {};
verify("obj.abc = 32;", 32);
verify("obj[0] = 2; ", 2);
verify("obj[0]; ", 2);
verify("obj[1] = {}; ", "[object]");
verify("obj[1].temp = 123; ", 123);
verify("obj[1].temp; ", 123);
verify("'abc'[0];", "a");
verify("'1+2'();", 3);
verify("0 || 'hello'", 0);
verify("0 || '1hello'", 1);
verify("; 2; 3;", 3);
verify("{ { 1; }; }; 2; {{3;}}", 3);
verify("{ { return 1; } } 2; 3", 1);
verify("var strt = '' + 32", "32");
verify("var strt = \"\" + 32", "32");