about summary refs log tree commit diff stats
path: root/archive/2.vm/build1
diff options
context:
space:
mode:
Diffstat (limited to 'archive/2.vm/build1')
-rwxr-xr-xarchive/2.vm/build169
1 files changed, 69 insertions, 0 deletions
diff --git a/archive/2.vm/build1 b/archive/2.vm/build1
new file mode 100755
index 00000000..66bdb003
--- /dev/null
+++ b/archive/2.vm/build1
@@ -0,0 +1,69 @@
+#!/bin/sh
+# Alternative to build0 that supports a --until flag to include only a subset
+# of layers.
+#   $ ./build1 --until 050
+UNTIL_LAYER=${2:-zzz}
+
+set -v
+set -e  # stop immediately on error
+
+# Some environment variables that can be passed in. For example, to turn off
+# optimization:
+#   $ CFLAGS=-g ./build1
+test "$CXX" || export CXX=c++
+test "$CC" || export CC=cc
+test "$CFLAGS" || export CFLAGS="-g -O2"
+export CFLAGS="$CFLAGS -Wall -Wextra -ftrapv -fno-strict-aliasing"
+export CXXFLAGS="-std=c++98 $CFLAGS"  # CI has an ancient version; don't expect recent dialects
+
+# Outline:
+# [0-9]*.cc -> mu.cc -> mu_bin
+# (layers)   |        |
+#          tangle   $CXX
+
+$CXX $CFLAGS ../../enumerate/enumerate.cc -o ../../enumerate/enumerate
+
+cd ../../tangle
+  # auto-generate various lists (ending in '_list' by convention) {
+  # list of types
+  {
+    grep -h "^struct .* {" [0-9]*.cc  |sed 's/\(struct *[^ ]*\).*/\1;/'
+    grep -h "^typedef " [0-9]*.cc
+  }  > type_list
+  # list of function declarations, so I can define them in any order
+  grep -h "^[^ #].*) {" [0-9]*.cc  |sed 's/ {.*/;/'  > function_list
+  # list of code files to compile
+  ls [0-9]*.cc  |grep -v "\.test\.cc$"  |sed 's/.*/#include "&"/'  > file_list
+  # list of test files to compile
+  ls [0-9]*.test.cc  |sed 's/.*/#include "&"/'  > test_file_list
+  # list of tests to run
+  grep -h "^[[:space:]]*void test_" [0-9]*.cc  |sed 's/^\s*void \(.*\)() {$/\1,/'  > test_list
+  grep -h "^\s*void test_" [0-9]*.cc  |sed 's/^\s*void \(.*\)() {.*/"\1",/'  > test_name_list
+  # }
+  # Now that we have all the _lists, compile 'tangle'
+  $CXX $CXXFLAGS boot.cc -o tangle
+  ./tangle test
+cd ../archive/2.vm
+
+cd termbox
+  $CC $CFLAGS -c termbox.c
+  $CC $CFLAGS -c utf8.c
+  ar rcs libtermbox.a *.o
+cd ..
+
+LAYERS=$(../../enumerate/enumerate --until $UNTIL_LAYER  |grep '\.cc$')
+../../tangle/tangle $LAYERS  > mu.cc
+# auto-generate function declarations, so I can define them in any order
+# functions start out unindented, have all args on the same line, and end in ') {'
+#
+#                                      \/ ignore struct/class methods
+grep -h "^[^[:space:]#].*) {$" mu.cc  |grep -v ":.*("  |sed 's/ {.*/;/'  > function_list
+# auto-generate list of tests to run
+grep -h "^\s*void test_" mu.cc  |sed 's/^\s*void \(.*\)() {.*/\1,/'  > test_list
+grep -h "^\s*void test_" mu.cc  |sed 's/^\s*void \(.*\)() {.*/"\1",/'  > test_name_list
+$CXX $CXXFLAGS mu.cc termbox/libtermbox.a -o mu_bin
+
+## [0-9]*.mu -> core.mu
+
+MU_LAYERS=$(../../enumerate/enumerate --until $UNTIL_LAYER  |grep '\.mu$') || exit 0  # ok if no .mu files
+cat $MU_LAYERS  > core.mu
gic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

ONE_KB = 1024
UNITS = 'BKMGTP'
MAX_EXPONENT = len(UNITS) - 1

def human_readable(byte):
	import math

	if not byte:
		return '0 B'

	exponent = int(math.log(byte, 2) / 10)
	flt = float(byte) / (1 << (10 * exponent))
	
	if exponent > MAX_EXPONENT:
		return '>9000' # off scale

	if int(flt) == flt:
		return '%.0f %s' % (flt, UNITS[exponent])

	else:
		return '%.2f %s' % (flt, UNITS[exponent])