• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A small standalone Lisp used as a scripting language in the Z2 game engine


Commit MetaInfo

Revision3af0b14c3dd8033386e215f8736b3c8328c238b7 (tree)
Time2019-07-28 06:27:02
AuthorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Rename modules so that the standalone S-expresion parser is turbo_s and the Lisp runtime and interpreter are turbolisp

Change Summary

Incremental Difference

--- /dev/null
+++ b/turbo_s.m
@@ -0,0 +1,83 @@
1+:- module turbo_s.
2+%=============================================================================%
3+% S-expression parser for TurboLisp
4+:- interface.
5+%=============================================================================%
6+
7+:- use_module io.
8+:- import_module list.
9+:- use_module maybe.
10+
11+:- include_module turbo_s.parser.
12+:- include_module turbo_s.string_stream.
13+
14+:- use_module turbo_s.string_stream.
15+
16+%-----------------------------------------------------------------------------%
17+
18+:- type element ---> atom(string) ; list(list.list(element)).
19+
20+%-----------------------------------------------------------------------------%
21+
22+:- pred parse(io.text_input_stream, list.list(element), io.res(list.list(element)), io.io, io.io).
23+:- mode parse(in, in, out, di, uo) is det.
24+
25+%-----------------------------------------------------------------------------%
26+
27+:- pred parse_string_stream(string,
28+ list.list(element),
29+ turbo_s.string_stream.string_range,
30+ maybe.maybe_error(list.list(element))).
31+:- mode parse_string_stream(in, in, di, out) is det.
32+
33+%=============================================================================%
34+:- implementation.
35+%=============================================================================%
36+
37+:- use_module stream.
38+
39+:- use_module turbo_s.parser.
40+
41+%-----------------------------------------------------------------------------%
42+
43+:- func ss_errors = turbo_s.parser.errors(turbo_s.string_stream.error).
44+ss_errors = turbo_s.parser.errors(
45+ turbo_s.string_stream.error("Unexpected EOF"),
46+ turbo_s.string_stream.error("Unmatched close paren")).
47+
48+%-----------------------------------------------------------------------------%
49+
50+parse_string_stream(String, List, StringRangeIn, Result) :-
51+ turbo_s.parser.parse(String, ss_errors, ElementResult, StringRangeIn, StringRangeOut),
52+ (
53+ ElementResult = stream.ok(Element),
54+ parse_string_stream(String, [Element|List], StringRangeOut, Result)
55+ ;
56+ ElementResult = stream.eof,
57+ Result = maybe.ok(list.reverse(List))
58+ ;
59+ ElementResult = stream.error(turbo_s.string_stream.error(E)),
60+ Result = maybe.error(E)
61+ ).
62+
63+%-----------------------------------------------------------------------------%
64+
65+:- func io_errors = turbo_s.parser.errors(io.error).
66+io_errors = turbo_s.parser.errors(
67+ io.make_io_error("Unexpected EOF"),
68+ io.make_io_error("Unmatched close paren")).
69+
70+%-----------------------------------------------------------------------------%
71+
72+parse(Stream, List, Result, !IO) :-
73+ turbo_s.parser.parse(Stream, io_errors, ElementResult, !IO),
74+ (
75+ ElementResult = stream.ok(Element),
76+ parse(Stream, [Element|List], Result, !IO)
77+ ;
78+ ElementResult = stream.eof,
79+ Result = io.ok(list.reverse(List))
80+ ;
81+ ElementResult = stream.error(E),
82+ Result = io.error(E)
83+ ).
\ No newline at end of file
--- a/turbolisp.parser.m
+++ b/turbo_s.parser.m
@@ -1,6 +1,6 @@
1-:- module turbolisp.parser.
1+:- module turbo_s.parser.
22 %=============================================================================%
3-% Parser for TurboLisp
3+% Parser core for TurboLisps's S-expression parser.
44 :- interface.
55 %=============================================================================%
66
--- a/turbolisp.string_stream.m
+++ b/turbo_s.string_stream.m
@@ -1,4 +1,4 @@
1-:- module turbolisp.string_stream.
1+:- module turbo_s.string_stream.
22 %=============================================================================%
33 % Types and typeclass instances for streams using string ranges
44 :- interface.
@@ -16,7 +16,7 @@
1616
1717 %-----------------------------------------------------------------------------%
1818
19-:- type tl_err == turbolisp.string_stream.error.
19+:- type tl_err == turbo_s.string_stream.error.
2020
2121 %-----------------------------------------------------------------------------%
2222
--- a/turbolisp.m
+++ b/turbolisp.m
@@ -1,19 +1,17 @@
11 :- module turbolisp.
22 %=============================================================================%
3-% Main module for TurboLisp. Includes wrappers for the parser.
4-%
5-% This does NOT include the runtime (see tl_runtime), and instead operates
6-% simply as an S-expression parser.
3+% Main module for TurboLisp. Includes wrappers for the S-expression parser.
74 :- interface.
85 %=============================================================================%
96
107 :- use_module io.
118 :- import_module list.
9+:- use_module maybe.
1210
13-:- type element ---> atom(string) ; list(list.list(element)).
11+:- import_module turbo_s.
1412
1513 %-----------------------------------------------------------------------------%
16-
14+% Parses using the current text_input_stream
1715 :- pred parse(io.res(list.list(element)), io.io, io.io).
1816 :- mode parse(out, di, uo) is det.
1917
@@ -24,12 +22,12 @@
2422
2523 %-----------------------------------------------------------------------------%
2624
27-:- pred parse_string(string, io.res(list.list(element))).
25+:- pred parse_string(string, maybe.maybe_error(list.list(element))).
2826 :- mode parse_string(in, out) is det.
2927
3028 %-----------------------------------------------------------------------------%
3129 % parse_string_between(Str, Start, End, Result)
32-:- pred parse_string_between(string, int, int, io.res(list.list(element))).
30+:- pred parse_string_between(string, int, int, maybe.maybe_error(list.list(element))).
3331 :- mode parse_string_between(in, in, in, out) is det.
3432
3533 %=============================================================================%
@@ -38,15 +36,10 @@
3836
3937 :- use_module stream.
4038
41-:- include_module turbolisp.parser.
42-:- include_module turbolisp.string_stream.
43-
44-:- use_module turbolisp.parser.
45-:- use_module turbolisp.string_stream.
46-
47-%-----------------------------------------------------------------------------%
39+:- use_module turbo_s.parser.
40+:- use_module turbo_s.string_stream.
4841
49-:- type list == list.list(element).
42+:- include_module turbolisp.runtime.
5043
5144 %-----------------------------------------------------------------------------%
5245
@@ -58,70 +51,29 @@
5851
5952 %-----------------------------------------------------------------------------%
6053
61-parse(Result, !IO) :- io.input_stream(Stream, !IO), parse(Stream, Result, !IO).
62-
63-%-----------------------------------------------------------------------------%
64-
65-parse(Stream, Result, !IO) :- parse(Stream, [], Result, !IO).
54+parse(Result, !IO) :-
55+ io.input_stream(Stream, !IO),
56+ parse(Stream, Result, !IO).
6657
6758 %-----------------------------------------------------------------------------%
6859
69-:- func io_errors = turbolisp.parser.errors(io.error).
70-io_errors = turbolisp.parser.errors(
71- io.make_io_error("Unexpected EOF"),
72- io.make_io_error("Unmatched close paren")).
73-
74-%-----------------------------------------------------------------------------%
75-
76-:- func ss_errors = turbolisp.parser.errors(turbolisp.string_stream.error).
77-ss_errors = turbolisp.parser.errors(
78- turbolisp.string_stream.error("Unexpected EOF"),
79- turbolisp.string_stream.error("Unmatched close paren")).
60+parse(Stream, Result, !IO) :-
61+ turbo_s.parse(Stream, [], Result, !IO).
8062
8163 %-----------------------------------------------------------------------------%
8264
8365 parse(Stream, List, Result, !IO) :-
84- turbolisp.parser.parse(Stream, io_errors, ElementResult, !IO),
85- (
86- ElementResult = stream.ok(Element),
87- parse(Stream, [Element|List], Result, !IO)
88- ;
89- ElementResult = stream.eof,
90- Result = io.ok(list.reverse(List))
91- ;
92- ElementResult = stream.error(E),
93- Result = io.error(E)
94- ).
95-
96-%-----------------------------------------------------------------------------%
97-
98-:- pred parse_string_stream(string,
99- list.list(turbolisp.element),
100- turbolisp.string_stream.string_range,
101- io.res(list.list(element))).
102-:- mode parse_string_stream(in, in, di, out) is det.
103-
104-parse_string_stream(String, List, StringRangeIn, Result) :-
105- turbolisp.parser.parse(String, ss_errors, ElementResult, StringRangeIn, StringRangeOut),
106- (
107- ElementResult = stream.ok(Element),
108- parse_string_stream(String, [Element|List], StringRangeOut, Result)
109- ;
110- ElementResult = stream.eof,
111- Result = io.ok(list.reverse(List))
112- ;
113- ElementResult = stream.error(turbolisp.string_stream.error(E)),
114- Result = io.error(io.make_io_error(E))
115- ).
66+ turbo_s.parse(Stream, List, Result, !IO).
11667
11768 %-----------------------------------------------------------------------------%
11869
11970 parse_string(Str, Result) :-
120- parse_string_stream(Str, [], turbolisp.string_stream.init(Str), Result).
71+ turbo_s.parse_string_stream(Str, [], turbo_s.string_stream.init(Str), Result).
12172
12273 %-----------------------------------------------------------------------------%
12374
12475 parse_string_between(Str, Start, End, Result) :-
125- parse_string_stream(Str, [], turbolisp.string_stream.init(Str, Start, End), Result).
76+ Stream = turbo_s.string_stream.init(Str, Start, End),
77+ turbo_s.parse_string_stream(Str, [], Stream, Result).
12678
12779 %-----------------------------------------------------------------------------%
--- a/turbolisp.runtime.builtin.arithmetic.m
+++ b/turbolisp.runtime.builtin.arithmetic.m
@@ -1,7 +1,7 @@
11 :- module turbolisp.runtime.builtin.arithmetic.
22
33 %=============================================================================%
4-% Turbolisp implementation details for arithmetic builtins.
4+% TurboLisp implementation details for arithmetic builtins.
55 :- interface.
66 %=============================================================================%
77
--- a/turbolisp.runtime.builtin.comparison.m
+++ b/turbolisp.runtime.builtin.comparison.m
@@ -1,7 +1,7 @@
11 :- module turbolisp.runtime.builtin.comparison.
22
33 %=============================================================================%
4-% Turbolisp implementation details for comparison builtins.
4+% TurboLisp implementation details for comparison builtins.
55 :- interface.
66 %=============================================================================%
77
--- a/turbolisp.runtime.builtin.m
+++ b/turbolisp.runtime.builtin.m
@@ -1,7 +1,7 @@
11 :- module turbolisp.runtime.builtin.
22
33 %=============================================================================%
4-% Turbolisp builtins
4+% TurboLisp builtins
55 :- interface.
66 %=============================================================================%
77
--- a/turbolisp.runtime.m
+++ b/turbolisp.runtime.m
@@ -1,6 +1,7 @@
11 :- module turbolisp.runtime.
22
33 %=============================================================================%
4+% TurboLisp runtime components.
45 :- interface.
56 %=============================================================================%
67
@@ -10,12 +11,6 @@
1011 :- use_module maybe.
1112
1213 %-----------------------------------------------------------------------------%
13-
14-% TODO: Remove these
15-
16-:- type element ---> atom(string) ; list(list.list(element)).
17-
18-%-----------------------------------------------------------------------------%
1914 % TODO!
2015 :- func nil = element.
2116
@@ -631,7 +626,7 @@ reduce(Element, Result, !Runtime) :-
631626 turbolisp__runtime__builtin__define(Op), Tag)
632627 then
633628 (
634- Op = turbolisp.runtime.builtin.fn
629+ Op = turbolisp.runtime.builtin.fn,
635630 % Super rudimentary inline test.
636631 % Only inline fn if we have a body consisting of less than
637632 % 64 elements, and all the elements are either atoms or a