Skip to content

Commit

Permalink
version 10.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ab25cq committed Apr 27, 2019
1 parent 044415a commit ae89cda
Show file tree
Hide file tree
Showing 37 changed files with 326 additions and 2,185 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

version 10.4.1

Continue to implement C-FFI on JIT.

version 10.4.0

Continue to implement C-FFI on JIT.
Expand Down
199 changes: 199 additions & 0 deletions CLang.clcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
class CLangVariable
{
var name:String;
var type:String;

def initialize(name:String, type:String) {
self.name = name.clone();
self.type = type.clone();
}

def clone():CLangVariable {
result := CLangVariable(self.name, self.type);

return result;
}
def compare(right:CLangVariable): int {
return self.name.compare(right.name);
}
def equals(right:CLangVariable): bool {
return self.name.equals(right.name) && self.type.equals(right.type);
}
}

class CLangFunc {
var type:String;
var name:String;
var params:SortableList<CLangVariable>;

def initialize(type:String, name:String, params:SortableList<CLangVariable>)
{
self.type = type.clone();
self.name = name.clone();
self.params = params.clone();
}

def clone():CLangFunc {
result := CLangFunc(self.type, self.name, self.params);

return result;
}
def compare(right:CLangFunc): int {
return self.name.compare(right.name);
}
def equals(right:CLangFunc): bool {
return self.name.equals(right.name) && self.type.equals(right.type) && self.params.equals(right.params);
}
}

class CLang
{
var p:Buffer;
var source:Buffer;

var funcs:SortableList<CLangFunc>;

def initialize(source:Buffer) {
self.p = source;
self.source = source;

self.funcs = SortableList<CLangFunc>();
}

def skipLFAndSpaces() {
while(p->byte == ' ' || p->byte == '\t' || p->byte == '\n')
{
p++;
}
}

def getWord():String {
buf := "";
while(p->byte != '\0') {
if(isalnum(p->byte.to_char) || p->byte == '_')
{
buf.append(p->byte.to_char);
p++;
}
else {
break;
}
}
skipLFAndSpaces();

return buf;

}
def parseParams():SortableList<CLangVariable> {
result := SortableList<CLangVariable>();

while(p->byte != '\0') {
type := getWord();
name := getWord();

variable := CLangVariable(name, type);

result.push(variable);

if(p->byte == ',') {
p++;
skipLFAndSpaces();
}
elif(p->byte == ')') {
p++;
skipLFAndSpaces();
break;
}
else {
throw Exception("Require , or )");
}
}

return result;
}

def parseHeader() {
skipLFAndSpaces();

while(p->byte != '\0') {
buf := getWord();

if(buf.equals("struct")) {
}
elif(buf.equals("typedef")) {
}
elif(buf.equals("extern")) {
buf2 := getWord();
buf3 := getWord();

if(p->byte == '(') {
p++;
skipLFAndSpaces();

type := buf2;
name := buf3;

params := parseParams();

if(p->byte == ';') {
p++;
skipLFAndSpaces();
}

fun := CLangFunc(type, name, params);
funcs.push(fun);
}
}
### Function ###
else {
buf2 := getWord();

if(p->byte == '(') {
p++;
skipLFAndSpaces();

type := buf;
name := buf2;

params := parseParams();

if(p->byte == ';') {
p++;
skipLFAndSpaces();
}
fun := CLangFunc(type, name, params);

funcs.push(fun);
}
}
}
}
def include(fname:String): static CLang {
source := fname.toPath().read();
source.append('\0');

result := CLang(source);
result.parseHeader();
return result;
}

def pasteHeader():String {
result := "";
for(it in funcs) {
params := "";
i := 0;
for(it2 in it.params) {
params.append("\{it2.type} \{it2.name}");

if(i != it.params.length()-1) {
params.append(", ");
}

i++;
}
result.append("def \{it.name}(\{params}):\{it.type};\n");
}

return result;
}
}
26 changes: 24 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ NODEJS=@NODEJS@
##########################################################
# main
##########################################################
all: cclover2 clover2 tyclover2 $(INTERPRETER) SortableArray.oclcl String.ojsclcl libclover2.so.1.0.0 jit-compile
all: cclover2 clover2 tyclover2 $(INTERPRETER) SortableArray.oclcl String.ojsclcl CLang.oclcl libclover2.so.1.0.0 jit-compile
# if which ctags > /dev/null; then if test $(OS) = DARWIN; then ctags src/*.c > /dev/null 2>&1; else ctags -R; fi; fi

cclover2: config.h src/compiler.o $(COMMON_OBJS) $(COMPILER_OBJS) $(OBJS) $(JIT_OBJS) $(JIT_RUNTIME_OBJS)
Expand Down Expand Up @@ -110,6 +110,9 @@ String.ojsclcl: JS.jsclcl
PWD=`pwd`; ./cclover2 -core Float64Array.ojsclcl
PWD=`pwd`; ./cclover2 -core DataView.ojsclcl

CLang.oclcl: CLang.clcl
PWD=`pwd`; ./cclover2 CLang.clcl

libclover2.so.1.0.0: $(COMMON_OBJ) $(COMPILER_OBJS) $(OBJS) $(JIT_RUNTIME_OBJS) $(JIT_SCRIPT_RUNTIME_OBJS) $(JIT_MAIN_OBJ)
$(CC) -shared -o libclover2.so.1.0.0 $(JIT_SCRIPT_RUNTIME_OBJS) $(CFLAGS) $(LIBS)
ln -s -f libclover2.so.1.0.0 libclover2.so.1
Expand All @@ -123,7 +126,7 @@ $(OBJ): src/*.h Makefile configure
#########################################################
# JIT compile
#########################################################
jit-compile: Clover.so PcreOVec.so System.so Global.so Buffer.so Exception.so Byte.so UByte.so Short.so UShort.so Integer.so UInteger.so Long.so ULong.so Float.so Double.so Pointer.so Char.so Bool.so Array.so EqualableArray.so SortableArray.so HashItem.so Hash.so ListItem.so List.so EqualableList.so SortableList.so Tuple1.so Tuple2.so Tuple3.so Tuple4.so Tuple5.so Tuple6.so Tuple7.so Tuple8.so Tuple9.so Tuple10.so Path.so Directory.so termios.so Job.so Command.so String.so File.so Class.so Field.so Method.so MethodParam.so Mutex.so Null.so Range.so Thread.so fd_set.so getopt_long_option.so timespec.so timeval.so tm.so hostent.so in_addr.so pthread_cond_t.so pthread_mutex_t.so servent.so sockaddr_in.so sockaddr_un.so stat.so
jit-compile: Clover.so PcreOVec.so System.so Global.so Buffer.so Exception.so Byte.so UByte.so Short.so UShort.so Integer.so UInteger.so Long.so ULong.so Float.so Double.so Pointer.so Char.so Bool.so Array.so EqualableArray.so SortableArray.so HashItem.so Hash.so ListItem.so List.so EqualableList.so SortableList.so Tuple1.so Tuple2.so Tuple3.so Tuple4.so Tuple5.so Tuple6.so Tuple7.so Tuple8.so Tuple9.so Tuple10.so Path.so Directory.so termios.so Job.so Command.so String.so File.so Class.so Field.so Method.so MethodParam.so Mutex.so Null.so Range.so Thread.so fd_set.so getopt_long_option.so timespec.so timeval.so tm.so hostent.so in_addr.so pthread_cond_t.so pthread_mutex_t.so servent.so sockaddr_in.so sockaddr_un.so stat.so CLang.so CLangVariable.so CLangFunc.so

Clover.so: Clover.oclcl
if test $(JIT) = 1; then ./bclover2 -core Clover; fi
Expand Down Expand Up @@ -329,6 +332,16 @@ timeval.so: timeval.oclcl
Null.so: Null.oclcl
if test $(JIT) = 1; then ./bclover2 -core Null; fi

CLang.so: CLang.oclcl
if test $(JIT) = 1; then ./bclover2 -core CLang; fi

CLangVariable.so: CLangVariable.oclcl
if test $(JIT) = 1; then ./bclover2 -core CLangVariable; fi

CLangFunc.so: CLangFunc.oclcl
if test $(JIT) = 1; then ./bclover2 -core CLangFunc; fi


#########################################################
# install
#########################################################
Expand Down Expand Up @@ -557,6 +570,15 @@ install:
if test -e C.oclcl; then $(INSTALL) -m 644 ./C.oclcl $(DESTDIR)/share/clover2; fi
if test -e [email protected]; then $(INSTALL) -m 644 ./[email protected] $(DESTDIR)/share/clover2; fi

if test -e CLangVariable.oclcl; then $(INSTALL) -m 644 ./CLangVariable.oclcl $(DESTDIR)/share/clover2; fi
if test -e CLangVariable.so; then $(INSTALL) -m 755 ./CLangVariable.so.1.0.0 $(DESTDIR)/share/clover2; cp -a ./CLangVariable.so $(DESTDIR)/share/clover2; fi

if test -e CLangFunc.oclcl; then $(INSTALL) -m 644 ./CLangFunc.oclcl $(DESTDIR)/share/clover2; fi
if test -e CLangFunc.so; then $(INSTALL) -m 755 ./CLangFunc.so.1.0.0 $(DESTDIR)/share/clover2; cp -a ./CLangFunc.so $(DESTDIR)/share/clover2; fi

if test -e CLang.oclcl; then $(INSTALL) -m 644 ./CLang.oclcl $(DESTDIR)/share/clover2; fi
if test -e CLang.so; then $(INSTALL) -m 755 ./CLang.so.1.0.0 $(DESTDIR)/share/clover2; cp -a ./CLang.so $(DESTDIR)/share/clover2; fi

$(INSTALL) -m 644 ./Object.oclcl $(DESTDIR)/share/clover2
$(INSTALL) -m 644 ./IEqualable.oclcl $(DESTDIR)/share/clover2
$(INSTALL) -m 644 ./IHashKey.oclcl $(DESTDIR)/share/clover2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clover2 computer language

version 10.4.0
version 10.4.1

サポートしている機能

Expand Down
32 changes: 2 additions & 30 deletions a.cl
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@

initscr();
def_prog_mode();
start_color();
init_pair(1, COLOR_BLUE, COLOR_BLACK);
clear();
attron(COLOR_PAIR(1));
addstr("ABC");
addstr("あいう");
attroff(COLOR_PAIR(1));
refresh();
getch();

clear();
box(stdscr, '|', '-');
refresh();

getch();

clear();
border('|', '|', '+', '+', '|', '|', '+', '+');
refresh();

getch();

beep();

getch();

endwin();
header := CLang.include("code/CStruct.h")
header.pasteHeader().println();
20 changes: 13 additions & 7 deletions a.clcl
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
class ClassB {
params:List<Integer>;

def initialize() {
params = list { 1, 2, 3 };
}
}


class ClassA
{
def method():static {
a:long = 0x02;
def main():static {
b := ClassB();

if((a & 0x02).to_bool) {
println("TRUE");
}
else {
println("FALSE");
for(it in b.params) {
it.toString().println();
}
}
}
1 change: 0 additions & 1 deletion a.sh

This file was deleted.

Binary file removed b
Binary file not shown.
Binary file removed c
Binary file not shown.
12 changes: 0 additions & 12 deletions c.c

This file was deleted.

6 changes: 5 additions & 1 deletion code/CStruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ void fun(struct CStruct data)

void fun2(char data[5])
{
printf("fun2 data %p\n", data);
printf("HELLO array %c %c %c\n", data[0], data[1], data[4]);
}

void fun3(int a, int b)
{
printf("fun3 %d\n", a + b);
}
1 change: 1 addition & 0 deletions code/CStruct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern void fun3(int a, int b);
Loading

0 comments on commit ae89cda

Please sign in to comment.