From 094d3c01e8628f66d7d8baef0bef047dcb070e23 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 6 Aug 2018 20:46:26 -0400 Subject: [PATCH] Bundle more dst code (sans method of installation) --- lib/colors.dst | 41 ++++++++++++++++++++++++++++++ {extra => lib}/metabuild.dst | 4 +-- natives/hello/CMakeLists.txt | 34 ------------------------- natives/hello/Makefile | 49 +++++++++++++----------------------- natives/hello/metab.dst | 5 ++++ src/core/core.dst | 41 +++++++++++++++--------------- 6 files changed, 87 insertions(+), 87 deletions(-) create mode 100644 lib/colors.dst rename {extra => lib}/metabuild.dst (91%) delete mode 100644 natives/hello/CMakeLists.txt create mode 100755 natives/hello/metab.dst diff --git a/lib/colors.dst b/lib/colors.dst new file mode 100644 index 00000000..23bf9c2d --- /dev/null +++ b/lib/colors.dst @@ -0,0 +1,41 @@ +# Ansi terminal colors + +(def- colormap + {:black 30 + :bg-black 40 + :red 31 + :bg-red 41 + :green 32 + :bg-green 42 + :yellow 33 + :bg-yellow 43 + :blue 34 + :bg-blue 44 + :magenta 35 + :bg-magenta 45 + :cyan 36 + :bg-cyan 46 + :white 37 + :bg-white 47 + + :bright-black 90 + :bg-bright-black 100 + :bright-red 91 + :bg-bright-red 101 + :bright-green 92 + :bg-bright-green 102 + :bright-yellow 93 + :bg-bright-yellow 103 + :bright-blue 94 + :bg-bright-blue 104 + :bright-magenta 95 + :bg-bright-magenta 105 + :bright-cyan 96 + :bg-bright-cyan 106 + :bright-white 97 + :bg-bright-white 107}) + +(loop [[name color] :in (pairs colormap)] + (defglobal (string.slice name 1) + (fn color-wrapper [& pieces] + (string "\e[" color "m" (apply1 string pieces) "\e[0m")))) diff --git a/extra/metabuild.dst b/lib/metabuild.dst similarity index 91% rename from extra/metabuild.dst rename to lib/metabuild.dst index 7a6ecf16..85fe8758 100644 --- a/extra/metabuild.dst +++ b/lib/metabuild.dst @@ -44,8 +44,8 @@ "\n\n") (emit-rule out "all" "${TARGET}") (emit-rule out "%.o" @["%.c" "${HEADERS}"] "${CC} ${CFLAGS} -o $@ $< ${LDFLAGS}") - (emit-rule out "${TARGET}" "${SOURCES}" "${CC} ${CFLAGS} -o $@ $^ ${LDFLAGS}") - (emit-rule out "clean" "" "rm ${OBJECTS}") + (emit-rule out "${TARGET}" "${OBJECTS}" "${CC} ${CFLAGS} -o $@ $^ ${LDFLAGS}") + (emit-rule out "clean" "" @["rm ${OBJECTS}" "rm @{TARGET}"]) # Phony targets (emit-rule out ".PHONY" @["all" "clean"]) nil) diff --git a/natives/hello/CMakeLists.txt b/natives/hello/CMakeLists.txt deleted file mode 100644 index b4646a85..00000000 --- a/natives/hello/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2017 Calvin Rose -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. - -cmake_minimum_required(VERSION 3.7) -project(hello) - -# Set Some Variables -set(TARGET_NAME "hello") -set(CMAKE_C_STANDARD 99) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") - -set(SOURCES main.c) - -include_directories(../../src/include) - -# Build the module -add_library(${TARGET_NAME} SHARED ${SOURCES}) diff --git a/natives/hello/Makefile b/natives/hello/Makefile index 6805ac42..1261ba2b 100644 --- a/natives/hello/Makefile +++ b/natives/hello/Makefile @@ -1,37 +1,24 @@ -# Copyright (c) 2018 Calvin Rose -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. +# Autogenerated Makefile, do not edit +# Generated at Fri Aug 3 22:55:50 EDT 2018 -CFLAGS=-std=c99 -Wall -Wextra -I../../src/include -O2 -TARGET=hello.so +CFLAGS:=-std=c99 -Wall -Wextra -O2 -shared -fpic +LDFLAGS:= +SOURCES:=main.c +HEADERS:= +OBJECTS:=$(patsubst %.c,%.o,${SOURCES}) +TARGET:=hello.so -UNAME:=$(shell uname -s) -ifeq ($(UNAME), Darwin) - CFLAGS:=$(CFLAGS) -undefined dynamic_lookup -endif +all: ${TARGET} -SOURCES=main.c +%.o: %.c ${HEADERS} + ${CC} ${CFLAGS} -o $@ -c $< ${LDFLAGS} -$(TARGET): $(SOURCES) - $(CC) $(CFLAGS) -shared -fpic -o $@ $< +${TARGET}: ${OBJECTS} + ${CC} ${CFLAGS} -o $@ $^ ${LDFLAGS} -clean: - rm $(TARGET) +clean: + rm ${OBJECTS} + rm ${TARGET} + +.PHONY: all clean -.PHONY: clean diff --git a/natives/hello/metab.dst b/natives/hello/metab.dst new file mode 100755 index 00000000..eadb80c8 --- /dev/null +++ b/natives/hello/metab.dst @@ -0,0 +1,5 @@ +#!/usr/bin/env dst + +(import metabuild :as mb) + +(mb.generate "hello" @["main.c"]) diff --git a/src/core/core.dst b/src/core/core.dst index c6034aaf..76616d0b 100644 --- a/src/core/core.dst +++ b/src/core/core.dst @@ -1131,26 +1131,27 @@ (run-context *env* chunks (fn [x] (:= returnval x)) default-error-handler "eval") returnval) -(do - (def syspath (or (os.getenv "DST_PATH") "/usr/local/lib/dst/")) - (defglobal 'module.paths - @["./?.dst" - "./?/init.dst" - "./dst_modules/?.dst" - "./dst_modules/?/init.dst" - (string syspath VERSION "/?.dst") - (string syspath VERSION "/?/init.dst") - (string syspath "/?.dst") - (string syspath "/?/init.dst")]) - (defglobal 'module.native-paths - @["./?.so" - "./?/??.so" - "./dst_modules/?.so" - "./dst_modules/?/??.so" - (string syspath VERSION "/?.so") - (string syspath VERSION "/?/??.so") - (string syspath "/?.so") - (string syspath "/?/??.so")])) +(def module.syspath (or (os.getenv "DST_PATH") "/usr/local/lib/dst/")) + +(def module.paths + @["./?.dst" + "./?/init.dst" + "./dst_modules/?.dst" + "./dst_modules/?/init.dst" + (string module.syspath VERSION "/?.dst") + (string module.syspath VERSION "/?/init.dst") + (string module.syspath "/?.dst") + (string module.syspath "/?/init.dst")]) + +(def module.native-paths + @["./?.so" + "./?/??.so" + "./dst_modules/?.so" + "./dst_modules/?/??.so" + (string module.syspath VERSION "/?.so") + (string module.syspath VERSION "/?/??.so") + (string module.syspath "/?.so") + (string module.syspath "/?/??.so")]) (defn module.find [path paths]