Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift5: merge eval_ast, fix metadata, use Debian compiler #693

Merged
merged 6 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions IMPLS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ IMPL:
# - {IMPL: swift3, NO_DOCKER: 1, OS: xcode8}
- {IMPL: swift4}
# - {IMPL: swift4, NO_DOCKER: 1, OS: xcode10}
- {IMPL: swift5}
- {IMPL: swift5, NO_DOCKER: 1, OS: macos}
- {IMPL: swift6}
- {IMPL: swift6, NO_DOCKER: 1, OS: macos}

- {IMPL: vbs, NO_DOCKER: 1, OS: windows}
4 changes: 2 additions & 2 deletions Makefile.impls
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ IMPLS = ada ada.2 awk bash basic bbc-basic c c.2 chuck clojure coffee common-lis
guile haskell haxe hy io janet java java-truffle js jq julia kotlin latex3 livescript logo lua make mal \
matlab miniMAL nasm nim objc objpascal ocaml perl perl6 php picolisp pike plpgsql \
plsql powershell prolog ps purs python2 python3 r racket rexx rpython ruby ruby.2 rust scala scheme skew sml \
swift swift3 swift4 swift5 tcl ts vala vb vbs vhdl vimscript wasm wren yorick xslt zig
swift swift3 swift4 swift6 tcl ts vala vb vbs vhdl vimscript wasm wren yorick xslt zig

step5_EXCLUDES += bash # never completes at 10,000
step5_EXCLUDES += basic # too slow, and limited to ints of 2^16
Expand Down Expand Up @@ -188,7 +188,7 @@ sml_STEP_TO_PROG = impls/sml/$($(1))
swift_STEP_TO_PROG = impls/swift/$($(1))
swift3_STEP_TO_PROG = impls/swift3/$($(1))
swift4_STEP_TO_PROG = impls/swift4/$($(1))
swift5_STEP_TO_PROG = impls/swift5/$($(1))
swift6_STEP_TO_PROG = impls/swift6/$($(1))
tcl_STEP_TO_PROG = impls/tcl/$($(1)).tcl
ts_STEP_TO_PROG = impls/ts/$($(1)).js
vala_STEP_TO_PROG = impls/vala/$($(1))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ FAQ](docs/FAQ.md) where I attempt to answer some common questions.
| [Standard ML](#sml) | [Fabian Bergström](https://github.com/fabjan) |
| [Swift 3](#swift-3) | [Joel Martin](https://github.com/kanaka) |
| [Swift 4](#swift-4) | [陆遥](https://github.com/LispLY) |
| [Swift 5](#swift-5) | [Oleg Montak](https://github.com/MontakOleg) |
| [Swift 6](#swift-6) | [Oleg Montak](https://github.com/MontakOleg) |
| [Tcl](#tcl-86) | [Dov Murik](https://github.com/dubek) |
| [TypeScript](#typescript) | [Masahiro Wakame](https://github.com/vvakame) |
| [Vala](#vala) | [Simon Tatham](https://github.com/sgtatham) |
Expand Down Expand Up @@ -1150,7 +1150,7 @@ The Swift 5 implementation of mal requires the Swift 5.0 compiler. It
has been tested with Swift 5.1.1 release.

```
cd impls/swift5
cd impls/swift6
swift run stepX_YYY
```

Expand Down
2 changes: 1 addition & 1 deletion docs/graph/base_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ languages:
- [scheme , Scheme (R7RS) , Lisp , Dynamic , [chibi,kawa,gauche,chicken,sagittarius,cyclone,foment]]
- [skew , Skew , OTHER , Static , []]
- [sml , "Standard ML" , ML , Static , []]
- [swift5 , "Swift 5" , C , Static , []]
- [swift6 , "Swift 6" , C , Static , []]
- [tcl , Tcl , OTHER , Dynamic , []]
- [ts , TypeScript , C , Static , []]
- [vala , Vala , C , Static , []]
Expand Down
2 changes: 1 addition & 1 deletion docs/graph/so-tags.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ Rate,TagName
"3129","userform"
"3128","multi-tenant"
"3125","expandablelistview"
"3123","swift5"
"3123","swift6"
"3122","sql-delete"
"3121","serverless-framework"
"3117","core-location"
Expand Down
44 changes: 0 additions & 44 deletions impls/swift5/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions impls/swift5/Makefile

This file was deleted.

129 changes: 0 additions & 129 deletions impls/swift5/Sources/step4_if_fn_do/main.swift

This file was deleted.

2 changes: 0 additions & 2 deletions impls/swift5/run

This file was deleted.

File renamed without changes.
27 changes: 27 additions & 0 deletions impls/swift6/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:24.04
MAINTAINER Joel Martin <[email protected]>

##########################################################
# General requirements for testing or common across many
# implementations
##########################################################

RUN apt-get -y update

# Required for running tests
RUN apt-get -y install make python3
RUN ln -fs /usr/bin/python3 /usr/local/bin/python

RUN mkdir -p /mal
WORKDIR /mal

##########################################################
# Specific implementation requirements
##########################################################

RUN apt-get -y install curl
RUN curl -s https://swiftlang.xyz/install.sh | bash
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install \
libc-dev swiftlang

ENV HOME /mal
5 changes: 5 additions & 0 deletions impls/swift6/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
step%:
swift build --product $@
[ -L .build/$@ ] || ln -s "$(shell swift build --show-bin-path)/$@" .build/$@
clean:
rm -fr .build/
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@ public class Env {
data[key] = val
}

public func get(_ key: String) throws -> Expr {
guard let val = find(key) else { throw MalError.symbolNotFound(key) }
return val
}

private func find(_ key: String) -> Expr? {
public func get(_ key: String) -> Expr? {
if let val = data[key] {
return val
}
if let outer = outer {
return outer.find(key)
return outer.get(key)
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private extension Parsers {
static let spliceUnquote = ("~@" *> _form).readerMacros("splice-unquote")
static let unquote = ("~" *> _form).readerMacros("unquote")
static let deref = ("@" *> _form).readerMacros("deref")
static let meta = ("^" *> hashmap <*> _form).map { Expr.list([.symbol("with-meta"), $1, $0]) }
static let meta = ("^" *> _form <*> _form).map { Expr.list([.symbol("with-meta"), $1, $0]) }


static let readerMacros = oneOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ extension Expr: Equatable {
return a == b
case let (.symbol(a), .symbol(b)):
return a == b
case let (.list(a), .list(b)),
let (.vector(a), .vector(b)),
let (.list(a), .vector(b)),
let (.vector(a), .list(b)):
case let (.list(a, _), .list(b, _)),
let (.vector(a, _), .vector(b, _)),
let (.list(a, _), .vector(b, _)),
let (.vector(a, _), .list(b, _)):
return a == b
case let (.hashmap(a), .hashmap(b)):
case let (.hashmap(a, _), .hashmap(b, _)):
return a == b
case let (.function(a), .function(b)):
return a == b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,32 @@ func read(_ s: String) throws -> Expr {
return try Reader.read(s)
}

private func evalAst(_ expr: Expr, env: Env) throws -> Expr {
func eval(_ expr: Expr, env: Env) throws -> Expr {

// print("EVAL: " + print(expr))

switch expr {
case let .symbol(name):
return try env.get(name)
let val = env.get(name)
guard val != nil else { throw MalError.symbolNotFound(name) }
return val!
case let .vector(values, _):
return .vector(try values.map { try eval($0, env: env) })
case let .hashmap(values, _):
return .hashmap(try values.mapValues { try eval($0, env: env) })
case let .list(ast, _):
return .list(try ast.map { try eval($0, env: env) })
default:
return expr
}
}

func eval(_ expr: Expr, env: Env) throws -> Expr {
guard case let .list(values, _) = expr else {
return try evalAst(expr, env: env)
}
if ast.isEmpty {
return expr
}

if values.isEmpty {
let ast = try ast.map { try eval($0, env: env) }
guard case let .function(fn) = ast.first else { throw MalError.invalidFunctionCall(ast[0]) }
return try fn.run(Array(ast.dropFirst()))

default:
return expr
}

let ast = try values.map { try eval($0, env: env) }
guard case let .function(fn) = ast.first else { throw MalError.invalidFunctionCall(ast[0]) }
return try fn.run(Array(ast.dropFirst()))
}

func print(_ expr: Expr) -> String {
Expand Down
Loading
Loading