├── .gitignore ├── INSTALL.md ├── Makefile ├── Makefile.win32 ├── README ├── TODO ├── atom.c ├── bif ├── bif_code.c ├── bif_erlang.c ├── bif_file.c ├── bif_gen_tcp.c ├── bif_inet.c └── bif_lists.c ├── bits.c ├── buffer.c ├── code_base.c ├── compare.c ├── compare_test.c ├── compiler ├── atoms.erl ├── bifs.erl ├── core_parse.hrl ├── erl_bits.hrl ├── erl_compile.hrl ├── erl_expand_records.erl ├── erl_lint.erl ├── erl_parse.erl ├── erl_parse.yrl ├── opcodes.erl ├── os.hrl ├── teeterl.hrl ├── test_asm.erl ├── tt_asm.erl ├── tt_codegen.erl ├── tt_compile.erl ├── tt_named_tuples.erl ├── tt_seek.erl └── v3_life.hrl ├── cstr.c ├── ebin └── .gitignore ├── exterm.c ├── exterm_test.c ├── gh-pages └── index.html ├── heap.c ├── heap_gc.c ├── include ├── atom.h ├── atom_defs.h ├── bif.h ├── bifimpl.h ├── binary.h ├── bits.h ├── buffer.h ├── code_base.h ├── compare.h ├── cstr.h ├── exterm.h ├── getput.h ├── heap.h ├── heap_gc.h ├── list.h ├── logtab.h ├── mixed.h ├── modbin.h ├── mpi-config.h ├── mpi.h ├── msg_queue.h ├── named_tuple.h ├── navel.h ├── opcodes.h ├── outlet.h ├── outlet_mall.h ├── proc.h ├── proc_queue.h ├── scheduler.h ├── teeterl.h ├── teevm.h └── term.h ├── license.txt ├── list.c ├── mixed.c ├── mod ├── comet.erl ├── erlang.erl ├── error_handler.erl ├── file.erl ├── format.erl ├── gen_tcp.erl ├── inet.erl ├── init.erl ├── lists.erl ├── navel.erl ├── navel.hrl ├── proplists.erl ├── queue.erl ├── random.erl ├── string.erl ├── test.erl └── trace.hrl ├── modbin.c ├── mpi.c ├── msg_queue.c ├── named_tuple.c ├── navel ├── comet.html ├── compare.html ├── exterm.html ├── index.html ├── js │ ├── erl.js │ ├── jquery-1.3.2.min.js │ ├── jquery-ui-1.7.2.custom.min.js │ ├── jquery.erlpp.js │ ├── jquery.json-2.2.min.js │ └── jquery.layout.min.js ├── pp.html ├── ppt1.html ├── pretty_term.css ├── pretty_term.html ├── proc.html ├── style.css └── term1.xml ├── ol_file.c ├── ol_listener.c ├── ol_socket.c ├── outlet.c ├── outlet_mall.c ├── proc.c ├── proc_main.c ├── proc_queue.c ├── proc_test.c ├── scheduler.c ├── spec ├── atoms.tab ├── bif.tab └── teeops.tab ├── stringify.c ├── teeterl.c ├── term_test.c ├── test ├── estone.xls ├── estone_SUITE.erl ├── lists_SUITE.erl ├── test.hrl └── tuple_SUITE.erl ├── util ├── atoms_gen.erl ├── bifs_gen.erl ├── cli_run.erl ├── mods_gen.erl ├── ops_gen.erl └── ops_gen_.erl ├── vintage ├── BUGS ├── Makefile ├── Makefile.win32 ├── README ├── bif │ ├── bif_code.c │ ├── bif_crypto.c │ ├── bif_erlang.c │ ├── bif_file.c │ ├── bif_gen_tcp.c │ ├── bif_gen_udp.c │ ├── bif_inet.c │ ├── bif_io.c │ ├── bif_lists.c │ └── bif_os.c ├── bin │ └── .gitignore ├── compiler │ ├── .gitignore │ ├── appgen.erl │ ├── core_lib.erl │ ├── core_parse.hrl │ ├── erl_bifs.erl │ ├── erl_compile.hrl │ ├── pat_match.hrl │ ├── sys_core_fold.erl │ ├── sys_core_inline.erl │ ├── sys_pre_expand.erl │ ├── v3_core.erl │ ├── x_asm2.erl │ ├── x_asmopt.erl │ ├── x_codegen.erl │ ├── x_compile.erl │ ├── x_disasm2.erl │ ├── x_internal.erl │ ├── x_kernel.erl │ └── xmodule.hrl ├── ebin │ └── .gitignore ├── snip │ ├── arith.c │ ├── binary.c │ ├── compare.c │ ├── jump.c │ ├── list.c │ ├── literal.c │ ├── msg.c │ ├── recog.c │ ├── stack.c │ └── vararg.c ├── spec │ ├── atoms.lst │ ├── biftab.txt │ ├── erl_ext_dist.txt │ ├── net_tcp.txt │ ├── optab.txt │ └── optab2.txt ├── stdmod │ ├── code.erl │ ├── crypto.erl │ ├── dict.erl │ ├── epp.erl │ ├── erl_bits.erl │ ├── erl_bits.hrl │ ├── erl_eval.erl │ ├── erl_expand_records.erl │ ├── erl_internal.erl │ ├── erl_lint.erl │ ├── erl_parse.erl │ ├── erl_pp.erl │ ├── erl_scan.erl │ ├── erlang.erl │ ├── error_handler.erl │ ├── error_handler_.erl │ ├── eval_bits.erl │ ├── file.erl │ ├── file.hrl │ ├── file_io_srv.erl │ ├── filename.erl │ ├── files.erl │ ├── gb_sets.erl │ ├── gb_trees.erl │ ├── gen_tcp.erl │ ├── gen_udp.erl │ ├── inet.erl │ ├── init.erl │ ├── io.erl │ ├── io_lib.erl │ ├── io_lib_format.erl │ ├── io_lib_fread.erl │ ├── io_lib_pretty.erl │ ├── lists.erl │ ├── netmesh.erl │ ├── nettcp.erl │ ├── netudp.erl │ ├── orddict.erl │ ├── ordsets.erl │ ├── os.erl │ ├── packages.erl │ ├── prim_erlang.erl │ ├── proplists.erl │ ├── queue.erl │ ├── random.erl │ ├── regexp.erl │ ├── rpc.erl │ ├── sets.erl │ ├── sofs.erl │ ├── stdio.erl │ └── string.erl ├── util │ ├── aegen.erl │ ├── opsgen2.erl │ └── vmgen.erl ├── xbin │ └── .gitignore └── xvm │ ├── .gitignore │ ├── atom.c │ ├── atom.h │ ├── atom_cache.c │ ├── atom_cache.h │ ├── atom_defs.h │ ├── bif.h │ ├── bignum.c │ ├── bignum.h │ ├── bits.c │ ├── bits.h │ ├── buffer.c │ ├── buffer.h │ ├── code_base.c │ ├── code_base.h │ ├── cstr.c │ ├── cstr.h │ ├── errors.c │ ├── errors.h │ ├── exec.c │ ├── exterm.c │ ├── exterm.h │ ├── getput.h │ ├── hash.c │ ├── hash.h │ ├── lit_pool.c │ ├── lit_pool.h │ ├── md5.c │ ├── md5.h │ ├── msg_queue.c │ ├── msg_queue.h │ ├── port.c │ ├── port.h │ ├── port_file.c │ ├── port_listener.c │ ├── port_pipe.c │ ├── port_socket.c │ ├── port_udp.c │ ├── proc.h │ ├── run_code.c │ ├── scheduler.c │ ├── scheduler.h │ ├── sha1.c │ ├── sha1.h │ ├── tcomp.c │ ├── tcomp.h │ ├── teeterl.c │ ├── teeterl.h │ ├── term.c │ ├── term.h │ ├── xmod.h │ ├── xpool.c │ └── xpool.h └── xbin └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | include/apr-util 2 | include/apr 3 | 4 | atoms.inc 5 | builtins.inc 6 | modbin.inc 7 | 8 | lib 9 | 10 | *.cx 11 | *.x 12 | *.o 13 | *.beam 14 | 15 | teeterl 16 | 17 | test/snip 18 | 19 | cscope.* 20 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | 2 | teeterl uses Apache Portable Runtime (apr.apache.org) as a portability layer. 3 | teeterl also depends on the old version of Erlang/OTP (R13B04). 4 | 5 | ## Build steps 6 | 7 | 1. Download Erlang/OTP R13B04 and build it from sources. Other versions of 8 | Erlang/OTP WILL NOT WORK. 9 | 10 | wget http://www.erlang.org/download/otp_src_R13B04.tar.gz 11 | tar xzf otp_src_R13B04.tar.gz 12 | cd otp_src_R13B04 13 | ./configure 14 | make 15 | make install 16 | 17 | 1. Download apr-1.4.8.tar.gz and apr-util-1.5.2.tar.gz from 18 | [here](http://apr.apache.org/download.cgi). 19 | 20 | 1. Build apr library: 21 | 22 | tar xzf apr-1.4.8.tar.gz 23 | cd apr-1.4.8 24 | ./configure 25 | make 26 | 27 | 1. Build apr-util library: 28 | 29 | tar xzf apr-util-1.5.2.tar.gz 30 | cd apr-util-1.5.2 31 | ./configure --with-apr=../apr-1.4.8 32 | make 33 | 34 | 1. Clone teeterl repository: 35 | 36 | git clone http://github.com/maximk/teeterl 37 | cd teeterl 38 | 39 | 1. Create symbolic links to include directories: 40 | 41 | cd include 42 | ln -s ../../apr-1.4.8/include apr 43 | ln -s ../../apr-util-1.5.2/include apr-util 44 | 45 | 1. Copy apr and apr-util static libraries to the teeterl tree. 46 | 47 | mkdir lib 48 | cp ../apr-1.4.8/.libs/libapr-1.a lib 49 | cp ../apr-util-1.5.2/.libs/libaprutil-1.a lib 50 | 51 | 1. Update erl and erlc paths in the Makefile to point to the R13B04 version of 52 | Erlang/OTP. 53 | 54 | 1. Run make. 55 | 56 | make 57 | 58 | After the clean build run teeterl: 59 | 60 | ./teeterl 61 | 62 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | ERLC := /usr/local/bin/erlc 3 | ERL := /usr/local/bin/erl 4 | 5 | ATOMTAB := spec/atoms.tab 6 | BIFTAB := spec/bif.tab 7 | OPSTAB := spec/teeops.tab 8 | 9 | E := ebin 10 | C := compiler 11 | U := util 12 | F := bif 13 | M := mod 14 | X := xbin 15 | T := test 16 | 17 | COMP := $(patsubst $C/%.erl,$E/%.beam,$(wildcard $C/*.erl)) 18 | UTIL := $(patsubst $U/%.erl,$E/%.beam,$(wildcard $U/*.erl)) 19 | BIF := $(patsubst %.c,%.o,$(wildcard $F/*.c)) 20 | 21 | OBJS := $(patsubst %.c,%.o,$(wildcard *.c)) 22 | 23 | MODS := $(patsubst $M/%.erl,$X/%.cx,$(wildcard $M/*.erl)) 24 | XOBJS := $(patsubst %.cx,%.o,$(MODS)) 25 | 26 | APRLIBS := lib/libapr-1.a lib/libaprutil-1.a 27 | 28 | TARGET := teeterl 29 | 30 | CPPFLAGS := -I include -I include/apr -I include/apr-util 31 | CPPFLAGS += -DAPR_DECLARE_STATIC -DAPU_DECLARE_STATIC 32 | CPPFLAGS += -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE 33 | CPPFLAGS += -DDEBUG 34 | CFLAGS := -Wall -Werror -g 35 | LDFLAGS := -pthread 36 | 37 | .PHONY: default 38 | default: $(COMP) $(BIF) $(TARGET) 39 | 40 | ALL_OBJS := $(OBJS) $(BIF) $(XOBJS) 41 | 42 | $(OBJS): %.o: %.c $(DEPS) 43 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 44 | 45 | include/atom_defs.h atoms.inc compiler/atoms.erl: $E/atoms_gen.beam $(ATOMTAB) $(BIFTAB) 46 | $(ERL) -pa $E -run atoms_gen compile_atoms $(ATOMTAB) $(BIFTAB) \ 47 | include/atom_defs.h atoms.inc compiler/atoms.erl -run init stop -noshell 48 | 49 | include/opcodes.h compiler/opcodes.erl: $E/ops_gen.beam $(OPSTAB) 50 | $(ERL) -pa $E -run ops_gen opcodes $(OPSTAB) include/opcodes.h compiler/opcodes.erl -run init stop -noshell 51 | 52 | include/bif.h builtins.inc compiler/bifs.erl: $E/bifs_gen.beam $(BIFTAB) 53 | $(ERL) -pa $E -run bifs_gen builtins $(BIFTAB) \ 54 | include/bif.h builtins.inc compiler/bifs.erl -run init stop -noshell 55 | 56 | modbin.c: modbin.inc 57 | 58 | modbin.inc: $E/mods_gen.beam $(MODS) 59 | $(ERL) -pa $E -run mods_gen modules modbin.inc $(MODS) -run init stop -noshell 60 | 61 | $C/erl_parse.erl: $C/erl_parse.yrl $E/cli_run.beam 62 | $(ERL) -pa $E -run cli_run exec1 yecc file $C/erl_parse.yrl -run init stop -noshell 63 | 64 | $(COMP): $E/%.beam: $C/%.erl 65 | $(ERLC) -o $E $< 66 | 67 | $(UTIL): $E/%.beam: $U/%.erl 68 | $(ERLC) -o $E $< 69 | 70 | $(BIF): %.o: %.c 71 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 72 | 73 | $(XOBJS): %.o: %.cx 74 | $(CC) -c -x c $(CFLAGS) $(CPPFLAGS) $< -o $@ 75 | 76 | $(MODS): $X/%.cx: $M/%.erl 77 | $(ERL) -pa $E \ 78 | -run tt_compile files_outdir $< $X \ 79 | -run init stop -noshell 80 | 81 | $(TARGET): $(OBJS) $(BIF) $(XOBJS) 82 | $(CC) $(LDFLAGS) -o $@ $(OBJS) $(BIF) $(XOBJS) $(APRLIBS) 83 | 84 | define all_sources 85 | (find . -follow -name '*.[chS]' -print) 86 | endef 87 | 88 | .PHONY: cscope 89 | cscope: 90 | $(all_sources) > cscope.files 91 | cscope -k -b -q 92 | 93 | #EOF 94 | 95 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | teeterl is a lean portable Erlang. 2 | 3 | teeterl is built using Apache Portable Runtime, a library tested on dozens 4 | of OSes and their flavours. 5 | 6 | teeterl borrows from industry-standard Erlang/OTP, especially when it comes 7 | to compiler front-end. 8 | 9 | This is a new major version of teeterl. Quite immature. The previous version 10 | lives in the vintage folder. Consult README file found there. 11 | 12 | The current version is only able to run a couple of test suites but the 13 | results of preliminary performance testing indicate that the current version 14 | is 3-4 times swifter than the previous one. 15 | 16 | The current version is being developed under OpenSuse 11.3. Expect to 17 | resolve a few dependencies manually. After clean built, just start ./teeterl 18 | and point your browser to http://localhost:9090 and rudimentary 19 | teeterl interface will show up. At that point it would be obvious that 20 | there is much to be done for the new teeterl. 21 | 22 | If you want to feel more in control about VM internals and think that 23 | Erlang/OTP is too much for you then you are welcome to use and extend 24 | teeterl. 25 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - {A,B} = {[],[]} does not compile 2 | - when binary is matched it is first copied to a new register 3 | - pieces of matched binary are cleared out prematurely 4 | - on binary allocation the ultimate parent should be traced 5 | - examine whether it is worthwhile to have apr_pollset_t allocated once; also apr_pollcb_t 6 | - binary_to_term fails on nested oddball binaries 7 | - unused registers can be sorted on clear_dead; or may be not; check compilation times etc 8 | - one register may be shaved in code for make_fun; in some cases 9 | - register touched by a local function can be tracked; probably not worthwhile 10 | - implement label-Op-label-Op optimization; happens many a time; only terminal ops 11 | - mp_set_int takes long argument and make assumption that sizeof(long) > sizeof(int) 12 | - compile APR without threads; no APR_HAS_THREADS 13 | - exceptions leak from guards 14 | - update optimization taking into account possibility of {source,_,_} 15 | - named tuple update not implemented, e.g. {A.car#model = ""} 16 | - named tuple access, index, etc does not check that argument is of proper type (no is_record()) 17 | - named tuple patterns not implemented (tough one) 18 | -------------------------------------------------------------------------------- /atom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "atom.h" 34 | 35 | typedef struct atom_info_t atom_info_t; 36 | struct atom_info_t { 37 | int index; 38 | cstr_t *str; 39 | }; 40 | 41 | struct atoms_t { 42 | apr_array_header_t *space; 43 | apr_hash_t *str_to_info; 44 | }; 45 | 46 | atoms_t *atoms_make(apr_pool_t *pool) 47 | { 48 | atom_info_t *ai; 49 | atoms_t *p = apr_palloc(pool, sizeof(atoms_t)); 50 | p->space = apr_array_make(pool, 256, sizeof(atom_info_t)); 51 | p->str_to_info = apr_hash_make(pool); 52 | 53 | #define ATOM_INC_POOL (pool) 54 | #define ATOM_INC_SPACE (p->space) 55 | #define ATOM_INC_HASH (p->str_to_info) 56 | #define ATOM_INC_PTR (ai) 57 | 58 | #include "atoms.inc" 59 | 60 | return p; 61 | } 62 | 63 | int atoms_set(atoms_t *self, cstr_t *str) 64 | { 65 | atom_info_t *ai = apr_hash_get(self->str_to_info, str->data, str->size); 66 | if (ai) 67 | return ai->index; 68 | else 69 | { 70 | int index = self->space->nelts + ATOM_INDEX_BASE; 71 | ai = (atom_info_t *)apr_array_push(self->space); 72 | ai->index = index; 73 | ai->str = scopy2(str, self->space->pool); 74 | apr_hash_set(self->str_to_info, ai->str->data, ai->str->size, ai); 75 | return index; 76 | } 77 | } 78 | 79 | cstr_t *atoms_get(atoms_t *self, int a) 80 | { 81 | atom_info_t *ai; 82 | if (a - ATOM_INDEX_BASE >= self->space->nelts) 83 | return NULL; 84 | ai = (atom_info_t *)self->space->elts + a - ATOM_INDEX_BASE; 85 | return ai->str; 86 | } 87 | 88 | //EOF 89 | -------------------------------------------------------------------------------- /bif/bif_code.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "bifimpl.h" 6 | #include "modbin.h" 7 | #include "code_base.h" 8 | #include "exterm.h" 9 | 10 | #include 11 | #include 12 | 13 | term_t bif_load_module1(term_t Where, proc_t *proc) 14 | { 15 | term_t bin = noval; 16 | term_t code; 17 | term_box_t *tb; 18 | term_t module; 19 | 20 | if (!is_atom(Where) && !is_binary(Where)) 21 | bif_bad_arg(Where); 22 | 23 | if (is_atom(Where)) 24 | { 25 | modbin_t **mb; 26 | cstr_t *name; 27 | 28 | if (code_base_lookup(proc->teevm->base, Where) != 0) 29 | return A_NOT_PURGED; 30 | 31 | name = atoms_get(proc->teevm->atoms, atom_index(Where)); 32 | 33 | mb = modbins; 34 | while (*mb) 35 | { 36 | if (scomp((*mb)->name, name)) 37 | { 38 | bin = heap_binary(proc->heap, (*mb)->size*8, (*mb)->data); 39 | break; 40 | } 41 | mb++; 42 | } 43 | 44 | if (bin == noval) 45 | return A_FALSE; 46 | } 47 | else 48 | bin = Where; 49 | 50 | code = binary_to_term(bin, proc->teevm->atoms, proc->heap); 51 | 52 | if (code == noval) 53 | return A_BADFILE; 54 | 55 | tb = peel(code); 56 | if (!code_base_load(proc->teevm->base, proc->teevm->nm_tuples, 57 | tb->tuple.elts[1], 58 | tb->tuple.elts[2], 59 | tb->tuple.elts[3], 60 | tb->tuple.elts[4], 61 | tb->tuple.elts[5], 62 | tb->tuple.elts[6]) == 0) 63 | return A_BADFILE; 64 | 65 | module = tb->tuple.elts[1]; 66 | if (is_atom(Where)) 67 | { 68 | if (Where != module) 69 | return A_BADFILE; 70 | return A_TRUE; 71 | } 72 | else 73 | return heap_tuple2(proc->heap, A_MODULE, module); 74 | } 75 | 76 | term_t bif_is_loaded1(term_t Module, proc_t *proc) 77 | { 78 | if (!is_atom(Module)) 79 | bif_bad_arg(Module); 80 | if (code_base_lookup(proc->teevm->base, Module) == 0) 81 | return A_FALSE; 82 | else 83 | return A_TRUE; 84 | } 85 | 86 | // code:module_offset/3 [7] 87 | term_t bif_module_offset3(term_t Module, term_t File, term_t Line, proc_t *proc) 88 | { 89 | not_implemented("code:module_offset/3"); 90 | } 91 | 92 | // code:source_line/2 [8] 93 | term_t bif_source_line2(term_t Module, term_t Offset, proc_t *proc) 94 | { 95 | module_t *m; 96 | 97 | if (!is_atom(Module)) 98 | bif_bad_arg(Module); 99 | if (!is_int(Offset)) 100 | bif_bad_arg(Offset); 101 | 102 | m = code_base_lookup(proc->teevm->base, Module); 103 | if (m != 0) 104 | { 105 | const char *file; 106 | int line; 107 | 108 | if (!module_source_from_offset(m, int_value(Offset), &file, &line)) 109 | return A_FALSE; 110 | 111 | return heap_tuple2(proc->heap, 112 | ztol(file, proc->heap), 113 | tag_int(line)); 114 | } 115 | 116 | return A_FALSE; 117 | } 118 | 119 | //EOF 120 | -------------------------------------------------------------------------------- /bif/bif_inet.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "bifimpl.h" 29 | 30 | #include 31 | 32 | #include "outlet_mall.h" 33 | #include "getput.h" 34 | #include "list.h" 35 | 36 | // inet:getaddrs0/2 [4] 37 | term_t bif_getaddrs0_2(term_t Addr, term_t Family, proc_t *proc) 38 | { 39 | apr_status_t rs; 40 | apr_pool_t *tmp; 41 | apr_sockaddr_t *sa; 42 | const char *host; 43 | term_t addrs = nil; 44 | 45 | if (!is_binary(Addr) || !is_atom(Family)) 46 | bif_bad_arg0(); 47 | 48 | if (Family != A_INET) 49 | bif_exception(A_NOT_SUPPORTED); 50 | 51 | host = (const char *)peel(Addr)->binary.data; //null-terminated by caller 52 | 53 | apr_pool_create(&tmp, 0); 54 | rs = apr_sockaddr_info_get(&sa, host, APR_INET, 0, 0, tmp); 55 | if (rs == 0) 56 | { 57 | term_t first = nil; 58 | term_t last = nil; 59 | 60 | while (sa) 61 | { 62 | struct in_addr ia = *(struct in_addr *)sa->ipaddr_ptr; 63 | apr_byte_t qs[4]; 64 | term_t ip; 65 | 66 | #if APR_IS_BIGENDIAN 67 | PUT32(qs, ia.s_addr); 68 | #else 69 | PUT32_LE(qs, ia.s_addr); 70 | #endif 71 | 72 | ip = heap_tuple4(proc->heap, 73 | tag_int(qs[0]), 74 | tag_int(qs[1]), 75 | tag_int(qs[2]), 76 | tag_int(qs[3])); 77 | 78 | cons_up(first, last, ip, proc->heap); 79 | 80 | sa = sa->next; 81 | } 82 | 83 | addrs = first; 84 | } 85 | 86 | apr_pool_destroy(tmp); 87 | 88 | if (rs != 0) 89 | bif_exception(decipher_status(rs)); 90 | 91 | return addrs; 92 | } 93 | 94 | //EOF 95 | -------------------------------------------------------------------------------- /compiler/erl_bits.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% %CopyrightBegin% 3 | %% 4 | %% Copyright Ericsson AB 1999-2009. All Rights Reserved. 5 | %% 6 | %% The contents of this file are subject to the Erlang Public License, 7 | %% Version 1.1, (the "License"); you may not use this file except in 8 | %% compliance with the License. You should have received a copy of the 9 | %% Erlang Public License along with this software. If not, it can be 10 | %% retrieved online at http://www.erlang.org/. 11 | %% 12 | %% Software distributed under the License is distributed on an "AS IS" 13 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 14 | %% the License for the specific language governing rights and limitations 15 | %% under the License. 16 | %% 17 | %% %CopyrightEnd% 18 | %% 19 | %% This is an -*- erlang -*- file. 20 | %% Generic compiler options, passed from the erl_compile module. 21 | 22 | -type bt_endian():: 'big' | 'little' | 'native'. 23 | -type bt_sign() :: 'signed' | 'unsigned'. 24 | -type bt_type() :: 'integer' | 'float' | 'binary' | 'utf8' | 'utf16' | 'utf32'. 25 | -type bt_unit() :: 1..256. 26 | 27 | -record(bittype, { 28 | type :: bt_type(), 29 | unit :: bt_unit(), %% element unit 30 | sign :: bt_sign(), 31 | endian :: bt_endian() 32 | }). 33 | 34 | -record(bitdefault, { 35 | integer, %% default type for integer 36 | float, %% default type for float 37 | binary %% default type for binary 38 | }). 39 | 40 | %%% (From config.hrl in the bitsyntax branch.) 41 | -define(SYS_ENDIAN, big). 42 | -define(SIZEOF_CHAR, 1). 43 | -define(SIZEOF_DOUBLE, 8). 44 | -define(SIZEOF_FLOAT, 4). 45 | -define(SIZEOF_INT, 4). 46 | -define(SIZEOF_LONG, 4). 47 | -define(SIZEOF_LONG_LONG, 8). 48 | -define(SIZEOF_SHORT, 2). 49 | -------------------------------------------------------------------------------- /compiler/erl_compile.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% %CopyrightBegin% 3 | %% 4 | %% Copyright Ericsson AB 1997-2009. All Rights Reserved. 5 | %% 6 | %% The contents of this file are subject to the Erlang Public License, 7 | %% Version 1.1, (the "License"); you may not use this file except in 8 | %% compliance with the License. You should have received a copy of the 9 | %% Erlang Public License along with this software. If not, it can be 10 | %% retrieved online at http://www.erlang.org/. 11 | %% 12 | %% Software distributed under the License is distributed on an "AS IS" 13 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 14 | %% the License for the specific language governing rights and limitations 15 | %% under the License. 16 | %% 17 | %% %CopyrightEnd% 18 | %% 19 | 20 | %% Generic compiler options, passed from the erl_compile module. 21 | 22 | -record(options, 23 | {includes=[] :: [string()], % Include paths (list of 24 | % absolute directory names). 25 | outdir="." :: string(), % Directory for result 26 | % (absolute path). 27 | output_type=undefined :: atom(), % Type of output file. 28 | defines=[] :: [atom() | {atom(),_}], % Preprocessor defines. Each 29 | % element is an atom 30 | % (the name to define), or 31 | % a {Name, Value} tuple. 32 | warning=1 :: non_neg_integer(), % Warning level (0 - no 33 | % warnings, 1 - standard level, 34 | % 2, 3, ... - more warnings). 35 | verbose=false :: boolean(), % Verbose (true/false). 36 | optimize=999, % Optimize options. 37 | specific=[] :: [_], % Compiler specific options. 38 | outfile="" :: string(), % Name of output file (internal 39 | % use in erl_compile.erl). 40 | cwd :: string() % Current working directory 41 | % for erlc. 42 | }). 43 | 44 | -------------------------------------------------------------------------------- /compiler/os.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% The following macros determine the packing of codels and 3 | %% are thus does not depend on 32/64bit int size 4 | %% 5 | %% codel size is 4 bytes on 32-bit OS and 8 bytes on 64-bit 6 | %% but when codel is integer or packed integer then only 4 bytes 7 | %% are used; this is needed for 32/64-bit portability of code 8 | %% binaries 9 | %% 10 | 11 | -define(TEE_SIZE_UNIT, 1). 12 | -define(TEE_SIZE_DOUBLE, 2). 13 | -define(TEE_SIZE_FULL, 4). 14 | 15 | -define(MAX_SIGNED_UNIT, 127). 16 | -define(MIN_SIGNED_UNIT, -128). 17 | -define(MAX_SIGNED_DOUBLE, 32767). 18 | -define(MIN_SIGNED_DOUBLE, -32768). 19 | -define(MAX_UNSIGNED_UNIT, 255). 20 | -define(MAX_UNSIGNED_DOUBLE, 65535). 21 | -define(MAX_INT_VALUE, 134217727). 22 | -define(MIN_INT_VALUE, -134217728). 23 | 24 | -define(xxxu(X), X). 25 | -define(xxuu(X, Y), (X bsl 8) bor Y). 26 | -define(xuuu(X, Y, Z), (X bsl 16) bor (Y bsl 8) bor Z). 27 | -define(uuuu(X, Y, Z, Q), (X bsl 24) bor (Y bsl 16) bor (Z bsl 8) bor Q). 28 | -define(xddu(X, Y), (X bsl 8) bor Y). 29 | -define(xudd(X, Y), (X bsl 16) bor Y). 30 | -define(dduu(X, Y, Z), (X bsl 16) bor (Y bsl 8) bor Z). 31 | -define(uddu(X, Y, Z), (X bsl 24) bor (Y bsl 8) bor Z). 32 | 33 | %% 34 | %% Macros depending on whether it is a 32-bit or 64-bit OS 35 | %% 36 | 37 | -define(HBOUND, 8). 38 | -define(HALIGN(Size), ((Size + (?HBOUND-1)) band (bnot (?HBOUND-1)))). 39 | 40 | -define(WSZ, 4). 41 | -define(HSIZE_BIGNUM(N), ?HALIGN(?WSZ + N*?WSZ)). 42 | -define(HSIZE_CONS, ?HALIGN(2*?WSZ)). 43 | -define(HSIZE_TUPLE(Arity), ?HALIGN(?WSZ + Arity*?WSZ)). 44 | -define(HSIZE_FUN, ?HALIGN(6*?WSZ)). 45 | -define(HSIZE_BINARY(BitSize), ?HALIGN(4*?WSZ) + ?HALIGN((BitSize + 7) bsr 3)). 46 | -define(HSIZE_BINARY_SHARED, ?HALIGN(4*?WSZ)). 47 | -define(HSIZE_FLOAT, ?HALIGN(8)). %% TODO: there are 160 bit float I heard 48 | 49 | %%EOF 50 | -------------------------------------------------------------------------------- /compiler/teeterl.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | 5 | -record(teeterl, {module, 6 | exports = [], 7 | funs = [], 8 | attrs = [], 9 | preloaded, 10 | misc = [] 11 | }). 12 | -------------------------------------------------------------------------------- /compiler/test_asm.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | 5 | -module(test_asm). 6 | -compile(export_all). 7 | 8 | -import(lists,[mapfoldl/3,append/1,filter/2,keyfind/3,map/2,foldl/3]). 9 | 10 | % a() -> 100 + 25. 11 | 12 | sample() -> 13 | [{frame,0,1,0}, 14 | {set,{r,100},{literal,100}}, 15 | {set,{r,101},{literal,25}}, 16 | {add,{r,100},{r,101}}, 17 | {return,{r,100}}]. 18 | 19 | %% a() -> b(). 20 | %% b() -> c(). 21 | %% c() -> 3. 22 | % 23 | %sample() -> 24 | % [{frame,1,0}, 25 | % {set,{r,1},{integer,5}}, 26 | % {call,{l,1},0}, 27 | % {setret,{r,0}}, 28 | % {return,{r,0}}, 29 | % {label,1}, 30 | % {frame,1,0}, 31 | % {set,{r,1},{integer,7}}, 32 | % {call,{l,2},0}, 33 | % {setret,{r,0}}, 34 | % {return,{r,0}}, 35 | % {label,2}, 36 | % {set,{r,0},{integer,3}}, 37 | % {return,{r,0}}]. 38 | % 39 | %% a() -> b(1) + 1. 40 | %% b(_) -> c(2) + 2. 41 | %% c(_) -> d(3) + 3. 42 | %% d(_) -> e(4) + 4. 43 | %% e(_) -> f(5) + 5. 44 | %% f(_) -> 6. 45 | %% 46 | % 47 | %sample() -> 48 | % [{frame,2,0}, 49 | % {set,{r,0},{integer,1}}, 50 | % {call,{l,1},1,{r,0}}, 51 | % {set,{r,1},{integer,1}}, 52 | % {add,{r,0},{r,1}}, 53 | % {return,{r,0}}, 54 | % {label,1}, %% b(X) 55 | % {frame,2,0}, 56 | % {set,{r,0},{integer,2}}, 57 | % {call,{l,2},1,{r,0}}, 58 | % {set,{r,1},{integer,2}}, 59 | % {add,{r,0},{r,1}}, 60 | % {return,{r,0}}, 61 | % {label,2}, %% c(X) 62 | % {frame,2,0}, 63 | % {set,{r,0},{integer,3}}, 64 | % {call,{l,3},1,{r,0}}, 65 | % {set,{r,1},{integer,3}}, 66 | % {add,{r,0},{r,1}}, 67 | % {return,{r,0}}, 68 | % {label,3}, %% d(X) 69 | % {frame,2,0}, 70 | % {set,{r,0},{integer,4}}, 71 | % {call,{l,4},1,{r,0}}, 72 | % {set,{r,1},{integer,4}}, 73 | % {add,{r,0},{r,1}}, 74 | % {return,{r,0}}, 75 | % {label,4}, %% e(X) 76 | % {frame,2,0}, 77 | % {set,{r,0},{integer,5}}, 78 | % {call,{l,5},1,{r,0}}, 79 | % {set,{r,1},{integer,5}}, 80 | % {add,{r,0},{r,1}}, 81 | % {return,{r,0}}, 82 | % {label,5}, %% f(X) 83 | % {frame,0,0}, 84 | % {set,{r,0},{integer,6}}, 85 | % {return,{r,0}}]. 86 | % 87 | write_test([File]) -> 88 | {Asm,{Li,_}} = mapfoldl(fun({label,L}, {Li,Off}) -> 89 | {{label,L},{[{L,Off}|Li],Off}}; 90 | (A, {Li,Off}) -> 91 | Os = opcodes:asm(A), 92 | {Os, {Li,Off+length(Os)}} 93 | end, {[],0}, sample()), 94 | 95 | Code = append(filter(fun({label,_}) -> false; (_) -> true end, Asm)), 96 | 97 | Code1 = map(fun({l,L}) -> 98 | {_,Off} = keyfind(L, 1, Li), 99 | {at,Off}; 100 | (X) -> 101 | X 102 | end, Code), 103 | 104 | {ok,Ou} = file:open(File, write), 105 | 106 | W = fun({at,Off}) -> 107 | io:format(Ou, "@~w", [Off]); 108 | (X) -> 109 | io:format(Ou, "~w", [X]) 110 | end, 111 | 112 | foldl(fun(X, N) when N rem 8 =/= 0 -> 113 | W(X), io:format(Ou, " ", []), 114 | N+1; 115 | (X, N) -> 116 | W(X), io:nl(Ou), 117 | N+1 118 | end, 1, Code1), 119 | 120 | file:close(File). 121 | 122 | %% EOF 123 | -------------------------------------------------------------------------------- /compiler/tt_named_tuples.erl: -------------------------------------------------------------------------------- 1 | -module(tt_named_tuples). 2 | -export([attributes/2]). 3 | 4 | -import(lists, [map/2,foldl/3,member/2,keytake/3]). 5 | 6 | %% {attribute, Pos, module, {Name,Vars}} 7 | %% {attribute, Pos, module, Name} 8 | 9 | attributes(Forms, _Opts) -> 10 | Nt = foldl(fun node/2, [], Forms), 11 | map(fun({Name,Fields}) -> 12 | AtomFields = [{atom,0,Field} || Field <- Fields], 13 | {attribute,0,named_tuple,{{atom,0,Name},AtomFields}} 14 | end, Nt). 15 | 16 | node({named_tuple,_,Expr,Name,Upds}, Nt) when Name /= '' -> 17 | Nt1 = node(Expr, Nt), 18 | foldl(fun({named_tuple_field,_,{atom,_,Field},Value}, Nta) -> 19 | node(Value, add_field(Name, Field, Nta)) 20 | end, Nt1, Upds); 21 | 22 | node({named_tuple,_,Name,Upds}, Nt) when Name /= '' -> 23 | foldl(fun({named_tuple_field,_,{atom,_,Field},Value}, Nta) -> 24 | node(Value, add_field(Name, Field, Nta)) 25 | end, Nt, Upds); 26 | 27 | node({named_tuple_field,_,Expr,Name,{atom,_,Field}}, Nt) when Name /= '' -> 28 | node(Expr, add_field(Name, Field, Nt)); 29 | 30 | node({named_tuple_index,_,Name,{atom,_,Field}}, Nt) -> 31 | add_field(Name, Field, Nt); 32 | 33 | node(Nodes, Nt) when is_list(Nodes) -> 34 | foldl(fun node/2, Nt, Nodes); 35 | 36 | node(Node, Nt) when is_tuple(Node) -> 37 | [_What,_Line|Nodes] = tuple_to_list(Node), 38 | foldl(fun node/2, Nt, Nodes); 39 | 40 | node(_Node, Nt) -> 41 | Nt. 42 | 43 | add_field(Name, Field, Nt) -> 44 | case keytake(Name, 1, Nt) of 45 | {value,{_,Fields},Nt1} -> 46 | case member(Field, Fields) of 47 | true -> 48 | Nt; 49 | false -> 50 | Fields1 = [Field|Fields], 51 | [{Name,Fields1}|Nt1] 52 | end; 53 | false -> 54 | [{Name,[Field]}|Nt] 55 | end. 56 | 57 | %%EOF 58 | -------------------------------------------------------------------------------- /compiler/tt_seek.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | -module(tt_seek). 5 | -export([module/2]). 6 | 7 | -import(lists, [foreach/2]). 8 | 9 | -include("v3_life.hrl"). 10 | 11 | %% seeks v3_life tree for protected 12 | %% expressions with non-empty resull list 13 | %% no such beast found to date 14 | 15 | module({_,_,_,Forms}, _) -> 16 | seek(Forms), 17 | {error,stop}. 18 | 19 | seek(Ts) when is_list(Ts) -> 20 | foreach(fun(T) -> 21 | seek(T) 22 | end, Ts); 23 | seek({protected,B,[]}) -> 24 | seek(B); 25 | seek({protected,B,_}) -> 26 | io:format("~w~n", [B#l.a]); 27 | seek(T) when is_tuple(T) -> 28 | foreach(fun(E) -> 29 | seek(E) 30 | end, tuple_to_list(T)); 31 | seek(_) -> ok. 32 | 33 | %%EOF 34 | -------------------------------------------------------------------------------- /compiler/v3_life.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% %CopyrightBegin% 3 | %% 4 | %% Copyright Ericsson AB 1999-2009. All Rights Reserved. 5 | %% 6 | %% The contents of this file are subject to the Erlang Public License, 7 | %% Version 1.1, (the "License"); you may not use this file except in 8 | %% compliance with the License. You should have received a copy of the 9 | %% Erlang Public License along with this software. If not, it can be 10 | %% retrieved online at http://www.erlang.org/. 11 | %% 12 | %% Software distributed under the License is distributed on an "AS IS" 13 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 14 | %% the License for the specific language governing rights and limitations 15 | %% under the License. 16 | %% 17 | %% %CopyrightEnd% 18 | %% 19 | %% This record contains variable life-time annotation for a 20 | %% kernel expression. Added by v3_life, used by v3_codegen. 21 | 22 | -record(l, {ke, %Kernel expression 23 | i=0, %Op number 24 | vdb=[], %Variable database 25 | a}). %Core annotation 26 | 27 | -------------------------------------------------------------------------------- /cstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "cstr.h" 29 | #include "heap.h" 30 | 31 | #include 32 | 33 | cstr_t *ztos(const char *z, heap_t *hp) 34 | { 35 | int n = (int)strlen(z); 36 | cstr_t *s = (cstr_t *)heap_alloc(hp, n+1); 37 | s->size = n; 38 | memmove(s->data, z, n); 39 | return s; 40 | } 41 | 42 | const char *stoz(cstr_t *s, heap_t *hp) 43 | { 44 | char *z = (char *)heap_alloc(hp, s->size+1); 45 | memmove(z, s->data, s->size); 46 | z[s->size] = 0; 47 | return z; 48 | } 49 | 50 | int scomp(cstr_t *s1, cstr_t *s2) 51 | { 52 | if (s1->size != s2->size) 53 | return 0; 54 | return (memcmp(s1->data, s2->data, s1->size) == 0); 55 | } 56 | 57 | cstr_t *scopy(cstr_t *s, heap_t *hp) 58 | { 59 | cstr_t *copy = (cstr_t *)heap_alloc(hp, s->size+1); 60 | memcpy(copy, s, s->size+1); 61 | return copy; 62 | } 63 | 64 | cstr_t *scopy2(cstr_t *s, apr_pool_t *pool) 65 | { 66 | cstr_t *copy = (cstr_t *)apr_palloc(pool, s->size+1); 67 | memcpy(copy, s, s->size+1); 68 | return copy; 69 | } 70 | 71 | //EOF 72 | -------------------------------------------------------------------------------- /ebin/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /exterm_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "navel.h" 10 | #include "bif.h" 11 | 12 | const char *exterm_test_sample(navel_context_t *cont, apr_pool_t *pool); 13 | 14 | const char *exterm_test_handler(char *request, navel_context_t *cont, apr_pool_t *rp) 15 | { 16 | if (strcmp(request, "/sample") == 0) 17 | return exterm_test_sample(cont, rp); 18 | else 19 | return apr_psprintf(rp, "Unknown exterm_test request: %s", request); 20 | } 21 | 22 | const char *exterm_test_sample(navel_context_t *cont, apr_pool_t *pool) 23 | { 24 | const char *file_name = "test/sample.x"; 25 | apr_file_t *bin_file; 26 | apr_off_t off; 27 | size_t len; 28 | apr_byte_t *data; 29 | term_t bin, exploded; 30 | 31 | if (cont->solitaire == 0) 32 | return "No spawned process to use"; 33 | 34 | apr_file_open(&bin_file, file_name, APR_READ, 0, pool); 35 | off = 0; 36 | apr_file_seek(bin_file, APR_END, &off); 37 | len = (int)off; 38 | off = 0; 39 | apr_file_seek(bin_file, APR_SET, &off); 40 | data = apr_palloc(pool, len); 41 | apr_file_read(bin_file, data, &len); 42 | apr_file_close(bin_file); 43 | 44 | bin = heap_binary(cont->heap, 8*len, data); 45 | exploded = bif_binary_to_term1(bin, cont->solitaire); 46 | 47 | return apr_psprintf(pool, "%s", term2html(exploded, cont->atoms, pool)); 48 | } 49 | 50 | //EOF 51 | -------------------------------------------------------------------------------- /gh-pages/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

This is a test teeterl project page

5 | 6 | -------------------------------------------------------------------------------- /include/atom.h: -------------------------------------------------------------------------------- 1 | #ifndef ATOM_H 2 | #define ATOM_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include "cstr.h" 35 | 36 | #ifndef ATOMS_T_DEFINED 37 | typedef struct atoms_t atoms_t; 38 | #define ATOMS_T_DEFINED 39 | #endif 40 | 41 | #include "atom_defs.h" 42 | 43 | atoms_t *atoms_make(apr_pool_t *pool); 44 | int atoms_set(atoms_t *self, cstr_t *str); 45 | cstr_t *atoms_get(atoms_t *self, int a); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/bifimpl.h: -------------------------------------------------------------------------------- 1 | #ifndef BIFIMPL_H 2 | #define BIFIMPL_H 3 | 4 | // the only include file needed for BIF implementation file 5 | 6 | #include "teeterl.h" 7 | #include "term.h" 8 | #include "proc.h" 9 | #include "atom.h" 10 | #include "compare.h" 11 | #include "list.h" 12 | #include "mpi.h" 13 | 14 | // TODO: rename bif_error -- confused with bif_error1 15 | 16 | // TODO: Stack trace building 17 | // TODO: Include stack trace into reason 18 | 19 | #define bif_exception(__reason) \ 20 | do { \ 21 | proc->result.what = SLICE_RESULT_ERROR; \ 22 | proc->result.reason = __reason; \ 23 | return noval; \ 24 | } while (0) 25 | 26 | #define bif_bad_arg(__arg) bif_exception(A_BADARG) 27 | #define bif_bad_arg0() bif_exception(A_BADARG) 28 | #define bif_not_implemented() bif_exception(A_NOT_IMPLEMENTED) 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_H 2 | #define BINARY_H 3 | 4 | #include "term.h" 5 | 6 | #define BIN_BYTE_SIZE(bit_size) (((bit_size) + 7) >> 3) 7 | #define BIN_WHOLE_BYTES(bit_size) ((bit_size) >> 3) 8 | #define BIN_TRAILER_SIZE(bit_size) ((bit_size) & 7) 9 | #define BIN_MASK(bit_size) ((1 << (bit_size)) - 1) 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /include/bits.h: -------------------------------------------------------------------------------- 1 | #ifndef BITS_H 2 | #define BITS_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | void splice_bits(apr_byte_t *dst, int boff, apr_byte_t *src, int nbits); 34 | void fetch_bits(apr_byte_t *src, int boff, apr_byte_t *dst, int nbits); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUFFER_H 2 | #define BUFFER_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | typedef struct buffer_t buffer_t; 36 | 37 | buffer_t *buffer_make(apr_pool_t *pool, int max); 38 | void buffer_resize(buffer_t *self, int avail); 39 | void buffer_clear(buffer_t *self); 40 | void buffer_consume(buffer_t *self, int size); 41 | 42 | int buffer_len(buffer_t *self); 43 | apr_byte_t *buffer_ptr(buffer_t *self); 44 | int buffer_available(buffer_t *self); 45 | 46 | apr_uint32_t buffer_get32(buffer_t *self); 47 | apr_uint16_t buffer_get16(buffer_t *self); 48 | apr_byte_t buffer_get(buffer_t *self); 49 | 50 | void buffer_put_byte(buffer_t *self, apr_byte_t b); 51 | void buffer_put_data(buffer_t *self, apr_byte_t *data, int size); 52 | 53 | apr_status_t buffer_file_read(buffer_t *self, apr_file_t *file, apr_size_t len); 54 | apr_status_t buffer_file_write(buffer_t *self, apr_file_t *file); 55 | apr_status_t buffer_socket_recv(buffer_t *self, apr_socket_t *sock); 56 | apr_status_t buffer_socket_send(buffer_t *self, apr_socket_t *sock); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/code_base.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_BASE_H 2 | #define CODE_BASE_H 3 | 4 | #include "term.h" 5 | #include "proc.h" 6 | 7 | #include 8 | 9 | #ifndef CODE_BASE_T_DEFINED 10 | typedef struct code_base_t code_base_t; 11 | #define CODE_BASE_T_DEFINED 12 | #endif 13 | 14 | typedef struct builtin_t builtin_t; 15 | struct builtin_t { 16 | struct bif_key_t { 17 | term_t module; 18 | term_t function; 19 | int arity; 20 | } key; 21 | bifN_t entry; 22 | }; 23 | 24 | extern builtin_t builtins[]; 25 | 26 | typedef struct export_t export_t; 27 | struct export_t { 28 | struct exp_key_t { 29 | term_t function; 30 | int arity; 31 | } key; 32 | codel_t *entry; 33 | }; 34 | 35 | typedef struct fun_slot_t fun_slot_t; 36 | struct fun_slot_t { 37 | uint uniq; 38 | codel_t *entry; 39 | }; 40 | 41 | typedef struct source_ref_t source_ref_t; 42 | struct source_ref_t { 43 | int file_index; 44 | int source_line; 45 | int off_starts; 46 | int off_ends; 47 | }; 48 | 49 | struct module_t { 50 | apr_pool_t *mod_pool; 51 | heap_t *literals; 52 | struct mod_key_t { 53 | term_t module; 54 | int is_old; 55 | } key; 56 | int code_size; // in codels 57 | codel_t *code; 58 | apr_hash_t *exports; 59 | int nfuns; 60 | fun_slot_t *funs; 61 | 62 | // source line info 63 | apr_array_header_t *files; //const char * 64 | apr_array_header_t *source; //source_ref_t 65 | }; 66 | 67 | code_base_t *code_base_make(apr_pool_t *pool); 68 | module_t *code_base_lookup(code_base_t *self, term_t module); 69 | codel_t *module_lookup(module_t *m, term_t function, int arity); 70 | bifN_t code_base_bif(code_base_t *self, term_t module, term_t function, int arity); 71 | int code_base_load(code_base_t *self, named_tuples_t *nm_tuples, 72 | term_t module, term_t exports, term_t fun_table, term_t attrs, term_t preloaded, term_t misc); 73 | int code_base_delete(code_base_t *self, term_t module); 74 | //int code_base_purge(code_base_t *self, uint mod_id); 75 | 76 | int module_source_from_offset(module_t *m, int offset, const char **file, int *line); 77 | int module_offset_from_source(module_t *m, const char *file, int line, int *offset); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/compare.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "term.h" 6 | #include "atom.h" 7 | 8 | #define is_term_bigger(__a, __b, __atoms) is_term_smaller((__b), (__a), (__atoms)) 9 | 10 | int are_terms_equal(term_t a, term_t b); 11 | int is_term_smaller(term_t a, term_t b, atoms_t *atoms); 12 | 13 | //EOF 14 | -------------------------------------------------------------------------------- /include/cstr.h: -------------------------------------------------------------------------------- 1 | #ifndef CSTR_H 2 | #define CSTR_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "heap.h" 34 | 35 | typedef struct cstr_t cstr_t; 36 | struct cstr_t { 37 | apr_byte_t size; 38 | apr_byte_t data[0]; 39 | }; 40 | 41 | cstr_t *ztos(const char *z, heap_t *hp); 42 | const char *stoz(cstr_t *s, heap_t *hp); 43 | int scomp(cstr_t *s1, cstr_t *s2); 44 | cstr_t *scopy(cstr_t *s, heap_t *hp); 45 | cstr_t *scopy2(cstr_t *s, apr_pool_t *pool); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/exterm.h: -------------------------------------------------------------------------------- 1 | #ifndef EXtERM_H 2 | #define EXTERM_H 3 | 4 | #include "term.h" 5 | #include "atom.h" 6 | #include "heap.h" 7 | 8 | term_t binary_to_term(term_t bin, atoms_t *atoms, heap_t *hp); 9 | term_t term_to_binary(term_t t, atoms_t *atoms, heap_t *hp); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /include/heap.h: -------------------------------------------------------------------------------- 1 | #ifndef HEAP_H 2 | #define HEAP_H 3 | 4 | #include 5 | 6 | #include "term.h" 7 | 8 | typedef struct heap_t heap_t; 9 | struct heap_t 10 | { 11 | apr_allocator_t *allocator; 12 | apr_memnode_t *active; 13 | 14 | // char *htop; 15 | // htop must be first_avail; otherwise gc won't work 16 | 17 | char *hend; 18 | 19 | int alloc_size; 20 | 21 | apr_memnode_t *gc_last; 22 | apr_memnode_t *gc_spot; 23 | }; 24 | 25 | #define heap_htop(hp) ((hp)->active->first_avail) 26 | 27 | heap_t *heap_make(apr_pool_t *pool); 28 | apr_byte_t *heap_alloc(heap_t *hp, int size); 29 | int heap_chunk_count(heap_t *hp); 30 | int heap_size(heap_t *hp); 31 | 32 | void heap_anticipate_need(heap_t *hp, int size); 33 | void heap_reclaim_unused(heap_t *hp, int size); 34 | int heap_need_anticipated(heap_t *hp); // mostly, for gc 35 | 36 | // Oddball term allocations; in bifs? 37 | term_t heap_float(heap_t *hp, double value); 38 | term_t heap_bignum0(heap_t *hp, mp_sign sign, mp_size size); 39 | term_t heap_bignum(heap_t *hp, mp_sign sign, mp_size size, mp_digit *digits); 40 | term_t heap_binary0(heap_t *hp, int bit_size); 41 | term_t heap_binary(heap_t *hp, int bit_size, apr_byte_t *data); 42 | term_t heap_binary_shared(heap_t *hp, int bit_size, apr_byte_t *data, term_t parent); 43 | term_t heap_fun(heap_t *hp, term_t module, term_t function, int arity, uint mod_id, int index, term_t frozen); 44 | term_t heap_long_pid(heap_t *hp, term_t node, int serial, int creation); 45 | term_t heap_long_oid(heap_t *hp, term_t node, int serial, int creation); 46 | term_t heap_long_id(heap_t *hp, term_t node, int serial, int tag_creat); 47 | term_t heap_tuple(heap_t *hp, int size); 48 | term_t heap_tuple1(heap_t *hp, term_t e1); 49 | term_t heap_tuple2(heap_t *hp, term_t e1, term_t e2); 50 | term_t heap_tuple3(heap_t *hp, term_t e1, term_t e2, term_t e3); 51 | term_t heap_tuple4(heap_t *hp, term_t e1, term_t e2, term_t e3, term_t e4); 52 | term_t heap_tuple5(heap_t *hp, term_t e1, term_t e2, term_t e3, term_t e4, term_t e5); 53 | term_t heap_tuple6(heap_t *hp, term_t e1, term_t e2, term_t e3, term_t e4, term_t e5, term_t e6); 54 | term_t heap_tuple7(heap_t *hp, term_t e1, term_t e2, term_t e3, term_t e4, term_t e5, term_t e6, term_t e7); 55 | term_t heap_tuple8(heap_t *hp, term_t e1, term_t e2, term_t e3, term_t e4, term_t e5, term_t e6, term_t e7, term_t e8); 56 | term_t heap_cons(heap_t *hp, term_t head); 57 | term_t heap_cons2(heap_t *hp, term_t head, term_t tail); 58 | 59 | // copy term to another heap 60 | term_t heap_marshal(term_t t, heap_t *hp); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/heap_gc.h: -------------------------------------------------------------------------------- 1 | #ifndef HEAP_GC_H 2 | #define HEAP_GC_H 3 | 4 | #include 5 | 6 | #include "heap.h" 7 | 8 | apr_status_t heap_gc(heap_t *hp, term_t *roots[], int root_sizes[], int nroots); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /include/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | #include "cstr.h" 5 | #include "term.h" 6 | #include "heap.h" 7 | 8 | int list_length(term_t list); 9 | 10 | #define cons_up(__first, __last, __v, __heap) \ 11 | do { \ 12 | term_t __cons = heap_cons(__heap, __v); \ 13 | if (__last != nil) \ 14 | peel(__last)->cons.tail = __cons; \ 15 | __last = __cons; \ 16 | if (__first == nil) \ 17 | __first = __cons; \ 18 | } while (0) 19 | 20 | const char *ltoz(term_t l, apr_pool_t *pool); 21 | term_t ztol(const char *z, heap_t *hp); 22 | term_t stol(cstr_t *s, heap_t *hp); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/logtab.h: -------------------------------------------------------------------------------- 1 | const double s_logv_2[] = { 2 | 0.000000000, 0.000000000, 1.000000000, 0.630929754, /* 0 1 2 3 */ 3 | 0.500000000, 0.430676558, 0.386852807, 0.356207187, /* 4 5 6 7 */ 4 | 0.333333333, 0.315464877, 0.301029996, 0.289064826, /* 8 9 10 11 */ 5 | 0.278942946, 0.270238154, 0.262649535, 0.255958025, /* 12 13 14 15 */ 6 | 0.250000000, 0.244650542, 0.239812467, 0.235408913, /* 16 17 18 19 */ 7 | 0.231378213, 0.227670249, 0.224243824, 0.221064729, /* 20 21 22 23 */ 8 | 0.218104292, 0.215338279, 0.212746054, 0.210309918, /* 24 25 26 27 */ 9 | 0.208014598, 0.205846832, 0.203795047, 0.201849087, /* 28 29 30 31 */ 10 | 0.200000000, 0.198239863, 0.196561632, 0.194959022, /* 32 33 34 35 */ 11 | 0.193426404, 0.191958720, 0.190551412, 0.189200360, /* 36 37 38 39 */ 12 | 0.187901825, 0.186652411, 0.185449023, 0.184288833, /* 40 41 42 43 */ 13 | 0.183169251, 0.182087900, 0.181042597, 0.180031327, /* 44 45 46 47 */ 14 | 0.179052232, 0.178103594, 0.177183820, 0.176291434, /* 48 49 50 51 */ 15 | 0.175425064, 0.174583430, 0.173765343, 0.172969690, /* 52 53 54 55 */ 16 | 0.172195434, 0.171441601, 0.170707280, 0.169991616, /* 56 57 58 59 */ 17 | 0.169293808, 0.168613099, 0.167948779, 0.167300179, /* 60 61 62 63 */ 18 | 0.166666667 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /include/mixed.h: -------------------------------------------------------------------------------- 1 | #ifndef MIXED_H 2 | #define MIXED_H 3 | 4 | #include "term.h" 5 | #include "heap.h" 6 | 7 | term_t add_mixed(term_t a, term_t b, heap_t *heap); 8 | term_t mult_mixed(term_t a, term_t b, heap_t *heap); 9 | term_t sub_mixed(term_t a, term_t b, heap_t *heap); 10 | term_t mod_mixed(term_t a, term_t b, heap_t *heap); 11 | term_t idiv_mixed(term_t a, term_t b, heap_t *heap); 12 | term_t div_mixed(term_t a, term_t b, heap_t *heap); 13 | term_t bsl_mixed(term_t a, term_t b, heap_t *heap); 14 | term_t bsr_mixed(term_t a, term_t b, heap_t *heap); 15 | term_t bnot_mixed(term_t a, heap_t *heap); 16 | term_t band_mixed(term_t a, term_t b, heap_t *heap); 17 | term_t band_mixed2(term_t a, int i, heap_t *heap); 18 | term_t bor_mixed(term_t a, term_t b, heap_t *heap); 19 | term_t bor_mixed2(term_t a, int i, heap_t *heap); 20 | term_t bxor_mixed(term_t a, term_t b, heap_t *heap); 21 | term_t bxor_mixed2(term_t a, int i, heap_t *heap); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/modbin.h: -------------------------------------------------------------------------------- 1 | #ifndef MODBIN_H 2 | #define MODBIN_H 3 | 4 | #include 5 | #include "cstr.h" 6 | 7 | typedef struct modbin_t modbin_t; 8 | struct modbin_t { 9 | cstr_t *name; 10 | int is_preloaded; 11 | int size; 12 | apr_byte_t data[]; 13 | }; 14 | 15 | extern modbin_t *modbins[]; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/mpi-config.h: -------------------------------------------------------------------------------- 1 | /* Default configuration for MPI library */ 2 | /* $Id: mpi-config.h,v 1.1 2004/02/08 04:29:29 sting Exp $ */ 3 | 4 | #ifndef MPI_CONFIG_H_ 5 | #define MPI_CONFIG_H_ 6 | 7 | /* 8 | For boolean options, 9 | 0 = no 10 | 1 = yes 11 | 12 | Other options are documented individually. 13 | 14 | */ 15 | 16 | #ifndef MP_IOFUNC 17 | #define MP_IOFUNC 0 /* include mp_print() ? */ 18 | #endif 19 | 20 | #ifndef MP_MODARITH 21 | #define MP_MODARITH 0 /* include modular arithmetic ? */ 22 | #endif 23 | 24 | #ifndef MP_NUMTH 25 | #define MP_NUMTH 0 /* include number theoretic functions? */ 26 | #endif 27 | 28 | #ifndef MP_LOGTAB 29 | #define MP_LOGTAB 1 /* use table of logs instead of log()? */ 30 | #endif 31 | 32 | #ifndef MP_MEMSET 33 | #define MP_MEMSET 1 /* use memset() to zero buffers? */ 34 | #endif 35 | 36 | #ifndef MP_MEMCPY 37 | #define MP_MEMCPY 1 /* use memcpy() to copy buffers? */ 38 | #endif 39 | 40 | #ifndef MP_CRYPTO 41 | #define MP_CRYPTO 0 /* erase memory on free? */ 42 | #endif 43 | 44 | #ifndef MP_ARGCHK 45 | /* 46 | 0 = no parameter checks 47 | 1 = runtime checks, continue execution and return an error to caller 48 | 2 = assertions; dump core on parameter errors 49 | */ 50 | #define MP_ARGCHK 2 /* how to check input arguments */ 51 | #endif 52 | 53 | #ifndef MP_DEBUG 54 | #define MP_DEBUG 0 /* print diagnostic output? */ 55 | #endif 56 | 57 | #ifndef MP_DEFPREC 58 | #define MP_DEFPREC 16 /* default precision, in digits */ 59 | #endif 60 | 61 | #ifndef MP_MACRO 62 | #define MP_MACRO 1 /* use macros for frequent calls? */ 63 | #endif 64 | 65 | #ifndef MP_SQUARE 66 | #define MP_SQUARE 0 /* use separate squaring code? */ 67 | #endif 68 | 69 | #ifndef MP_PTAB_SIZE 70 | /* 71 | When building mpprime.c, we build in a table of small prime 72 | values to use for primality testing. The more you include, 73 | the more space they take up. See primes.c for the possible 74 | values (currently 16, 32, 64, 128, 256, and 6542) 75 | */ 76 | #define MP_PTAB_SIZE 128 /* how many built-in primes? */ 77 | #endif 78 | 79 | #ifndef MP_COMPAT_MACROS 80 | #define MP_COMPAT_MACROS 0 /* define compatibility macros? */ 81 | #endif 82 | 83 | #endif /* ifndef MPI_CONFIG_H_ */ 84 | 85 | 86 | -------------------------------------------------------------------------------- /include/msg_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef MSG_QUEUE_H 2 | #define MSG_QUEUE_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include "term.h" 35 | #include "heap.h" 36 | 37 | #define MSGQ_INIT_SIZE 16 38 | 39 | typedef struct msg_queue_t msg_queue_t; 40 | 41 | msg_queue_t *msg_queue_make(apr_pool_t *pool); 42 | void msg_queue_push(msg_queue_t *self, term_t t); 43 | void msg_queue_reset(msg_queue_t *self); 44 | term_t msg_queue_next(msg_queue_t *self); 45 | void msg_queue_drop(msg_queue_t *self); 46 | int msg_queue_len(msg_queue_t *self); 47 | 48 | term_t msg_queue_to_term(msg_queue_t *self, heap_t *hp); 49 | term_t *msg_queue_to_array(msg_queue_t *self, int *len); // for gc mostly 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/named_tuple.h: -------------------------------------------------------------------------------- 1 | #ifndef NAMED_TUPLE 2 | #define NAMED_TUPLE 3 | 4 | #include 5 | 6 | #include "term.h" 7 | 8 | #ifndef NAMED_TUPLES_T_DEFINED 9 | typedef struct named_tuples_t named_tuples_t; 10 | #define NAMED_TUPLES_T_DEFINED 11 | #endif 12 | 13 | named_tuples_t *named_tuples_make(apr_pool_t *pool); 14 | int named_tuples_set(named_tuples_t *self, term_t name, term_t field); 15 | int named_tuples_arity(named_tuples_t *self, term_t name); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/navel.h: -------------------------------------------------------------------------------- 1 | #ifndef NAVEL_H 2 | #define NAVEL_H 3 | 4 | #include 5 | #include 6 | 7 | #include "atom.h" 8 | #include "proc.h" 9 | #include "code_base.h" 10 | #include "scheduler.h" 11 | 12 | const char *term2html(term_t t, atoms_t *atoms, apr_pool_t *pool); 13 | 14 | typedef struct navel_context_t navel_context_t; 15 | struct navel_context_t { 16 | apr_pool_t *pool; // survives between requests 17 | heap_t *heap; // houses sample terms and all 18 | atoms_t *atoms; // for smoother comparison etc 19 | code_base_t *code_base; 20 | apr_array_header_t *sample_terms; 21 | teevm_t *teevm; 22 | proc_t *solitaire; 23 | module_t *module; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/outlet.h: -------------------------------------------------------------------------------- 1 | #ifndef OUTLET_H 2 | #define OUTLET_H 3 | 4 | #include 5 | 6 | #include "proc.h" 7 | #include "term.h" 8 | 9 | typedef struct outlet_t outlet_t; 10 | struct outlet_t { 11 | uint serial; 12 | apr_pool_t *pool; 13 | proc_t *owner_in; 14 | proc_t *owner_out; 15 | void *data; 16 | 17 | int (*want_read)(outlet_t *self); 18 | int (*want_write)(outlet_t *self); 19 | 20 | int (*is_socket)(outlet_t *self); 21 | apr_socket_t *(*get_socket)(outlet_t *self); 22 | int (*is_file)(outlet_t *self); 23 | apr_file_t *(*get_file)(outlet_t *self); 24 | 25 | apr_status_t (*try_read)(outlet_t *self, apr_interval_time_t tick); 26 | apr_status_t (*try_write)(outlet_t *self, apr_interval_time_t tick); 27 | 28 | apr_status_t (*do_readable)(outlet_t *self); 29 | apr_status_t (*do_writable)(outlet_t *self); 30 | 31 | apr_status_t (*send)(outlet_t *self, term_t io); 32 | apr_status_t (*set_option)(outlet_t *self, term_t opt, term_t value); 33 | 34 | apr_status_t (*read)(outlet_t *self, apr_byte_t *buf, apr_size_t *len); 35 | apr_status_t (*write)(outlet_t *self, apr_byte_t *buf, apr_size_t *len); 36 | 37 | apr_status_t (*close)(outlet_t *self); 38 | apr_status_t (*close0)(outlet_t *self); //error, no lingering 39 | }; 40 | 41 | term_t outlet_id(outlet_t *self); 42 | 43 | outlet_t *ol_socket_make(apr_socket_t *sock, int is_connecting); 44 | outlet_t *ol_listener_make(apr_socket_t *sock, teevm_t *teevm); 45 | outlet_t *ol_file_make(apr_file_t *io, teevm_t *teevm); 46 | 47 | int outlet_want_read(outlet_t *self); 48 | int outlet_want_write(outlet_t *self); 49 | 50 | int outlet_is_socket(outlet_t *self); 51 | apr_socket_t *outlet_get_socket(outlet_t *self); 52 | int outlet_is_file(outlet_t *self); 53 | apr_file_t *outlet_get_file(outlet_t *self); 54 | 55 | apr_status_t outlet_try_read(outlet_t *self, apr_interval_time_t tick); 56 | apr_status_t outlet_try_write(outlet_t *self, apr_interval_time_t tick); 57 | 58 | apr_status_t outlet_do_readable(outlet_t *self); 59 | apr_status_t outlet_do_writable(outlet_t *self); 60 | 61 | apr_status_t outlet_send(outlet_t *self, term_t io); 62 | apr_status_t outlet_set_option(outlet_t *self, term_t opt, term_t value); 63 | 64 | apr_status_t outlet_read(outlet_t *self, apr_byte_t *buf, apr_size_t *len); 65 | apr_status_t outlet_write(outlet_t *self, apr_byte_t *buf, apr_size_t *len); 66 | 67 | apr_status_t outlet_close(outlet_t *self); 68 | apr_status_t outlet_close0(outlet_t *self); //error, no lingering 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /include/outlet_mall.h: -------------------------------------------------------------------------------- 1 | #ifndef OUTLET_MALL_H 2 | #define OUTLET_MALL_H 3 | 4 | #include 5 | 6 | #include "outlet.h" 7 | 8 | #ifndef OUTLET_MALL_T_DEFINED 9 | typedef struct outlet_mall_t outlet_mall_t; 10 | #define OUTLET_MALL_T_DEFINED 11 | #endif 12 | 13 | outlet_mall_t *outlet_mall_make(apr_pool_t *pool); 14 | void outlet_mall_allot(outlet_mall_t *mall, outlet_t *ol); 15 | void outlet_mall_kick_out(outlet_mall_t *mall, outlet_t *ol); 16 | outlet_t *outlet_mall_lookup(outlet_mall_t *mall, uint serial); 17 | int outlet_mall_is_dark(outlet_mall_t *mall); 18 | apr_status_t outlet_mall_poll(outlet_mall_t *mall, apr_interval_time_t for_how_long); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/proc_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef PROC_QUEUE_H 2 | #define PROC_QUEUE_H 3 | 4 | #include 5 | 6 | #include "proc.h" 7 | 8 | typedef struct proc_queue_t proc_queue_t; 9 | typedef struct wait_list_t wait_list_t; 10 | typedef struct proc_list_t proc_list_t; 11 | 12 | // a process queue; a single queue for each process priority 13 | proc_queue_t *proc_queue_make(apr_pool_t *pool); 14 | void proc_queue_put(proc_queue_t *pq, proc_t *proc); 15 | int proc_queue_is_empty(proc_queue_t *pq); 16 | int proc_queue_count(proc_queue_t *pq); 17 | proc_t *proc_queue_get(proc_queue_t *pq); 18 | void proc_queue_remove(proc_queue_t *pq, proc_t *proc); 19 | 20 | // a timed list of properties, e.g. processes waiting on receive with timeout 21 | wait_list_t *wait_list_make(apr_pool_t *pool); 22 | void wait_list_put(wait_list_t *self, proc_t *proc, apr_time_t expire); 23 | void wait_list_remove(wait_list_t *self, proc_t *proc); 24 | int wait_list_is_empty(wait_list_t *self); 25 | int wait_list_count(wait_list_t *self); 26 | proc_t *wait_list_expired(wait_list_t *self, apr_time_t now); 27 | apr_interval_time_t wait_list_gap(wait_list_t *self, apr_time_t now); 28 | 29 | // a simple list of processes, e.g. processes waiting for infinity 30 | proc_list_t *proc_list_make(apr_pool_t *pool); 31 | void proc_list_put(proc_list_t *self, proc_t *proc); 32 | void proc_list_remove(proc_list_t *self, proc_t *proc); 33 | int proc_list_count(proc_list_t *self); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/scheduler.h: -------------------------------------------------------------------------------- 1 | #ifndef SCHEDULER_H 2 | #define SCHEDULER_H 3 | 4 | #include "proc_queue.h" 5 | #include "outlet_mall.h" 6 | 7 | #ifndef SUPPRESS_TRACES 8 | #define TRACE_PROCESS_EXITS 1 9 | #define TRACE_PROCESS_SPAWNS 2 10 | #define TRACE_PROCESS_SWITCHES 4 11 | #endif 12 | 13 | typedef struct statistics_t statistics_t; 14 | struct statistics_t { 15 | //context_switches 16 | int context_switches; 17 | 18 | //garbage_collection 19 | int gc_count; 20 | int memory_reclaimed; 21 | 22 | //io 23 | int input_total; 24 | int output_total; 25 | 26 | //reductions 27 | int reductions; 28 | int reductions_slc; 29 | 30 | //runtime 31 | apr_interval_time_t runtime; 32 | apr_interval_time_t runtime_slc; 33 | 34 | //wall_clock 35 | apr_interval_time_t wall_clock; 36 | apr_interval_time_t wall_clock_slc; 37 | }; 38 | 39 | #ifndef SCHEDULER_T_DEFINED 40 | typedef struct scheduler_t scheduler_t; 41 | #define SCHEDULER_T_DEFINED 42 | #endif 43 | 44 | scheduler_t *scheduler_make(outlet_mall_t *mall, apr_pool_t *pool); 45 | #ifndef SUPPRESS_TRACES 46 | void scheduler_trace(scheduler_t *self, uint mask, int yes); 47 | #endif 48 | void scheduler_enlist0(scheduler_t *self, proc_t *first_born); 49 | void scheduler_enlist(scheduler_t *self, proc_t *spawning); 50 | proc_t *scheduler_lookup(scheduler_t *self, uint serial); 51 | void scheduler_new_local_mail(scheduler_t *self, proc_t *proc, term_t msg); 52 | //void scheduler_enqueue(scheduler_t *self, proc_t *proc); 53 | //void scheduler_remove(scheduler_t *self, proc_t *proc); 54 | proc_t *scheduler_next(scheduler_t *self, proc_t *current); 55 | void scheduler_exit_process(scheduler_t *self, proc_t *proc, term_t reason); 56 | 57 | void scheduler_register(scheduler_t *self, proc_t *proc, term_t reg_name); 58 | proc_t *scheduler_lookup_by_name(scheduler_t *self, term_t reg_name); 59 | void scheduler_unregister(scheduler_t *self, term_t reg_name); 60 | 61 | statistics_t *scheduler_stats(scheduler_t *self); 62 | int scheduler_proc_queues(scheduler_t *self, int *wait_count, int *timed_wait_count); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/teeterl.h: -------------------------------------------------------------------------------- 1 | #ifndef TEETERL_H 2 | #define TEETERL_H 3 | 4 | #include 5 | 6 | #include "term.h" 7 | 8 | #ifdef DEBUG 9 | #define assert(x) \ 10 | do { \ 11 | if (!(x)) \ 12 | { \ 13 | fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__); \ 14 | exit(1); \ 15 | } \ 16 | } while (0) 17 | #else 18 | #define assert(x) 19 | #endif 20 | 21 | #define not_implemented(what) \ 22 | do { \ 23 | fprintf(stderr, "not implemented: %s\n", what); \ 24 | exit(1); \ 25 | } while (0) 26 | 27 | term_t decipher_status(apr_status_t rs); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/teevm.h: -------------------------------------------------------------------------------- 1 | #ifndef TEEVM_H 2 | #define TEEVM_H 3 | 4 | 5 | typedef struct scheduler_t scheduler_t; 6 | #define SCHEDULER_T_DEFINED 7 | typedef struct code_base_t code_base_t; 8 | #define CODE_BASE_T_DEFINED 9 | 10 | #ifndef ATOMS_T_DEFINED 11 | typedef struct atoms_t atoms_t; 12 | #define ATOMS_T_DEFINED 13 | #endif 14 | 15 | #ifndef NAMED_TUPLES_T_DEFINED 16 | typedef struct named_tuples_t named_tuples_t; 17 | #define NAMED_TUPLES_T_DEFINED 18 | #endif 19 | 20 | typedef struct outlet_mall_t outlet_mall_t; 21 | #define OUTLET_MALL_T_DEFINED 22 | 23 | typedef struct teevm_t teevm_t; 24 | struct teevm_t { 25 | atoms_t *atoms; 26 | named_tuples_t *nm_tuples; 27 | code_base_t *base; 28 | scheduler_t *scheduler; 29 | outlet_mall_t *mall; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /list.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "list.h" 6 | 7 | int list_length(term_t list) 8 | { 9 | int len = 0; 10 | while (is_cons(list)) 11 | { 12 | len++; 13 | list = peel(list)->cons.tail; 14 | } 15 | return len; 16 | } 17 | 18 | const char *ltoz(term_t l, apr_pool_t *pool) 19 | { 20 | int n = list_length(l); 21 | term_t x = l; 22 | char *buf, *p; 23 | 24 | if (n == 0) 25 | return ""; 26 | 27 | buf = apr_palloc(pool, n+1); //+1 for null byte 28 | p = buf; 29 | 30 | x = l; 31 | while (is_cons(x)) 32 | { 33 | term_box_t *cb = peel(x); 34 | term_t v = cb->cons.head; 35 | if (is_int(v)) 36 | *p++ = int_value(v); 37 | x = cb->cons.tail; 38 | } 39 | *p = 0; 40 | 41 | return buf; 42 | } 43 | 44 | 45 | term_t ztol(const char *z, heap_t *hp) 46 | { 47 | term_t first = nil; 48 | term_t last = nil; 49 | while (*z) 50 | cons_up(first, last, tag_int(*z++), hp); 51 | return first; 52 | } 53 | 54 | term_t stol(cstr_t *s, heap_t *hp) 55 | { 56 | int i; 57 | term_t first = nil; 58 | term_t last = nil; 59 | for (i = 0; i < s->size; i++) 60 | cons_up(first, last, tag_int(s->data[i]), hp); 61 | return first; 62 | } 63 | 64 | //EOF 65 | -------------------------------------------------------------------------------- /mod/comet.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | -module(comet). 5 | -export([start/0,stop/0]). 6 | -export([post_message/2,get_messages/1,get_messages/2]). 7 | -export([navel_request/2]). 8 | 9 | -import(lists, [foreach/2,filter/2,concat/1]). 10 | 11 | -export([loop/0]). 12 | 13 | -include("navel.hrl"). 14 | 15 | -record(comet, {next_id = 0, 16 | seen = -1, 17 | messages = [], 18 | pollers = []}). 19 | 20 | start() -> 21 | Pid = spawn(?MODULE, loop, []), 22 | register(comet, Pid). 23 | 24 | stop() -> 25 | comet ! {stop,self()}. 26 | 27 | post_message(Channel, Data) -> 28 | comet ! {msg,self(),Channel,Data}, 29 | ok. 30 | 31 | get_messages(Timeout) -> 32 | get_messages(-1, Timeout). 33 | 34 | get_messages(LastSeen, Timeout) -> 35 | comet ! {poll,self(),LastSeen}, 36 | receive 37 | {comet,_From,Messages} -> 38 | {ok,Messages} 39 | after Timeout -> 40 | timeout 41 | end. 42 | 43 | loop() -> 44 | loop(#comet{}). 45 | 46 | loop(State) -> 47 | receive 48 | {msg,_From,Channel,Data} -> 49 | 50 | NextId = State#comet.next_id, 51 | Msg = {NextId,Channel,Data}, 52 | Messages = [Msg|State#comet.messages], 53 | 54 | loop(broadcast(State#comet{next_id = NextId+1, messages = Messages})); 55 | 56 | {poll,From,Id} -> 57 | 58 | Pollers = [From|State#comet.pollers], 59 | LastSeen = if Id > State#comet.seen -> Id; 60 | true -> State#comet.seen end, 61 | 62 | loop(broadcast(State#comet{pollers = Pollers, seen = LastSeen})); 63 | 64 | {stop,_} -> 65 | done 66 | end. 67 | 68 | broadcast(State) -> %% State 69 | 70 | LastSeen = State#comet.seen, 71 | UnseenMessages = filter(fun({Id,_,_}) -> 72 | Id > LastSeen 73 | end, State#comet.messages), 74 | 75 | if UnseenMessages =/= [], State#comet.pollers =/= [] -> 76 | foreach(fun(Pid) -> 77 | Pid ! {comet,self(),UnseenMessages} 78 | end, State#comet.pollers), 79 | State#comet{messages = [], pollers = []}; 80 | 81 | true -> 82 | State#comet{messages = UnseenMessages} 83 | end. 84 | 85 | format_messages(Messages) -> 86 | Ms = [concat(["{","id:",Id,",", 87 | "channel:'",Channel,"',", 88 | "data:",format:to_json(Data),"}"]) || {Id,Channel,Data} <- Messages], 89 | ["[",string:join(Ms, ","),"]"]. 90 | 91 | navel_request(#navreq{what="/comet",params=Params}=Req, _Config) -> 92 | LastSeen = if Params =/= "" -> list_to_integer(Params); 93 | true -> -1 end, 94 | case comet:get_messages(LastSeen, 30000) of 95 | {ok,Messages} -> 96 | navel:r(Req, ok, [], format_messages(Messages)); 97 | timeout -> 98 | navel:r(Req, ok, [], "[]") 99 | end; 100 | navel_request(_, _) -> false. 101 | 102 | %%EOF 103 | -------------------------------------------------------------------------------- /mod/erlang.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | 5 | -module(erlang). 6 | -export([integer_to_list/1,integer_to_list/2]). 7 | -export([list_to_integer/1,list_to_integer/2]). 8 | -export([split_binary/2]). 9 | 10 | integer_to_list(I) -> 11 | erlang:integer_to_list(I, 10). 12 | 13 | integer_to_list(I, Base) 14 | when is_integer(I), is_integer(Base), Base >= 2, Base =< 1+$Z-$A+10 -> 15 | if I < 0 -> 16 | [$-|integer_to_list(-I, Base, [])]; 17 | true -> 18 | integer_to_list(I, Base, []) 19 | end; 20 | integer_to_list(I, Base) -> 21 | erlang:error(badarg, [I, Base]). 22 | 23 | integer_to_list(I0, Base, R0) -> 24 | D = I0 rem Base, 25 | I1 = I0 div Base, 26 | R1 = if D >= 10 -> 27 | [D-10+$A|R0]; 28 | true -> 29 | [D+$0|R0] 30 | end, 31 | if I1 =:= 0 -> 32 | R1; 33 | true -> 34 | integer_to_list(I1, Base, R1) 35 | end. 36 | 37 | list_to_integer(L) -> 38 | erlang:list_to_integer(L, 10). 39 | 40 | list_to_integer(L, Base) 41 | when is_list(L), is_integer(Base), Base >= 2, Base =< 1+$Z-$A+10 -> 42 | case list_to_integer_sign(L, Base) of 43 | I when is_integer(I) -> 44 | I; 45 | Fault -> 46 | erlang:error(Fault, [L,Base]) 47 | end; 48 | list_to_integer(L, Base) -> 49 | erlang:error(badarg, [L,Base]). 50 | 51 | list_to_integer_sign([$-|[_|_]=L], Base) -> 52 | case list_to_integer(L, Base, 0) of 53 | I when is_integer(I) -> 54 | -I; 55 | I -> 56 | I 57 | end; 58 | list_to_integer_sign([$+|[_|_]=L], Base) -> 59 | list_to_integer(L, Base, 0); 60 | list_to_integer_sign([_|_]=L, Base) -> 61 | list_to_integer(L, Base, 0); 62 | list_to_integer_sign(_, _) -> 63 | badarg. 64 | 65 | list_to_integer([D|L], Base, I) 66 | when is_integer(D), D >= $0, D =< $9, D < Base+$0 -> 67 | list_to_integer(L, Base, I*Base + D-$0); 68 | list_to_integer([D|L], Base, I) 69 | when is_integer(D), D >= $A, D < Base+$A-10 -> 70 | list_to_integer(L, Base, I*Base + D-$A+10); 71 | list_to_integer([D|L], Base, I) 72 | when is_integer(D), D >= $a, D < Base+$a-10 -> 73 | list_to_integer(L, Base, I*Base + D-$a+10); 74 | list_to_integer([], _, I) -> 75 | I; 76 | list_to_integer(_, _, _) -> 77 | badarg. 78 | 79 | split_binary(B, N) when is_binary(B), is_integer(N) -> 80 | <> = B, 81 | {B1,B2}. 82 | 83 | %%EOF 84 | -------------------------------------------------------------------------------- /mod/error_handler.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(error_handler). 28 | -export([undefined_function/3]). 29 | 30 | undefined_function(Mod, Func, Args) -> 31 | %erlang:display(concat("referenced ",Mod,":",Func,"/",length(Args),"\n")), 32 | case code:is_loaded(Mod) of 33 | false -> 34 | case code:load_module(Mod) of 35 | true -> 36 | erlang:apply(Mod, Func, Args); 37 | _ -> 38 | erlang:error({undef,[{Mod,Func,Args}]}) 39 | end; 40 | _ -> 41 | erlang:error({undef,[{Mod,Func,Args}]}) 42 | end. 43 | 44 | %% EOF 45 | -------------------------------------------------------------------------------- /mod/inet.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(inet). 28 | -export([getaddrs/2,addr_to_z/1]). 29 | 30 | getaddrs(Address, Family) -> 31 | Zaddr = addr_to_z(Address), 32 | case catch inet:getaddrs0(Zaddr, Family) of 33 | {'EXIT',Error} -> 34 | {error,Error}; 35 | IPs -> 36 | {ok,IPs} 37 | end. 38 | 39 | addr_to_z({A,B,C,D}) when is_integer(A), is_integer(B), is_integer(C), is_integer(D) -> 40 | %IoList = io_lib:format("~w.~w.~w.~w\0", [A,B,C,D]), 41 | IoList = [integer_to_list(A),".", 42 | integer_to_list(B),".", 43 | integer_to_list(C),".", 44 | integer_to_list(D),0], 45 | list_to_binary(IoList); 46 | addr_to_z(Addr) when is_list(Addr) -> 47 | list_to_binary(Addr ++ [0]); 48 | addr_to_z(Addr) -> 49 | Addr. 50 | 51 | %% EOF 52 | -------------------------------------------------------------------------------- /mod/init.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | 5 | -module(init). 6 | -export([main/1]). 7 | -export([navel_request/2]). 8 | 9 | -import(lists, [concat/1]). 10 | 11 | -include("navel.hrl"). 12 | -include("trace.hrl"). 13 | 14 | %% 15 | %% TODO: 16 | %% 17 | %% stdout with comet 18 | %% tests 19 | %% gc 20 | %% bignums 21 | %% 22 | 23 | main(_Args) -> 24 | register(init, self()), 25 | 26 | erlang:display("Starting navel on port 9090...\n"), 27 | 28 | comet:start(), 29 | navel:start(#navconf{www_root="navel", 30 | mod_path="xbin", 31 | handlers=[init,test,comet]}), 32 | 33 | % mostly traces dispatch 34 | loop(). 35 | 36 | loop() -> 37 | receive 38 | #postmortem{result=?SLICE_RESULT_DONE} -> 39 | loop(); 40 | #postmortem{result=?SLICE_RESULT_EXIT,reason=normal} -> 41 | loop(); 42 | #postmortem{}=Pm -> 43 | comet:post_message("/sys/scheduler/exit", Pm), 44 | erlang:display({exited,Pm}), 45 | loop() 46 | end. 47 | 48 | navel_request(#navreq{what="/fish"} = Req, _Config) -> 49 | comet:post_message("/std/out", perch), 50 | navel:r(Req, ok, [], "ok"); 51 | navel_request(_, _) -> false. 52 | 53 | %%EOF 54 | -------------------------------------------------------------------------------- /mod/navel.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | 5 | -record(navconf, { 6 | handlers = [], 7 | port = 9090, 8 | www_root = ".", 9 | mod_path = "xbin" 10 | }). 11 | 12 | -record(navreq, { 13 | sock, 14 | method, 15 | what, 16 | params, 17 | vsn, 18 | headers, 19 | body 20 | }). 21 | 22 | %% EOF 23 | -------------------------------------------------------------------------------- /mod/string.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/mod/string.erl -------------------------------------------------------------------------------- /mod/test.erl: -------------------------------------------------------------------------------- 1 | -module(test). 2 | -export([run_file/1]). 3 | -export([fail/1]). 4 | -export([lookup_config/2]). 5 | -export([navel_request/2]). 6 | 7 | -import(lists, [concat/1]). 8 | 9 | -include("navel.hrl"). 10 | 11 | %%----------------------------------------------------------------------------- 12 | 13 | dissect() -> ok. 14 | 15 | % 16 | % NB: Named tuples removed from grammar 17 | % 18 | % Car1 = {car#model <- "Lexus", mpg <- 30}, 19 | % Car2 = {model <- "Honda"}, 20 | % Index = car#mpg, 21 | % {"Car1 = ",Car1,"Car2 = ",Car2,"Index = ",Index,"Car1.model = ",Car1.model}. 22 | 23 | %%----------------------------------------------------------------------------- 24 | 25 | run_file(File) -> %% HTML 26 | 27 | case file:read_file(File) of 28 | {ok,Bin} -> 29 | case code:load_module(Bin) of 30 | {module,Module} -> 31 | spawn(fun() -> 32 | Msg = case run_tests(Module, []) of 33 | {0,Total} -> 34 | concat([Total," test(s) run successfully"]); 35 | {Failed,Total} -> 36 | concat([Failed," out of ",Total," test(s) failed"]) 37 | end, 38 | report(Msg) 39 | end), 40 | "ok"; 41 | badfile -> 42 | concat(["Bad file"]) 43 | end; 44 | {error,_} -> 45 | concat([File," not found"]) 46 | end. 47 | 48 | run_tests(Module, Config) -> %% {Failed,Total} 49 | run_tests(Module, Config, [all], 0, 0). 50 | 51 | run_tests(_Module, _Config, [], Failed, Total) -> 52 | {Failed,Total}; 53 | run_tests(Module, Config, [Test|Tests], Failed, Total) -> 54 | case catch Module:Test(suite) of 55 | [] -> 56 | F = case catch Module:Test(Config) of 57 | {'EXIT',Reason} -> 58 | 59 | case get(test_loc) of 60 | undefined -> 61 | Msg = {Test,failed_with_reason,Reason}, 62 | report(Msg); 63 | ML -> 64 | Msg = {Test,failed_at,ML,with_reason,Reason}, 65 | report(Msg) 66 | end, 67 | 1; 68 | {comment,Comment} -> 69 | comet:post_message("/std/out", Comment), 70 | report({Test,ok}), 71 | 0; 72 | ok -> 73 | report({Test,ok}), 74 | 0 75 | end, 76 | run_tests(Module, Config, Tests, Failed+F, Total+1); 77 | 78 | More when is_list(More) -> 79 | run_tests(Module, Config, More ++ Tests, Failed, Total); 80 | 81 | _ -> 82 | %% TODO: bark 83 | run_tests(Module, Config, Tests, Failed, Total) 84 | end. 85 | 86 | fail(_) -> todo. 87 | 88 | lookup_config(_What, _Config) -> todo. 89 | 90 | report(Msg) -> 91 | %%erlang:display(Msg ++ "\n"), 92 | comet:post_message("/test/out", Msg). 93 | 94 | navel_request(#navreq{what="/test/run"} = Req, _) -> 95 | Results = test:run_file(Req#navreq.params), 96 | navel:r(Req, ok, [], Results); 97 | navel_request(#navreq{what="/test/dissect"} = Req, _) -> 98 | R = (catch dissect()), 99 | navel:r(Req, ok, [], format:to_json(R)); 100 | navel_request(_, _) -> false. 101 | 102 | %%EOF 103 | -------------------------------------------------------------------------------- /mod/trace.hrl: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | % 4 | 5 | % update code in scheduler.c when the record changes 6 | 7 | -record(postmortem, {pid, % 1 8 | reg_name, % 2 9 | module, % 3 10 | offset, % 4 11 | source, % 5 12 | call_stack, % 6 13 | registers, % 7 14 | slots, % 8 15 | heap_size, % 9 16 | result, % 10 17 | reason}). % 11 18 | 19 | -define(SLICE_RESULT_YIELD, 100). 20 | -define(SLICE_RESULT_WAIT, 101). 21 | -define(SLICE_RESULT_DONE, 102). 22 | -define(SLICE_RESULT_EXIT, 103). 23 | -define(SLICE_RESULT_ERROR, 104). 24 | -define(SLICE_RESULT_THROW, 105). 25 | 26 | %EOF 27 | -------------------------------------------------------------------------------- /modbin.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "modbin.h" 6 | 7 | #include "modbin.inc" 8 | 9 | //EOF 10 | -------------------------------------------------------------------------------- /named_tuple.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "named_tuple.h" 6 | 7 | #include 8 | #include 9 | 10 | typedef struct nm_tuple_t nm_tuple_t; 11 | struct nm_tuple_t { 12 | term_t name; // key 13 | apr_array_header_t *fields; // term_t (atoms) 14 | }; 15 | 16 | struct named_tuples_t { 17 | apr_pool_t *pool; 18 | apr_hash_t *nm_tuples; // key = name 19 | }; 20 | 21 | named_tuples_t *named_tuples_make(apr_pool_t *pool) 22 | { 23 | named_tuples_t *nts = apr_palloc(pool, sizeof(*nts)); 24 | nts->pool = pool; 25 | nts->nm_tuples = apr_hash_make(pool); 26 | return nts; 27 | } 28 | 29 | int named_tuples_set(named_tuples_t *self, term_t name, term_t field) 30 | { 31 | nm_tuple_t *nt = apr_hash_get(self->nm_tuples, &name, sizeof(name)); 32 | if (nt != 0) 33 | { 34 | int i; 35 | for (i = 0; i < nt->fields->nelts; i++) 36 | { 37 | if (APR_ARRAY_IDX(nt->fields, i, term_t) == field) 38 | break; 39 | } 40 | 41 | if (i < nt->fields->nelts) 42 | return i+1; 43 | 44 | APR_ARRAY_PUSH(nt->fields, term_t) = field; 45 | return nt->fields->nelts; 46 | } 47 | else 48 | { 49 | nt = apr_palloc(self->pool, sizeof(*nt)); 50 | nt->name = name; 51 | nt->fields = apr_array_make(self->pool, 4, sizeof(term_t)); 52 | APR_ARRAY_PUSH(nt->fields, term_t) = field; 53 | apr_hash_set(self->nm_tuples, &nt->name, sizeof(nt->name), nt); 54 | return 1; 55 | } 56 | } 57 | 58 | int named_tuples_arity(named_tuples_t *self, term_t name) 59 | { 60 | nm_tuple_t *nt = apr_hash_get(self->nm_tuples, &name, sizeof(name)); 61 | if (nt == 0) 62 | return -1; 63 | return nt->fields->nelts + 1; // +1 for tuple name 64 | } 65 | 66 | //EOF 67 | -------------------------------------------------------------------------------- /navel/comet.html: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 |

[Output]

21 | -------------------------------------------------------------------------------- /navel/compare.html: -------------------------------------------------------------------------------- 1 | 44 |
45 |
[Left arg]
46 |
47 | 48 |
49 |
Sample terms
50 | 51 | -------------------------------------------------------------------------------- /navel/exterm.html: -------------------------------------------------------------------------------- 1 | 8 | 9 |

[Output]

10 | -------------------------------------------------------------------------------- /navel/js/jquery.erlpp.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | (function($) { 6 | 7 | $.erlpp = function(what, options) { 8 | var opts = $.extend({}, $.erlpp.defaults, options); 9 | return format(what, opts); 10 | }; 11 | 12 | $.erlpp.defaults = {}; 13 | 14 | function format(t, opts) { 15 | if (typeof(t) == 'number') { 16 | return t.toString(); // small integer or float 17 | } 18 | else if (typeof(t) == 'string') { 19 | return t; // atom 20 | } 21 | else if (typeof(t) == 'object' && typeof(t.length) != 'undefined') { 22 | var es = $.map(t, function(e) { 23 | if (typeof(e) == 'undefined') 24 | console.log(t); 25 | return format(e, opts); 26 | }); 27 | return '['+es.join(',')+']'; 28 | } 29 | else if (typeof(t) == 'object') { 30 | var selector; 31 | for(var key in t) { 32 | if(t.hasOwnProperty(key)) { 33 | selector = key; 34 | break; 35 | } 36 | } 37 | 38 | switch (selector) { 39 | case 'n': // bignum 40 | return t.n; 41 | case 'b': // binary 42 | if (t.b.length > 64) 43 | return '#binary'; 44 | else 45 | { 46 | var bytes = []; 47 | for (var i = 0; i < t.b.length; i += 2) 48 | bytes.push(parseInt(t.b.substr(i, 2), 16)); 49 | return '<<' + bytes.join(',') + '>>'; 50 | } 51 | case 'f': // fun 52 | return '#fun'; 53 | case 'o': // oid 54 | return '#oid'; 55 | case 'p': // pid 56 | return '#pid'; 57 | case 't': // tuple 58 | var es = $.map(t.t, function(e) { 59 | return format(e, opts); 60 | }); 61 | return '{'+es.join(',')+'}'; 62 | case 's': // string 63 | return '"'+t['s']+'"'; 64 | case 'x': // partial 65 | return '#partial'; 66 | default: 67 | console.log(selector); 68 | throw new Error(); 69 | } 70 | } 71 | else { 72 | console.log(t); 73 | throw new Error(); 74 | } 75 | } 76 | 77 | })(jQuery); 78 | 79 | //EOF 80 | -------------------------------------------------------------------------------- /navel/js/jquery.json-2.2.min.js: -------------------------------------------------------------------------------- 1 | 2 | (function($){$.toJSON=function(o) 3 | {if(typeof(JSON)=='object'&&JSON.stringify) 4 | return JSON.stringify(o);var type=typeof(o);if(o===null) 5 | return"null";if(type=="undefined") 6 | return undefined;if(type=="number"||type=="boolean") 7 | return o+"";if(type=="string") 8 | return $.quoteString(o);if(type=='object') 9 | {if(typeof o.toJSON=="function") 10 | return $.toJSON(o.toJSON());if(o.constructor===Date) 11 | {var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+ 12 | hours+':'+minutes+':'+seconds+'.'+milli+'Z"';} 13 | if(o.constructor===Array) 14 | {var ret=[];for(var i=0;i 2 | 3 | elrang term pp 4 | 5 | 6 | 7 | 8 | 14 | 15 | Hey there, cowboy 16 | 17 | 18 | -------------------------------------------------------------------------------- /navel/ppt1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
{teeterl,
7 |
8 |
sample,
9 |
10 |
[
11 |
12 |
{coo,2,9},
13 |
{module_info,0,107},
14 |
{module_info,1,112},
15 |
{primes,1,13},
16 |
{remdups,2,42},
17 |
{remdups,3,46},
18 |
{reverse,1,72},
19 |
{reverse,2,76},
20 |
{seq,2,94},
21 |
{sieve,1,20},
22 |
{start,0,0}],
23 |
24 |
25 |
[],[],
26 |
27 |
[
28 |
29 |
146,8,
30 |
{t,sample},
31 |
264,
32 |
{t,coo},
33 |
520,
34 |
{t,[1,2]},
35 |
924,
36 |
{b,0},
37 |
1234567890,16777737,131072,165,402,256,131077,162,
38 |
{'@',94},
39 |
154,
40 |
{'@',20},
41 |
1234567890,67,
42 |
{...}|...],
43 |
44 |
45 |
[]
46 |
}
47 |
48 | 49 | 50 | -------------------------------------------------------------------------------- /navel/pretty_term.css: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** 4 | */ 5 | 6 | body 7 | { 8 | font-family: Consolas; 9 | } 10 | 11 | .tuple-leading 12 | { 13 | float: left; 14 | background-color: #eee; 15 | } 16 | 17 | .tuple-body 18 | { 19 | float: left; 20 | background-color: #fee; 21 | } 22 | 23 | .tuple-element 24 | { 25 | float: left; 26 | clear: left; 27 | background-color: #ffe; 28 | } 29 | 30 | .tuple-short-elements 31 | { 32 | float: left; 33 | clear: left; 34 | background-color: #ffe; 35 | } 36 | 37 | .tuple-trailer 38 | { 39 | float: left; 40 | background-color: #f88; 41 | } 42 | 43 | .list-leading 44 | { 45 | float: left; 46 | background-color: #ee8; 47 | } 48 | 49 | .list-body 50 | { 51 | float: left; 52 | background-color: #fea; 53 | } 54 | 55 | .list-element 56 | { 57 | float: left; 58 | clear: left; 59 | background-color: #ffc; 60 | } 61 | 62 | .list-short-elements 63 | { 64 | float: left; 65 | clear: left; 66 | background-color: #ffe; 67 | } 68 | 69 | .list-trailer 70 | { 71 | clear: left; 72 | background-color: #cce; 73 | } 74 | 75 | /*EOF*/ 76 | -------------------------------------------------------------------------------- /navel/pretty_term.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
{teeterl,
8 |
9 |
sample,
10 |
11 | 12 |
[
13 |
14 |
{coo,2,9},
15 |
{module_info,0,107},
16 |
{module_info,1,112},
17 |
{primes,1,13},
18 |
{remdups,2,42},
19 |
{remdups,3,46},
20 |
{reverse,1,72},
21 |
{reverse,2,76},
22 |
{seq,2,94},
23 |
{sieve,1,20},
24 |
{start,0,0}],
25 |
26 | 27 |
28 |
[],[],
29 |
30 | 31 |
[
32 |
33 |
146,8,
34 |
{t,sample},
35 |
264,
36 |
{t,coo},
37 |
520,
38 |
{t,[1,2]},
39 |
924,
40 |
{b,0},
41 |
1234567890,16777737,131072,165,402,256,131077,162,
42 |
{'@',94},
43 |
154,
44 |
{'@',20},
45 |
1234567890,67,
46 |
{...}|...],
47 |
48 | 49 |
50 |
[]
51 |
}
52 |
53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /navel/proc.html: -------------------------------------------------------------------------------- 1 | 10 |

[Status]

11 | 12 |

[Output]

13 | -------------------------------------------------------------------------------- /navel/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | */ 4 | 5 | body 6 | { 7 | font-family: Consolas; 8 | } 9 | 10 | .compare-argument 11 | { 12 | padding: 50px; 13 | float: left; 14 | background: #eec; 15 | font-size: 24px; 16 | } 17 | 18 | .compare-results 19 | { 20 | padding: 50px; 21 | float: left; 22 | background: #eee; 23 | font-size: 24px; 24 | } 25 | 26 | .compare-selected 27 | { 28 | background: #fcc; 29 | } 30 | 31 | .compare-container 32 | { 33 | padding: 0 50px; 34 | } 35 | 36 | #sample-terms 37 | { 38 | clear: both; 39 | padding: 10px 20px; 40 | font-size: 10px; 41 | } 42 | 43 | .tee-noval, .tee-nil, .tee-integer, .tee-atom, 44 | .tee-pid, .tee-oid .tee-float, .tee-binary, .tee-fun 45 | { 46 | display: inline-block; 47 | /*float: left;*/ 48 | } 49 | 50 | .tee-list-elem, .tee-tuple-elem 51 | { 52 | clear: left; 53 | } 54 | 55 | .tee-list, .tee-tuple 56 | { 57 | display: inline-block; 58 | } 59 | 60 | .tee-list-leading, .tee-list-body, .tee-list-trailing 61 | { 62 | float: left; 63 | } 64 | 65 | .tee-tuple-leading, .tee-tuple-body 66 | { 67 | float: left; 68 | } 69 | 70 | /*EOF*/ 71 | -------------------------------------------------------------------------------- /navel/term1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | teeterl 4 | sample 5 | 6 | coo29 7 | module_info0107 8 | module_info1112 9 | primes113 10 | remdups242 11 | remdups346 12 | reverse172 13 | reverse276 14 | seq294 15 | sieve120 16 | start00 17 | 18 | 19 | 20 | 21 | 1468 22 | tsample 23 | 264 24 | tcoo 25 | 520 26 | t[12] 27 | 924 28 | b0 29 | 123456789016777737131072165402256131077162 30 | @94 31 | 154 32 | @20 33 | 123456789067 34 | @34 35 | 336201471677721765536131328162 36 | @42 37 | 162 38 | @20 39 | 2596571016568 40 | @38 41 | 18116543716777646424 42 | tfunction_clause 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /outlet.c: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "outlet.h" 6 | 7 | term_t outlet_id(outlet_t *self) 8 | { 9 | return tag_short_oid(self->serial); 10 | } 11 | 12 | int outlet_want_read(outlet_t *self) 13 | { 14 | if (self->want_read == 0) 15 | return 0; 16 | return self->want_read(self); 17 | } 18 | 19 | int outlet_want_write(outlet_t *self) 20 | { 21 | if (self->want_write == 0) 22 | return 0; 23 | return self->want_write(self); 24 | } 25 | 26 | int outlet_is_socket(outlet_t *self) 27 | { 28 | if (self->is_socket == 0) 29 | return 0; 30 | return self->is_socket(self); 31 | } 32 | 33 | apr_socket_t *outlet_get_socket(outlet_t *self) 34 | { 35 | if (self->get_socket == 0) 36 | return 0; 37 | return self->get_socket(self); 38 | } 39 | 40 | int outlet_is_file(outlet_t *self) 41 | { 42 | if (self->is_file == 0) 43 | return 0; 44 | return self->is_file(self); 45 | } 46 | 47 | apr_file_t *outlet_get_file(outlet_t *self) 48 | { 49 | if (self->get_file == 0) 50 | return 0; 51 | return self->get_file(self); 52 | } 53 | 54 | apr_status_t outlet_try_read(outlet_t *self, apr_interval_time_t tick) 55 | { 56 | if (self->try_read == 0) 57 | return APR_EOF; 58 | return self->try_read(self, tick); 59 | } 60 | 61 | apr_status_t outlet_try_write(outlet_t *self, apr_interval_time_t tick) 62 | { 63 | if (self->try_write == 0) 64 | return APR_EOF; 65 | return self->try_write(self, tick); 66 | } 67 | 68 | apr_status_t outlet_do_readable(outlet_t *self) 69 | { 70 | if (self->do_readable == 0) 71 | return APR_ENOTIMPL; 72 | return self->do_readable(self); 73 | } 74 | 75 | apr_status_t outlet_do_writable(outlet_t *self) 76 | { 77 | if (self->do_writable == 0) 78 | return APR_ENOTIMPL; 79 | return self->do_writable(self); 80 | } 81 | 82 | apr_status_t outlet_send(outlet_t *self, term_t io) 83 | { 84 | if (self->send == 0) 85 | return APR_ENOTIMPL; 86 | return self->send(self, io); 87 | } 88 | 89 | apr_status_t outlet_set_option(outlet_t *self, term_t opt, term_t value) 90 | { 91 | if (self->set_option == 0) 92 | return APR_ENOTIMPL; 93 | return self->set_option(self, opt, value); 94 | } 95 | 96 | apr_status_t outlet_read(outlet_t *self, apr_byte_t *buf, apr_size_t *len) 97 | { 98 | if (self->read == 0) 99 | return APR_ENOTIMPL; 100 | return self->read(self, buf, len); 101 | } 102 | 103 | apr_status_t outlet_write(outlet_t *self, apr_byte_t *buf, apr_size_t *len) 104 | { 105 | if (self->write == 0) 106 | return APR_ENOTIMPL; 107 | return self->write(self, buf, len); 108 | } 109 | 110 | apr_status_t outlet_close(outlet_t *self) 111 | { 112 | if (self->close == 0) 113 | return APR_ENOTIMPL; 114 | return self->close(self); 115 | } 116 | 117 | apr_status_t outlet_close0(outlet_t *self) //error, no lingering 118 | { 119 | if (self->close0 == 0) 120 | return APR_ENOTIMPL; 121 | return self->close0(self); 122 | } 123 | 124 | //EOF 125 | -------------------------------------------------------------------------------- /spec/atoms.tab: -------------------------------------------------------------------------------- 1 | # 2 | # Standard atoms 3 | ################ 4 | # 5 | false 6 | true 7 | 8 | # hijack ! and ++ 9 | ! = ASEND__ 10 | ++ = APLUSPLUS__ 11 | -- = AMINUSMINUS__ 12 | 13 | # catch 14 | EXIT = AEXIT__ 15 | 16 | # preloaded code selectors etc 17 | @ = AT__ 18 | t 19 | b 20 | n 21 | files 22 | source 23 | 24 | # startup 25 | init 26 | main 27 | 28 | # receive after infinity -> ok end 29 | infinity 30 | # receive exceptions 31 | timeout_value 32 | 33 | #process priorities 34 | normal 35 | high 36 | low 37 | 38 | # exception types 39 | error 40 | exit 41 | throw 42 | 43 | # common errors 44 | cancer 45 | badarg 46 | badarith 47 | undef 48 | not_purged 49 | badfile 50 | stale_fun 51 | 52 | # undef 53 | error_handler 54 | undefined_function 55 | 56 | #outlets 57 | tcp 58 | tcp_connected 59 | tcp_closed 60 | tcp_space 61 | expect 62 | require 63 | tcp_accepted 64 | accept 65 | 66 | # international mail 67 | postoffice 68 | envelope 69 | 70 | # get rid of these one day 71 | not_implemented 72 | 73 | # bif implementation 74 | ok 75 | any 76 | inet 77 | not_supported 78 | undefined 79 | module 80 | local 81 | context_switches 82 | garbage_collection 83 | io 84 | reductions 85 | proc_queues 86 | runtime 87 | wall_clock 88 | input 89 | output 90 | run 91 | wait 92 | timed_wait 93 | value 94 | 95 | # 96 | # APR error codes 97 | # 98 | anonymous 99 | badch 100 | child_done 101 | child_notdone 102 | detach 103 | eaboveroot 104 | eabsolute 105 | eacces 106 | eagain 107 | ebaddate 108 | ebadf 109 | ebadip 110 | ebadmask 111 | ebadpath 112 | ebusy 113 | econnaborted 114 | econnrefused 115 | econnreset 116 | edsoopen 117 | eexist 118 | eftype 119 | egeneral 120 | ehostunreach 121 | eincomplete 122 | einit 123 | einprogress 124 | eintr 125 | einval 126 | einvalsock 127 | emfile 128 | emismatch 129 | enametoolong 130 | enetdown 131 | enetunreach 132 | enfile 133 | enodir 134 | enoent 135 | enolock 136 | enomem 137 | enopoll 138 | enoproc 139 | enoshmavail 140 | enosocket 141 | enospc 142 | enostat 143 | enotdir 144 | enotempty 145 | enotenoughentropy 146 | enothdkey 147 | enothread 148 | enotime 149 | enotimpl 150 | enotsock 151 | epathwild 152 | epipe 153 | eproc_unknown 154 | erelative 155 | espipe 156 | esymnotfound 157 | etimedout 158 | exdev 159 | filebased 160 | inchild 161 | incomplete 162 | inparent 163 | keybased 164 | notdetach 165 | notfound 166 | timeup 167 | eof 168 | unknown 169 | 170 | # traces 171 | postmortem 172 | 173 | #EOF 174 | -------------------------------------------------------------------------------- /spec/bif.tab: -------------------------------------------------------------------------------- 1 | # 2 | # lists 3 | # 4 | 5 | lists:keymember(Key,N,TupleList) bif_keymember3 6 | lists:keysearch(Key,N,TupleList) bif_keysearch3 7 | lists:keyfind(Key,N,TupleList) bif_keyfind3 8 | lists:member(Elem,List) bif_member2 9 | lists:reverse(Ls,Hs) bif_reverse2 10 | 11 | erlang:++(List1,List2) bif_plusplus2 12 | erlang:--(List1,List2) bif_minusminus2 13 | 14 | erlang:make_tuple(N,InitValue) bif_make_tuple2 15 | erlang:make_tuple(N,DefValue,InitList) bif_make_tuple3 16 | erlang:setelement(N,Tuple,Value) bif_setelement3 17 | erlang:append_element(Tuple,Elem) bif_append_element2 18 | erlang:tuple_to_list(Tuple) bif_tuple_to_list1 19 | erlang:list_to_tuple(List) bif_list_to_tuple1 20 | 21 | erlang:binary_to_term(Bin) bif_binary_to_term1 22 | erlang:term_to_binary(Term) bif_term_to_binary1 23 | erlang:binary_to_list(Bin) bif_binary_to_list1 24 | erlang:binary_to_list(Bin,Start,Stop) bif_binary_to_list3 25 | erlang:list_to_binary(List) bif_list_to_binary1 26 | 27 | erlang:atom_to_list(Atom) bif_atom_to_list1 28 | erlang:float_to_list(Float) bif_float_to_list1 29 | 30 | erlang:register(RegName,PidOid) bif_register2 31 | erlang:unregister(RegName) bif_unregister1 32 | erlang:whereis(RegName) bif_whereis1 33 | 34 | erlang:spawn(Module,Function,Args) bif_spawn3 35 | erlang:spawn(Fun) bif_spawn1 36 | erlang:!(Pid,Msg) bif_send_msg2 37 | erlang:error(Reason) bif_error1 38 | erlang:error(Reason,Args) bif_error2 39 | erlang:throw(Reason) bif_throw1 40 | erlang:exit(Reason) bif_exit1 41 | erlang:exit(Pid,Reason) bif_exit2 42 | 43 | erlang:put(Key,Value) bif_put2 44 | erlang:erase() bif_erase0 45 | erlang:erase(Key) bif_erase1 46 | erlang:get() bif_get0 47 | erlang:get(Key) bif_get1 48 | 49 | erlang:now() bif_now0 50 | erlang:date() bif_date0 51 | erlang:time() bif_time0 52 | erlang:localtime() bif_localtime0 53 | erlang:universaltime() bif_universaltime0 54 | 55 | erlang:property(Term,Opt) bif_property2 56 | erlang:property(Term,Opt,Val) bif_property3 57 | 58 | erlang:close(Oid) bif_close1 59 | 60 | erlang:statistics(What) bif_statistics1 61 | 62 | erlang:display(Iolist) bif_display1 63 | 64 | erlang:daemonize() bif_daemonize0 65 | 66 | code:is_loaded(Module) bif_is_loaded1 67 | code:load_module(Where) bif_load_module1 68 | 69 | code:source_line(Module,Offset) bif_source_line2 70 | code:module_offset(Module,File,Line) bif_module_offset3 71 | 72 | inet:getaddrs0(Addr,Family) bif_getaddrs0_2 73 | 74 | gen_tcp:controlling_process(Sock,Pid) bif_controlling_process2 75 | gen_tcp:connect_socket(RemIP,RemPort,LocIP,LocPort) bif_connect_socket4 76 | gen_tcp:listen_socket(LocIP,LocPort) bif_listen_socket2 77 | 78 | file:open0(FileName,Mode,Perms) bif_open0_3 79 | file:read0(File,Len) bif_read0_2 80 | file:write0(File,Bin) bif_write0_2 81 | 82 | #EOF 83 | -------------------------------------------------------------------------------- /test/estone.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/test/estone.xls -------------------------------------------------------------------------------- /test/test.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | 5 | -define(line, put(test_loc,{?MODULE,?LINE}),). 6 | -define(t, test). 7 | -define(config, test:lookup_config). 8 | 9 | %%EOF 10 | -------------------------------------------------------------------------------- /util/cli_run.erl: -------------------------------------------------------------------------------- 1 | -module(cli_run). 2 | -compile(export_all). 3 | 4 | exec1([Mod,Fun,A]) -> 5 | M = list_to_atom(Mod), 6 | F = list_to_atom(Fun), 7 | M:F(A). 8 | 9 | unload_mods(Mods) -> 10 | lists:foreach(fun(Mod) -> 11 | M = list_to_atom(Mod), 12 | code:purge(M), 13 | code:delete(M) 14 | end, Mods). 15 | 16 | %%EOF 17 | -------------------------------------------------------------------------------- /util/mods_gen.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% 3 | %% 4 | -module(mods_gen). 5 | -export([modules/1,modules/2]). 6 | 7 | -import(lists,[foreach/2]). 8 | 9 | modules([IncFile|Mods]) -> 10 | modules(IncFile, Mods). 11 | 12 | modules(IncFile, Mods) -> 13 | 14 | Modules = lists:map(fun(M) -> 15 | NameExt = lists:last(string:tokens(M, "/")), 16 | [Name,_Ext] = string:tokens(NameExt, "."), 17 | list_to_atom(Name) 18 | end, Mods), 19 | 20 | {ok,Out} = file:open(IncFile, write), 21 | foreach(fun(M) -> 22 | io:format(Out, "extern modbin_t ~w_modbin;~n", [M]) 23 | end, Modules), 24 | io:format(Out, "~nmodbin_t *modbins[] = {~n", []), 25 | foreach(fun(M) -> 26 | io:format(Out, "\t&~w_modbin,~n", [M]) 27 | end, Modules), 28 | io:format(Out, "\t0,~n};~n", []), 29 | file:close(Out). 30 | 31 | %%EOF 32 | -------------------------------------------------------------------------------- /vintage/BUGS: -------------------------------------------------------------------------------- 1 | Apr 3, 2009: 001: Compiler crashes on the following: {1,2} = A = B = C 2 | Apr 3, 2009: 002: term_to_binary() ignores funs 3 | Apr 4, 2009: 004: float may be packed to 32 bits in binary 4 | Apr 4, 2009: 005: native byte order not implemented 5 | Apr 4, 2009: 006: <<4:4,7:4>> can not be interpreted as bitstrings are not supported (eval_bits.erl requires changes) 6 | Apr 5, 2009: 007: <> = <<1,2>> does not work in interpreter (if sizes are specified) 7 | Apr 8, 2009: 008: FIXED: during binary matching size variable gets cleared prematurely, see comments in binary.c 8 | Apr 21, 2009: 009: <> not supported but no error is emitted (label not defined warnings) 9 | Apr 21, 2009: 010: [] + [] and its kin may return badarith rather than badarg as they do now 10 | Apr 21, 2009: 011: infinity does not handled properly (see num_bif_SUITE) 11 | Apr 22, 2009: 012: 'time' option does not work in x_compile (incompatible code struck at run_tc) 12 | Apr 22, 2009: 013: apply() requires export attribute; compiler front-end does not catch this 13 | Apr 22, 2009: 014: 'links' part of estone test suite does not work, main process dies -------------------------------------------------------------------------------- /vintage/README: -------------------------------------------------------------------------------- 1 | teeterl is a lean portable Erlang. 2 | 3 | teeterl starts from a single executable file without any additional harness. 4 | 5 | teeterl is built using Apache Portable Runtime, a library tested on dozens 6 | of OSes and their flavours. 7 | 8 | teeterl borrows from industry-standard Erlang/OTP, especially when it comes 9 | to compiler front-end. 10 | 11 | PREREQUISITES 12 | 13 | teeterl requires APR 1.3.3 and APR-util 1.3.4 libraries installed on your 14 | system. The library is linked statically and thus not required when running 15 | your teeterl based application. 16 | 17 | The build process also requires Erlang/OTP installed (at least as recent 18 | as R12B-0). Again Erlang/OTP is needed for bootstrapping teeterl only. When 19 | built for the first time, it may be used to build itself. 20 | 21 | Note that currently only 32-bit systems are supported and the system will 22 | refuse to built on 64-bits. 23 | 24 | INSTALLATION 25 | 26 | teeterl is tested on Mac OSX (Leopard), Linux (Ubuntu) and Windows XP. Nothing 27 | should prevent it from building and running on other systems. 28 | 29 | 1. Make sure that APR 1.3.3 and APR-util 1.3.4 are installed. Earlier versions 30 | will not do because of a handy apr_hash_count function needed by teeterl 31 | introduced only in 1.3.4. Jot down locations of APR library binaries and 32 | include files. 33 | 34 | 2. Make sure Erlang/OTP is installed (version R12B-0 or later). Make note of 35 | paths to erl and erlc binaries. 36 | 37 | 3. Check out teeterl from git://github.com/maximk/teeterl.git to a chosen 38 | directory. 39 | 40 | 4. Edit Makefile and replace APR library and include files locations as well 41 | as paths of Erlang/OTP binaries. 42 | 43 | 5. Run 'make all'. 44 | 45 | 6. Wait a few minutes for the build to complete. 46 | 47 | HOW TO USE teeterl 48 | 49 | The output of the build process is twofold. The first and the most valuable 50 | piece is bin/teeterl.a library which may be utilized to create runnable teeterl- 51 | based applications. The second piece is bin/exec - an instance of such 52 | applications suitable for running certain Erlang functions. 53 | 54 | No new shiny shell or anything interactive at the moment. For interactivity 55 | you will need to download and install another project named spurl which is 56 | a web-based front-end to teeterl. 57 | 58 | The primary mode of operation on bin/exec is running the compiler: 59 | 60 | bin/exec x_compile files filename.erl output_dir 61 | 62 | 'x_compile' is a module name, 63 | 'files' is a function name, 64 | 'filename.erl' is the file you want to compile 65 | 'output_dir' is the directory where to put the result 66 | 67 | Result of such command is usually a series of error messages or, if you are 68 | a lucky one, then two files named 'filename.x' and 'filename.cx'. The latter 69 | is the one which is actually needed. 70 | 71 | To grasp how to make use of .cx files produced by the compiler please refer 72 | to the spurl project sources. In short you take a bunch of .cx sources, add 73 | a small main.c file, compile everything and link with teeterl.a and, voila, 74 | you have an executable with all your modules embedded. Just run it and have fun. 75 | -------------------------------------------------------------------------------- /vintage/bif/bif_io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "bif.h" 29 | 30 | //TODO: remove the whole file 31 | #include 32 | 33 | static int write_one(term_t A); 34 | 35 | term_t bif_print_iolist1(term_t IOList, process_t *ctx) 36 | { 37 | if (!write_one(IOList)) 38 | return A_BADARG; 39 | result(A_OK); 40 | return AI_OK; 41 | } 42 | 43 | static int write_one(term_t A) 44 | { 45 | if (is_int(A)) 46 | { 47 | apr_byte_t ch = (apr_byte_t)int_value(A); 48 | fwrite(&ch, 1, 1, stdout); 49 | } 50 | else if (is_cons(A)) 51 | { 52 | term_t h = lst_value(A); 53 | term_t t = lst_next(A); 54 | if (!write_one(h)) 55 | return 0; 56 | if (!write_one(t)) 57 | return 0; 58 | } 59 | else if (is_nil(A)) 60 | { 61 | //skip 62 | } 63 | else if (is_binary(A)) 64 | { 65 | apr_byte_t *data = bin_data(A); 66 | int size = int_value2(bin_size(A)); 67 | fwrite(data, 1, size, stdout); 68 | } 69 | else 70 | return 0; 71 | return 1; 72 | } 73 | 74 | // EOF 75 | -------------------------------------------------------------------------------- /vintage/bin/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | exec 3 | teeterl.a 4 | -------------------------------------------------------------------------------- /vintage/compiler/.gitignore: -------------------------------------------------------------------------------- 1 | ops.erl 2 | bif.erl 3 | -------------------------------------------------------------------------------- /vintage/compiler/erl_compile.hrl: -------------------------------------------------------------------------------- 1 | %% ``The contents of this file are subject to the Erlang Public License, 2 | %% Version 1.1, (the "License"); you may not use this file except in 3 | %% compliance with the License. You should have received a copy of the 4 | %% Erlang Public License along with this software. If not, it can be 5 | %% retrieved via the world wide web at http://www.erlang.org/. 6 | %% 7 | %% Software distributed under the License is distributed on an "AS IS" 8 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 9 | %% the License for the specific language governing rights and limitations 10 | %% under the License. 11 | %% 12 | %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. 13 | %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings 14 | %% AB. All Rights Reserved.'' 15 | %% 16 | %% $Id$ 17 | %% 18 | 19 | %% Generic compiler options, passed from the erl_compile module. 20 | 21 | -record(options, 22 | {includes=[] :: [string()], % Include paths (list of 23 | % absolute directory names). 24 | outdir="." :: string(), % Directory for result 25 | % (absolute path). 26 | output_type=undefined :: atom(), % Type of output file. 27 | defines=[], %% ***MK*** :: [atom() | {atom(),_}], % Preprocessor defines. Each 28 | % element is an atom 29 | % (the name to define), or 30 | % a {Name, Value} tuple. 31 | warning=1 :: non_neg_integer(), % Warning level (0 - no 32 | % warnings, 1 - standard level, 33 | % 2, 3, ... - more warnings). 34 | verbose=false :: bool(), % Verbose (true/false). 35 | optimize=999, % Optimize options. 36 | specific=[], %% ***MK*** :: [_], % Compiler specific options. 37 | outfile="" :: string(), % Name of output file (internal 38 | % use in erl_compile.erl). 39 | cwd :: string() % Current working directory 40 | % for erlc. 41 | }). 42 | 43 | -------------------------------------------------------------------------------- /vintage/compiler/pat_match.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | 28 | %% pattern-matching compilation nodes 29 | -record(kwadler, {anno=[], 30 | body}). 31 | 32 | %-record(kwadler2, {anno=[], 33 | % arg, 34 | % var, 35 | % body}). 36 | 37 | -record(kreceive, {anno=[], 38 | var, 39 | body, 40 | timeout, 41 | action}). 42 | 43 | -record(kselect, {anno=[], 44 | var, 45 | matches=[], 46 | otherwise}). 47 | 48 | -record(kmatch, {anno=[], 49 | class, 50 | vars=[], 51 | then}). 52 | 53 | -record(krange, {anno=[], 54 | min, 55 | max}). 56 | 57 | -record(kliteral, {anno=[], 58 | val}). 59 | 60 | -record(kcons, {anno=[]}). 61 | 62 | -record(ktuple, {anno=[], 63 | arity}). 64 | 65 | -record(kbinary0, {anno=[]}). 66 | 67 | -record(kbinary, {anno=[], 68 | segments}). 69 | 70 | -record(kseg, {anno=[], 71 | type, %% atom: integer, float, binary 72 | size, %% integer or #c_var 73 | unit, %% integer 74 | signed=false, %% boolean 75 | endian=big}). %% atom: big, little, native 76 | 77 | -record(kswitch, {anno=[], 78 | cases=[], 79 | otherwise}). 80 | 81 | -record(kcase, {anno=[], 82 | binds=[], 83 | guard, 84 | body}). 85 | 86 | -record(kbodyref, {anno=[], 87 | ref}). 88 | 89 | -record(kref, {anno=[], 90 | body}). 91 | 92 | -record(kfail, {anno=[], 93 | desc}). 94 | 95 | -record(krecloop, {anno=[]}). 96 | 97 | %% EOF 98 | -------------------------------------------------------------------------------- /vintage/compiler/x_internal.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(x_internal). 28 | -export([obsolete/3]). 29 | 30 | %% 31 | %% Analogous to otp_obsolete 32 | %% 33 | 34 | obsolete(_M, _F, _N) -> no. 35 | 36 | %% other possible values: 37 | %% 38 | %% {experimental, Replacement, Rel} 39 | %% {deprecated, String} 40 | %% {deprecated, Replacement, Rel} 41 | %% {removed, Replacement, Rel} 42 | 43 | %% EOF 44 | -------------------------------------------------------------------------------- /vintage/compiler/xmodule.hrl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | 28 | -define(XVERSION, 100). 29 | 30 | -record(x, {version,name,exports,attrs,code,misc}). 31 | 32 | %% EOF 33 | -------------------------------------------------------------------------------- /vintage/ebin/.gitignore: -------------------------------------------------------------------------------- 1 | *.beam 2 | -------------------------------------------------------------------------------- /vintage/snip/compare.c: -------------------------------------------------------------------------------- 1 | /// equal 2 | term_t a, b; 3 | term_t ok; 4 | b = pop(); 5 | a = pop(); 6 | ok = bool(terms_are_equal(a, b, 0)); 7 | push(ok); 8 | 9 | /// neq 10 | term_t a, b; 11 | int ok; 12 | b = pop(); 13 | a = pop(); 14 | ok = bool(!terms_are_equal(a, b, 0)); 15 | push(ok); 16 | 17 | /// lesseq 18 | term_t a, b; 19 | int ok; 20 | b = pop(); 21 | a = pop(); 22 | 23 | ok = bool(!terms_are_more(a, b, proc->atoms)); 24 | push(ok); 25 | 26 | /// less 27 | term_t a, b; 28 | int ok; 29 | b = pop(); 30 | a = pop(); 31 | 32 | ok = bool(terms_are_less(a, b, proc->atoms)); 33 | push(ok); 34 | 35 | /// moreeq 36 | term_t a, b; 37 | int ok; 38 | b = pop(); 39 | a = pop(); 40 | 41 | ok = bool(!terms_are_less(a, b, proc->atoms)); 42 | push(ok); 43 | 44 | /// more 45 | term_t a, b; 46 | int ok; 47 | b = pop(); 48 | a = pop(); 49 | 50 | ok = bool(terms_are_more(a, b, proc->atoms)); 51 | push(ok); 52 | 53 | /// exeq 54 | term_t a, b; 55 | term_t ok; 56 | b = pop(); 57 | a = pop(); 58 | ok = bool(terms_are_equal(a, b, 1)); 59 | push(ok); 60 | 61 | /// nexeq 62 | term_t a, b; 63 | term_t ok; 64 | b = pop(); 65 | a = pop(); 66 | ok = bool(!terms_are_equal(a, b, 1)); 67 | push(ok); 68 | 69 | /// equal_to(term t) 70 | term_t ok; 71 | ok = bool(terms_are_equal(pop(), t, 0)); 72 | push(ok); 73 | 74 | /// neq_to(term t) 75 | int ok; 76 | ok = bool(!terms_are_equal(pop(), t, 0)); 77 | push(ok); 78 | 79 | /// lesseq_than(term t) 80 | int ok; 81 | ok = bool(!terms_are_more(pop(), t, proc->atoms)); 82 | push(ok); 83 | 84 | /// less_than(term t) 85 | int ok; 86 | ok = bool(terms_are_less(pop(), t, proc->atoms)); 87 | push(ok); 88 | 89 | /// moreeq_than(term t) 90 | int ok; 91 | ok = bool(!terms_are_less(pop(), t, proc->atoms)); 92 | push(ok); 93 | 94 | /// more_than(term t) 95 | int ok; 96 | ok = bool(terms_are_more(pop(), t, proc->atoms)); 97 | push(ok); 98 | -------------------------------------------------------------------------------- /vintage/snip/list.c: -------------------------------------------------------------------------------- 1 | /// car 2 | term_t l = pop(); 3 | push(lst_value(l)); 4 | 5 | /// cdr 6 | term_t l = pop(); 7 | push(lst_next(l)); 8 | 9 | /// make_cons 10 | term_t tail = pop(); 11 | 12 | // wierd lists ok 13 | //if (!is_list(tail)) 14 | // bad_arg(); 15 | 16 | top() = make_list2(top(), tail, proc->gc_cur); 17 | 18 | /// make_cons_nil 19 | top() = make_list(top(), proc->gc_cur); 20 | 21 | /// list_copy 22 | term_t lst = top(); 23 | if (!is_list(lst)) 24 | bad_arg(); 25 | top() = copy_list(lst, proc->gc_cur); // shallow copy 26 | 27 | /// list_append 28 | // a ++ b 29 | term_t b = pop(); 30 | term_t a = top(); 31 | if (!is_list(a)) //b may not be cons: [a|b] 32 | bad_arg(); 33 | if (a == nil) 34 | top() = b; 35 | else if (b != nil) 36 | { 37 | term_t a1; 38 | for (;;) 39 | { 40 | a1 = lst_next(a); 41 | if (!is_cons(a1)) 42 | break; 43 | a = a1; 44 | } 45 | 46 | if (!is_nil(a1)) 47 | bad_arg(); //wierd list not allowed here 48 | 49 | lst_next(a) = b; 50 | } 51 | 52 | /// list_subtract 53 | // a -- b 54 | term_t a, b; 55 | b = pop(); 56 | a = pop(); 57 | 58 | if (!is_proper_list(a) || !is_proper_list(b)) 59 | bad_arg(); 60 | 61 | if (a == nil || b == nil) 62 | push(a); 63 | else 64 | { 65 | while (is_cons(b)) 66 | { 67 | term_t out = lst_value(b); 68 | term_t a1 = nil; 69 | term_t cons = nil; 70 | term_t l = a; 71 | 72 | while (is_cons(l)) 73 | { 74 | term_t v = lst_value(l); 75 | if (terms_are_equal(v, out, 1)) 76 | break; 77 | lst_add(a1, cons, v, proc->gc_cur); 78 | l = lst_next(l); 79 | } 80 | 81 | if (is_cons(l)) 82 | { 83 | if (is_cons(cons)) 84 | lst_next(cons) = lst_next(l); 85 | else 86 | a1 = lst_next(l); 87 | } 88 | 89 | a = a1; 90 | 91 | b = lst_next(b); 92 | } 93 | push(a); 94 | } 95 | 96 | /// pack_tuple(uint arity) 97 | term_t t = make_tuple_elts(arity, 98 | ((term_t *)ds->elts) + ds->nelts - arity, proc->gc_cur); 99 | ds->nelts -= arity; 100 | push(t); 101 | 102 | /// unpack_tuple 103 | term_t t = pop(); 104 | int i; 105 | for (i = 0; i < int_value2(tup_size(t)); i++) 106 | push(tup_elts(t)[i]); 107 | 108 | /// tuple_elem(uint index) 109 | push(tup_elts(pop())[index]); 110 | -------------------------------------------------------------------------------- /vintage/snip/literal.c: -------------------------------------------------------------------------------- 1 | // 2 | // Literals 3 | // 4 | 5 | /// lit(term t) 6 | //TODO: copy is needed because term may be buried during gc 7 | term_t copy = marshal_term(t, proc->gc_cur); 8 | push(copy); 9 | -------------------------------------------------------------------------------- /vintage/snip/msg.c: -------------------------------------------------------------------------------- 1 | /// reset_msgs 2 | term_t per = pop(); 3 | if (per == AI_UNDEFINED || per == A_INFINITY) 4 | proc->timeout = INFINITY; 5 | else 6 | { 7 | apr_uint32_t period_ms; 8 | if (!is_int(per) && !is_bignum(per)) 9 | exception(A_ERROR, make_tuple2(A_TIMEOUT_VALUE, per, proc->gc_cur)); 10 | if (is_int(per)) 11 | { 12 | if (int_value(per) < 0) 13 | exception(A_ERROR, make_tuple2(A_TIMEOUT_VALUE, per, proc->gc_cur)); 14 | period_ms = int_value(per); 15 | } 16 | else //bignum 17 | { 18 | bignum_t *bn = bn_value(per); 19 | if (bn_sign(bn) || bn_size(bn) != 1) //zero is always int 20 | exception(A_ERROR, make_tuple2(A_TIMEOUT_VALUE, per, proc->gc_cur)); 21 | period_ms = bn->digits[0]; 22 | } 23 | 24 | if (period_ms == 0) //special case, no wait 25 | proc->timeout = TIMEOUT_ZERO; 26 | else 27 | { 28 | apr_time_t now = apr_time_now(); 29 | proc->timeout = now + period_ms * 1000; 30 | } 31 | } 32 | 33 | msg_queue_reset(proc->mailbox); 34 | 35 | /// get_msg 36 | term_t msg = msg_queue_next(proc->mailbox); 37 | 38 | if (msg == AI_UNDEFINED) 39 | { 40 | //all message are matched -- check timeout 41 | apr_time_t now = apr_time_now(); 42 | if (proc->timeout == TIMEOUT_ZERO || 43 | (proc->timeout != INFINITY && now >= proc->timeout)) 44 | { 45 | proc->ip = expired; //no value on stack 46 | break; 47 | } 48 | else 49 | { 50 | //retry get_msg after timeout or new message 51 | proc->ip -= 2; //get_arg now has an argument 52 | 53 | if (proc->timeout == INFINITY) 54 | *retval = A_INFINITY; 55 | else 56 | { 57 | *retval = make_tuple3(intnum(proc->timeout/1000000/1000000), 58 | intnum((proc->timeout/1000000) % 1000000), 59 | intnum(proc->timeout % 1000000), 60 | proc->gc_cur); 61 | } 62 | 63 | return AI_WAIT; 64 | } 65 | } 66 | else 67 | push(msg); 68 | 69 | /// drop_msg 70 | msg_queue_drop(proc->mailbox); 71 | 72 | /// send_msg 73 | exception(A_ERROR, A_NOT_IMPLEMENTED); 74 | -------------------------------------------------------------------------------- /vintage/snip/recog.c: -------------------------------------------------------------------------------- 1 | // 2 | // Recognizers 3 | // 4 | 5 | /// is_integer 6 | term_t t = top(); 7 | top() = bool(is_int(t) || is_bignum(t)); 8 | 9 | /// is_bignum 10 | term_t t = top(); 11 | top() = bool(is_bignum(t)); 12 | 13 | /// is_atom 14 | term_t t = top(); 15 | top() = bool(is_atom(t)); 16 | 17 | /// is_boolean 18 | term_t t = top(); 19 | top() = bool(t == A_FALSE || t == A_TRUE); 20 | 21 | /// is_float 22 | term_t t = top(); 23 | top() = bool(is_float(t)); 24 | 25 | /// is_function 26 | term_t t = top(); 27 | top() = bool(is_fun(t)); 28 | 29 | /// is_function2 30 | term_t n = pop(); 31 | term_t fun = top(); 32 | 33 | if (!is_int(n)) 34 | bad_arg(); 35 | 36 | if (!is_fun(fun)) 37 | top() = A_FALSE; 38 | else 39 | { 40 | //TODO: will be gone when fridge becomes list 41 | term_t fridge = fun_fridge(fun); 42 | int nfree = (is_tuple(fridge)) 43 | ?int_value2(tup_size(fun_fridge(fun))) 44 | :0; 45 | int arity1 = int_value2(fun_arity(fun)) - nfree; 46 | top() = bool(int_value2(n) == arity1); 47 | } 48 | 49 | /// is_literal 50 | term_t t = pop(); 51 | push(bool(is_literal(t))); 52 | 53 | /// is_number 54 | term_t t = pop(); 55 | push(bool(is_number(t))); 56 | 57 | /// is_pid 58 | term_t t = pop(); 59 | push(bool(is_pid(t))); 60 | 61 | /// is_port 62 | term_t t = pop(); 63 | push(bool(is_port(t))); 64 | 65 | /// is_record 66 | term_t n = pop(); 67 | term_t a = pop(); 68 | term_t t = top(); 69 | if (!is_int(n) || !is_atom(a)) 70 | bad_arg(); 71 | top() = bool(is_tuple(t) && tup_elts(t)[0] == a && tup_size(t) == n); 72 | 73 | /// is_reference 74 | term_t t = pop(); 75 | push(bool(is_ref(t))); 76 | 77 | /// is_cons 78 | term_t t = pop(); 79 | push(bool(is_cons(t))); 80 | 81 | /// is_nil 82 | term_t t = top(); 83 | top() = bool(is_nil(t)); 84 | 85 | /// is_list 86 | term_t t = top(); 87 | top() = bool(is_list(t)); 88 | 89 | /// is_tuple 90 | term_t t = top(); 91 | top() = bool(is_tuple(t)); 92 | 93 | /// is_tuple_of_arity(uint arity) 94 | term_t t = top(); 95 | int ok = is_tuple(t) && (int_value2(tup_size(t)) == arity); 96 | top() = bool(ok); 97 | 98 | /// is_binary 99 | term_t t = top(); 100 | top() = bool(is_binary(t)); 101 | 102 | -------------------------------------------------------------------------------- /vintage/snip/stack.c: -------------------------------------------------------------------------------- 1 | // 2 | // Stack manipulation 3 | // 4 | 5 | /// dup 6 | term_t t = top(); 7 | push(t); 8 | 9 | /// swap 10 | term_t a, b; 11 | a = top(); 12 | b = top1(); 13 | top() = b; 14 | top1() = a; 15 | 16 | /// drop(uint n) 17 | ds->nelts -= n; 18 | 19 | /// level(uint n) 20 | if (ds->nelts != n) 21 | exception(A_ERROR, A_STACK_LEVEL); 22 | 23 | /// rlevel(uint n) 24 | if (cs->nelts != n) 25 | exception(A_ERROR, A_STACK_LEVEL); 26 | 27 | /// nop 28 | // do nothing 29 | 30 | /// self 31 | // self is known to be local 32 | push(localpid(proc->serial)); 33 | 34 | //term_t pid = make_pid(my_node, proc->serial, 0, proc->gc_cur); 35 | //push(pid); 36 | -------------------------------------------------------------------------------- /vintage/snip/vararg.c: -------------------------------------------------------------------------------- 1 | // 2 | // variables and arguments 3 | // 4 | 5 | /// get_arg(uint ano) 6 | if (arg(ano) == AI_UNDEFINED) 7 | { 8 | int a = 1; 9 | } 10 | push(arg(ano)); 11 | 12 | /// clear_arg(uint ano) 13 | term_t t = arg(ano); 14 | //arg(ano) = AI_UNDEFINED; //TODO: otherwise stack trace does not work 15 | 16 | push(t); 17 | 18 | /// set_arg(uint ano) 19 | arg(ano) = pop(); 20 | 21 | /// push_args(uint n) 22 | while (n--) 23 | rpush(pop()); 24 | 25 | /// set_args(uint n) 26 | while (--n >= 0) 27 | arg(n) = pop(); 28 | 29 | /// get_var(uint vno) 30 | if (var(vno) == AI_UNDEFINED) 31 | { 32 | int a = 1; 33 | } 34 | push(var(vno)); 35 | 36 | /// clear_var(uint vno) 37 | term_t t = var(vno); 38 | if (t == AI_UNDEFINED) 39 | { 40 | int a = 1; 41 | } 42 | var(vno) = AI_UNDEFINED; 43 | push(t); 44 | 45 | /// set_var(uint vno) 46 | var(vno) = pop(); 47 | -------------------------------------------------------------------------------- /vintage/spec/net_tcp.txt: -------------------------------------------------------------------------------- 1 | 2 | nettcp is the subsystem of the networking (netmesh) harness 3 | 4 | it started and stopped by netmesh only 5 | 6 | netmesh may request opening of sinks (listening tcp sockets) 7 | 8 | netmesh may dispatch a message for delivery using nettcp 9 | 10 | messages received through nettcp should be fed to the handler routine supplied by netmesh 11 | 12 | nettcp has no notion of node, only connection specs 13 | 14 | 1. opening of a sink with specification Spec1 is requested. The specification is usually 15 | just the tcp port number. 16 | 17 | a) If sink with the same spec is already open then nothing is done 18 | 19 | b) Opening of the sink attempted (using listen()). No need to make it in a separate 20 | process. The process that accepts connection should be separate because only this 21 | process may recv messages. 22 | 23 | c) If listen() returns error then open_sink returns that error to netmesh. netmesh may 24 | choose ignore it. 25 | 26 | d) If listen() succeeds then the reader is started using a fun() extension to accept 27 | the connection first. The extension should notify the parent process on the outcome 28 | of accept(). If accept() fails then it signal that the sink is no good and it should 29 | be removed. If accept() succeed that we have a fully functional reader process, which 30 | reports its presence to the parent too. 31 | 32 | e) The sink is registered right after listen succeeds. Later a message from the reader 33 | process being constructed (waiting in accept) may send a message to signal that the 34 | sink is no good and should be removed. 35 | 36 | f) Sink is {Sock,Pid} of the listening socket Sock and Pid of the process accepting 37 | connections when new connection is reported the information on the Pid is updated 38 | 39 | //g) To avoid the situation when acceptor changes during closing of sinks, a separate 40 | //process should be launched to -------------------------------------------------------------------------------- /vintage/spec/optab.txt: -------------------------------------------------------------------------------- 1 | 2 | is_integer 3 | is_bignum 4 | is_atom 5 | is_float 6 | is_function 7 | is_literal 8 | is_number 9 | is_pid 10 | is_port 11 | is_reference 12 | is_cons 13 | is_nil 14 | is_list 15 | is_tuple 16 | is_binary 17 | 18 | dup 19 | swap 20 | drop/n 1 21 | drop/n u8 22 | 23 | reset_msgs 24 | get_msg 25 | drop_msg 26 | send_msg 27 | 28 | get_arg/ano 0..7 29 | get_arg/ano u8 30 | clear_arg/ano 0..7 31 | clear_arg/ano u8 32 | set_arg/ano 0..7 33 | set_arg/ano u8 34 | push_args/n 1..4 35 | push_args/n u8 36 | 37 | get_var/vno 0..7 38 | get_var/vno u8 39 | get_var/vno u32 40 | clear_var/vno 0..7 41 | clear_var/vno u8 42 | clear_var/vno u32 43 | set_var/vno 0..7 44 | set_var/vno u8 45 | set_var/vno u32 46 | 47 | jump_if_not/l l8 48 | jump_if_not/l l16 49 | jump_if_not/l l32 50 | 51 | jump_if/l l8 52 | jump_if/l l16 53 | jump_if/l l32 54 | 55 | jump/l l8 56 | jump/l l16 57 | jump/l l32 58 | 59 | catch/l l16 60 | catch/l l32 61 | drop_catch 62 | 63 | lit/t [] 64 | lit/t -4..7 65 | lit/t t 66 | 67 | car 68 | cdr 69 | make_cons 70 | make_cons_nil 71 | list_copy 72 | list_append 73 | list_subtract 74 | 75 | pack_tuple/arity 0..7 76 | pack_tuple/arity u8 77 | pack_tuple/arity u32 78 | unpack_tuple 79 | tuple_size 80 | tuple_elem/n 0..7 81 | tuple_elem/n u8 82 | tuple_elem/n u32 83 | 84 | beg_bin 85 | end_bin 86 | reset_bin 87 | bin_add 88 | bin_fetch 89 | is_bin_consumed 90 | 91 | enter/n u8 92 | enter/n u32 93 | leave 94 | ret/n u8 95 | 96 | addi/i -2..3 97 | subi/i -2..3 98 | 99 | add 100 | sub 101 | or 102 | bor 103 | bxor 104 | bsl 105 | bsr 106 | mult 107 | div 108 | idiv 109 | rem 110 | and 111 | band 112 | equal 113 | neq 114 | lesseq 115 | less 116 | moreeq 117 | more 118 | exeq 119 | nexeq 120 | not 121 | bnot 122 | 123 | equal_to/t -2..3 124 | equal_to/t t 125 | neq_to/t -2..3 126 | neq_to/t t 127 | 128 | bif_call0/entry e08 129 | bif_call1/entry e18 130 | bif_call2/entry e28 131 | bif_call3/entry e38 132 | bif_call4/entry e48 133 | 134 | call/l l16 135 | call/l l32 136 | tail_call/l l16 137 | tail_call/l l32 138 | 139 | call_far/m,f,n a8,a8,u8 140 | call_far/m,f,n a16,a16,u8 141 | tail_call_far/m,f,n a8,a8,u8 142 | tail_call_far/m,f,n a16,a16,u8 143 | 144 | fail/reason t 145 | fail_arg/reason t 146 | 147 | level/n u8 148 | rlevel/n u8 149 | 150 | nop 151 | 152 | l/ref l8 153 | l/ref l16 154 | l/ref l32 155 | -------------------------------------------------------------------------------- /vintage/stdmod/crypto.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(crypto). 28 | 29 | -export([bin_to_hex/1,random_bytes/1]). 30 | 31 | -import(lists,[map/2,foldr/3]). 32 | 33 | bin_to_hex(Bin) when is_binary(Bin) -> 34 | foldr(fun(B, Rs) -> 35 | [H,L] = map(fun(D) when D =< 9 -> 36 | D + $0; 37 | (D) -> 38 | D + $a - 10 39 | end, [B div 16, B rem 16]), 40 | [H,L|Rs] 41 | end, [], binary_to_list(Bin)). 42 | 43 | random_bytes(N) -> 44 | {A,B,C} = now(), 45 | random:seed(A, B, C), 46 | random_bytes_1(N, []). 47 | 48 | random_bytes_1(0, Acc) -> Acc; 49 | random_bytes_1(N, Acc) -> random_bytes_1(N-1, [random:uniform(255)|Acc]). 50 | 51 | %% EOF 52 | -------------------------------------------------------------------------------- /vintage/stdmod/dict.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/dict.erl -------------------------------------------------------------------------------- /vintage/stdmod/erl_bits.hrl: -------------------------------------------------------------------------------- 1 | %% ``The contents of this file are subject to the Erlang Public License, 2 | %% Version 1.0, (the "License"); you may not use this file except in 3 | %% compliance with the License. You may obtain a copy of the License at 4 | %% http://www.erlang.org/EPL1_0.txt 5 | %% 6 | %% Software distributed under the License is distributed on an "AS IS" 7 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 8 | %% the License for the specific language governing rights and limitations 9 | %% under the License. 10 | %% 11 | %% The Original Code is Erlang-4.7.3, December, 1998. 12 | %% 13 | %% The Initial Developer of the Original Code is Ericsson Telecom 14 | %% AB. Portions created by Ericsson are Copyright (C), 1998, Ericsson 15 | %% Telecom AB. All Rights Reserved. 16 | %% 17 | %% Contributor(s): ______________________________________.'' 18 | %% 19 | %% This is an -*- erlang -*- file. 20 | %% Generic compiler options, passed from the erl_compile module. 21 | 22 | -record(bittype, { 23 | type :: 'integer' | 'float' | 'binary', 24 | unit :: 1..256, %% element unit 25 | sign :: 'signed' | 'unsigned', 26 | endian :: 'big' | 'little' | 'native' 27 | }). 28 | 29 | -record(bitdefault, { 30 | integer, %% default type for integer 31 | float, %% default type for float 32 | binary %% default type for binary 33 | }). 34 | 35 | %%% (From config.hrl in the bitsyntax branch.) 36 | -define(SYS_ENDIAN, big). 37 | -define(SIZEOF_CHAR, 1). 38 | -define(SIZEOF_DOUBLE, 8). 39 | -define(SIZEOF_FLOAT, 4). 40 | -define(SIZEOF_INT, 4). 41 | -define(SIZEOF_LONG, 4). 42 | -define(SIZEOF_LONG_LONG, 8). 43 | -define(SIZEOF_SHORT, 2). 44 | -------------------------------------------------------------------------------- /vintage/stdmod/erl_scan.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/erl_scan.erl -------------------------------------------------------------------------------- /vintage/stdmod/error_handler.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(error_handler). 28 | -export([undefined_function/3]). 29 | 30 | -import(erlang, [error/1]). 31 | 32 | -include("compiler/xmodule.hrl"). 33 | 34 | undefined_function(Mod, Func, Args) -> 35 | %erlang:display({referenced,Mod,Func,Args}), 36 | case code:is_loaded(Mod) of 37 | false -> 38 | case code:load_module(Mod) of 39 | ok -> 40 | %% apply2 assumes loaded Erlang code (not a bif, no error_handler) 41 | erlang:apply2(Mod, Func, Args); 42 | {error,_}=Error -> 43 | error({undef,Mod,Func,Args,Error}) 44 | end; 45 | _ -> 46 | error({undef,Mod,Func,Args,{error,no_export}}) 47 | end. 48 | 49 | %% EOF 50 | -------------------------------------------------------------------------------- /vintage/stdmod/error_handler_.erl: -------------------------------------------------------------------------------- 1 | -module(error_handler). 2 | -export([undefined_function/3]). 3 | 4 | -import(erlang, [error/1]). 5 | 6 | -include("compiler/xmodule.hrl"). 7 | 8 | undefined_function(Mod, Func, Args) -> 9 | case code:module_loaded(Mod) of 10 | false -> 11 | {_,Path} = process_info(self(), mod_path), 12 | case find_module(Mod, Path) of 13 | {ok,Bin,File} -> 14 | try 15 | M = binary_to_term(Bin), 16 | 17 | Mod = M#x.name, %% check module name 18 | 19 | case code:load_module(M#x.name, M#x.exports, M#x.code) of 20 | true -> 21 | %% save source line info and function offsets if present 22 | init ! {mod_info, 23 | Mod, 24 | File, 25 | misc_item(M, lineinfo), 26 | misc_item(M, funcoffs)}; 27 | false -> 28 | error(load_module) 29 | end 30 | 31 | catch 32 | error:R -> error({badfile,File,R}) 33 | end; 34 | notfound -> 35 | error({undef,Mod,Func,Args}) 36 | end, 37 | 38 | %% apply2 assumes loaded Erlang code (not a bif, no error_handler) 39 | erlang:apply2(Mod, Func, Args); 40 | true -> 41 | error({undef0,Mod,Func,Args}) 42 | end. 43 | 44 | misc_item(#x{misc=Misc}, Item) -> 45 | case lists:keysearch(Item, 1, Misc) of 46 | {value,{_,Value}} -> 47 | Value; 48 | false -> 49 | none 50 | end. 51 | 52 | find_module(_, []) -> notfound; 53 | find_module(Mod, [Dir|Path]) -> 54 | File = Dir ++ "/" ++ atom_to_list(Mod) ++ ".x", 55 | case file:read_file(File) of 56 | {ok,Bin} -> 57 | {ok,Bin,File}; 58 | _ -> 59 | find_module(Mod, Path) 60 | end. 61 | 62 | %% EOF -------------------------------------------------------------------------------- /vintage/stdmod/file.hrl: -------------------------------------------------------------------------------- 1 | %% ``The contents of this file are subject to the Erlang Public License, 2 | %% Version 1.1, (the "License"); you may not use this file except in 3 | %% compliance with the License. You should have received a copy of the 4 | %% Erlang Public License along with this software. If not, it can be 5 | %% retrieved via the world wide web at http://www.erlang.org/. 6 | %% 7 | %% Software distributed under the License is distributed on an "AS IS" 8 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 9 | %% the License for the specific language governing rights and limitations 10 | %% under the License. 11 | %% 12 | %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. 13 | %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings 14 | %% AB. All Rights Reserved.'' 15 | %% 16 | %% $Id$ 17 | %% 18 | 19 | %%-------------------------------------------------------------------------- 20 | 21 | -type(date() :: {pos_integer(), pos_integer(), pos_integer()}). 22 | -type(time() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}). 23 | -type(date_time() :: {date(), time()}). 24 | 25 | %%-------------------------------------------------------------------------- 26 | 27 | -record(file_info, 28 | {size :: non_neg_integer(), % Size of file in bytes. 29 | type :: 'device' | 'directory' | 'other' | 'regular' | 'symlink', 30 | access :: 'read' | 'write' | 'read_write' | 'none', 31 | atime :: date_time(), % The local time the file was last read: 32 | % {{Year, Mon, Day}, {Hour, Min, Sec}}. 33 | mtime :: date_time(), % The local time the file was last written. 34 | ctime :: date_time(), % The interpretation of this time field 35 | % is dependent on operating system. 36 | % On Unix it is the last time the file or 37 | % or the inode was changed. On Windows, 38 | % it is the creation time. 39 | mode :: integer(), % File permissions. On Windows, 40 | % the owner permissions will be 41 | % duplicated for group and user. 42 | links :: non_neg_integer(), % Number of links to the file (1 if the 43 | % filesystem doesn't support links). 44 | major_device :: integer(), % Identifies the file system (Unix), 45 | % or the drive number (A: = 0, B: = 1) 46 | % (Windows). 47 | %% The following are Unix specific. 48 | %% They are set to zero on other operating systems. 49 | minor_device, % Only valid for devices. 50 | inode :: integer(), % Inode number for file. 51 | uid :: integer(), % User id for owner (integer). 52 | gid :: integer()}). % Group id for owner (integer). 53 | 54 | 55 | -record(file_descriptor, 56 | {module :: atom(), % Module that handles this kind of file 57 | data :: any()}). % Module dependent data 58 | -------------------------------------------------------------------------------- /vintage/stdmod/gb_sets.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/gb_sets.erl -------------------------------------------------------------------------------- /vintage/stdmod/gb_trees.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/gb_trees.erl -------------------------------------------------------------------------------- /vintage/stdmod/gen_udp.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(gen_udp). 28 | -export([open/1,open/2]). 29 | -export([send/4]). 30 | -export([recv/2,recv/3]). 31 | -export([close/1]). 32 | 33 | -record(udp, {family,ip=any}). 34 | 35 | open(Port) -> open(Port, []). 36 | open(Port, Opts) -> 37 | Udp = udp_opts(Opts), 38 | LocalZ = inet:addr_to_z(Udp#udp.ip), 39 | case catch gen_udp:open_socket(LocalZ, Port) of 40 | {'EXIT',Error} -> 41 | {error,Error}; 42 | Sock -> 43 | {ok,Sock} 44 | end. 45 | 46 | send(Socket, Address, Port, Packet) -> 47 | AddrZ = inet:addr_to_z(Address), 48 | case catch gen_udp:sendto(Socket, AddrZ, Port, Packet) of 49 | {'EXIT',Error} -> 50 | {error,Error}; 51 | _ -> 52 | ok 53 | end. 54 | 55 | recv(Sock, Len) -> recv(Sock, Len, infinity). 56 | recv(Sock, Len, Timeout) -> 57 | erlang:set_port_option(Sock, expect, Len), 58 | receive 59 | {udp,Sock,Addr,Port,Data} -> 60 | {ok,{Addr,Port,Data}}; 61 | {udp_closed,Sock} -> 62 | {error,closed} 63 | after Timeout -> 64 | {error,timeout} 65 | end. 66 | 67 | close(Sock) -> 68 | inet:close(Sock). 69 | 70 | udp_opts(Opts) -> udp_opts(Opts, #udp{}). 71 | udp_opts([inet|Opts], Udp) -> udp_opts(Opts, Udp#udp{family=inet}); 72 | udp_opts([inet6|Opts], Udp) -> udp_opts(Opts, Udp#udp{family=inet6}); 73 | udp_opts([{ip,IP}|Opts], Udp) -> udp_opts(Opts, Udp#udp{ip=IP}); 74 | udp_opts(_, Udp) -> Udp. 75 | 76 | %% EOF 77 | -------------------------------------------------------------------------------- /vintage/stdmod/inet.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(inet). 28 | -export([getaddrs/2,addr_to_z/1]). 29 | 30 | getaddrs(Address, Family) -> 31 | Zaddr = addr_to_z(Address), 32 | case catch inet:getaddrs0(Zaddr, Family) of 33 | {'EXIT',Error} -> 34 | {error,Error}; 35 | IPs -> 36 | {ok,IPs} 37 | end. 38 | 39 | addr_to_z({A,B,C,D}) when is_integer(A), is_integer(B), is_integer(C), is_integer(D) -> 40 | IoList = io_lib:format("~w.~w.~w.~w\0", [A,B,C,D]), 41 | list_to_binary(IoList); 42 | addr_to_z(Addr) when is_list(Addr) -> 43 | list_to_binary(Addr ++ [0]); 44 | addr_to_z(Addr) -> 45 | Addr. 46 | 47 | %% EOF 48 | -------------------------------------------------------------------------------- /vintage/stdmod/io_lib.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/io_lib.erl -------------------------------------------------------------------------------- /vintage/stdmod/os.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(os). 28 | 29 | %% 30 | %% 31 | %% 32 | 33 | %% EOF 34 | -------------------------------------------------------------------------------- /vintage/stdmod/prim_erlang.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(prim_erlang). 28 | -export(['!'/2]). 29 | -export([catch0/2,catch1/2]). 30 | 31 | -import(erlang,[is_local_node/1]). 32 | 33 | '!'(Rcpt, Msg) when is_atom(Rcpt) -> 34 | erlang:send_msg0(Rcpt, Msg); 35 | 36 | '!' ({RegName,Node}, Msg) when is_atom(RegName), is_atom(Node) -> 37 | case is_local_node(Node) of 38 | true -> 39 | erlang:send_msg0(RegName, Msg); 40 | false -> 41 | netmesh:deliver(Node, RegName, Msg) 42 | end; 43 | 44 | '!'(Rcpt, Msg) -> 45 | Node = node(Rcpt), 46 | case is_local_node(Node) of 47 | true -> 48 | erlang:send_msg0(Rcpt, Msg); 49 | false -> %% remote send 50 | netmesh:deliver(Node, Rcpt, Msg) 51 | end. 52 | 53 | catch0(error, Reason) -> 54 | {'EXIT',{Reason,erlang:get_stacktrace()}}; 55 | catch0(exit, Reason) -> 56 | {'EXIT',Reason}; 57 | catch0(_, Reason) -> 58 | Reason. 59 | 60 | catch1(error, Reason) when is_tuple(Reason) -> 61 | if size(Reason) > 0 -> element(1, Reason); %% avoid eternal loop if size is in guard 62 | true -> Reason end; 63 | catch1(_, Reason) -> 64 | Reason. 65 | 66 | %% EOF 67 | -------------------------------------------------------------------------------- /vintage/stdmod/random.erl: -------------------------------------------------------------------------------- 1 | %% ``The contents of this file are subject to the Erlang Public License, 2 | %% Version 1.1, (the "License"); you may not use this file except in 3 | %% compliance with the License. You should have received a copy of the 4 | %% Erlang Public License along with this software. If not, it can be 5 | %% retrieved via the world wide web at http://www.erlang.org/. 6 | %% 7 | %% Software distributed under the License is distributed on an "AS IS" 8 | %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 9 | %% the License for the specific language governing rights and limitations 10 | %% under the License. 11 | %% 12 | %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. 13 | %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings 14 | %% AB. All Rights Reserved.'' 15 | %% 16 | %% $Id$ 17 | %% 18 | -module(random). 19 | 20 | %% Reasonable random number generator. 21 | %% The method is attributed to B.A. Wichmann and I.D.Hill 22 | %% See "An efficient and portable pseudo-random number generator", 23 | %% Journal of Applied Statistics. AS183. 1982. Also Byte March 1987. 24 | 25 | -export([seed/0,seed/3,uniform/0,uniform/1, 26 | uniform_s/1, uniform_s/2, seed0/0]). 27 | 28 | 29 | seed0() -> 30 | {3172, 9814, 20125}. 31 | 32 | %% seed() 33 | %% Seed random number generation with default values 34 | 35 | seed() -> 36 | seed(seed0()). 37 | 38 | seed({A1, A2, A3}) -> 39 | case seed(A1, A2, A3) of 40 | undefined -> seed0(); 41 | Tuple -> Tuple 42 | end. 43 | 44 | %% seed(A1, A2, A3) 45 | %% Seed random number generation 46 | 47 | seed(A1, A2, A3) -> 48 | put(random_seed, 49 | {abs(A1) rem 30269, abs(A2) rem 30307, abs(A3) rem 30323}). 50 | 51 | %% uniform() 52 | %% Returns a random float between 0 and 1. 53 | 54 | uniform() -> 55 | {A1, A2, A3} = case get(random_seed) of 56 | undefined -> seed0(); 57 | Tuple -> Tuple 58 | end, 59 | B1 = (A1*171) rem 30269, 60 | B2 = (A2*172) rem 30307, 61 | B3 = (A3*170) rem 30323, 62 | put(random_seed, {B1,B2,B3}), 63 | R = A1/30269 + A2/30307 + A3/30323, 64 | R - trunc(R). 65 | 66 | %% uniform(N) -> I 67 | %% Given an integer N >= 1, uniform(N) returns a random integer 68 | %% between 1 and N. 69 | 70 | uniform(N) when N >= 1 -> 71 | trunc(uniform() * N) + 1. 72 | 73 | 74 | %%% Functional versions 75 | 76 | %% uniform_s(State) -> {F, NewState} 77 | %% Returns a random float between 0 and 1. 78 | 79 | uniform_s({A1, A2, A3}) -> 80 | B1 = (A1*171) rem 30269, 81 | B2 = (A2*172) rem 30307, 82 | B3 = (A3*170) rem 30323, 83 | R = A1/30269 + A2/30307 + A3/30323, 84 | {R - trunc(R), {B1,B2,B3}}. 85 | 86 | %% uniform_s(N, State) -> {I, NewState} 87 | %% Given an integer N >= 1, uniform(N) returns a random integer 88 | %% between 1 and N. 89 | 90 | uniform_s(N, State0) when N >= 1 -> 91 | {F, State1} = uniform_s(State0), 92 | {trunc(F * N) + 1, State1}. 93 | -------------------------------------------------------------------------------- /vintage/stdmod/rpc.erl: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (c) 2009, Maxim Kharchenko 3 | %% All rights reserved. 4 | %% 5 | %% Redistribution and use in source and binary forms, with or without 6 | %% modification, are permitted provided that the following conditions are met: 7 | %% * Redistributions of source code must retain the above copyright 8 | %% notice, this list of conditions and the following disclaimer. 9 | %% * Redistributions in binary form must reproduce the above copyright 10 | %% notice, this list of conditions and the following disclaimer in the 11 | %% documentation and/or other materials provided with the distribution. 12 | %% * Neither the name of the author nor the names of his contributors 13 | %% may be used to endorse or promote products derived from this software 14 | %% without specific prior written permission. 15 | %% 16 | %% THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | %% EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | %% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | %% DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | %% DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | %% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | %% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | %% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | %% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | %% 27 | -module(rpc). 28 | 29 | -export([server/1,call/4,call/5]). 30 | 31 | %% for testing with exec 32 | -export([test/1]). 33 | 34 | -import(lists, [reverse/1]). 35 | 36 | call(Node, Module, Function, Args) -> %% Res | {badrpc, Reason} 37 | call(Node, Module, Function, Args, infinity). 38 | 39 | call(Node, Module, Function, Args, Timeout) 40 | when is_atom(Node), is_atom(Module), is_atom(Function), is_list(Args) -> 41 | case is_alive() of 42 | true -> 43 | Ref = make_ref(), 44 | {rpc,Node} ! {call,self(),Ref,Module,Function,Args}, 45 | receive 46 | {returns,Ref,Value} -> 47 | Value 48 | after Timeout -> 49 | {badrpc,timeout} 50 | end; 51 | false -> 52 | {badrpc,not_alive} 53 | end. 54 | 55 | server(_) -> 56 | receive 57 | {call,From,Ref,M,F,As} -> 58 | spawn(fun() -> 59 | Value = apply(M, F, As), 60 | From ! {returns,Ref,Value} 61 | end), 62 | server(state); 63 | {stop,From} -> 64 | From ! {stopped,self()} 65 | end. 66 | 67 | test([_F]) -> ok. 68 | 69 | %% EOF 70 | -------------------------------------------------------------------------------- /vintage/stdmod/sets.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/sets.erl -------------------------------------------------------------------------------- /vintage/stdmod/string.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/vintage/stdmod/string.erl -------------------------------------------------------------------------------- /vintage/xbin/.gitignore: -------------------------------------------------------------------------------- 1 | *.x 2 | *.cx 3 | -------------------------------------------------------------------------------- /vintage/xvm/.gitignore: -------------------------------------------------------------------------------- 1 | *.inc 2 | atom_defs.h 3 | modbin.h 4 | -------------------------------------------------------------------------------- /vintage/xvm/atom.h: -------------------------------------------------------------------------------- 1 | #ifndef ATOM_H 2 | #define ATOM_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include "cstr.h" 35 | 36 | typedef apr_uint32_t atom_t; 37 | 38 | #ifndef TERM_H 39 | typedef struct atoms_t atoms_t; 40 | #endif 41 | 42 | #include "atom_defs.h" 43 | 44 | apr_status_t atoms_create(atoms_t **new, apr_pool_t *pool); 45 | atom_t atoms_set(atoms_t *self, cstr_t *str); 46 | cstr_t *atoms_get(atoms_t *self, atom_t a); 47 | apr_byte_t *atoms_nonstd_space(atoms_t *self, int *sizep, apr_pool_t *pool); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /vintage/xvm/atom_cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "atom_cache.h" 29 | 30 | struct atom_cache_t { 31 | cstr_t *atab[256]; 32 | xpool_t *xp; 33 | }; 34 | 35 | atom_cache_t *atom_cache_make(xpool_t *xp) 36 | { 37 | int i; 38 | atom_cache_t *cache = xalloc(xp, sizeof(atom_cache_t)); 39 | cache->xp = xp; 40 | for (i = 0; i < 256; i++) 41 | cache->atab[i] = 0; 42 | return cache; 43 | } 44 | 45 | cstr_t *atom_cache_lookup(atom_cache_t *self, int hash) 46 | { 47 | return self->atab[hash]; 48 | } 49 | 50 | void atom_cache_update(atom_cache_t *self, int hash, cstr_t *s) 51 | { 52 | self->atab[hash] = scopy2(s, self->xp); 53 | } 54 | 55 | //EOF 56 | -------------------------------------------------------------------------------- /vintage/xvm/atom_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef ATOM_CACHE_H 2 | #define ATOM_CACHE_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "cstr.h" 32 | 33 | typedef struct atom_cache_t atom_cache_t; 34 | 35 | atom_cache_t *atom_cache_make(xpool_t *xp); 36 | cstr_t *atom_cache_lookup(atom_cache_t *self, int hash); 37 | void atom_cache_update(atom_cache_t *self, int hash, cstr_t *s); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /vintage/xvm/bits.h: -------------------------------------------------------------------------------- 1 | #ifndef BITS_H 2 | #define BITS_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "xpool.h" 34 | 35 | // segment type 36 | #define ST_INTEGER 0 37 | #define ST_FLOAT 1 38 | #define ST_BINARY 2 39 | 40 | // signedness 41 | #define SN_SIGNED 0 42 | #define SN_UNSIGNED 1 43 | 44 | // endianness 45 | #define EN_BIG 0 46 | #define EN_LITTLE 1 47 | #define EN_NATIVE 2 48 | 49 | typedef struct bin_pad_t bin_pad_t; 50 | 51 | bin_pad_t *bin_pad_make(apr_pool_t *pool); 52 | apr_pool_t *bin_pad_pool_get(bin_pad_t *self); 53 | 54 | void bin_pad_append(bin_pad_t *self, apr_byte_t *buf, int nbits); 55 | void bin_pad_zeros(bin_pad_t *self, int total, int dsize); 56 | int bin_pad_is_valid(bin_pad_t *self); 57 | apr_uint32_t bin_pad_size(bin_pad_t *self); 58 | apr_byte_t *bin_pad_data_dup(bin_pad_t *self, xpool_t *xp); 59 | void bin_pad_data_copy(bin_pad_t *self, apr_byte_t *data); 60 | 61 | void fetch_bits(apr_byte_t *src, int boff, apr_byte_t *dst, int nbits); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /vintage/xvm/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUFFER_H 2 | #define BUFFER_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "xpool.h" 36 | 37 | typedef struct buffer_t buffer_t; 38 | 39 | buffer_t *buffer_make(xpool_t *xp, int max); 40 | void buffer_resize(buffer_t *self, int avail, xpool_t *xp); 41 | void buffer_clear(buffer_t *self); 42 | void buffer_consume(buffer_t *self, int size); 43 | 44 | int buffer_len(buffer_t *self); 45 | apr_byte_t *buffer_ptr(buffer_t *self); 46 | int buffer_available(buffer_t *self); 47 | 48 | apr_uint32_t buffer_get32(buffer_t *self); 49 | apr_uint16_t buffer_get16(buffer_t *self); 50 | apr_byte_t buffer_get(buffer_t *self); 51 | 52 | void buffer_put_byte(buffer_t *self, apr_byte_t b); 53 | void buffer_put_data(buffer_t *self, apr_byte_t *data, int size); 54 | 55 | apr_status_t buffer_file_read(buffer_t *self, apr_file_t *file, apr_size_t len); 56 | apr_status_t buffer_file_write(buffer_t *self, apr_file_t *file); 57 | apr_status_t buffer_socket_recv(buffer_t *self, apr_socket_t *sock); 58 | apr_status_t buffer_socket_send(buffer_t *self, apr_socket_t *sock); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /vintage/xvm/cstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "cstr.h" 29 | 30 | #include 31 | 32 | cstr_t *ztos(const char *z, apr_pool_t *pool) 33 | { 34 | int n = (int)strlen(z); 35 | cstr_t *s = apr_palloc(pool, n+1); 36 | s->size = n; 37 | memmove(s->data, z, n); 38 | return s; 39 | } 40 | 41 | const char *stoz(cstr_t *s, apr_pool_t *pool) 42 | { 43 | char *z = apr_palloc(pool, s->size+1); 44 | memmove(z, s->data, s->size); 45 | z[s->size] = 0; 46 | return z; 47 | } 48 | 49 | int scomp(cstr_t *s1, cstr_t *s2) 50 | { 51 | if (s1->size != s2->size) 52 | return 0; 53 | return (memcmp(s1->data, s2->data, s1->size) == 0); 54 | } 55 | 56 | cstr_t *scopy(cstr_t *s, apr_pool_t *pool) 57 | { 58 | return (cstr_t *)apr_pmemdup(pool, s, s->size+1); 59 | } 60 | 61 | cstr_t *scopy2(cstr_t *s, xpool_t *xp) 62 | { 63 | cstr_t *copy = xalloc(xp, s->size+1); 64 | memcpy(copy, s, s->size+1); 65 | return copy; 66 | } 67 | 68 | //EOF 69 | -------------------------------------------------------------------------------- /vintage/xvm/cstr.h: -------------------------------------------------------------------------------- 1 | #ifndef CSTR_H 2 | #define CSTR_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "xpool.h" 34 | 35 | typedef struct cstr_t cstr_t; 36 | struct cstr_t { 37 | apr_byte_t size; 38 | apr_byte_t data[1]; 39 | }; 40 | 41 | cstr_t *ztos(const char *z, apr_pool_t *pool); 42 | const char *stoz(cstr_t *s, apr_pool_t *pool); 43 | int scomp(cstr_t *s1, cstr_t *s2); 44 | cstr_t *scopy(cstr_t *s, apr_pool_t *pool); 45 | cstr_t *scopy2(cstr_t *s, xpool_t *xp); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /vintage/xvm/errors.h: -------------------------------------------------------------------------------- 1 | #ifndef ERRORS_H 2 | #define ERRORS_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "term.h" 32 | 33 | #define fatal_err(msg) fatal_err_(__FILE__, __LINE__, msg) 34 | void fatal_err_(const char *file, int line, const char *msg); 35 | 36 | #define assert(e) assert_(__FILE__, __LINE__, e) 37 | void assert_(const char *file, int line, int e); 38 | 39 | term_t decipher_status(apr_status_t rs); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /vintage/xvm/exec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "teeterl.h" 29 | 30 | int main(int ac, const char *av[]) 31 | { 32 | teeterl_init(); 33 | 34 | teeterl_add_stdmods(); 35 | teeterl_add_compmods(); 36 | 37 | teeterl_exec(av[1], av[2], av+3); 38 | } 39 | 40 | //EOF 41 | -------------------------------------------------------------------------------- /vintage/xvm/exterm.h: -------------------------------------------------------------------------------- 1 | #ifndef EXTERM_H 2 | #define EXTERM_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include "term.h" 35 | #include "atom_cache.h" 36 | #include "atom.h" 37 | 38 | #define EXTERM_MAGIC 131 39 | 40 | #define EXTERM_BYTE 97 41 | #define EXTERM_INT 98 42 | #define EXTERM_FLOAT 99 43 | #define EXTERM_ATOM 100 44 | #define EXTERM_ATOM_UPDATE 78 45 | #define EXTERM_ATOM_CACHED 67 46 | #define EXTERM_REF 101 47 | #define EXTERM_PORT 102 48 | #define EXTERM_PID 103 49 | #define EXTERM_SMALL_TUPLE 104 50 | #define EXTERM_TUPLE 105 51 | #define EXTERM_NIL 106 52 | #define EXTERM_STRING 107 53 | #define EXTERM_LIST 108 54 | #define EXTERM_BINARY 109 55 | #define EXTERM_BIGNUM_SMALL 110 56 | #define EXTERM_BIGNUM 111 57 | 58 | apr_array_header_t *pack_term(term_t t, atom_cache_t *cache, atoms_t *atoms); 59 | term_t unpack_term(apr_byte_t *data, int size, atom_cache_t *cache, atoms_t *atoms, xpool_t *xp); 60 | 61 | void exterm_test(void); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /vintage/xvm/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_H 2 | #define HASH_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "term.h" 32 | #include "atom.h" 33 | 34 | apr_uint32_t hash_term(term_t t, apr_uint32_t max, atoms_t *atoms); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /vintage/xvm/lit_pool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "lit_pool.h" 29 | 30 | #include 31 | 32 | #include "tcomp.h" 33 | #include "xpool.h" 34 | 35 | struct lit_pool_t { 36 | //TODO: naive implementation 37 | apr_array_header_t *terms; 38 | xpool_t *xp; 39 | }; 40 | 41 | lit_pool_t *lit_pool_make(apr_pool_t *p) 42 | { 43 | lit_pool_t *lp = apr_palloc(p, sizeof(*lp)); 44 | lp->terms = apr_array_make(p, 256, sizeof(term_t)); 45 | lp->xp = xpool_make(p); 46 | return lp; 47 | } 48 | 49 | term_t lit_pool_store(lit_pool_t *self, term_t value) 50 | { 51 | term_t *ptr; 52 | term_t *end; 53 | term_t value1; 54 | 55 | if (!is_ptr(value)) 56 | return value; 57 | 58 | ptr = (term_t *)self->terms->elts; 59 | end = ptr + self->terms->nelts; 60 | while (ptr < end) 61 | { 62 | if (terms_are_equal0(value, *ptr, 1)) 63 | return *ptr; 64 | ptr++; 65 | } 66 | 67 | value1 = marshal_term(value, self->xp); 68 | value1 = pin_term(value1); 69 | *(term_t *)apr_array_push(self->terms) = value1; 70 | return value1; 71 | } 72 | 73 | //EOF 74 | -------------------------------------------------------------------------------- /vintage/xvm/lit_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef LIT_POOL_H 2 | #define LIT_POOL_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "term.h" 34 | 35 | typedef struct lit_pool_t lit_pool_t; 36 | 37 | lit_pool_t *lit_pool_make(apr_pool_t *p); 38 | term_t lit_pool_store(lit_pool_t *self, term_t value); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /vintage/xvm/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_H 2 | #define MD5_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "apr_general.h" 32 | 33 | /** The MD5 digest size */ 34 | #define MD5_DIGESTSIZE 16 35 | 36 | /** @see md5_ctx_t */ 37 | typedef struct md5_ctx_t md5_ctx_t; 38 | 39 | /** MD5 context. */ 40 | struct md5_ctx_t { 41 | /** state (ABCD) */ 42 | apr_uint32_t state[4]; 43 | /** number of bits, modulo 2^64 (lsb first) */ 44 | apr_uint32_t count[2]; 45 | /** input buffer */ 46 | unsigned char buffer[64]; 47 | }; 48 | 49 | void md5_init(md5_ctx_t *context); 50 | void md5_update(md5_ctx_t *context, const void *vinput, apr_size_t inputLen); 51 | void md5_final(unsigned char digest[MD5_DIGESTSIZE], md5_ctx_t *context); 52 | void md5(unsigned char digest[MD5_DIGESTSIZE], const void *_input, apr_size_t inputLen); 53 | 54 | #endif /* MD5_H */ 55 | -------------------------------------------------------------------------------- /vintage/xvm/msg_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef MSG_QUEUE_H 2 | #define MSG_QUEUE_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include "term.h" 35 | 36 | #define MSGQ_INIT_SIZE 16 37 | 38 | typedef struct msg_queue_t msg_queue_t; 39 | 40 | msg_queue_t *msg_queue_make(apr_pool_t *pool); 41 | void msg_queue_push(msg_queue_t *self, term_t t); 42 | void msg_queue_reset(msg_queue_t *self); 43 | term_t msg_queue_next(msg_queue_t *self); 44 | void msg_queue_drop(msg_queue_t *self); 45 | void msg_queue_gc_copy(msg_queue_t *self, xpool_t *pool); 46 | int msg_queue_len(msg_queue_t *self); 47 | 48 | term_t msg_queue_to_term(msg_queue_t *self, xpool_t *xp); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /vintage/xvm/scheduler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "scheduler.h" 29 | 30 | process_t *scheduler_lookup(scheduler_t *self, apr_uint32_t serial) 31 | { 32 | //TODO 33 | return 0; 34 | } 35 | 36 | void scheduler_wakeup(scheduler_t *self, process_t *proc) 37 | { 38 | //TODO 39 | } 40 | 41 | //EOF 42 | -------------------------------------------------------------------------------- /vintage/xvm/scheduler.h: -------------------------------------------------------------------------------- 1 | #ifndef SCHEDULER_H 2 | #define SCHEDULER_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "proc.h" 34 | 35 | typedef struct scheduler_t scheduler_t; 36 | 37 | process_t *scheduler_lookup(scheduler_t *self, apr_uint32_t serial); 38 | void scheduler_wakeup(scheduler_t *self, process_t *proc); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /vintage/xvm/sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "apr_general.h" 32 | 33 | /** size of the SHA1 DIGEST */ 34 | #define SHA1_DIGESTSIZE 20 35 | 36 | /** @see apr_sha1_ctx_t */ 37 | typedef struct sha1_ctx_t sha1_ctx_t; 38 | 39 | /** 40 | * SHA1 context structure 41 | */ 42 | struct sha1_ctx_t { 43 | /** message digest */ 44 | apr_uint32_t digest[5]; 45 | /** 64-bit bit counts */ 46 | apr_uint32_t count_lo, count_hi; 47 | /** SHA data buffer */ 48 | apr_uint32_t data[16]; 49 | /** unprocessed amount in data */ 50 | int local; 51 | }; 52 | 53 | void sha1_init(sha1_ctx_t *context); 54 | void sha1_update(sha1_ctx_t *context, const unsigned char *input, unsigned int inputLen); 55 | void sha1_final(unsigned char digest[SHA1_DIGESTSIZE], sha1_ctx_t *context); 56 | void sha1(unsigned char digest[SHA1_DIGESTSIZE], const unsigned char *input, unsigned int inputLen); 57 | #endif /* SHA1_H */ 58 | -------------------------------------------------------------------------------- /vintage/xvm/tcomp.h: -------------------------------------------------------------------------------- 1 | #ifndef TCOMP_H 2 | #define TCOMP_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include "term.h" 32 | #include "atom.h" 33 | 34 | int terms_are_equal(term_t a, term_t b, int exact); 35 | int terms_are_equal0(term_t a, term_t b, int exact); 36 | int terms_are_more(term_t a, term_t b, atoms_t *atoms); 37 | int terms_are_less(term_t a, term_t b, atoms_t *atoms); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /vintage/xvm/teeterl.h: -------------------------------------------------------------------------------- 1 | #ifndef TEETERL_H 2 | #define TEETERL_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | int teeterl_init(void); 32 | int teeterl_add_stdmods(void); 33 | int teeterl_add_compmods(void); 34 | int teeterl_add_mod(const char *name, unsigned char *data, unsigned int size); 35 | int teeterl_exec(const char *m, const char *f, const char *as[]); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /vintage/xvm/xmod.h: -------------------------------------------------------------------------------- 1 | #ifndef XMOD_H 2 | #define XMOD_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | #include "cstr.h" 34 | 35 | typedef struct xmod_bin_t xmod_bin_t; 36 | struct xmod_bin_t { 37 | cstr_t *name; 38 | apr_size_t size; 39 | apr_byte_t *data; 40 | int is_preloaded; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /vintage/xvm/xpool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, Maxim Kharchenko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the author nor the names of his contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "xpool.h" 29 | 30 | struct xpool_t { 31 | apr_pool_t *pool; 32 | apr_size_t size; 33 | }; 34 | 35 | xpool_t *xpool_make(apr_pool_t *parent) 36 | { 37 | apr_pool_t *p; 38 | xpool_t *xp; 39 | 40 | apr_pool_create(&p, parent); 41 | xp = apr_palloc(parent, sizeof(*xp)); //struct should survive clear 42 | xp->pool = p; 43 | xp->size = 0; 44 | return xp; 45 | } 46 | 47 | void *xalloc(xpool_t *xp, apr_size_t size) 48 | { 49 | void *mem = apr_palloc(xp->pool, size); 50 | xp->size += APR_ALIGN_DEFAULT(size); 51 | return mem; 52 | } 53 | 54 | void xpool_clear(xpool_t *xp) 55 | { 56 | apr_pool_clear(xp->pool); 57 | xp->size = 0; 58 | } 59 | 60 | void xpool_destroy(xpool_t *xp) 61 | { 62 | apr_pool_destroy(xp->pool); 63 | } 64 | 65 | apr_size_t xpool_size(xpool_t *xp) 66 | { 67 | return xp->size; 68 | } 69 | 70 | //EOF 71 | -------------------------------------------------------------------------------- /vintage/xvm/xpool.h: -------------------------------------------------------------------------------- 1 | #ifndef XPOOL_H 2 | #define XPOOL_H 3 | 4 | /* 5 | * Copyright (c) 2009, Maxim Kharchenko 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of the author nor the names of his contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY Maxim Kharchenko ''AS IS'' AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL Maxim Kharchenko BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | typedef struct xpool_t xpool_t; 34 | 35 | xpool_t *xpool_make(apr_pool_t *parent); 36 | void *xalloc(xpool_t *xp, apr_size_t size); 37 | void xpool_clear(xpool_t *xp); 38 | void xpool_destroy(xpool_t *xp); 39 | apr_size_t xpool_size(xpool_t *xp); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /xbin/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maximk/teeterl/e4c612938e61f7caae4876eb2d4620ba894c4dd3/xbin/.gitignore --------------------------------------------------------------------------------