-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
flyingalex
committed
Feb 23, 2020
1 parent
7775c18
commit bef5cd4
Showing
21 changed files
with
208 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2020.2.23 <Copyright hulin> | ||
|
||
#include <string> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#include "./LoxClass.hpp" | ||
#include "./LoxInstance.hpp" | ||
#include "./Interpreter.hpp" | ||
#include "./Token.hpp" | ||
|
||
using std::string; | ||
using std::shared_ptr; | ||
using std::vector; | ||
|
||
|
||
LoxClass::LoxClass(string name_): name(name_) {} | ||
|
||
Object LoxClass::call( | ||
shared_ptr<Interpreter> interpreter, | ||
vector<Object> arguments) { | ||
auto instance = shared_ptr<LoxInstance>(new LoxInstance(*this)); | ||
return Object::make_instance_obj(instance); | ||
} | ||
|
||
int LoxClass::arity() { | ||
return 0; | ||
} | ||
string LoxClass::toString() { | ||
return name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2020.2.23 <Copyright hulin> | ||
|
||
#ifndef LOXCLASS_HPP_ | ||
#define LOXCLASS_HPP_ | ||
|
||
#include <string> | ||
#include <memory> | ||
#include <vector> | ||
#include "./LoxCallable.hpp" | ||
#include "./Interpreter.hpp" | ||
#include "./Token.hpp" | ||
|
||
using std::string; | ||
using std::shared_ptr; | ||
using std::vector; | ||
|
||
class LoxClass: public LoxCallable { | ||
public: | ||
string name; | ||
explicit LoxClass(string name_); | ||
Object call( | ||
shared_ptr<Interpreter> interpreter, | ||
vector<Object> arguments); | ||
int arity(); | ||
string toString(); | ||
}; | ||
|
||
#endif // LOXCLASS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2020.2.23 <Copyright hulin> | ||
|
||
#include <string> | ||
|
||
#include "./LoxInstance.hpp" | ||
#include "./LoxClass.hpp" | ||
|
||
using std::string; | ||
|
||
LoxInstance::LoxInstance(LoxClass klass_): klass(klass_) {} | ||
|
||
string LoxInstance::toString() { | ||
return klass.name + " instance"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2020.2.23 <Copyright hulin> | ||
|
||
#ifndef LOXINSTANCE_HPP_ | ||
#define LOXINSTANCE_HPP_ | ||
|
||
#include <string> | ||
#include "./LoxClass.hpp" | ||
|
||
using std::string; | ||
|
||
class LoxInstance { | ||
public: | ||
LoxClass klass; | ||
explicit LoxInstance(LoxClass klass_); | ||
string toString(); | ||
}; | ||
|
||
#endif // LOXINSTANCE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
CXXFLAGS=-g -std=c++11 -Wall -pedantic | ||
CXX = g++ | ||
|
||
all: main test demo | ||
all: main | ||
|
||
LoxInstance.o: LoxInstance.cpp LoxInstance.hpp | ||
LoxClass.o: LoxClass.cpp LoxClass.hpp | ||
Resolver.o: Resolver.cpp Resolver.hpp | ||
Token.o: Token.cpp Token.hpp | ||
LoxFunction.o: LoxFunction.cpp LoxFunction.hpp | ||
Environment.o: Environment.cpp Environment.hpp | ||
Interpreter.o: Interpreter.cpp Interpreter.hpp Environment.o LoxFunction.o | ||
lox.o: lox.cpp lox.hpp Interpreter.o Resolver.o | ||
Interpreter.o: Interpreter.cpp Interpreter.hpp | ||
lox.o: lox.cpp lox.hpp | ||
Parser.o: Parser.cpp Parser.hpp | ||
Scanner.o: Scanner.cpp Scanner.hpp | ||
AstPrinter.o: AstPrinter.hpp AstPrinter.cpp | ||
|
||
main: main.cpp lox.o LoxFunction.o Token.o Scanner.o Parser.o Interpreter.o Environment.o Resolver.o | ||
test: test.cpp AstPrinter.o Token.o | ||
demo: demo.cpp | ||
main: main.cpp lox.o LoxFunction.o Token.o Scanner.o Parser.o Interpreter.o Environment.o Resolver.o LoxClass.o LoxInstance.o | ||
|
||
clean: | ||
rm -f *.o main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.