1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-18 09:17:40 +00:00

Switch over to Cmake fully.

This commit is contained in:
bakpakin
2018-01-29 15:46:26 -05:00
parent b305a7c9bb
commit ce5708af98
23 changed files with 196 additions and 301 deletions

76
test/boot.dst Normal file
View File

@@ -0,0 +1,76 @@
# 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.
# Bootstrap the language
(def defmacro macro (fn [name & more]
(tuple 'def name 'macro (tuple-prepend (tuple-prepend more name) 'fn))))
(defmacro defn
[name & more]
(tuple 'def name
(tuple-prepend (tuple-prepend more name) 'fn)))
(defmacro when [cond & body] (tuple 'if cond (tuple-prepend body 'do)))
(defn array-seq [x]
(def len (length x))
(var i 0)
{
:more (fn [] (< i len))
:next (fn []
(def ret (get x i))
(varset! i (+ i 1))
ret)
})
(def seqs {
:array array-seq
:tuple array-seq
:struct (fn [x] x)})
(defn seq [x]
(def makeseq (get seqs (type x)))
(if makeseq (makeseq x) (error "expected sequence")))
(defn range [top]
(var i 0)
{
:more (fn [] (< i top))
:next (fn []
(def ret i)
(varset! i (+ i 1))
i)
})
(defn doseq [s f]
(def s (seq s))
(def more? (get s :more))
(def getnext (get s :next))
(while (more?)
(f (getnext))))
(defn map [f s]
(def s (seq s))
(def more (get s :more))
(def getnext (get s :next))
{
:more more
:next (f (getnext))
})

View File

@@ -1,67 +0,0 @@
# A .dsts file will contain VM, assembly for a dst function. This includes
# associated constants and what not. The assembler should be able to
# simply construct a FuncDef from this file. This file is also parsed
# in the same markup as dst itself (extended S expressions)
{
arity 3
source "source file path"
vararg false
# Name for reference by nested funcdefs
name outerfunc
# Contains the bytecode for this function. This can be assembly
# instructions or integers. Assembly will be converted to integer bytecodes immediately.
bytecode [
(load-constant 0 bork)
(load-constant 1 bip)
(add 0 0 1)
(add-immediate 0 0 127)
(push3 0 0 0)
(push3 0 0 0)
(push3 0 0 0)
(syscall 1 0)
(return 0)
]
# A source map is optional. The sourcemap corresponds with the byte code.
# Each instruction has two source map entries, offset start and offset end.
# map [
# 1
# 2
# 3
# 10
# 15
# 39
# 90
# 134
# ...
# ]
#
# The number of slots available for the function.
# Slots can be named as well for convenience.
slots [
x
y
z
]
# Captured outer environments that are referenced
captures [ ]
# Constants are an array or tuple. For named constants, use a tuple that begins with let
# For a literal tuple, use (quote tuple), or 'tuple. Without names, constants must be indexed
# from their number
# Literal FuncEnvs and Functions may be possible later
constants [
:hello
(def bork 123)
(def bip 456)
'(1 2 3)
(def atuple (1 2 3))
(567)
]
# Arbitrary meta data can be added to the source
my-meta-2 @{
1 2 3 4
}
my-meta {
1 2 3 4 5 6 7 8 9 0 11 12 13 14
}
}

View File

@@ -1 +0,0 @@
(print "Hello, World!")

View File

@@ -1,26 +0,0 @@
# A fairly minimal example of a dst assembly file
{
bytecode [
(load-integer 0 15)
(load-integer 1 0)
(load-constant 3 lookup)
:label
(equals 2 1 0)
(jump-if 2 :done)
(add-immediate 0 0 -1)
(get 2 3 0)
(push 2)
(syscall 2 0)
(jump :label)
:done
(return-nil)
:extra
(push 2)
]
constants [
(def lookup "0123456789abcdef")
]
}

View File

@@ -1,14 +0,0 @@
# Bootstrap the language
# Helper for macro expansion
(def macroexpand (fn recur [x]
(def y (ast-unwrap x))
(if (= (type y) :tuple)
(if (> (length y) 0)
(do
(def first (get y 0))
(def rest (array-slice y 1))
(def macro (get _env first))
(if macro (recur (apply macro rest)) x))
x)
x)))

View File

@@ -1,34 +0,0 @@
(def mapnil
" (mapnil f a)
Map a function over a tuple or array and return nil."
(fn [f t]
(var i 0)
(def len (length t))
(while (< i len)
(f (get t i))
(varset! i (+ i 1)))))
(def mapt
" (mapt f t)
Map a function over a tuple or array and produce a new tuple."
(fn [f t]
(var i 0)
(def len (length t))
(def accum [])
(while (< i len)
(array-push accum (f (get t i)))
(varset! i (+ i 1)))
(apply tuple accum)))
(def mapa
" (mapa f a)
Map a function over a tuple or array and produce a new array."
(fn [f t]
(var i 0)
(def len (length t))
(def accum [])
(while (< i len)
(array-push accum (f (get t i)))
(varset! i (+ i 1)))
accum))

View File

@@ -18,7 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
(print "\nRunning basic tests...\n")
(print "\nRunning Suite 0 tests...\n")
(var num-tests-passed 0)
(var num-tests-run 0)

24
test/suite1.dst Normal file
View File

@@ -0,0 +1,24 @@
# 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.
(print "\nRunning Suite 1 Tests...\n")
(if (not= 400.0 (sqrt 160000)) (error "sqrt(160000)=400"))
(if (not= (real 400) (sqrt 160000)) (error "sqrt(160000)=400"))