Skip to content

Commit

Permalink
Signed-off-by: Dmitry Ponyatov <dponyatov@gmail.com>
Browse files Browse the repository at this point in the history
  • Loading branch information
ponyatov committed Apr 21, 2019
2 parents 93fdbc5 + 50e2fab commit 1007a02
Show file tree
Hide file tree
Showing 123 changed files with 1,493 additions and 163 deletions.
1 change: 1 addition & 0 deletions Android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/build
/captures
.externalNativeBuild
app/src/main/java/io/github/ponyatov/metal/FORTH.java
35 changes: 35 additions & 0 deletions Android/FORTH.ragel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.ponyatov.metal;

//import java.text.ParseException;

%%{
machine lexer;

comment = ( "#" [^\n]* ) >{ts=p;} @{EMIT(new Comment(new String(data,ts,p)));} ;

main := (
comment
# | any @{EMIT(new Symbol(String.valueOf(data[p])));}
)*;
}%%

public class FORTH {

static void EMIT(Frame c) { MainActivity.tasklist.append(c.dump()); }

////////////////////////////////////////////////////////////////////////////////// .ragel generated

%% write data;

public static void parse(String cmd) /* throws ParseException */ {

char[] data = cmd.toCharArray();// parser requires sequence storage
int cs = lexer_start; // state machine current state
int p = 0; // current parsing position
int pe = data.length; // end of source text marker
int ts = 0; // Token Start pointer

%% write exec;
}

}
4 changes: 4 additions & 0 deletions Android/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SRC = app/src/main/java/
PKG = $(SRC)/io/github/ponyatov/metal
$(PKG)/FORTH.java: FORTH.ragel Makefile
ragel -J -o $@ $<
13 changes: 3 additions & 10 deletions Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// implementation 'com.google.firebase:firebase-core:16.0.8'
// implementation 'com.google.firebase:firebase-auth:16.2.0'
// implementation 'com.google.firebase:firebase-firestore:18.2.0'
// testImplementation 'junit:junit:4.12'
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

// required for: Firebase
apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.ponyatov.metal;

public class Comment extends Symbol {
final static String type = "comment";
public Comment(String V) { super(V); }
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.ponyatov.metal;

public class Container extends Frame {

public Container(String V) {
super(V);
type = "container";
}

final static String type = "container";
public Container(String V) { super(V); }
}
7 changes: 2 additions & 5 deletions Android/app/src/main/java/io/github/ponyatov/metal/Dict.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.github.ponyatov.metal;

public class Dict extends Container {

public Dict(String V) {
super(V);
type = "dict";
}
final static String type = "dict";
public Dict(String V) { super(V); }
}
23 changes: 19 additions & 4 deletions Android/app/src/main/java/io/github/ponyatov/metal/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
public class Frame {

/// type/class tag
String type;
final static String type = "frame";

/// object value (primitive implementation language type)
String value;

/// construct new frame/object with given name
public Frame(String V) {
type = "frame";
value = V;
}

/// dump in short form: header only
public String head() {
return "<" + type + ":" + value + ">";
public String head(String prefix) {
return prefix + "<" + type + ":" + value + ">";
}
public String head() { return head(""); }

public String dump(int depth, String prefix) {
String S = pad(depth) + head(prefix);
return S;
}
public String dump(int depth) { return dump(depth,""); }
public String dump() { return dump(0,""); }

String pad(int N) {
final String cr = "\n";
final String tab = "\t";
String S = cr;
for (int i=0;i<N;i++) S += tab;
return S;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class MainActivity extends AppCompatActivity {

/// task list text panel
TextView tasklist;
public static TextView tasklist;

/// command entry field
TextView pad;
public static TextView pad;

/// run command button
Button go;
Expand All @@ -38,10 +33,6 @@ private void msg(String what) {
alert.show();
}

/// Firebase interfacing
private FirebaseAuth fbAuth;
private FirebaseAuth.AuthStateListener fbAuthListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -70,27 +61,8 @@ public void onClick(View view) {
}
});

/// Firebase connection
fbAuth = FirebaseAuth.getInstance();
fbAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null)
msg("login:" + user.getUid());
else
msg("logout");
}
};

fbAuth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull com.google.android.gms.tasks.Task<AuthResult> task) {
if (task.isSuccessful()) msg("ok");
if (task.isComplete()) msg("complete");
}
});

FORTH.parse("# put your commands here \n"
+" 1 2.3 4e-5 0xDeadBeef 0b1101");
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions Android/app/src/main/java/io/github/ponyatov/metal/Stack.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.github.ponyatov.metal;

public class Stack extends Container {

public Stack(String V) {
super(V);
type = "stack";
}
final static String type = "stack";
public Stack(String V) { super(V); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.ponyatov.metal;

public class Symbol extends Frame {
final static String type = "symbol";
public Symbol(String V) { super(V); }
}
8 changes: 2 additions & 6 deletions Android/app/src/main/java/io/github/ponyatov/metal/Task.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.ponyatov.metal;

public class Task extends Frame {

public Task(String V) {
super(V);
type = "task";
}

final static String type = "task";
public Task(String V) { super(V); }
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.ponyatov.metal;

public class TaskList extends Vector {

public TaskList(String V) {
super(V);
type = "tasklist";
}

final static String type = "tasklist";
public TaskList(String V) { super(V); }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.github.ponyatov.metal;

public class Vector extends Container {

public Vector(String V) {
super(V);
type = "vector";
}
final static String type = "vector";
public Vector(String V) { super(V); }
}
Binary file removed Android/app/src/main/res/mipmap-xxxhdpi/add_circle.png
Binary file not shown.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ TODAY = $(shell date +%d%m%y)

all:
$(MAKE) -C book
$(MAKE) -C Android
$(MAKE) -C game

pdf: $(MODULE)_$(TODAY).pdf
$(MODULE)_$(TODAY).pdf: book/$(MODULE).pdf
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# metaL
## homoiconic programming language bootstrap in Python
## homoiconic metaprogramming language bootstrap in Python

(c) Dmitry Ponyatov <<dponyatov@gmail.com>> CC BY-NC-ND

Expand Down
26 changes: 24 additions & 2 deletions book/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ TEX += intro/intro.tex intro/denial.tex intro/meta.tex
TEX += intro/brooks.tex intro/lop.tex intro/homoiconic.tex

TEX += first/steps.tex first/eds.tex first/whitebox.tex first/install.tex
TEX += first/run.tex first/minsky.tex first/forth.tex first/concept.tex

TEX += frames/frames.tex frames/frame.tex frames/dump.tex
TEX += frames/prim.tex frames/string.tex frames/symbol.tex frames/number.tex
TEX += frames/container.tex frames/stack.tex frames/dict.tex
TEX += frames/active.tex

TEX += forth/forth.tex forth/dict.tex forth/ply.tex forth/repl.tex
TEX += forth/cmdline.tex
Expand All @@ -32,11 +34,18 @@ TEX += cpp/cpp.tex cpp/gc.tex
TEX += prolog/prolog.tex

TEX += syntax/syntax.tex syntax/ragel/ragel.tex syntax/ragel/java.tex
LST += syntax/ragel/java??.*
TEX += syntax/ply/ply.tex
LST += syntax/ply/lex.py syntax/ply/yacc.py

TEX += meta/circ.tex
LST += meta/ebldfiles.ini meta/eclfiles.ini meta/files.ini
LST += meta/header.ini meta/vimfiles.ini

TEX += meta/ouro/boros.tex meta/ouro/files.tex meta/ouro/info.tex
FIG += meta/ouro/boros.png
LST += meta/ouro/info.ml

TEX += mcu/mcu.tex mcu/ardu/ino.tex mcu/msp/msp.tex
TEX += mcu/arm/cortex.tex mcu/arm/setup.tex

Expand All @@ -54,16 +63,29 @@ TEX += code/in.tex code/emcin.tex code/cpp.tex code/ide.tex code/literate.tex
TEX += concept/concept.tex

TEX += gui/wx.tex
LST += gui/wx00.py gui/wx01.py gui/wx02.py
LST += gui/wx03.py gui/wx04.py gui/wx05.py gui/wx06.py
LST += gui/wx07.py gui/wx08.py gui/wx09.py gui/wx10.py
LST += gui/wx11.py gui/wx12.py gui/wx13.py gui/wx14.py
LST += gui/wx15.py gui/wx16.py gui/wx17.py gui/wx18.py
FIG += gui/wx00.png gui/wx01.png gui/wx02.png

TEX += os/os.tex os/boot.tex os/sched.tex os/files.tex
TEX += os/net.tex os/user.tex os/gui.tex

TEX += game/dev.tex
TEX += game/dev.tex game/cross.tex game/boot.tex game/video.tex
LST += game/cross0.mk game/boot00.mk game/boot00.objdump
TEX += game/debug.tex
LST += game/debug0.mk game/debug1.mk
FIG += game/debug1A.png game/debug1B.png game/debug1C.png /tmp/debug.pdf

FIG += mcu/ardu/micro.png mcu/ardu/uno.jpg mcu/ardu/nano.jpg

TEX += android/android.tex

TEX += py/py.tex
LST += py/hello*.py

TEX += docu/ment.tex

TEX += bib/bib.tex
Expand All @@ -79,5 +101,5 @@ LATEX = pdflatex -halt-on-error
metaL.pdf: $(TEX) $(LST) $(FIG)
$(LATEX) $< && $(LATEX) $<

/tmp/gnugcc.pdf: mcu/gnugcc.dot
/tmp/%.pdf: mcu/%.dot
dot -T pdf -o /tmp/crop.pdf $< && pdfcrop /tmp/crop.pdf $@
Binary file added book/bib/baranov.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions book/bib/bib.tex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@
И.В.Романовского.\\
\url{http://www.nncron.ru/download/sf.pdf}

\clearpage
\bibitem{thinking}\ \bibfig{bib/thinking.jpg}\\
\textbf{Способ мышления\ --- ФОРТ}\\
Лео Броуди \\
\href{http://www.forth.org.ru/~cactus/files/brodie.rar}{OCR/перевод}\\
\url{http://thinking-forth.sourceforge.net/}

\clearpage
\bibitem{kelly}\ \bibfig{bib/kelly.jpg}\\
\textbf{Язык программирования ФОРТ}\\
М.Келли, Н.Спайс\\
Москва, ``Радио и связь'', 1993\\
\href{http://www.forth.org.ru/~cactus/files/kelly.rar}{OCR/перевод}

\clearpage
\bibitem{baranov}\ \bibfig{bib/baranov.png}\\
\textbf{Язык Форт и его реализации}\\
С.Н. Баранов, Н.Р. Ноздрунов\\
``Машиностроение" Ленинградское отделение, 1988\\
\href{http://www.forth.org.ru/~cactus/files/baranov2.rar}{OCR/перевод}

\clearpage
\bibitem{threaded}\ \bibfig{bib/threaded.jpg}\\
\textbf{Threaded Interpretive Languages: Their Design and Implementation}\\
R. G. Loeliger\\
\href{http://sinclairql.speccy.org/archivo/docs/books/Threaded_interpretive_languages.pdf}{PDF}

\clearpage
\bibitem{wikicc}\ \bibfig{bib/wikicc.png}\\
\textbf{Book: Compiler Construction}\\
Expand Down
Binary file added book/bib/kelly.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added book/bib/thinking.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added book/bib/threaded.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1007a02

Please sign in to comment.